diff --git a/sda/cmd/api/api.go b/sda/cmd/api/api.go index 649a7231e..8eb2f004a 100644 --- a/sda/cmd/api/api.go +++ b/sda/cmd/api/api.go @@ -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 } diff --git a/sda/cmd/api/api_test.go b/sda/cmd/api/api_test.go index bab7e247d..cdbeb75ed 100644 --- a/sda/cmd/api/api_test.go +++ b/sda/cmd/api/api_test.go @@ -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() }