Skip to content

Commit

Permalink
Simplify deprecation function
Browse files Browse the repository at this point in the history
The heavy lifting is down in the database function.
  • Loading branch information
jbygdell committed Nov 4, 2024
1 parent 446d782 commit cf34114
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 23 deletions.
23 changes: 1 addition & 22 deletions sda/cmd/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,30 +527,9 @@ func listC4ghHashes(c *gin.Context) {

func deprecateC4ghHash(c *gin.Context) {
keyHash := strings.TrimPrefix(c.Param("keyHash"), "/")

hashes, err := Conf.API.DB.ListKeyHashes()
if err != nil {
c.AbortWithStatusJSON(http.StatusInternalServerError, err.Error())

return
}
found := false
for _, h := range hashes {
if h.Hash == keyHash {
found = true

break
}
}
if !found {
c.AbortWithStatusJSON(http.StatusBadRequest, fmt.Errorf("%s not found", keyHash))

return
}

err = Conf.API.DB.DeprecateKeyHash(keyHash)
if err != nil {
c.AbortWithStatusJSON(http.StatusInternalServerError, err.Error())
c.AbortWithStatusJSON(http.StatusBadRequest, err.Error())

return
}
Expand Down
2 changes: 1 addition & 1 deletion sda/cmd/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1450,7 +1450,7 @@ func (suite *TestSuite) TestDeprecateC4ghHash() {
// a second time gives an error since the key is alreadu deprecated
resp2, err := client.Do(req)
assert.NoError(suite.T(), err)
assert.Equal(suite.T(), http.StatusInternalServerError, resp2.StatusCode)
assert.Equal(suite.T(), http.StatusBadRequest, resp2.StatusCode)
defer resp2.Body.Close()
}

Expand Down

0 comments on commit cf34114

Please sign in to comment.