diff --git a/controllers/storeSecrets.go b/controllers/storeSecrets.go index 20597a7..13e67d5 100644 --- a/controllers/storeSecrets.go +++ b/controllers/storeSecrets.go @@ -141,7 +141,7 @@ func StoreSecret(c *gin.Context) { return } - c.JSON(http.StatusOK, gin.H{"message": "secret stored successfully", "data": s}) + c.JSON(http.StatusOK, gin.H{"message": "secret stored successfully", "data": models.SecretRestricted(s)}) } /* diff --git a/models/secret.go b/models/secret.go index f9dfb12..7beb8a9 100644 --- a/models/secret.go +++ b/models/secret.go @@ -25,6 +25,16 @@ type Secret struct { Secret string `db:"Secret" json:"secret"` } +// SecretRestricted is for when we want to output a Secret but not the protected information +type SecretRestricted struct { + SecretId int `db:"SecretId" json:"secretId"` + SafeId int `db:"SafeId" json:"safeId"` + DeviceName string `db:"DeviceName" json:"deviceName"` + DeviceCategory string `db:"DeviceCategory" json:"deviceCategory"` + UserName string `db:"UserName" json:"userName"` + Secret string `db:"Secret" json:"-"` +} + // Used for querying all secrets the user has access to // Since there are some ambiguous column names (eg UserName is present in both users and secrets table), the order of fields in this struct matters type UserSecret struct { @@ -50,12 +60,13 @@ func (s *Secret) SaveSecret() (*Secret, error) { if err != nil { log.Printf("StoreSecret error executing sql record : '%s'\n", err) return s, err - } else { - affected, _ := result.RowsAffected() - id, _ := result.LastInsertId() - log.Printf("StoreSecret insert returned result id '%d' affecting %d row(s).\n", id, affected) } + affected, _ := result.RowsAffected() + id, _ := result.LastInsertId() + s.SecretId = int(id) + log.Printf("StoreSecret insert returned result id '%d' affecting %d row(s).\n", id, affected) + return s, nil }