change some error messages
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-04-03 16:50:23 +10:00
parent 3407dfe4fe
commit 4529663864
3 changed files with 11 additions and 9 deletions

View File

@@ -27,7 +27,8 @@ func StoreSecret(c *gin.Context) {
return
}
log.Printf("StoreSecret received JSON input '%v'\n", input)
// Don't log this since it contains plaintext secrets
//log.Printf("StoreSecret received JSON input '%v'\n", input)
// Populate fields
s := models.Secret{}
@@ -39,6 +40,7 @@ func StoreSecret(c *gin.Context) {
if input.RoleId != 0 {
s.RoleId = input.RoleId
} else {
log.Printf("StoreSecret setting default RoleId of 1\n")
s.RoleId = 1
}
@@ -64,13 +66,13 @@ func StoreSecret(c *gin.Context) {
s.Secret = input.SecretValue
_, err = s.EncryptSecret()
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"Error encrypting secret": err.Error()})
c.JSON(http.StatusBadRequest, gin.H{"error": "StoreSecret error encrypting secret : " + err.Error()})
return
}
_, err = s.SaveSecret()
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"Error saving secret": err.Error()})
c.JSON(http.StatusBadRequest, gin.H{"error": "StoreSecret error saving secret : " + err.Error()})
return
}
@@ -82,7 +84,7 @@ func UpdateSecret(c *gin.Context) {
var input StoreInput
if err := c.ShouldBindJSON(&input); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
c.JSON(http.StatusBadRequest, gin.H{"error": "UpdateSecret error binding to input JSON : " + err.Error()})
return
}
@@ -96,7 +98,7 @@ func UpdateSecret(c *gin.Context) {
}
// Verify that the user role is not readonly
if u.ReadOnly {
c.JSON(http.StatusForbidden, gin.H{"error": "user role does not permit updates"})
c.JSON(http.StatusForbidden, gin.H{"error": "UpdateSecret user role does not permit updates"})
return
}
@@ -144,13 +146,13 @@ func UpdateSecret(c *gin.Context) {
s.Secret = input.SecretValue
_, err = s.EncryptSecret()
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"Error encrypting secret": err.Error()})
c.JSON(http.StatusBadRequest, gin.H{"error": "UpdateSecret error encrypting secret : " + err.Error()})
return
}
_, err = s.UpdateSecret()
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"Error saving secret": err.Error()})
c.JSON(http.StatusBadRequest, gin.H{"error": "UpdateSecret error saving secret : " + err.Error()})
return
}