Skip to content
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

fix: Validation of resource request for app type both helm and devtron #5348

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

komalreddy3
Copy link
Contributor

Description

Fixes #

Checklist:

  • The title of the PR states what changed and the related issues number (used for the release note).
  • Does this PR requires documentation updates?
  • I've updated documentation as required by this PR.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have tested it for all user roles.
  • I have added all the required unit/api test cases.

Does this PR introduce a user-facing change?


Copy link

sonarcloud bot commented Jun 23, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
62.3% Duplication on New Code (required ≤ 3%)

See analysis details on SonarCloud

handler.logger.Errorw("error in validating resource request", "err", err)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
if !valid {
apiError := utils.ApiError{
InternalMessage: fmt.Sprintf("resource %s: \"%s\" doesn't exist", request.K8sRequest.ResourceIdentifier.GroupVersionKind.Kind, request.K8sRequest.ResourceIdentifier.Name),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract the error message into variable adn use that here

}
if !valid {
apiError := utils.ApiError{
InternalMessage: fmt.Sprintf("resource %s: \"%s\" doesn't exist", request.K8sRequest.ResourceIdentifier.GroupVersionKind.Kind, request.K8sRequest.ResourceIdentifier.Name),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

@@ -204,10 +240,52 @@ func (handler *K8sApplicationRestHandlerImpl) GetResource(w http.ResponseWriter,
//setting devtronAppIdentifier value in request
request.DevtronAppIdentifier = devtronAppIdentifier
request.ClusterId = request.DevtronAppIdentifier.ClusterId
appId := request.DevtronAppIdentifier.AppId
envId := request.DevtronAppIdentifier.EnvId
cdPipeline, err := handler.k8sApplicationService.GetPipelineByAppIdEnvId(appId, envId)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this method in k8's application service. this logic should be in pipeline service or pipeline config service.

}
common.WriteJsonResp(w, &apiError, nil, http.StatusBadRequest)
return
}
} else if request.DeploymentType == bean2.ArgoInstalledType {
//TODO Implement ResourceRequest Validation for ArgoCD Installed APPs From ResourceTree
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the below logic seems duplicate, please move it to seperate method which will handle this validation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants