Skip to content

Commit a72f269

Browse files
Merge pull request #6248 from devtron-labs/release-candidate-v0.26.0
sync: Release candidate v0.26.0
2 parents d13188c + 23b9560 commit a72f269

File tree

72 files changed

+2508
-947
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+2508
-947
lines changed

Wire.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import (
4646
"github.com/devtron-labs/devtron/api/infraConfig"
4747
"github.com/devtron-labs/devtron/api/k8s"
4848
"github.com/devtron-labs/devtron/api/module"
49+
"github.com/devtron-labs/devtron/api/resourceScan"
4950
"github.com/devtron-labs/devtron/api/restHandler"
5051
"github.com/devtron-labs/devtron/api/restHandler/app/appInfo"
5152
appList2 "github.com/devtron-labs/devtron/api/restHandler/app/appList"
@@ -141,7 +142,8 @@ import (
141142
"github.com/devtron-labs/devtron/pkg/generateManifest"
142143
"github.com/devtron-labs/devtron/pkg/gitops"
143144
"github.com/devtron-labs/devtron/pkg/imageDigestPolicy"
144-
infraConfigService "github.com/devtron-labs/devtron/pkg/infraConfig"
145+
repository11 "github.com/devtron-labs/devtron/pkg/infraConfig/repository"
146+
infraConfigService "github.com/devtron-labs/devtron/pkg/infraConfig/service"
145147
"github.com/devtron-labs/devtron/pkg/infraConfig/units"
146148
"github.com/devtron-labs/devtron/pkg/kubernetesResourceAuditLogs"
147149
repository7 "github.com/devtron-labs/devtron/pkg/kubernetesResourceAuditLogs/repository"
@@ -210,6 +212,7 @@ func InitializeApp() (*App, error) {
210212
imageTagging.WireSet,
211213
devtronResource.DevtronResourceWireSet,
212214
policyGovernance.PolicyGovernanceWireSet,
215+
resourceScan.ScanningResultWireSet,
213216

214217
// -------wireset end ----------
215218
// -------
@@ -275,8 +278,8 @@ func InitializeApp() (*App, error) {
275278
wire.Bind(new(dashboardEvent.DashboardTelemetryRouter),
276279
new(*dashboardEvent.DashboardTelemetryRouterImpl)),
277280

278-
infraConfigService.NewInfraProfileRepositoryImpl,
279-
wire.Bind(new(infraConfigService.InfraConfigRepository), new(*infraConfigService.InfraConfigRepositoryImpl)),
281+
repository11.NewInfraProfileRepositoryImpl,
282+
wire.Bind(new(repository11.InfraConfigRepository), new(*repository11.InfraConfigRepositoryImpl)),
280283

281284
units.NewUnits,
282285
infraConfigService.NewInfraConfigServiceImpl,

api/helm-app/service/HelmAppService.go

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/devtron-labs/devtron/api/helm-app/models"
2828
helmBean "github.com/devtron-labs/devtron/api/helm-app/service/bean"
2929
"github.com/devtron-labs/devtron/api/helm-app/service/read"
30+
"github.com/devtron-labs/devtron/api/restHandler/common"
3031
"github.com/devtron-labs/devtron/internal/constants"
3132
repository2 "github.com/devtron-labs/devtron/internal/sql/repository/dockerRegistry"
3233
bean2 "github.com/devtron-labs/devtron/pkg/cluster/bean"
@@ -158,35 +159,45 @@ func GetHelmReleaseConfig() (*HelmReleaseConfig, error) {
158159
func (impl *HelmAppServiceImpl) ListHelmApplications(ctx context.Context, clusterIds []int, w http.ResponseWriter, token string, helmAuth func(token string, object string) bool) {
159160
var helmCdPipelines []*pipelineConfig.Pipeline
160161
var installedHelmApps []*repository.InstalledApps
162+
if len(clusterIds) == 0 {
163+
common.WriteJsonResp(w, util.DefaultApiError().WithHttpStatusCode(http.StatusBadRequest).WithInternalMessage("Invalid payload. Provide cluster ids in request").WithUserMessage("Invalid payload. Provide cluster ids in request"),
164+
nil,
165+
http.StatusBadRequest)
166+
return
167+
}
161168
start := time.Now()
162169
appStream, err := impl.listApplications(ctx, clusterIds)
163170
middleware.AppListingDuration.WithLabelValues("listApplications", "helm").Observe(time.Since(start).Seconds())
164171
if err != nil {
165172
impl.logger.Errorw("error in fetching app list", "clusters", clusterIds, "err", err)
173+
common.WriteJsonResp(w, util.DefaultApiError().WithHttpStatusCode(http.StatusInternalServerError).WithInternalMessage("error in fetching app list").WithUserMessage("error in fetching app list"),
174+
nil,
175+
http.StatusInternalServerError)
176+
return
177+
}
178+
179+
// get helm apps which are created using cd_pipelines
180+
newCtx, span := otel.Tracer("pipelineRepository").Start(ctx, "GetAppAndEnvDetailsForDeploymentAppTypePipeline")
181+
start = time.Now()
182+
helmCdPipelines, err = impl.pipelineRepository.GetAppAndEnvDetailsForDeploymentAppTypePipeline(util.PIPELINE_DEPLOYMENT_TYPE_HELM, clusterIds)
183+
middleware.AppListingDuration.WithLabelValues("getAppAndEnvDetailsForDeploymentAppTypePipeline", "helm").Observe(time.Since(start).Seconds())
184+
span.End()
185+
if err != nil {
186+
impl.logger.Errorw("error in fetching helm app list from DB created using cd_pipelines", "clusters", clusterIds, "err", err)
166187
}
167-
if err == nil && len(clusterIds) > 0 {
168-
// get helm apps which are created using cd_pipelines
169-
newCtx, span := otel.Tracer("pipelineRepository").Start(ctx, "GetAppAndEnvDetailsForDeploymentAppTypePipeline")
188+
189+
// if not hyperion mode, then fetch from installed_apps whose deploymentAppType is helm (as in hyperion mode, these apps should be treated as external-apps)
190+
if !util2.IsBaseStack() {
191+
newCtx, span = otel.Tracer("pipelineRepository").Start(newCtx, "GetAppAndEnvDetailsForDeploymentAppTypePipeline")
170192
start = time.Now()
171-
helmCdPipelines, err = impl.pipelineRepository.GetAppAndEnvDetailsForDeploymentAppTypePipeline(util.PIPELINE_DEPLOYMENT_TYPE_HELM, clusterIds)
172-
middleware.AppListingDuration.WithLabelValues("getAppAndEnvDetailsForDeploymentAppTypePipeline", "helm").Observe(time.Since(start).Seconds())
193+
installedHelmApps, err = impl.installedAppRepository.GetAppAndEnvDetailsForDeploymentAppTypeInstalledApps(util.PIPELINE_DEPLOYMENT_TYPE_HELM, clusterIds)
194+
middleware.AppListingDuration.WithLabelValues("getAppAndEnvDetailsForDeploymentAppTypeInstalledApps", "helm").Observe(time.Since(start).Seconds())
173195
span.End()
174196
if err != nil {
175-
impl.logger.Errorw("error in fetching helm app list from DB created using cd_pipelines", "clusters", clusterIds, "err", err)
176-
}
177-
178-
// if not hyperion mode, then fetch from installed_apps whose deploymentAppType is helm (as in hyperion mode, these apps should be treated as external-apps)
179-
if !util2.IsBaseStack() {
180-
newCtx, span = otel.Tracer("pipelineRepository").Start(newCtx, "GetAppAndEnvDetailsForDeploymentAppTypePipeline")
181-
start = time.Now()
182-
installedHelmApps, err = impl.installedAppRepository.GetAppAndEnvDetailsForDeploymentAppTypeInstalledApps(util.PIPELINE_DEPLOYMENT_TYPE_HELM, clusterIds)
183-
middleware.AppListingDuration.WithLabelValues("getAppAndEnvDetailsForDeploymentAppTypeInstalledApps", "helm").Observe(time.Since(start).Seconds())
184-
span.End()
185-
if err != nil {
186-
impl.logger.Errorw("error in fetching helm app list from DB created from app store", "clusters", clusterIds, "err", err)
187-
}
197+
impl.logger.Errorw("error in fetching helm app list from DB created from app store", "clusters", clusterIds, "err", err)
188198
}
189199
}
200+
190201
impl.pump.StartStreamWithTransformer(w, func() (proto.Message, error) {
191202
return appStream.Recv()
192203
}, err,

api/infraConfig/restHandler.go

Lines changed: 87 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ import (
2121
"github.com/devtron-labs/devtron/api/restHandler/common"
2222
"github.com/devtron-labs/devtron/pkg/auth/authorisation/casbin"
2323
"github.com/devtron-labs/devtron/pkg/auth/user"
24-
"github.com/devtron-labs/devtron/pkg/infraConfig"
2524
"github.com/devtron-labs/devtron/pkg/infraConfig/adapter"
2625
"github.com/devtron-labs/devtron/pkg/infraConfig/bean"
27-
"github.com/devtron-labs/devtron/pkg/infraConfig/util"
26+
"github.com/devtron-labs/devtron/pkg/infraConfig/service"
27+
util2 "github.com/devtron-labs/devtron/pkg/infraConfig/util"
2828
"github.com/devtron-labs/devtron/util/rbac"
2929
"github.com/gorilla/mux"
3030
"github.com/pkg/errors"
@@ -35,25 +35,24 @@ import (
3535
)
3636

3737
type InfraConfigRestHandler interface {
38-
UpdateInfraProfile(w http.ResponseWriter, r *http.Request)
3938
GetProfile(w http.ResponseWriter, r *http.Request)
40-
41-
// Deprecated: UpdateInfraProfileV0 is deprecated in favour of UpdateInfraProfile
42-
UpdateInfraProfileV0(w http.ResponseWriter, r *http.Request)
39+
UpdateInfraProfile(w http.ResponseWriter, r *http.Request)
4340

4441
// Deprecated: GetProfileV0 is deprecated in favour of GetProfile
4542
GetProfileV0(w http.ResponseWriter, r *http.Request)
43+
// Deprecated: UpdateInfraProfileV0 is deprecated in favour of UpdateInfraProfile
44+
UpdateInfraProfileV0(w http.ResponseWriter, r *http.Request)
4645
}
4746
type InfraConfigRestHandlerImpl struct {
4847
logger *zap.SugaredLogger
49-
infraProfileService infraConfig.InfraConfigService
48+
infraProfileService service.InfraConfigService
5049
userService user.UserService
5150
enforcer casbin.Enforcer
5251
enforcerUtil rbac.EnforcerUtil
5352
validator *validator.Validate
5453
}
5554

56-
func NewInfraConfigRestHandlerImpl(logger *zap.SugaredLogger, infraProfileService infraConfig.InfraConfigService, userService user.UserService, enforcer casbin.Enforcer, enforcerUtil rbac.EnforcerUtil, validator *validator.Validate) *InfraConfigRestHandlerImpl {
55+
func NewInfraConfigRestHandlerImpl(logger *zap.SugaredLogger, infraProfileService service.InfraConfigService, userService user.UserService, enforcer casbin.Enforcer, enforcerUtil rbac.EnforcerUtil, validator *validator.Validate) *InfraConfigRestHandlerImpl {
5756
return &InfraConfigRestHandlerImpl{
5857
logger: logger,
5958
infraProfileService: infraProfileService,
@@ -64,6 +63,46 @@ func NewInfraConfigRestHandlerImpl(logger *zap.SugaredLogger, infraProfileServic
6463
}
6564
}
6665

66+
func (handler *InfraConfigRestHandlerImpl) GetProfile(w http.ResponseWriter, r *http.Request) {
67+
userId, err := handler.userService.GetLoggedInUser(r)
68+
if userId == 0 || err != nil {
69+
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
70+
return
71+
}
72+
token := r.Header.Get("token")
73+
if ok := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionGet, "*"); !ok {
74+
common.WriteJsonResp(w, errors.New("unauthorized"), nil, http.StatusForbidden)
75+
return
76+
}
77+
78+
identifier := r.URL.Query().Get("name")
79+
80+
if len(identifier) == 0 {
81+
common.WriteJsonResp(w, errors.New(bean.InvalidProfileName), nil, http.StatusBadRequest)
82+
return
83+
}
84+
profileName := strings.ToLower(identifier)
85+
var profile *bean.ProfileBeanDto
86+
if profileName != bean.GLOBAL_PROFILE_NAME {
87+
common.WriteJsonResp(w, errors.New(bean.InvalidProfileName), nil, http.StatusBadRequest)
88+
return
89+
}
90+
defaultProfile, err := handler.infraProfileService.GetProfileByName(profileName)
91+
if err != nil {
92+
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
93+
return
94+
}
95+
profile = defaultProfile
96+
97+
resp := bean.ProfileResponse{
98+
Profile: *profile,
99+
}
100+
resp.ConfigurationUnits = handler.infraProfileService.GetConfigurationUnits()
101+
//TODO: why below line ??
102+
resp.DefaultConfigurations = defaultProfile.Configurations
103+
common.WriteJsonResp(w, nil, resp, http.StatusOK)
104+
}
105+
67106
func (handler *InfraConfigRestHandlerImpl) UpdateInfraProfile(w http.ResponseWriter, r *http.Request) {
68107
userId, err := handler.userService.GetLoggedInUser(r)
69108
if userId == 0 || err != nil {
@@ -76,39 +115,44 @@ func (handler *InfraConfigRestHandlerImpl) UpdateInfraProfile(w http.ResponseWri
76115
return
77116
}
78117

79-
vars := mux.Vars(r)
80-
profileName := strings.ToLower(vars["name"])
81-
if profileName == "" {
82-
common.WriteJsonResp(w, errors.New(util.InvalidProfileName), nil, http.StatusBadRequest)
118+
//vars := mux.Vars(r)
119+
val := r.URL.Query().Get("name")
120+
if len(val) == 0 {
121+
common.WriteJsonResp(w, errors.New(bean.InvalidProfileName), nil, http.StatusBadRequest)
83122
return
84123
}
85-
payload := &bean.ProfileBean{}
124+
profileName := strings.ToLower(val)
125+
126+
payload := &bean.ProfileBeanDto{}
86127
decoder := json.NewDecoder(r.Body)
87128
err = decoder.Decode(payload)
88129
if err != nil {
89130
handler.logger.Errorw("error in decoding the request payload", "err", err, "requestBody", r.Body)
90131
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
91132
return
92133
}
134+
//handler.validator.RegisterValidation("validateValue", ValidateValue)
93135
payload.Name = strings.ToLower(payload.Name)
94136
err = handler.validator.Struct(payload)
95137
if err != nil {
96-
err = errors.Wrap(err, util.PayloadValidationError)
138+
err = errors.Wrap(err, bean.PayloadValidationError)
97139
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
98140
}
99-
if profileName == "" || (profileName == util.DEFAULT_PROFILE_NAME && payload.Name != util.DEFAULT_PROFILE_NAME) {
100-
common.WriteJsonResp(w, errors.New(util.InvalidProfileName), nil, http.StatusBadRequest)
141+
if !util2.IsValidProfileNameRequested(profileName, payload.Name) {
142+
common.WriteJsonResp(w, errors.New(bean.InvalidProfileName), nil, http.StatusBadRequest)
143+
return
101144
}
102145
err = handler.infraProfileService.UpdateProfile(userId, profileName, payload)
103146
if err != nil {
104147
handler.logger.Errorw("error in updating profile and configurations", "profileName", profileName, "payLoad", payload, "err", err)
105-
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
148+
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
106149
return
107150
}
108151
common.WriteJsonResp(w, nil, nil, http.StatusOK)
109152
}
110153

111-
func (handler *InfraConfigRestHandlerImpl) GetProfile(w http.ResponseWriter, r *http.Request) {
154+
// Deprecated
155+
func (handler *InfraConfigRestHandlerImpl) GetProfileV0(w http.ResponseWriter, r *http.Request) {
112156
userId, err := handler.userService.GetLoggedInUser(r)
113157
if userId == 0 || err != nil {
114158
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
@@ -123,25 +167,30 @@ func (handler *InfraConfigRestHandlerImpl) GetProfile(w http.ResponseWriter, r *
123167
vars := mux.Vars(r)
124168
profileName := strings.ToLower(vars["name"])
125169
if profileName == "" {
126-
common.WriteJsonResp(w, errors.New(util.InvalidProfileName), nil, http.StatusBadRequest)
170+
common.WriteJsonResp(w, errors.New(bean.InvalidProfileName), nil, http.StatusBadRequest)
127171
return
128172
}
129173

130-
var profile *bean.ProfileBean
131-
defaultProfile, err := handler.infraProfileService.GetProfileByName(profileName)
174+
if profileName != bean.DEFAULT_PROFILE_NAME {
175+
common.WriteJsonResp(w, errors.New(bean.InvalidProfileName), nil, http.StatusBadRequest)
176+
return
177+
}
178+
179+
profileName = bean.GLOBAL_PROFILE_NAME
180+
181+
var profile *bean.ProfileBeanV0
182+
defaultProfileV1, err := handler.infraProfileService.GetProfileByName(profileName)
183+
defaultProfileV0 := adapter.GetV0ProfileBean(defaultProfileV1)
132184
if err != nil {
133185
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
134186
return
135187
}
136-
if profileName == util.DEFAULT_PROFILE_NAME {
137-
profile = defaultProfile
138-
}
139-
resp := bean.ProfileResponse{
188+
profile = defaultProfileV0
189+
resp := bean.ProfileResponseV0{
140190
Profile: *profile,
141191
}
142192
resp.ConfigurationUnits = handler.infraProfileService.GetConfigurationUnits()
143-
//TODO: why below line ??
144-
resp.DefaultConfigurations = defaultProfile.Configurations
193+
resp.DefaultConfigurations = defaultProfileV0.Configurations
145194
common.WriteJsonResp(w, nil, resp, http.StatusOK)
146195
}
147196

@@ -161,7 +210,7 @@ func (handler *InfraConfigRestHandlerImpl) UpdateInfraProfileV0(w http.ResponseW
161210
vars := mux.Vars(r)
162211
profileName := strings.ToLower(vars["name"])
163212
if profileName == "" {
164-
common.WriteJsonResp(w, errors.New(util.InvalidProfileName), nil, http.StatusBadRequest)
213+
common.WriteJsonResp(w, errors.New(bean.InvalidProfileName), nil, http.StatusBadRequest)
165214
return
166215
}
167216
payload := &bean.ProfileBeanV0{}
@@ -175,57 +224,25 @@ func (handler *InfraConfigRestHandlerImpl) UpdateInfraProfileV0(w http.ResponseW
175224
payload.Name = strings.ToLower(payload.Name)
176225
err = handler.validator.Struct(payload)
177226
if err != nil {
178-
err = errors.Wrap(err, util.PayloadValidationError)
227+
err = errors.Wrap(err, bean.PayloadValidationError)
179228
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
180229
}
181-
if profileName == "" || (profileName == util.DEFAULT_PROFILE_NAME && payload.Name != util.DEFAULT_PROFILE_NAME) {
182-
common.WriteJsonResp(w, errors.New(util.InvalidProfileName), nil, http.StatusBadRequest)
183-
}
184-
payloadV1 := adapter.GetV1ProfileBean(payload)
185-
err = handler.infraProfileService.UpdateProfile(userId, profileName, payloadV1)
186-
if err != nil {
187-
handler.logger.Errorw("error in updating profile and configurations", "profileName", profileName, "payLoad", payload, "err", err)
188-
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
230+
if !util2.IsValidProfileNameRequestedV0(profileName, payload.Name) {
231+
common.WriteJsonResp(w, errors.New(bean.InvalidProfileName), nil, http.StatusBadRequest)
189232
return
190233
}
191-
common.WriteJsonResp(w, nil, nil, http.StatusOK)
192-
}
193-
194-
// Deprecated
195-
func (handler *InfraConfigRestHandlerImpl) GetProfileV0(w http.ResponseWriter, r *http.Request) {
196-
userId, err := handler.userService.GetLoggedInUser(r)
197-
if userId == 0 || err != nil {
198-
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
199-
return
200-
}
201-
token := r.Header.Get("token")
202-
if ok := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionGet, "*"); !ok {
203-
common.WriteJsonResp(w, errors.New("unauthorized"), nil, http.StatusForbidden)
234+
if payload.Name != bean.DEFAULT_PROFILE_NAME {
235+
common.WriteJsonResp(w, errors.New(bean.InvalidProfileName), nil, http.StatusBadRequest)
204236
return
205237
}
206238

207-
vars := mux.Vars(r)
208-
profileName := strings.ToLower(vars["name"])
209-
if profileName == "" {
210-
common.WriteJsonResp(w, errors.New(util.InvalidProfileName), nil, http.StatusBadRequest)
211-
return
212-
}
213-
214-
var profile *bean.ProfileBeanV0
215-
defaultProfileV1, err := handler.infraProfileService.GetProfileByName(profileName)
216-
defaultProfileV0 := adapter.GetV0ProfileBean(defaultProfileV1)
239+
profileName = bean.GLOBAL_PROFILE_NAME
240+
payloadV1 := adapter.GetV1ProfileBean(payload)
241+
err = handler.infraProfileService.UpdateProfile(userId, profileName, payloadV1)
217242
if err != nil {
243+
handler.logger.Errorw("error in updating profile and configurations", "profileName", profileName, "payLoad", payload, "err", err)
218244
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
219245
return
220246
}
221-
if profileName == util.DEFAULT_PROFILE_NAME {
222-
profile = defaultProfileV0
223-
}
224-
resp := bean.ProfileResponseV0{
225-
Profile: *profile,
226-
}
227-
resp.ConfigurationUnits = handler.infraProfileService.GetConfigurationUnits()
228-
//TODO: why below line ??
229-
resp.DefaultConfigurations = defaultProfileV0.Configurations
230-
common.WriteJsonResp(w, nil, resp, http.StatusOK)
247+
common.WriteJsonResp(w, nil, nil, http.StatusOK)
231248
}

0 commit comments

Comments
 (0)