improve checks
This commit is contained in:
@@ -41,6 +41,19 @@ func StoreSecret(c *gin.Context) {
|
||||
s.RoleId = 1
|
||||
}
|
||||
|
||||
// If this secret already exists in the database then generate an error
|
||||
checkExists, err := models.GetSecrets(&s)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
if len(checkExists) > 0 {
|
||||
fmt.Printf("StoreSecret not storing secret with '%d' already matching secrets.\n", len(checkExists))
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "StoreSecret attempting to store secret already defined. API calls for update/delete don't yet exist"})
|
||||
return
|
||||
}
|
||||
|
||||
// Encrypt secret
|
||||
s.Secret = input.SecretValue
|
||||
_, err = s.EncryptSecret()
|
||||
@@ -49,14 +62,6 @@ func StoreSecret(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// This is just here for testing to make sure that decryption works
|
||||
/*
|
||||
_, err = s.DecryptSecret()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"Error decrypting secret": err.Error()})
|
||||
return
|
||||
}
|
||||
*/
|
||||
_, err = s.SaveSecret()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"Error saving secret": err.Error()})
|
||||
|
Reference in New Issue
Block a user