mirror of
https://github.com/passbolt/go-passbolt.git
synced 2025-05-10 09:58:21 +00:00
make update functions keep old value if passed ""
This commit is contained in:
parent
8381328ea9
commit
444a3d0583
2 changed files with 56 additions and 5 deletions
|
@ -84,9 +84,11 @@ func UpdateGroup(ctx context.Context, c *api.Client, groupID, name string, opera
|
||||||
}
|
}
|
||||||
|
|
||||||
var currentMemberships []api.GroupMembership
|
var currentMemberships []api.GroupMembership
|
||||||
|
var currentName string
|
||||||
for _, g := range groups {
|
for _, g := range groups {
|
||||||
if g.ID == groupID {
|
if g.ID == groupID {
|
||||||
currentMemberships = g.GroupUsers
|
currentMemberships = g.GroupUsers
|
||||||
|
currentName = g.Name
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,6 +102,10 @@ func UpdateGroup(ctx context.Context, c *api.Client, groupID, name string, opera
|
||||||
Secrets: []api.Secret{},
|
Secrets: []api.Secret{},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if name == "" {
|
||||||
|
request.Name = currentName
|
||||||
|
}
|
||||||
|
|
||||||
// Generate Group Membership changes based on current Group Memberships
|
// Generate Group Membership changes based on current Group Memberships
|
||||||
for _, operation := range operations {
|
for _, operation := range operations {
|
||||||
membership, err := getMembershipByUserID(currentMemberships, operation.UserID)
|
membership, err := getMembershipByUserID(currentMemberships, operation.UserID)
|
||||||
|
|
|
@ -147,21 +147,66 @@ func UpdateResource(ctx context.Context, c *api.Client, resourceID, name, userna
|
||||||
ID: resourceID,
|
ID: resourceID,
|
||||||
// This needs to be specified or it will revert to a legacy password
|
// This needs to be specified or it will revert to a legacy password
|
||||||
ResourceTypeID: resource.ResourceTypeID,
|
ResourceTypeID: resource.ResourceTypeID,
|
||||||
Name: name,
|
Name: resource.Name,
|
||||||
Username: username,
|
Username: resource.Username,
|
||||||
URI: uri,
|
URI: resource.URI,
|
||||||
|
}
|
||||||
|
|
||||||
|
if name != "" {
|
||||||
|
newResource.Name = name
|
||||||
|
}
|
||||||
|
if username != "" {
|
||||||
|
newResource.Username = username
|
||||||
|
}
|
||||||
|
if uri != "" {
|
||||||
|
newResource.URI = uri
|
||||||
}
|
}
|
||||||
|
|
||||||
var secretData string
|
var secretData string
|
||||||
switch rType.Slug {
|
switch rType.Slug {
|
||||||
case "password-string":
|
case "password-string":
|
||||||
|
newResource.Description = resource.Description
|
||||||
|
if description != "" {
|
||||||
newResource.Description = description
|
newResource.Description = description
|
||||||
|
}
|
||||||
|
if password != "" {
|
||||||
secretData = password
|
secretData = password
|
||||||
|
} else {
|
||||||
|
secret, err := c.GetSecret(ctx, resourceID)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Getting Secret: %w", err)
|
||||||
|
}
|
||||||
|
secretData, err = c.DecryptMessage(secret.Data)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Decrypting Secret: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
case "password-and-description":
|
case "password-and-description":
|
||||||
tmp := api.SecretDataTypePasswordAndDescription{
|
tmp := api.SecretDataTypePasswordAndDescription{
|
||||||
Password: password,
|
Password: password,
|
||||||
Description: description,
|
Description: description,
|
||||||
}
|
}
|
||||||
|
if password != "" || description != "" {
|
||||||
|
secret, err := c.GetSecret(ctx, resourceID)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Getting Secret: %w", err)
|
||||||
|
}
|
||||||
|
oldSecretData, err := c.DecryptMessage(secret.Data)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Decrypting Secret: %w", err)
|
||||||
|
}
|
||||||
|
var oldSecret api.SecretDataTypePasswordAndDescription
|
||||||
|
err = json.Unmarshal([]byte(oldSecretData), &oldSecret)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Parsing Decrypted Secret Data: %w", err)
|
||||||
|
}
|
||||||
|
if password == "" {
|
||||||
|
tmp.Password = oldSecret.Password
|
||||||
|
}
|
||||||
|
if description == "" {
|
||||||
|
tmp.Description = oldSecret.Description
|
||||||
|
}
|
||||||
|
}
|
||||||
res, err := json.Marshal(&tmp)
|
res, err := json.Marshal(&tmp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Marshalling Secret Data: %w", err)
|
return fmt.Errorf("Marshalling Secret Data: %w", err)
|
||||||
|
|
Loading…
Add table
Reference in a new issue