Skip to content

Commit

Permalink
Add missing error handlings
Browse files Browse the repository at this point in the history
  • Loading branch information
VoigtS committed Mar 15, 2024
1 parent d4c3635 commit ddc1bca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/users/api-spec-resources.md
Expand Up @@ -775,6 +775,7 @@ The response is a JSON of the commitment including the following fields that ide
```
### POST /v1/domains/:id/projects/:id/transfer-commitment/:id?token=:token
Transfers the commitment from a source project to a target project.
Requires a project-admin token.
This endpoint receives the target project ID, but the commitment ID from the source project.
Requires a generated token from the API: `/v1/domains/:id/projects/:id/commitments/:id/start-transfer`.
On success the API clears the `transfer_token` and `transfer_status` from the commitment.
Expand Down
6 changes: 6 additions & 0 deletions internal/api/commitment.go
Expand Up @@ -463,10 +463,12 @@ func (p *v1Provider) StartCommitmentTransfer(w http.ResponseWriter, r *http.Requ
httpapi.IdentifyEndpoint(r, "/v1/domains/:id/projects/:id/commitments/:id/start-transfer")
token := p.CheckToken(r)
if !token.Require(w, "project:edit") {
http.Error(w, "insufficient access rights.", http.StatusForbidden)
return
}
dbDomain := p.FindDomainFromRequest(w, r)
if dbDomain == nil {
http.Error(w, "domain not found.", http.StatusNotFound)
return
}
dbProject := p.FindProjectFromRequest(w, r, dbDomain)
Expand All @@ -478,6 +480,7 @@ func (p *v1Provider) StartCommitmentTransfer(w http.ResponseWriter, r *http.Requ
Request limesresources.Commitment `json:"commitment"`
}
if !RequireJSON(w, r, &parseTarget) {
http.Error(w, "json not parsable.", http.StatusBadRequest)
return
}
req := parseTarget.Request
Expand Down Expand Up @@ -590,6 +593,7 @@ func (p *v1Provider) TransferCommitment(w http.ResponseWriter, r *http.Request)
httpapi.IdentifyEndpoint(r, "/v1/domains/:id/projects/:id/transfer-commitment/:id?token=:token")
token := p.CheckToken(r)
if !token.Require(w, "project:edit") {
http.Error(w, "insufficient access rights.", http.StatusForbidden)
return
}
transferToken := r.URL.Query().Get("token")
Expand All @@ -598,10 +602,12 @@ func (p *v1Provider) TransferCommitment(w http.ResponseWriter, r *http.Request)
}
dbDomain := p.FindDomainFromRequest(w, r)
if dbDomain == nil {
http.Error(w, "domain not found.", http.StatusNotFound)
return
}
targetProject := p.FindProjectFromRequest(w, r, dbDomain)
if targetProject == nil {
http.Error(w, "project not found.", http.StatusNotFound)
return
}

Expand Down

0 comments on commit ddc1bca

Please sign in to comment.