This commit is contained in:
@@ -141,7 +141,7 @@ func StoreSecret(c *gin.Context) {
|
|||||||
return
|
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)})
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -25,6 +25,16 @@ type Secret struct {
|
|||||||
Secret string `db:"Secret" json:"secret"`
|
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
|
// 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
|
// 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 {
|
type UserSecret struct {
|
||||||
@@ -50,12 +60,13 @@ func (s *Secret) SaveSecret() (*Secret, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("StoreSecret error executing sql record : '%s'\n", err)
|
log.Printf("StoreSecret error executing sql record : '%s'\n", err)
|
||||||
return s, 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
|
return s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user