Skip to content

Commit 3be33af

Browse files
committed
code review fixes: 1st level kartik
1 parent 538321e commit 3be33af

File tree

6 files changed

+20
-11
lines changed

6 files changed

+20
-11
lines changed

api/restHandler/BulkUpdateRestHandler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ func (handler BulkUpdateRestHandlerImpl) BulkHibernate(w http.ResponseWriter, r
289289
UserId: request.UserId,
290290
}
291291

292-
response, err := handler.bulkUpdateService.BulkHibernate(r.Context(), request, token, handler.checkAuthForBulkHibernateAndUnhibernate, userMetadata)
292+
response, err := handler.bulkUpdateService.BulkHibernate(r.Context(), request, handler.checkAuthForBulkHibernateAndUnhibernate, userMetadata)
293293
if err != nil {
294294
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
295295
return
@@ -337,7 +337,7 @@ func (handler BulkUpdateRestHandlerImpl) BulkUnHibernate(w http.ResponseWriter,
337337
IsUserSuperAdmin: isSuperAdmin,
338338
UserId: request.UserId,
339339
}
340-
response, err := handler.bulkUpdateService.BulkUnHibernate(r.Context(), request, token, handler.checkAuthForBulkHibernateAndUnhibernate, userMetadata)
340+
response, err := handler.bulkUpdateService.BulkUnHibernate(r.Context(), request, handler.checkAuthForBulkHibernateAndUnhibernate, userMetadata)
341341
if err != nil {
342342
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
343343
return

env_gen.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

env_gen.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@
168168
| DEX_CSTOREKEY | string | | | | false |
169169
| DEX_JWTKEY | string | | | | false |
170170
| DEX_RURL | string |http://127.0.0.1:8080/callback | | | false |
171+
| DEX_SCOPES | | | | | false |
171172
| DEX_SECRET | string | | | | false |
172173
| DEX_URL | string | | | | false |
173174
| ECR_REPO_NAME_PREFIX | string |test/ | | | false |

pkg/bulkAction/service/BulkUpdateService.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ type BulkUpdateService interface {
7474
BulkUpdateSecret(bulkUpdatePayload *bean4.BulkUpdatePayload, userMetadata *bean6.UserMetadata) *bean4.CmAndSecretBulkUpdateResponse
7575
BulkUpdate(bulkUpdateRequest *bean4.BulkUpdatePayload, userMetadata *bean6.UserMetadata) (bulkUpdateResponse *bean4.BulkUpdateResponse)
7676
// BulkHibernate deprecated
77-
BulkHibernate(ctx context.Context, request *bean4.BulkApplicationForEnvironmentPayload, token string, checkAuthForBulkActions func(token string, appObject string, envObject string) bool, userMetadata *bean6.UserMetadata) (*bean4.BulkApplicationHibernateUnhibernateForEnvironmentResponse, error)
78-
BulkHibernateV1(ctx context.Context, request *bean4.BulkApplicationForEnvironmentPayload, token string, checkAuthForBulkActions func(token string, appObject string, envObject string) bool, userMetadata *bean6.UserMetadata) (*bean4.BulkApplicationHibernateUnhibernateForEnvironmentResponse, error)
79-
BulkUnHibernate(ctx context.Context, request *bean4.BulkApplicationForEnvironmentPayload, token string, checkAuthForBulkActions func(token string, appObject string, envObject string) bool, userMetadata *bean6.UserMetadata) (*bean4.BulkApplicationHibernateUnhibernateForEnvironmentResponse, error)
77+
BulkHibernate(ctx context.Context, request *bean4.BulkApplicationForEnvironmentPayload, checkAuthForBulkActions func(token string, appObject string, envObject string) bool, userMetadata *bean6.UserMetadata) (*bean4.BulkApplicationHibernateUnhibernateForEnvironmentResponse, error)
78+
BulkHibernateV1(ctx context.Context, request *bean4.BulkApplicationForEnvironmentPayload, checkAuthForBulkActions func(token string, appObject string, envObject string) bool, userMetadata *bean6.UserMetadata) (*bean4.BulkApplicationHibernateUnhibernateForEnvironmentResponse, error)
79+
BulkUnHibernate(ctx context.Context, request *bean4.BulkApplicationForEnvironmentPayload, checkAuthForBulkActions func(token string, appObject string, envObject string) bool, userMetadata *bean6.UserMetadata) (*bean4.BulkApplicationHibernateUnhibernateForEnvironmentResponse, error)
8080
BulkDeploy(request *bean4.BulkApplicationForEnvironmentPayload, token string, checkAuthBatch func(token string, appObject []string, envObject []string) (map[string]bool, map[string]bool), userMetadata *bean6.UserMetadata) (*bean4.BulkApplicationForEnvironmentResponse, error)
8181
BulkBuildTrigger(request *bean4.BulkApplicationForEnvironmentPayload, ctx context.Context, w http.ResponseWriter, token string, checkAuthForBulkActions func(token string, appObject string, envObject string) bool) (*bean4.BulkApplicationForEnvironmentResponse, error)
8282

@@ -988,7 +988,7 @@ func (impl BulkUpdateServiceImpl) BulkUpdate(bulkUpdatePayload *bean4.BulkUpdate
988988
return bulkUpdateResponse
989989
}
990990

991-
func (impl BulkUpdateServiceImpl) BulkHibernate(ctx context.Context, request *bean4.BulkApplicationForEnvironmentPayload, token string, checkAuthForBulkActions func(token string, appObject string, envObject string) bool,
991+
func (impl BulkUpdateServiceImpl) BulkHibernate(ctx context.Context, request *bean4.BulkApplicationForEnvironmentPayload, checkAuthForBulkActions func(token string, appObject string, envObject string) bool,
992992
userMetadata *bean6.UserMetadata) (*bean4.BulkApplicationHibernateUnhibernateForEnvironmentResponse, error) {
993993
var pipelines []*pipelineConfig.Pipeline
994994
var err error
@@ -1024,7 +1024,7 @@ func (impl BulkUpdateServiceImpl) BulkHibernate(ctx context.Context, request *be
10241024
}
10251025
appObject := impl.enforcerUtil.GetAppRBACNameByAppId(pipeline.AppId)
10261026
envObject := impl.enforcerUtil.GetEnvRBACNameByAppId(pipeline.AppId, pipeline.EnvironmentId)
1027-
isValidAuth := checkAuthForBulkActions(token, appObject, envObject)
1027+
isValidAuth := checkAuthForBulkActions(util2.GetTokenFromContext(ctx), appObject, envObject)
10281028
if !isValidAuth {
10291029
//skip hibernate for the app if user does not have access on that
10301030
pipelineResponse := response[appKey]
@@ -1145,7 +1145,7 @@ func (impl BulkUpdateServiceImpl) buildHibernateUnHibernateRequestForHelmPipelin
11451145
}
11461146
return appIdentifier, hibernateRequest, nil
11471147
}
1148-
func (impl BulkUpdateServiceImpl) BulkUnHibernate(ctx context.Context, request *bean4.BulkApplicationForEnvironmentPayload, token string, checkAuthForBulkActions func(token string, appObject string, envObject string) bool,
1148+
func (impl BulkUpdateServiceImpl) BulkUnHibernate(ctx context.Context, request *bean4.BulkApplicationForEnvironmentPayload, checkAuthForBulkActions func(token string, appObject string, envObject string) bool,
11491149
userMetadata *bean6.UserMetadata) (*bean4.BulkApplicationHibernateUnhibernateForEnvironmentResponse, error) {
11501150
var pipelines []*pipelineConfig.Pipeline
11511151
var err error
@@ -1180,7 +1180,7 @@ func (impl BulkUpdateServiceImpl) BulkUnHibernate(ctx context.Context, request *
11801180
}
11811181
appObject := impl.enforcerUtil.GetAppRBACNameByAppId(pipeline.AppId)
11821182
envObject := impl.enforcerUtil.GetEnvRBACNameByAppId(pipeline.AppId, pipeline.EnvironmentId)
1183-
isValidAuth := checkAuthForBulkActions(token, appObject, envObject)
1183+
isValidAuth := checkAuthForBulkActions(util2.GetTokenFromContext(ctx), appObject, envObject)
11841184
if !isValidAuth {
11851185
//skip hibernate for the app if user does not have access on that
11861186
pipelineResponse := response[appKey]

pkg/bulkAction/service/BulkUpdateService_ent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"github.com/devtron-labs/devtron/pkg/bulkAction/bean"
77
)
88

9-
func (impl BulkUpdateServiceImpl) BulkHibernateV1(ctx context.Context, request *bean.BulkApplicationForEnvironmentPayload, token string, checkAuthForBulkActions func(token string, appObject string, envObject string) bool,
9+
func (impl BulkUpdateServiceImpl) BulkHibernateV1(ctx context.Context, request *bean.BulkApplicationForEnvironmentPayload, checkAuthForBulkActions func(token string, appObject string, envObject string) bool,
1010
userMetadata *bean2.UserMetadata) (*bean.BulkApplicationHibernateUnhibernateForEnvironmentResponse, error) {
1111
return nil, nil
1212
}

util/HttpUtil.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package util
1818

1919
import (
20+
"context"
2021
"crypto/tls"
2122
"errors"
2223
"fmt"
@@ -30,6 +31,8 @@ import (
3031
"time"
3132
)
3233

34+
const TokenKey = "token"
35+
3336
func ReadFromUrlWithRetry(url string) ([]byte, error) {
3437
var (
3538
err error
@@ -152,3 +155,8 @@ func getCertFileName() string {
152155
randomName := fmt.Sprintf("%v.crt", GetRandomName())
153156
return randomName
154157
}
158+
159+
func GetTokenFromContext(ctx context.Context) string {
160+
token, _ := ctx.Value(TokenKey).(string)
161+
return token
162+
}

0 commit comments

Comments
 (0)