Skip to content

Commit

Permalink
tmp: temporary fixes to api/hash
Browse files Browse the repository at this point in the history
- api/key/hashed sends 200 if key is already there
- linting stuff
  • Loading branch information
MalinAhlberg committed Oct 9, 2024
1 parent 3792697 commit ecec008
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
11 changes: 7 additions & 4 deletions sda/cmd/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,10 +409,13 @@ func addHashedKey(c *gin.Context) {
}

err = Conf.API.DB.AddKeyHash(keyhash.Hash, keyhash.Description)
if err != nil {
c.AbortWithStatusJSON(http.StatusInternalServerError, err.Error())
return
}
if err != nil {
log.Warnf("aborting! not happy %v", err)
c.AbortWithStatusJSON(http.StatusInternalServerError, err.Error())

return
}

log.Warnf("Is happy")
c.Status(http.StatusOK)
}
10 changes: 10 additions & 0 deletions sda/internal/database/db_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -747,10 +747,20 @@ func (dbs *SDAdb) addKeyHash(keyHash, keyDescription string) error {
if err != nil {
return err
}
var exists bool
err = db.QueryRow("SELECT EXISTS(SELECT 1 FROM sda.encryption_keys WHERE key_hash=$1 AND description=$2)", keyHash, keyDescription).Scan(&exists)
if err != nil {
return err
}
if exists {
return nil
}

if rowsAffected, _ := result.RowsAffected(); rowsAffected == 0 {

return errors.New("something went wrong with the query zero rows were changed")
}

return nil
}

Expand Down

0 comments on commit ecec008

Please sign in to comment.