Skip to content

Commit f71781e

Browse files
fixed response and rbac (#959)
Co-authored-by: Manish Agrawal <[email protected]>
1 parent c1da2a1 commit f71781e

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

api/restHandler/AppStoreRestHandler.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,16 @@ func (handler *AppStoreRestHandlerImpl) TriggerChartSyncManual(w http.ResponseWr
478478
return
479479
}
480480

481-
//Chart repo sync error handling
482-
TriggerResult := handler.appStoreService.TriggerChartSyncManual()
483-
common.WriteJsonResp(w, nil, TriggerResult, http.StatusOK)
481+
// RBAC enforcer applying
482+
token := r.Header.Get("token")
483+
if ok := handler.enforcer.Enforce(token, rbac.ResourceGlobal, rbac.ActionCreate, "*"); !ok {
484+
common.WriteJsonResp(w, errors.New("unauthorized"), nil, http.StatusForbidden)
485+
return
486+
}
487+
err2 := handler.appStoreService.TriggerChartSyncManual()
488+
if err2 != nil {
489+
common.WriteJsonResp(w, err2, nil, http.StatusInternalServerError)
490+
} else {
491+
common.WriteJsonResp(w, nil, map[string]string{"status": "ok"}, http.StatusOK)
492+
}
484493
}

api/router/AppStoreRouter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func (router AppStoreRouterImpl) initAppStoreRouter(configRouter *mux.Router) {
9696
Methods("GET")
9797

9898
configRouter.Path("/repo/sync-charts").
99-
HandlerFunc(router.appStoreRestHandler.TriggerChartSyncManual).Methods("GET")
99+
HandlerFunc(router.appStoreRestHandler.TriggerChartSyncManual).Methods("POST")
100100
configRouter.Path("/repo/list").
101101
HandlerFunc(router.appStoreRestHandler.GetChartRepoList).Methods("GET")
102102
configRouter.Path("/repo/{id}").

0 commit comments

Comments
 (0)