Skip to content

Commit 5c76bc5

Browse files
Merge pull request #6514 from devtron-labs/release-candidate-v0.33.0
sync: Release candidate v0.33.0
2 parents a16952b + 06ae166 commit 5c76bc5

File tree

666 files changed

+177145
-713
lines changed

Some content is hidden

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

666 files changed

+177145
-713
lines changed

Wire.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ import (
152152
repository7 "github.com/devtron-labs/devtron/pkg/kubernetesResourceAuditLogs/repository"
153153
"github.com/devtron-labs/devtron/pkg/notifier"
154154
"github.com/devtron-labs/devtron/pkg/pipeline"
155+
"github.com/devtron-labs/devtron/pkg/pipeline/draftAwareConfigService"
155156
"github.com/devtron-labs/devtron/pkg/pipeline/executors"
156157
history3 "github.com/devtron-labs/devtron/pkg/pipeline/history"
157158
repository3 "github.com/devtron-labs/devtron/pkg/pipeline/history/repository"
@@ -531,6 +532,9 @@ func InitializeApp() (*App, error) {
531532
chartConfig.NewConfigMapRepositoryImpl,
532533
wire.Bind(new(chartConfig.ConfigMapRepository), new(*chartConfig.ConfigMapRepositoryImpl)),
533534

535+
draftAwareConfigService.NewDraftAwareResourceServiceImpl,
536+
wire.Bind(new(draftAwareConfigService.DraftAwareConfigService), new(*draftAwareConfigService.DraftAwareConfigServiceImpl)),
537+
534538
config.WireSet,
535539

536540
infraConfig.WireSet,

api/restHandler/ConfigMapRestHandler.go

Lines changed: 108 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package restHandler
1919
import (
2020
"encoding/json"
2121
"fmt"
22+
"github.com/devtron-labs/devtron/pkg/pipeline/draftAwareConfigService"
2223
"net/http"
2324
"strconv"
2425

@@ -63,31 +64,35 @@ type ConfigMapRestHandler interface {
6364
}
6465

6566
type ConfigMapRestHandlerImpl struct {
66-
pipelineBuilder pipeline.PipelineBuilder
67-
Logger *zap.SugaredLogger
68-
chartService chart.ChartService
69-
userAuthService user.UserService
70-
teamService team.TeamService
71-
enforcer casbin.Enforcer
72-
pipelineRepository pipelineConfig.PipelineRepository
73-
enforcerUtil rbac.EnforcerUtil
74-
configMapService pipeline.ConfigMapService
67+
pipelineBuilder pipeline.PipelineBuilder
68+
Logger *zap.SugaredLogger
69+
chartService chart.ChartService
70+
userAuthService user.UserService
71+
teamService team.TeamService
72+
enforcer casbin.Enforcer
73+
pipelineRepository pipelineConfig.PipelineRepository
74+
enforcerUtil rbac.EnforcerUtil
75+
configMapService pipeline.ConfigMapService
76+
draftAwareResourceService draftAwareConfigService.DraftAwareConfigService
7577
}
7678

7779
func NewConfigMapRestHandlerImpl(pipelineBuilder pipeline.PipelineBuilder, Logger *zap.SugaredLogger,
7880
chartService chart.ChartService, userAuthService user.UserService, teamService team.TeamService,
7981
enforcer casbin.Enforcer, pipelineRepository pipelineConfig.PipelineRepository,
80-
enforcerUtil rbac.EnforcerUtil, configMapService pipeline.ConfigMapService) *ConfigMapRestHandlerImpl {
82+
enforcerUtil rbac.EnforcerUtil, configMapService pipeline.ConfigMapService,
83+
draftAwareResourceService draftAwareConfigService.DraftAwareConfigService,
84+
) *ConfigMapRestHandlerImpl {
8185
return &ConfigMapRestHandlerImpl{
82-
pipelineBuilder: pipelineBuilder,
83-
Logger: Logger,
84-
chartService: chartService,
85-
userAuthService: userAuthService,
86-
teamService: teamService,
87-
enforcer: enforcer,
88-
pipelineRepository: pipelineRepository,
89-
enforcerUtil: enforcerUtil,
90-
configMapService: configMapService,
86+
pipelineBuilder: pipelineBuilder,
87+
Logger: Logger,
88+
chartService: chartService,
89+
userAuthService: userAuthService,
90+
teamService: teamService,
91+
enforcer: enforcer,
92+
pipelineRepository: pipelineRepository,
93+
enforcerUtil: enforcerUtil,
94+
configMapService: configMapService,
95+
draftAwareResourceService: draftAwareResourceService,
9196
}
9297
}
9398

@@ -118,8 +123,14 @@ func (handler ConfigMapRestHandlerImpl) CMGlobalAddUpdate(w http.ResponseWriter,
118123
return
119124
}
120125
//RBAC END
121-
122-
res, err := handler.configMapService.CMGlobalAddUpdate(&configMapRequest)
126+
ctx := r.Context()
127+
isSuperAdmin := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionCreate, "*")
128+
userEmail, err := handler.userAuthService.GetActiveEmailById(userId)
129+
if err != nil {
130+
common.WriteJsonResp(w, fmt.Errorf("userEmail not found by userId"), "userEmail not found by userId", http.StatusNotFound)
131+
return
132+
}
133+
res, err := handler.draftAwareResourceService.CMGlobalAddUpdate(ctx, &configMapRequest, isSuperAdmin, userEmail)
123134
if err != nil {
124135
handler.Logger.Errorw("service err, CMGlobalAddUpdate", "err", err, "payload", configMapRequest)
125136
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
@@ -162,8 +173,14 @@ func (handler ConfigMapRestHandlerImpl) CMEnvironmentAddUpdate(w http.ResponseWr
162173
}
163174
}
164175
//RBAC END
165-
166-
res, err := handler.configMapService.CMEnvironmentAddUpdate(&configMapRequest)
176+
ctx := r.Context()
177+
isSuperAdmin := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionCreate, "*")
178+
userEmail, err := handler.userAuthService.GetActiveEmailById(userId)
179+
if err != nil {
180+
common.WriteJsonResp(w, fmt.Errorf("userEmail not found by userId"), "userEmail not found by userId", http.StatusNotFound)
181+
return
182+
}
183+
res, err := handler.draftAwareResourceService.CMEnvironmentAddUpdate(ctx, &configMapRequest, isSuperAdmin, userEmail)
167184
if err != nil {
168185
handler.Logger.Errorw("service err, CMEnvironmentAddUpdate", "err", err, "payload", configMapRequest)
169186
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
@@ -359,8 +376,14 @@ func (handler ConfigMapRestHandlerImpl) CSGlobalAddUpdate(w http.ResponseWriter,
359376
return
360377
}
361378
//RBAC END
362-
363-
res, err := handler.configMapService.CSGlobalAddUpdate(&configMapRequest)
379+
ctx := r.Context()
380+
isSuperAdmin := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionCreate, "*")
381+
userEmail, err := handler.userAuthService.GetActiveEmailById(userId)
382+
if err != nil {
383+
common.WriteJsonResp(w, fmt.Errorf("userEmail not found by userId"), "userEmail not found by userId", http.StatusNotFound)
384+
return
385+
}
386+
res, err := handler.draftAwareResourceService.CSGlobalAddUpdate(ctx, &configMapRequest, isSuperAdmin, userEmail)
364387
if err != nil {
365388
handler.Logger.Errorw("service err, CSGlobalAddUpdate", "err", err, "payload", configMapRequest)
366389
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
@@ -404,8 +427,14 @@ func (handler ConfigMapRestHandlerImpl) CSEnvironmentAddUpdate(w http.ResponseWr
404427
}
405428
}
406429
//RBAC END
407-
408-
res, err := handler.configMapService.CSEnvironmentAddUpdate(&configMapRequest)
430+
ctx := r.Context()
431+
isSuperAdmin := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionCreate, "*")
432+
userEmail, err := handler.userAuthService.GetActiveEmailById(userId)
433+
if err != nil {
434+
common.WriteJsonResp(w, fmt.Errorf("userEmail not found by userId"), "userEmail not found by userId", http.StatusNotFound)
435+
return
436+
}
437+
res, err := handler.draftAwareResourceService.CSEnvironmentAddUpdate(ctx, &configMapRequest, isSuperAdmin, userEmail)
409438
if err != nil {
410439
handler.Logger.Errorw("service err, CSEnvironmentAddUpdate", "err", err, "payload", configMapRequest)
411440
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
@@ -517,8 +546,19 @@ func (handler ConfigMapRestHandlerImpl) CMGlobalDelete(w http.ResponseWriter, r
517546
return
518547
}
519548
//RBAC END
520-
521-
res, err := handler.configMapService.CMGlobalDelete(name, id, userId)
549+
ctx := r.Context()
550+
isSuperAdmin := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionCreate, "*")
551+
userEmail, err := handler.userAuthService.GetActiveEmailById(userId)
552+
if err != nil {
553+
common.WriteJsonResp(w, fmt.Errorf("userEmail not found by userId"), "userEmail not found by userId", http.StatusNotFound)
554+
return
555+
}
556+
deleteReq := &bean.ConfigDataRequest{
557+
Id: id,
558+
AppId: appId,
559+
UserId: userId,
560+
}
561+
res, err := handler.draftAwareResourceService.CMGlobalDelete(ctx, name, deleteReq, isSuperAdmin, userEmail)
522562
if err != nil {
523563
handler.Logger.Errorw("service err, CMGlobalDelete", "err", err, "appId", appId, "id", id, "name", name)
524564
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
@@ -572,8 +612,19 @@ func (handler ConfigMapRestHandlerImpl) CMEnvironmentDelete(w http.ResponseWrite
572612
}
573613
}
574614
//RBAC END
575-
576-
res, err := handler.configMapService.CMEnvironmentDelete(name, id, userId)
615+
ctx := r.Context()
616+
isSuperAdmin := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionCreate, "*")
617+
userEmail, err := handler.userAuthService.GetActiveEmailById(userId)
618+
if err != nil {
619+
common.WriteJsonResp(w, fmt.Errorf("userEmail not found by userId"), "userEmail not found by userId", http.StatusNotFound)
620+
return
621+
}
622+
deleteReq := &bean.ConfigDataRequest{
623+
Id: id,
624+
AppId: appId,
625+
UserId: userId,
626+
}
627+
res, err := handler.draftAwareResourceService.CMEnvironmentDelete(ctx, name, deleteReq, isSuperAdmin, userEmail)
577628
if err != nil {
578629
handler.Logger.Errorw("service err, CMEnvironmentDelete", "err", err, "appId", appId, "envId", envId, "id", id)
579630
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
@@ -613,8 +664,19 @@ func (handler ConfigMapRestHandlerImpl) CSGlobalDelete(w http.ResponseWriter, r
613664
return
614665
}
615666
//RBAC END
616-
617-
res, err := handler.configMapService.CSGlobalDelete(name, id, userId)
667+
ctx := r.Context()
668+
isSuperAdmin := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionCreate, "*")
669+
userEmail, err := handler.userAuthService.GetActiveEmailById(userId)
670+
if err != nil {
671+
common.WriteJsonResp(w, fmt.Errorf("userEmail not found by userId"), "userEmail not found by userId", http.StatusNotFound)
672+
return
673+
}
674+
deleteReq := &bean.ConfigDataRequest{
675+
Id: id,
676+
AppId: appId,
677+
UserId: userId,
678+
}
679+
res, err := handler.draftAwareResourceService.CSGlobalDelete(ctx, name, deleteReq, isSuperAdmin, userEmail)
618680
if err != nil {
619681
handler.Logger.Errorw("service err, CSGlobalDelete", "err", err, "appId", appId, "id", id, "name", name)
620682
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
@@ -668,8 +730,19 @@ func (handler ConfigMapRestHandlerImpl) CSEnvironmentDelete(w http.ResponseWrite
668730
}
669731
}
670732
//RBAC END
671-
672-
res, err := handler.configMapService.CSEnvironmentDelete(name, id, userId)
733+
ctx := r.Context()
734+
isSuperAdmin := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionCreate, "*")
735+
userEmail, err := handler.userAuthService.GetActiveEmailById(userId)
736+
if err != nil {
737+
common.WriteJsonResp(w, fmt.Errorf("userEmail not found by userId"), "userEmail not found by userId", http.StatusNotFound)
738+
return
739+
}
740+
deleteReq := &bean.ConfigDataRequest{
741+
Id: id,
742+
AppId: appId,
743+
UserId: userId,
744+
}
745+
res, err := handler.draftAwareResourceService.CSEnvironmentDelete(ctx, name, deleteReq, isSuperAdmin, userEmail)
673746
if err != nil {
674747
handler.Logger.Errorw("service err, CSEnvironmentDelete", "err", err, "appId", appId, "envId", envId, "id", id)
675748
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)

