Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
584899a
performed the interface changes
RajeevRanjan27 Nov 27, 2024
7208234
modified the router
RajeevRanjan27 Nov 29, 2024
38b25fa
Merge branch 'develop' into feat-build-infra
RajeevRanjan27 Dec 2, 2024
b5ddd9c
added migration script
RajeevRanjan27 Dec 2, 2024
6ff60d3
added struct
RajeevRanjan27 Dec 2, 2024
3ee79d1
Merge branch 'develop' into feat-build-infra
RajeevRanjan27 Dec 15, 2024
84ba94a
done basic refactoing
RajeevRanjan27 Dec 15, 2024
25146e1
refactored a bit before sync in the ent feat branch
RajeevRanjan27 Dec 15, 2024
d0ef657
modified the script
RajeevRanjan27 Dec 15, 2024
cb2e733
modified script
RajeevRanjan27 Dec 15, 2024
cc910da
create update for new dashboard and old both done
RajeevRanjan27 Dec 15, 2024
95f9e72
resolved the comments
RajeevRanjan27 Dec 16, 2024
635642e
added log in hte loadDefault profile
RajeevRanjan27 Dec 16, 2024
77597f6
took merge from develop
RajeevRanjan27 Dec 16, 2024
f77f2ca
refactored and moved the constants to the bean
RajeevRanjan27 Dec 16, 2024
8e311a1
refactored teh bean
RajeevRanjan27 Dec 17, 2024
6d020ee
refactored the adapter
RajeevRanjan27 Dec 17, 2024
a8dde6e
renamed the script fiels
RajeevRanjan27 Dec 17, 2024
200eb94
Merge branch 'develop' into feat-build-infra
RajeevRanjan27 Dec 17, 2024
bbb6563
refactored the function
RajeevRanjan27 Dec 18, 2024
7c62602
Merge branch 'develop' into feat-build-infra
RajeevRanjan27 Dec 19, 2024
e187b47
merged from oss develop
RajeevRanjan27 Dec 23, 2024
ead2339
changed the default platform to runner
RajeevRanjan27 Dec 23, 2024
794199d
added script for description char limit to 350
RajeevRanjan27 Dec 24, 2024
68d445a
Merge branch 'develop' into feat-build-infra
RajeevRanjan27 Dec 26, 2024
4c81bc9
synced from develop
RajeevRanjan27 Dec 26, 2024
c8e94ef
updated script file names
RajeevRanjan27 Dec 26, 2024
437abc9
Merge branch 'develop' into feat-build-infra
RajeevRanjan27 Dec 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ import (
"github.com/devtron-labs/devtron/pkg/generateManifest"
"github.com/devtron-labs/devtron/pkg/gitops"
"github.com/devtron-labs/devtron/pkg/imageDigestPolicy"
infraConfigService "github.com/devtron-labs/devtron/pkg/infraConfig"
repository11 "github.com/devtron-labs/devtron/pkg/infraConfig/repository"
infraConfigService "github.com/devtron-labs/devtron/pkg/infraConfig/service"
"github.com/devtron-labs/devtron/pkg/infraConfig/units"
"github.com/devtron-labs/devtron/pkg/kubernetesResourceAuditLogs"
repository7 "github.com/devtron-labs/devtron/pkg/kubernetesResourceAuditLogs/repository"
Expand Down Expand Up @@ -275,8 +276,8 @@ func InitializeApp() (*App, error) {
wire.Bind(new(dashboardEvent.DashboardTelemetryRouter),
new(*dashboardEvent.DashboardTelemetryRouterImpl)),

infraConfigService.NewInfraProfileRepositoryImpl,
wire.Bind(new(infraConfigService.InfraConfigRepository), new(*infraConfigService.InfraConfigRepositoryImpl)),
repository11.NewInfraProfileRepositoryImpl,
wire.Bind(new(repository11.InfraConfigRepository), new(*repository11.InfraConfigRepositoryImpl)),

units.NewUnits,
infraConfigService.NewInfraConfigServiceImpl,
Expand Down
80 changes: 49 additions & 31 deletions api/infraConfig/restHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import (
"github.com/devtron-labs/devtron/api/restHandler/common"
"github.com/devtron-labs/devtron/pkg/auth/authorisation/casbin"
"github.com/devtron-labs/devtron/pkg/auth/user"
"github.com/devtron-labs/devtron/pkg/infraConfig"
"github.com/devtron-labs/devtron/pkg/infraConfig/adapter"
"github.com/devtron-labs/devtron/pkg/infraConfig/bean"
"github.com/devtron-labs/devtron/pkg/infraConfig/util"
"github.com/devtron-labs/devtron/pkg/infraConfig/constants"
"github.com/devtron-labs/devtron/pkg/infraConfig/service"
"github.com/devtron-labs/devtron/util/rbac"
"github.com/gorilla/mux"
"github.com/pkg/errors"
Expand All @@ -46,14 +46,14 @@ type InfraConfigRestHandler interface {
}
type InfraConfigRestHandlerImpl struct {
logger *zap.SugaredLogger
infraProfileService infraConfig.InfraConfigService
infraProfileService service.InfraConfigService
userService user.UserService
enforcer casbin.Enforcer
enforcerUtil rbac.EnforcerUtil
validator *validator.Validate
}

func NewInfraConfigRestHandlerImpl(logger *zap.SugaredLogger, infraProfileService infraConfig.InfraConfigService, userService user.UserService, enforcer casbin.Enforcer, enforcerUtil rbac.EnforcerUtil, validator *validator.Validate) *InfraConfigRestHandlerImpl {
func NewInfraConfigRestHandlerImpl(logger *zap.SugaredLogger, infraProfileService service.InfraConfigService, userService user.UserService, enforcer casbin.Enforcer, enforcerUtil rbac.EnforcerUtil, validator *validator.Validate) *InfraConfigRestHandlerImpl {
return &InfraConfigRestHandlerImpl{
logger: logger,
infraProfileService: infraProfileService,
Expand All @@ -76,33 +76,37 @@ func (handler *InfraConfigRestHandlerImpl) UpdateInfraProfile(w http.ResponseWri
return
}

vars := mux.Vars(r)
profileName := strings.ToLower(vars["name"])
if profileName == "" {
common.WriteJsonResp(w, errors.New(util.InvalidProfileName), nil, http.StatusBadRequest)
//vars := mux.Vars(r)
val := r.URL.Query().Get("name")
if len(val) == 0 {
common.WriteJsonResp(w, errors.New(constants.InvalidProfileName), nil, http.StatusBadRequest)
return
}
payload := &bean.ProfileBean{}
profileName := strings.ToLower(val)

payload := &bean.ProfileBeanDto{}
decoder := json.NewDecoder(r.Body)
err = decoder.Decode(payload)
if err != nil {
handler.logger.Errorw("error in decoding the request payload", "err", err, "requestBody", r.Body)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
//handler.validator.RegisterValidation("validateValue", ValidateValue)
payload.Name = strings.ToLower(payload.Name)
err = handler.validator.Struct(payload)
if err != nil {
err = errors.Wrap(err, util.PayloadValidationError)
err = errors.Wrap(err, constants.PayloadValidationError)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
}
if profileName == "" || (profileName == util.DEFAULT_PROFILE_NAME && payload.Name != util.DEFAULT_PROFILE_NAME) {
common.WriteJsonResp(w, errors.New(util.InvalidProfileName), nil, http.StatusBadRequest)

if profileName == "" || (profileName == constants.GLOBAL_PROFILE_NAME && payload.Name != constants.GLOBAL_PROFILE_NAME) {
common.WriteJsonResp(w, errors.New(constants.InvalidProfileName), nil, http.StatusBadRequest)
}
err = handler.infraProfileService.UpdateProfile(userId, profileName, payload)
if err != nil {
handler.logger.Errorw("error in updating profile and configurations", "profileName", profileName, "payLoad", payload, "err", err)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
common.WriteJsonResp(w, nil, nil, http.StatusOK)
Expand All @@ -120,22 +124,25 @@ func (handler *InfraConfigRestHandlerImpl) GetProfile(w http.ResponseWriter, r *
return
}

vars := mux.Vars(r)
profileName := strings.ToLower(vars["name"])
if profileName == "" {
common.WriteJsonResp(w, errors.New(util.InvalidProfileName), nil, http.StatusBadRequest)
identifier := r.URL.Query().Get("name")

if len(identifier) == 0 {
common.WriteJsonResp(w, errors.New(constants.InvalidProfileName), nil, http.StatusBadRequest)
return
}
profileName := strings.ToLower(identifier)
var profile *bean.ProfileBeanDto
if profileName != constants.GLOBAL_PROFILE_NAME {
common.WriteJsonResp(w, errors.New(constants.InvalidProfileName), nil, http.StatusBadRequest)
return
}

var profile *bean.ProfileBean
defaultProfile, err := handler.infraProfileService.GetProfileByName(profileName)
if err != nil {
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
if profileName == util.DEFAULT_PROFILE_NAME {
profile = defaultProfile
}
profile = defaultProfile

resp := bean.ProfileResponse{
Profile: *profile,
}
Expand All @@ -161,7 +168,7 @@ func (handler *InfraConfigRestHandlerImpl) UpdateInfraProfileV0(w http.ResponseW
vars := mux.Vars(r)
profileName := strings.ToLower(vars["name"])
if profileName == "" {
common.WriteJsonResp(w, errors.New(util.InvalidProfileName), nil, http.StatusBadRequest)
common.WriteJsonResp(w, errors.New(constants.InvalidProfileName), nil, http.StatusBadRequest)
return
}
payload := &bean.ProfileBeanV0{}
Expand All @@ -175,12 +182,19 @@ func (handler *InfraConfigRestHandlerImpl) UpdateInfraProfileV0(w http.ResponseW
payload.Name = strings.ToLower(payload.Name)
err = handler.validator.Struct(payload)
if err != nil {
err = errors.Wrap(err, util.PayloadValidationError)
err = errors.Wrap(err, constants.PayloadValidationError)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
}
if profileName == "" || (profileName == util.DEFAULT_PROFILE_NAME && payload.Name != util.DEFAULT_PROFILE_NAME) {
common.WriteJsonResp(w, errors.New(util.InvalidProfileName), nil, http.StatusBadRequest)
if profileName != constants.DEFAULT_PROFILE_NAME || payload.Name != constants.DEFAULT_PROFILE_NAME {
common.WriteJsonResp(w, errors.New(constants.InvalidProfileName), nil, http.StatusBadRequest)
return
}
if payload.Name != constants.DEFAULT_PROFILE_NAME {
common.WriteJsonResp(w, errors.New(constants.InvalidProfileName), nil, http.StatusBadRequest)
return
}
profileName = constants.GLOBAL_PROFILE_NAME

payloadV1 := adapter.GetV1ProfileBean(payload)
err = handler.infraProfileService.UpdateProfile(userId, profileName, payloadV1)
if err != nil {
Expand All @@ -207,25 +221,29 @@ func (handler *InfraConfigRestHandlerImpl) GetProfileV0(w http.ResponseWriter, r
vars := mux.Vars(r)
profileName := strings.ToLower(vars["name"])
if profileName == "" {
common.WriteJsonResp(w, errors.New(util.InvalidProfileName), nil, http.StatusBadRequest)
common.WriteJsonResp(w, errors.New(constants.InvalidProfileName), nil, http.StatusBadRequest)
return
}

if profileName != constants.DEFAULT_PROFILE_NAME {
common.WriteJsonResp(w, errors.New(constants.InvalidProfileName), nil, http.StatusBadRequest)
return
}

profileName = constants.GLOBAL_PROFILE_NAME

var profile *bean.ProfileBeanV0
defaultProfileV1, err := handler.infraProfileService.GetProfileByName(profileName)
defaultProfileV0 := adapter.GetV0ProfileBean(defaultProfileV1)
if err != nil {
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
if profileName == util.DEFAULT_PROFILE_NAME {
profile = defaultProfileV0
}
profile = defaultProfileV0
resp := bean.ProfileResponseV0{
Profile: *profile,
}
resp.ConfigurationUnits = handler.infraProfileService.GetConfigurationUnits()
//TODO: why below line ??
resp.DefaultConfigurations = defaultProfileV0.Configurations
common.WriteJsonResp(w, nil, resp, http.StatusOK)
}
18 changes: 10 additions & 8 deletions api/infraConfig/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,21 @@ func NewInfraProfileRouterImpl(infraConfigRestHandler InfraConfigRestHandler) *I
}

func (impl *InfraConfigRouterImpl) InitInfraConfigRouter(configRouter *mux.Router) {
configRouter.Path("/profile/{name}").
HandlerFunc(impl.infraConfigRestHandler.GetProfileV0).
configRouter.Path("/profile/alpha1").
Queries("name", "{name}").
HandlerFunc(impl.infraConfigRestHandler.GetProfile).
Methods("GET")

configRouter.Path("/profile/{name}").
HandlerFunc(impl.infraConfigRestHandler.UpdateInfraProfileV0).
configRouter.Path("/profile/alpha1").
Queries("name", "{name}").
HandlerFunc(impl.infraConfigRestHandler.UpdateInfraProfile).
Methods("PUT")

configRouter.Path("/v1/profile/{name}").
HandlerFunc(impl.infraConfigRestHandler.GetProfile).
configRouter.Path("/profile/{name}").
HandlerFunc(impl.infraConfigRestHandler.GetProfileV0).
Methods("GET")

configRouter.Path("/v1/profile/{name}").
HandlerFunc(impl.infraConfigRestHandler.UpdateInfraProfile).
configRouter.Path("/profile/{name}").
HandlerFunc(impl.infraConfigRestHandler.UpdateInfraProfileV0).
Methods("PUT")
}
2 changes: 1 addition & 1 deletion cmd/external-app/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading