Skip to content

fix: rest handler missing return statements #6545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions api/appStore/deployment/AppStoreDeploymentRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ func (handler AppStoreDeploymentRestHandlerImpl) UpdateProjectHelmApp(w http.Res
if err != nil {
handler.Logger.Errorw("error in decoding app id", "err", err)
common.WriteJsonResp(w, err, "error in decoding app id", http.StatusBadRequest)
return
}
// this rbac object checks that whether user have permission to change current project.
rbacObjectForCurrentProject, rbacObjectForCurrentProject2 := handler.enforcerUtilHelm.GetHelmObjectByClusterIdNamespaceAndAppName(appIdentifier.ClusterId, appIdentifier.Namespace, appIdentifier.ReleaseName)
Expand All @@ -555,6 +556,7 @@ func (handler AppStoreDeploymentRestHandlerImpl) UpdateProjectHelmApp(w http.Res
if err != nil {
handler.Logger.Errorw("service err, InstalledAppId", "err", err, "InstalledAppId", request.InstalledAppId)
common.WriteJsonResp(w, fmt.Errorf("Unable to fetch installed app details"), nil, http.StatusBadRequest)
return
}
if installedApp.IsVirtualEnvironment {
rbacObjectForCurrentProject, _ := handler.enforcerUtilHelm.GetAppRBACNameByInstalledAppId(request.InstalledAppId)
Expand All @@ -580,8 +582,10 @@ func (handler AppStoreDeploymentRestHandlerImpl) UpdateProjectHelmApp(w http.Res
if err != nil {
handler.Logger.Errorw("error in updating project for helm apps", "err", err)
common.WriteJsonResp(w, err, "error in updating project", http.StatusBadRequest)
return
} else {
handler.Logger.Errorw("Helm App project update")
common.WriteJsonResp(w, nil, "Project Updated", http.StatusOK)
return
}
}
1 change: 1 addition & 0 deletions api/appStore/deployment/CommonDeploymentRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ func (handler *CommonDeploymentRestHandlerImpl) RollbackApplication(w http.Respo
appOfferingMode, installedAppDto, err := handler.getAppOfferingMode(installedAppId, *request.HAppId)
if err != nil {
common.WriteJsonResp(w, err, "bad request", http.StatusBadRequest)
return
}
installedAppDto.UserId = userId
//rbac block starts from here
Expand Down
1 change: 1 addition & 0 deletions api/auth/user/UserAuthHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func (handler UserAuthHandlerImpl) LoginHandler(w http.ResponseWriter, r *http.R
if err != nil {
handler.logger.Errorw("request err, LoginHandler", "err", err, "payload", up)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}

err = handler.validator.Struct(up)
Expand Down
2 changes: 2 additions & 0 deletions api/helm-app/HelmAppRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ func (handler *HelmAppRestHandlerImpl) Hibernate(w http.ResponseWriter, r *http.
appType, err = strconv.Atoi(appTypeString)
if err != nil {
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
}

Expand Down Expand Up @@ -282,6 +283,7 @@ func (handler *HelmAppRestHandlerImpl) UnHibernate(w http.ResponseWriter, r *htt
appType, err = strconv.Atoi(appTypeString)
if err != nil {
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
}
token := r.Header.Get("token")
Expand Down
1 change: 1 addition & 0 deletions api/k8s/application/k8sApplicationRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,7 @@ func (handler *K8sApplicationRestHandlerImpl) requestValidationAndRBAC(w http.Re
if err != nil {
handler.logger.Errorw(bean2.AppIdDecodingError, "err", err, "appIdentifier", request.AppIdentifier)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
valid, err := handler.argoApplicationReadService.ValidateArgoResourceRequest(r.Context(), appIdentifier, request.K8sRequest)
if err != nil || !valid {
Expand Down
1 change: 1 addition & 0 deletions api/restHandler/BatchOperationRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ func (handler BatchOperationRestHandlerImpl) Operate(w http.ResponseWriter, r *h

if workflow.Destination.App == nil || len(*workflow.Destination.App) == 0 {
common.WriteJsonResp(w, errors.New("app name cannot be empty"), nil, http.StatusBadRequest)
return
}
rbacString := handler.enforcerUtil.GetProjectAdminRBACNameBYAppName(*workflow.Destination.App)
if ok := handler.enforcer.Enforce(token, casbin.ResourceApplications, casbin.ActionCreate, rbacString); !ok {
Expand Down
7 changes: 7 additions & 0 deletions api/restHandler/BulkUpdateRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,22 +181,26 @@ func (handler BulkUpdateRestHandlerImpl) GetImpactedAppsName(w http.ResponseWrit
ok := handler.CheckAuthForImpactedObjects(deploymentTemplateImpactedApp.AppId, deploymentTemplateImpactedApp.EnvId, appResourceObjects, envResourceObjects, token)
if !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), "Unauthorized User", http.StatusForbidden)
return
}
}
for _, configMapImpactedApp := range impactedApps.ConfigMap {
ok := handler.CheckAuthForImpactedObjects(configMapImpactedApp.AppId, configMapImpactedApp.EnvId, appResourceObjects, envResourceObjects, token)
if !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), "Unauthorized User", http.StatusForbidden)
return
}
}
for _, secretImpactedApp := range impactedApps.Secret {
ok := handler.CheckAuthForImpactedObjects(secretImpactedApp.AppId, secretImpactedApp.EnvId, appResourceObjects, envResourceObjects, token)
if !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), "Unauthorized User", http.StatusForbidden)
return
}
}
common.WriteJsonResp(w, err, impactedApps, http.StatusOK)
}

func (handler BulkUpdateRestHandlerImpl) CheckAuthForBulkUpdate(AppId int, EnvId int, AppName string, rbacObjects map[int]string, token string) bool {
resourceName := rbacObjects[AppId]
if ok := handler.enforcer.Enforce(token, casbin.ResourceApplications, casbin.ActionUpdate, resourceName); !ok {
Expand Down Expand Up @@ -236,18 +240,21 @@ func (handler BulkUpdateRestHandlerImpl) BulkUpdate(w http.ResponseWriter, r *ht
ok := handler.CheckAuthForBulkUpdate(deploymentTemplateImpactedApp.AppId, deploymentTemplateImpactedApp.EnvId, deploymentTemplateImpactedApp.AppName, rbacObjects, token)
if !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), "Unauthorized User", http.StatusForbidden)
return
}
}
for _, configMapImpactedApp := range impactedApps.ConfigMap {
ok := handler.CheckAuthForBulkUpdate(configMapImpactedApp.AppId, configMapImpactedApp.EnvId, configMapImpactedApp.AppName, rbacObjects, token)
if !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), "Unauthorized User", http.StatusForbidden)
return
}
}
for _, secretImpactedApp := range impactedApps.Secret {
ok := handler.CheckAuthForBulkUpdate(secretImpactedApp.AppId, secretImpactedApp.EnvId, secretImpactedApp.AppName, rbacObjects, token)
if !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), "Unauthorized User", http.StatusForbidden)
return
}
}