api/restHandler/CoreAppRestHandler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1847,11 +1847,11 @@ func (handler CoreAppRestHandlerImpl) createEnvDeploymentTemplate(appId int, use
18471847
templateRequest := bean3.TemplateRequest{
18481848
AppId: appId,
18491849
ChartRefId: chartRefId,
1850-
ValuesOverride: []byte("{}"),
1850+
ValuesOverride: util.GetEmptyJSON(),
18511851
UserId: userId,
18521852
IsAppMetricsEnabled: deploymentTemplateOverride.ShowAppMetrics,
18531853
}
1854-
newChartEntry, err := handler.chartService.CreateChartFromEnvOverride(templateRequest, context.Background())
1854+
newChartEntry, err := handler.chartService.CreateChartFromEnvOverride(context.Background(), templateRequest)
18551855
if err != nil {
18561856
handler.logger.Errorw("service err, CreateChartFromEnvOverride", "err", err, "appId", appId, "envId", envId, "chartRefId", chartRefId)
18571857
return err

api/restHandler/UserAttributesRestHandler.go

Lines changed: 42 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
type UserAttributesRestHandler interface {
3333
AddUserAttributes(w http.ResponseWriter, r *http.Request)
3434
UpdateUserAttributes(w http.ResponseWriter, r *http.Request)
35+
PatchUserAttributes(w http.ResponseWriter, r *http.Request)
3536
GetUserAttribute(w http.ResponseWriter, r *http.Request)
3637
}
3738

@@ -54,35 +55,13 @@ func NewUserAttributesRestHandlerImpl(logger *zap.SugaredLogger, enforcer casbin
5455
}
5556

5657
func (handler *UserAttributesRestHandlerImpl) AddUserAttributes(w http.ResponseWriter, r *http.Request) {
57-
userId, err := handler.userService.GetLoggedInUser(r)
58-
if userId == 0 || err != nil {
59-
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
60-
return
61-
}
62-
decoder := json.NewDecoder(r.Body)
63-
var dto attributes.UserAttributesDto
64-
err = decoder.Decode(&dto)
65-
if err != nil {
66-
handler.logger.Errorw("request err, AddUserAttributes", "err", err, "payload", dto)
67-
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
58+
dto, success := handler.validateUserAttributesRequest(w, r, "PatchUserAttributes")
59+
if !success {
6860
return
6961
}
7062

71-
dto.UserId = userId
72-
//if ok := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionCreate, "*"); !ok {
73-
// common.WriteJsonResp(w, errors.New("unauthorized"), nil, http.StatusForbidden)
74-
// return
75-
//}
76-
emailId, err := handler.userService.GetActiveEmailById(userId)
77-
if err != nil {
78-
handler.logger.Errorw("request err, UpdateUserAttributes", "err", err, "payload", dto)
79-
common.WriteJsonResp(w, errors.New("unauthorized"), nil, http.StatusForbidden)
80-
return
81-
}
82-
dto.EmailId = emailId
83-
8463
handler.logger.Infow("request payload, AddUserAttributes", "payload", dto)
85-
resp, err := handler.userAttributesService.AddUserAttributes(&dto)
64+
resp, err := handler.userAttributesService.AddUserAttributes(dto)
8665
if err != nil {
8766
handler.logger.Errorw("service err, AddUserAttributes", "err", err, "payload", dto)
8867
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
@@ -98,43 +77,64 @@ func (handler *UserAttributesRestHandlerImpl) AddUserAttributes(w http.ResponseW
9877
// @Success 200 {object} attributes.UserAttributesDto
9978
// @Router /orchestrator/attributes/user/update [POST]
10079
func (handler *UserAttributesRestHandlerImpl) UpdateUserAttributes(w http.ResponseWriter, r *http.Request) {
80+
dto, success := handler.validateUserAttributesRequest(w, r, "PatchUserAttributes")
81+
if !success {
82+
return
83+
}
84+
85+
handler.logger.Infow("request payload, UpdateUserAttributes", "payload", dto)
86+
resp, err := handler.userAttributesService.UpdateUserAttributes(dto)
87+
if err != nil {
88+
handler.logger.Errorw("service err, UpdateUserAttributes", "err", err, "payload", dto)
89+
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
90+
return
91+
}
92+
common.WriteJsonResp(w, nil, resp, http.StatusOK)
93+
}
94+
95+
func (handler *UserAttributesRestHandlerImpl) PatchUserAttributes(w http.ResponseWriter, r *http.Request) {
96+
dto, success := handler.validateUserAttributesRequest(w, r, "PatchUserAttributes")
97+
if !success {
98+
return
99+
}
100+
101+
handler.logger.Infow("request payload, PatchUserAttributes", "payload", dto)
102+
resp, err := handler.userAttributesService.PatchUserAttributes(dto)
103+
if err != nil {
104+
handler.logger.Errorw("service err, PatchUserAttributes", "err", err, "payload", dto)
105+
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
106+
return
107+
}
108+
common.WriteJsonResp(w, nil, resp, http.StatusOK)
109+
}
110+
111+
func (handler *UserAttributesRestHandlerImpl) validateUserAttributesRequest(w http.ResponseWriter, r *http.Request, operation string) (*attributes.UserAttributesDto, bool) {
101112
userId, err := handler.userService.GetLoggedInUser(r)
102113
if userId == 0 || err != nil {
103114
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
104-
return
115+
return nil, false
105116
}
106117

107118
decoder := json.NewDecoder(r.Body)
108119
var dto attributes.UserAttributesDto
109120
err = decoder.Decode(&dto)
110121
if err != nil {
111-
handler.logger.Errorw("request err, UpdateUserAttributes", "err", err, "payload", dto)
122+
handler.logger.Errorw("request err, "+operation, "err", err, "payload", dto)
112123
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
113-
return
124+
return nil, false
114125
}
115126

116127
dto.UserId = userId
117-
//if ok := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionUpdate, "*"); !ok {
118-
// common.WriteJsonResp(w, errors.New("unauthorized"), nil, http.StatusForbidden)
119-
// return
120-
//}
121128

122129
emailId, err := handler.userService.GetActiveEmailById(userId)
123130
if err != nil {
124-
handler.logger.Errorw("request err, UpdateUserAttributes", "err", err, "payload", dto)
131+
handler.logger.Errorw("request err, "+operation, "err", err, "payload", dto)
125132
common.WriteJsonResp(w, errors.New("unauthorized"), nil, http.StatusForbidden)
126-
return
133+
return nil, false
127134
}
128135
dto.EmailId = emailId
129136

130-
handler.logger.Infow("request payload, UpdateUserAttributes", "payload", dto)
131-
resp, err := handler.userAttributesService.UpdateUserAttributes(&dto)
132-
if err != nil {
133-
handler.logger.Errorw("service err, UpdateUserAttributes", "err", err, "payload", dto)
134-
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
135-
return
136-
}
137-
common.WriteJsonResp(w, nil, resp, http.StatusOK)
137+
return &dto, true
138138
}
139139

140140
// @Summary get user attributes
@@ -158,11 +158,6 @@ func (handler *UserAttributesRestHandlerImpl) GetUserAttribute(w http.ResponseWr
158158
return
159159
}
160160

161-
//if ok := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionGet, "*"); !ok {
162-
// common.WriteJsonResp(w, errors.New("unauthorized"), nil, http.StatusForbidden)
163-
// return
164-
//}
165-
166161
dto := attributes.UserAttributesDto{}
167162

168163
emailId, err := handler.userService.GetActiveEmailById(userId)

0 commit comments

Comments
 (0)