Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
fix: Handle upstream not found (#5977) (#5994)
Browse files Browse the repository at this point in the history
* fix: Handle upstram not found (#5977)

Signed-off-by: RealAnna <anna.reale@dynatrace.com>

* fix: added git error handling as bad request

Signed-off-by: RealAnna <anna.reale@dynatrace.com>

* fix: added 500 back

Signed-off-by: RealAnna <anna.reale@dynatrace.com>

* fix: added generic git error, changed handler to PUT

Signed-off-by: RealAnna <anna.reale@dynatrace.com>
  • Loading branch information
RealAnna committed Nov 18, 2021
1 parent b2e9960 commit 77240d4
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
4 changes: 4 additions & 0 deletions configuration-service/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ const StageDoesNotExistErrorMsg = "Stage does not exist"
const ServiceDoesNotExistErrorMsg = "Service does not exist"

const CannotCheckOutBranchErrorMsg = "Could not check out branch"
const GitURLNotFound = "Repository not found"
const HostNotFound = "host"
const GitError = "exit status 128"
const WrongToken = "access token"

const CannotAddResourceErrorMsg = "Could not add resource"
const CannotUpdateResourceErrorMsg = "Could not update resource"
13 changes: 7 additions & 6 deletions configuration-service/common/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,18 @@ func (g *Git) UpdateOrCreateOrigin(project string) error {
// create new remote origin in case updating was not possible
_, err := g.Executor.ExecuteCommand("git", []string{"remote", "add", "origin", repoURI}, projectConfigPath)
if err != nil {
err = removeRemoteOrigin(project)
if err != nil {
return err
err2 := removeRemoteOrigin(project)
if err2 != nil {
return err2
}

return obfuscateErrorMessage(err, credentials)
}
}
if err := setUpstreamsAndPush(project, credentials, repoURI); err != nil {
err = removeRemoteOrigin(project)
if err != nil {
return err
err2 := removeRemoteOrigin(project)
if err2 != nil {
return err2
}
return fmt.Errorf("failed to set upstream: %v", err)
}
Expand Down
14 changes: 13 additions & 1 deletion configuration-service/deploy/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,19 @@ spec:
serviceAccountName: keptn-configuration-service
containers:
- name: configuration-service
image: keptn/configuration-service:0.10.1-dev
livenessProbe:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 10
periodSeconds: 5
readinessProbe:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 10
periodSeconds: 5
image: keptn/configuration-service:latest
env:
- name: PREFIX_PATH
value: ""
Expand Down
13 changes: 9 additions & 4 deletions configuration-service/handlers/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,20 @@ func PutProjectProjectNameHandlerFunc(params project.PutProjectProjectNameParams
// TODO: use git library.
// until we do not use a propper git library it is hard/not possible to
// determine the correct error cases, so we need to rely on the output of the command
if strings.Contains(err.Error(), "Authentication failed") {
if strings.Contains(err.Error(), common.GitURLNotFound) || strings.Contains(err.Error(), common.HostNotFound) {
logger.Error("Invalid URL detected")
return project.NewPutProjectProjectNameBadRequest().WithPayload(&models.Error{Code: http.StatusNotFound, Message: swag.String(err.Error())})
}
if strings.Contains(err.Error(), "Authentication failed") || strings.Contains(err.Error(), common.WrongToken) || strings.Contains(err.Error(), common.GitError) {
logger.Error("Authentication error detected")
return project.NewPostProjectDefault(http.StatusFailedDependency).WithPayload(&models.Error{Code: http.StatusFailedDependency, Message: swag.String(err.Error())})
return project.NewPutProjectProjectNameBadRequest().WithPayload(&models.Error{Code: http.StatusFailedDependency, Message: swag.String(err.Error())})
}
return project.NewPostProjectDefault(http.StatusInternalServerError).WithPayload(&models.Error{Code: http.StatusInternalServerError, Message: swag.String(err.Error())})

return project.NewPutProjectProjectNameDefault(http.StatusInternalServerError).WithPayload(&models.Error{Code: http.StatusInternalServerError, Message: swag.String(err.Error())})
}
}
} else {
return project.NewPostProjectBadRequest().WithPayload(&models.Error{Code: http.StatusBadRequest, Message: swag.String(common.ProjectDoesNotExistErrorMsg)})
return project.NewPutProjectProjectNameDefault(http.StatusBadRequest).WithPayload(&models.Error{Code: http.StatusBadRequest, Message: swag.String(common.ProjectDoesNotExistErrorMsg)})
}
return project.NewPutProjectProjectNameNoContent()
}
Expand Down

0 comments on commit 77240d4

Please sign in to comment.