Skip to content

Commit 010fda4

Browse files
authored
Merge branch 'develop' into notifier-refac
2 parents d2a2b88 + 819743a commit 010fda4

File tree

68 files changed

+927
-493
lines changed

Some content is hidden

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

68 files changed

+927
-493
lines changed

api/appStore/deployment/AppStoreDeploymentRestHandler.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,7 @@ func (handler AppStoreDeploymentRestHandlerImpl) UpdateProjectHelmApp(w http.Res
539539
if err != nil {
540540
handler.Logger.Errorw("error in decoding app id", "err", err)
541541
common.WriteJsonResp(w, err, "error in decoding app id", http.StatusBadRequest)
542+
return
542543
}
543544
// this rbac object checks that whether user have permission to change current project.
544545
rbacObjectForCurrentProject, rbacObjectForCurrentProject2 := handler.enforcerUtilHelm.GetHelmObjectByClusterIdNamespaceAndAppName(appIdentifier.ClusterId, appIdentifier.Namespace, appIdentifier.ReleaseName)
@@ -555,6 +556,7 @@ func (handler AppStoreDeploymentRestHandlerImpl) UpdateProjectHelmApp(w http.Res
555556
if err != nil {
556557
handler.Logger.Errorw("service err, InstalledAppId", "err", err, "InstalledAppId", request.InstalledAppId)
557558
common.WriteJsonResp(w, fmt.Errorf("Unable to fetch installed app details"), nil, http.StatusBadRequest)
559+
return
558560
}
559561
if installedApp.IsVirtualEnvironment {
560562
rbacObjectForCurrentProject, _ := handler.enforcerUtilHelm.GetAppRBACNameByInstalledAppId(request.InstalledAppId)
@@ -580,8 +582,10 @@ func (handler AppStoreDeploymentRestHandlerImpl) UpdateProjectHelmApp(w http.Res
580582
if err != nil {
581583
handler.Logger.Errorw("error in updating project for helm apps", "err", err)
582584
common.WriteJsonResp(w, err, "error in updating project", http.StatusBadRequest)
585+
return
583586
} else {
584587
handler.Logger.Errorw("Helm App project update")
585588
common.WriteJsonResp(w, nil, "Project Updated", http.StatusOK)
589+
return
586590
}
587591
}

api/appStore/deployment/CommonDeploymentRestHandler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ func (handler *CommonDeploymentRestHandlerImpl) RollbackApplication(w http.Respo
268268
appOfferingMode, installedAppDto, err := handler.getAppOfferingMode(installedAppId, *request.HAppId)
269269
if err != nil {
270270
common.WriteJsonResp(w, err, "bad request", http.StatusBadRequest)
271+
return
271272
}
272273
installedAppDto.UserId = userId
273274
//rbac block starts from here

api/auth/user/UserAuthHandler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ func (handler UserAuthHandlerImpl) LoginHandler(w http.ResponseWriter, r *http.R
7070
if err != nil {
7171
handler.logger.Errorw("request err, LoginHandler", "err", err, "payload", up)
7272
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
73+
return
7374
}
7475

7576
err = handler.validator.Struct(up)

api/bean/ConfigMapAndSecret.go

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,19 @@ type ConfigSecretMap struct {
5757
SubPath bool `json:"subPath"`
5858
ESOSubPath []string `json:"esoSubPath"`
5959
FilePermission string `json:"filePermission"`
60+
ConfigSecretMapEnt
6061
}
6162

62-
func (configSecret ConfigSecretMap) GetDataMap() (map[string]string, error) {
63-
var datamap map[string]string
64-
err := json.Unmarshal(configSecret.Data, &datamap)
65-
return datamap, err
63+
func (configSecret *ConfigSecretMap) GetDataMap() (map[string]string, error) {
64+
if len(configSecret.Data) == 0 {
65+
return make(map[string]string), nil
66+
}
67+
var dataMap map[string]string
68+
err := json.Unmarshal(configSecret.Data, &dataMap)
69+
return dataMap, err
6670
}
67-
func (configSecretJson ConfigSecretJson) GetDereferencedSecrets() []ConfigSecretMap {
71+
72+
func (configSecretJson *ConfigSecretJson) GetDereferencedSecrets() []ConfigSecretMap {
6873
return sliceUtil.GetDeReferencedSlice(configSecretJson.Secrets)
6974
}
7075

@@ -95,3 +100,14 @@ func GetTransformedDataForSecretRootJsonData(data string, mode util.SecretTransf
95100
}
96101
return string(marshal), nil
97102
}
103+
104+
type ConfigType string
105+
106+
func (c ConfigType) String() string {
107+
return string(c)
108+
}
109+
110+
const (
111+
ConfigMap ConfigType = "cm"
112+
Secret ConfigType = "cs"
113+
)

api/bean/ConfigMapAndSecret_ent.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (c) 2024. Devtron Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package bean
18+
19+
type ConfigSecretMapEnt struct {
20+
}
21+
22+
func (configSecret *ConfigSecretMap) AddDataToKey(keyName string, data []byte) (*ConfigSecretMap, error) {
23+
return configSecret, nil
24+
}
25+
26+
func (configSecret *ConfigSecretMap) GetBinaryDataMap() map[string][]byte {
27+
return nil
28+
}

api/helm-app/HelmAppRestHandler.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ func (handler *HelmAppRestHandlerImpl) Hibernate(w http.ResponseWriter, r *http.
191191
appType, err = strconv.Atoi(appTypeString)
192192
if err != nil {
193193
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
194+
return
194195
}
195196
}
196197

@@ -282,6 +283,7 @@ func (handler *HelmAppRestHandlerImpl) UnHibernate(w http.ResponseWriter, r *htt
282283
appType, err = strconv.Atoi(appTypeString)
283284
if err != nil {
284285
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
286+
return
285287
}
286288
}
287289
token := r.Header.Get("token")

api/k8s/application/k8sApplicationRestHandler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,7 @@ func (handler *K8sApplicationRestHandlerImpl) requestValidationAndRBAC(w http.Re
729729
if err != nil {
730730
handler.logger.Errorw(bean2.AppIdDecodingError, "err", err, "appIdentifier", request.AppIdentifier)
731731
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
732+
return
732733
}
733734
valid, err := handler.argoApplicationReadService.ValidateArgoResourceRequest(r.Context(), appIdentifier, request.K8sRequest)
734735
if err != nil || !valid {

api/restHandler/BatchOperationRestHandler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ func (handler BatchOperationRestHandlerImpl) Operate(w http.ResponseWriter, r *h
9494

9595
if workflow.Destination.App == nil || len(*workflow.Destination.App) == 0 {
9696
common.WriteJsonResp(w, errors.New("app name cannot be empty"), nil, http.StatusBadRequest)
97+
return
9798
}
9899
rbacString := handler.enforcerUtil.GetProjectAdminRBACNameBYAppName(*workflow.Destination.App)
99100
if ok := handler.enforcer.Enforce(token, casbin.ResourceApplications, casbin.ActionCreate, rbacString); !ok {

api/restHandler/BulkUpdateRestHandler.go

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ package restHandler
1919
import (
2020
"encoding/json"
2121
"fmt"
22+
bean4 "github.com/devtron-labs/devtron/pkg/auth/user/bean"
2223
"github.com/devtron-labs/devtron/pkg/build/git/gitMaterial/repository"
2324
"github.com/devtron-labs/devtron/pkg/build/git/gitProvider"
2425
"github.com/devtron-labs/devtron/pkg/bulkAction/bean"
2526
"github.com/devtron-labs/devtron/pkg/bulkAction/service"
2627
"github.com/devtron-labs/devtron/pkg/cluster/environment"
28+
"github.com/devtron-labs/devtron/util"
2729
"net/http"
2830
"strconv"
2931
"strings"
@@ -181,22 +183,26 @@ func (handler BulkUpdateRestHandlerImpl) GetImpactedAppsName(w http.ResponseWrit
181183
ok := handler.CheckAuthForImpactedObjects(deploymentTemplateImpactedApp.AppId, deploymentTemplateImpactedApp.EnvId, appResourceObjects, envResourceObjects, token)
182184
if !ok {
183185
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), "Unauthorized User", http.StatusForbidden)
186+
return
184187
}
185188
}
186189
for _, configMapImpactedApp := range impactedApps.ConfigMap {
187190
ok := handler.CheckAuthForImpactedObjects(configMapImpactedApp.AppId, configMapImpactedApp.EnvId, appResourceObjects, envResourceObjects, token)
188191
if !ok {
189192
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), "Unauthorized User", http.StatusForbidden)
193+
return
190194
}
191195
}
192196
for _, secretImpactedApp := range impactedApps.Secret {
193197
ok := handler.CheckAuthForImpactedObjects(secretImpactedApp.AppId, secretImpactedApp.EnvId, appResourceObjects, envResourceObjects, token)
194198
if !ok {
195199
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), "Unauthorized User", http.StatusForbidden)
200+
return
196201
}
197202
}
198203
common.WriteJsonResp(w, err, impactedApps, http.StatusOK)
199204
}
205+
200206
func (handler BulkUpdateRestHandlerImpl) CheckAuthForBulkUpdate(AppId int, EnvId int, AppName string, rbacObjects map[int]string, token string) bool {
201207
resourceName := rbacObjects[AppId]
202208
if ok := handler.enforcer.Enforce(token, casbin.ResourceApplications, casbin.ActionUpdate, resourceName); !ok {
@@ -212,9 +218,14 @@ func (handler BulkUpdateRestHandlerImpl) CheckAuthForBulkUpdate(AppId int, EnvId
212218

213219
}
214220
func (handler BulkUpdateRestHandlerImpl) BulkUpdate(w http.ResponseWriter, r *http.Request) {
221+
userId, err := handler.userAuthService.GetLoggedInUser(r)
222+
if userId == 0 || err != nil {
223+
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
224+
return
225+
}
215226
decoder := json.NewDecoder(r.Body)
216227
var script bean.BulkUpdateScript
217-
err := decoder.Decode(&script)
228+
err = decoder.Decode(&script)
218229
if err != nil {
219230
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
220231
return
@@ -236,22 +247,31 @@ func (handler BulkUpdateRestHandlerImpl) BulkUpdate(w http.ResponseWriter, r *ht
236247
ok := handler.CheckAuthForBulkUpdate(deploymentTemplateImpactedApp.AppId, deploymentTemplateImpactedApp.EnvId, deploymentTemplateImpactedApp.AppName, rbacObjects, token)
237248
if !ok {
238249
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), "Unauthorized User", http.StatusForbidden)
250+
return
239251
}
240252
}
241253
for _, configMapImpactedApp := range impactedApps.ConfigMap {
242254
ok := handler.CheckAuthForBulkUpdate(configMapImpactedApp.AppId, configMapImpactedApp.EnvId, configMapImpactedApp.AppName, rbacObjects, token)
243255
if !ok {
244256
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), "Unauthorized User", http.StatusForbidden)
257+
return
245258
}
246259
}
247260
for _, secretImpactedApp := range impactedApps.Secret {
248261
ok := handler.CheckAuthForBulkUpdate(secretImpactedApp.AppId, secretImpactedApp.EnvId, secretImpactedApp.AppName, rbacObjects, token)
249262
if !ok {
250263
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), "Unauthorized User", http.StatusForbidden)
264+
return
251265
}
252266
}
253-
254-
response := handler.bulkUpdateService.BulkUpdate(script.Spec)
267+
isSuperAdmin := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionCreate, "*")
268+
userEmail := util.GetEmailFromContext(r.Context())
269+
userMetadata := &bean4.UserMetadata{
270+
UserEmailId: userEmail,
271+
IsUserSuperAdmin: isSuperAdmin,
272+
UserId: userId,
273+
}
274+
response := handler.bulkUpdateService.BulkUpdate(script.Spec, userMetadata)
255275
common.WriteJsonResp(w, nil, response, http.StatusOK)
256276
}
257277

@@ -261,7 +281,15 @@ func (handler BulkUpdateRestHandlerImpl) BulkHibernate(w http.ResponseWriter, r
261281
return // response already written by the helper on error.
262282
}
263283
token := r.Header.Get("token")
264-
response, err := handler.bulkUpdateService.BulkHibernate(request, r.Context(), w, token, handler.checkAuthForBulkHibernateAndUnhibernate)
284+
isSuperAdmin := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionCreate, "*")
285+
userEmail := util.GetEmailFromContext(r.Context())
286+
userMetadata := &bean4.UserMetadata{
287+
UserEmailId: userEmail,
288+
IsUserSuperAdmin: isSuperAdmin,
289+
UserId: request.UserId,
290+
}
291+
292+
response, err := handler.bulkUpdateService.BulkHibernate(r.Context(), request, handler.checkAuthForBulkHibernateAndUnhibernate, userMetadata)
265293
if err != nil {
266294
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
267295
return
@@ -298,7 +326,14 @@ func (handler BulkUpdateRestHandlerImpl) BulkUnHibernate(w http.ResponseWriter,
298326
return // response already written by the helper on error.
299327
}
300328
token := r.Header.Get("token")
301-
response, err := handler.bulkUpdateService.BulkUnHibernate(request, r.Context(), w, token, handler.checkAuthForBulkHibernateAndUnhibernate)
329+
isSuperAdmin := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionCreate, "*")
330+
userEmail := util.GetEmailFromContext(r.Context())
331+
userMetadata := &bean4.UserMetadata{
332+
UserEmailId: userEmail,
333+
IsUserSuperAdmin: isSuperAdmin,
334+
UserId: request.UserId,
335+
}
336+
response, err := handler.bulkUpdateService.BulkUnHibernate(r.Context(), request, handler.checkAuthForBulkHibernateAndUnhibernate, userMetadata)
302337
if err != nil {
303338
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
304339
return
@@ -326,7 +361,14 @@ func (handler BulkUpdateRestHandlerImpl) BulkDeploy(w http.ResponseWriter, r *ht
326361
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
327362
return
328363
}
329-
response, err := handler.bulkUpdateService.BulkDeploy(&request, token, handler.checkAuthBatch)
364+
isSuperAdmin := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionCreate, "*")
365+
userEmail := util.GetEmailFromContext(r.Context())
366+
userMetadata := &bean4.UserMetadata{
367+
UserEmailId: userEmail,
368+
IsUserSuperAdmin: isSuperAdmin,
369+
UserId: userId,
370+
}
371+
response, err := handler.bulkUpdateService.BulkDeploy(&request, token, handler.checkAuthBatch, userMetadata)
330372
if err != nil {
331373
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
332374
return

0 commit comments

Comments
 (0)