Expand Down
1 change: 1 addition & 0 deletions api/restHandler/GitOpsConfigRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ func (impl GitOpsConfigRestHandlerImpl) GitOpsValidator(w http.ResponseWriter, r
if err != nil && !errors.Is(err, moduleErr.ModuleNotFoundError) {
impl.logger.Errorw("error in getting argo module", "error", err)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
detailedErrorGitOpsConfigResponse := impl.gitOpsConfigService.GitOpsValidateDryRun(argoModule.IsInstalled(), &bean)
common.WriteJsonResp(w, nil, detailedErrorGitOpsConfigResponse, http.StatusOK)
Expand Down
7 changes: 7 additions & 0 deletions api/restHandler/ImageScanRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ func (impl ImageScanRestHandlerImpl) FetchExecutionDetail(w http.ResponseWriter,
if err != nil {
impl.logger.Errorw("request err, FetchExecutionDetail", "err", err, "imageScanDeployInfoIdS", imageScanDeployInfoIdS)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
}
artifactIdS := v.Get("artifactId")
Expand All @@ -206,6 +207,7 @@ func (impl ImageScanRestHandlerImpl) FetchExecutionDetail(w http.ResponseWriter,
if err != nil {
impl.logger.Errorw("request err, FetchExecutionDetail", "err", err, "artifactIdS", artifactIdS)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
}
appIds := v.Get("appId")
Expand All @@ -214,6 +216,7 @@ func (impl ImageScanRestHandlerImpl) FetchExecutionDetail(w http.ResponseWriter,
if err != nil {
impl.logger.Errorw("request err, FetchExecutionDetail", "err", err, "appIds", appIds)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
}
envIds := v.Get("envId")
Expand All @@ -222,6 +225,7 @@ func (impl ImageScanRestHandlerImpl) FetchExecutionDetail(w http.ResponseWriter,
if err != nil {
impl.logger.Errorw("request err, FetchExecutionDetail", "err", err, "envIds", envIds)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
}
image := v.Get("image")
Expand Down Expand Up @@ -266,6 +270,7 @@ func (impl ImageScanRestHandlerImpl) FetchExecutionDetail(w http.ResponseWriter,
}
} else {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), "Unauthorized User", http.StatusForbidden)
return
}
//RBAC
} else {
Expand All @@ -285,6 +290,7 @@ func (impl ImageScanRestHandlerImpl) FetchMinScanResultByAppIdAndEnvId(w http.Re
if err != nil {
impl.logger.Errorw("request err, FetchMinScanResultByAppIdAndEnvId", "err", err, "appIds", appIds)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
request.AppId = appId
}
Expand All @@ -294,6 +300,7 @@ func (impl ImageScanRestHandlerImpl) FetchMinScanResultByAppIdAndEnvId(w http.Re
if err != nil {
impl.logger.Errorw("request err, FetchMinScanResultByAppIdAndEnvId", "err", err, "envIds", envIds)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
request.EnvId = envId
}
Expand Down
1 change: 1 addition & 0 deletions api/restHandler/PolicyRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ func (impl PolicyRestHandlerImpl) GetPolicy(w http.ResponseWriter, r *http.Reque
if err != nil {
impl.logger.Errorw("request err, GetPolicy", "err", err, "id", id)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
req.Id = ids
}
Expand Down
1 change: 1 addition & 0 deletions api/restHandler/ReleaseMetricsRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func (impl *ReleaseMetricsRestHandlerImpl) ResetDataForAllAppEnvironment(w http.
if err != nil {
impl.logger.Errorw("service err, ResetDataForAllAppEnvironment", "err", err)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
for _, pipeline := range pipelines {
appRbacObject := impl.enforcerUtil.GetAppRBACNameByAppId(pipeline.AppId)
Expand Down
1 change: 1 addition & 0 deletions api/restHandler/WebhookEventHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,6 @@ func (impl WebhookEventHandlerImpl) OnWebhookEvent(w http.ResponseWriter, r *htt
if err != nil {
impl.logger.Errorw("Error while handling webhook in git-sensor", "err", err)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
}
2 changes: 2 additions & 0 deletions api/restHandler/app/appList/AppListingRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ func (handler AppListingRestHandlerImpl) FetchAppsByEnvironmentV2(w http.Respons
if err != nil {
handler.logger.Errorw("service err, FetchAppsByEnvironment", "err", err, "payload", fetchAppListingRequest)
common.WriteJsonResp(w, err, "", http.StatusInternalServerError)
return
}
}

Expand All @@ -370,6 +371,7 @@ func (handler AppListingRestHandlerImpl) FetchAppsByEnvironmentV2(w http.Respons
if err != nil {
handler.logger.Errorw("service err, FetchAppsByEnvironment", "err", err, "payload", fetchAppListingRequest)
common.WriteJsonResp(w, err, "", http.StatusInternalServerError)
return
}

appContainerResponse := AppView.AppContainerResponse{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -876,8 +876,10 @@ func (handler *PipelineConfigRestHandlerImpl) GetCiPipelineMin(w http.ResponseWr
if util.IsErrNoRows(err) {
err = &util.ApiError{Code: "404", HttpStatusCode: http.StatusNotFound, UserMessage: "no data found"}
common.WriteJsonResp(w, err, nil, http.StatusOK)
return
} else {
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
}
common.WriteJsonResp(w, nil, ciPipelines, http.StatusOK)
Expand Down
Loading