test storesecret update
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -162,7 +162,7 @@ func retrieveSpecifiedSecret(s *models.Secret, c *gin.Context) {
|
||||
return
|
||||
}
|
||||
*/
|
||||
|
||||
var UserId int
|
||||
var results []models.Secret
|
||||
/*
|
||||
user_id, err := token.ExtractTokenID(c)
|
||||
@@ -171,10 +171,16 @@ func retrieveSpecifiedSecret(s *models.Secret, c *gin.Context) {
|
||||
return
|
||||
}
|
||||
*/
|
||||
user_id := c.GetInt("user-id")
|
||||
// Get userId that we stored in the context earlier
|
||||
if val, ok := c.Get("user-id"); !ok {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "error determining user"})
|
||||
return
|
||||
} else {
|
||||
UserId = val.(int)
|
||||
}
|
||||
|
||||
// Work out which safe to query for this user if the safe was not specified
|
||||
safeList, err := models.UserGetSafesAllowed(int(user_id))
|
||||
safeList, err := models.UserGetSafesAllowed(int(UserId))
|
||||
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "error determining user safes"})
|
||||
@@ -189,7 +195,7 @@ func retrieveSpecifiedSecret(s *models.Secret, c *gin.Context) {
|
||||
return
|
||||
} else if len(safeList) == 1 {
|
||||
s.SafeId = safeList[0].SafeId
|
||||
results, err = models.SecretsGetMultipleSafes(s, []int{s.SafeId})
|
||||
results, err = models.SecretsGetFromMultipleSafes(s, []int{s.SafeId})
|
||||
} else {
|
||||
// Create a list of all the safes this user can access
|
||||
var safeIds []int
|
||||
@@ -197,7 +203,7 @@ func retrieveSpecifiedSecret(s *models.Secret, c *gin.Context) {
|
||||
safeIds = append(safeIds, safe.SafeId)
|
||||
}
|
||||
|
||||
results, err = models.SecretsGetMultipleSafes(s, safeIds)
|
||||
results, err = models.SecretsGetFromMultipleSafes(s, safeIds)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
@@ -31,8 +31,8 @@ type SecretInput struct {
|
||||
SecretValue string `json:"secretValue"`
|
||||
}
|
||||
|
||||
func FindSafeId(UserId int, input SecretInput) (int, error) {
|
||||
|
||||
// CheckSafeAllowed returns the SafeId of an allowed safe containing the secret specified by SafeId or SafeName
|
||||
func CheckSafeAllowed(UserId int, input SecretInput) (int, error) {
|
||||
// Check which safes a user is allowed to access
|
||||
allowedSafes, err := models.UserGetSafesAllowed(UserId)
|
||||
if err != nil {
|
||||
@@ -122,7 +122,9 @@ func StoreSecret(c *gin.Context) {
|
||||
//log.Printf("user_id: %v\n", user_id)
|
||||
}
|
||||
|
||||
safeId, err := FindSafeId(UserId, input)
|
||||
// TODO replace FindSafeId with models.SecretsGetAllowed()
|
||||
|
||||
safeId, err := CheckSafeAllowed(UserId, input)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
@@ -130,7 +132,11 @@ func StoreSecret(c *gin.Context) {
|
||||
s.SafeId = safeId
|
||||
|
||||
// If this secret already exists in the database then generate an error
|
||||
checkExists, err := models.GetSecrets(&s, false)
|
||||
//checkExists, err := models.GetSecrets(&s, false)
|
||||
checkExists, err := models.SecretsGetFromMultipleSafes(&s, []int{safeId})
|
||||
|
||||
// TODO replace GetSecrets with SecretsGetFromMultipleSafes
|
||||
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
|
Reference in New Issue
Block a user