mirror of
https://github.com/passbolt/go-passbolt.git
synced 2025-05-14 03:18:21 +00:00
Merge pull request #48 from passbolt/v5-resource-share
Some checks failed
Go / test (push) Has been cancelled
Some checks failed
Go / test (push) Has been cancelled
Implement sharing for metadata
This commit is contained in:
commit
7c15f80c7e
1 changed files with 27 additions and 0 deletions
|
@ -79,6 +79,33 @@ func ShareResource(ctx context.Context, c *api.Client, resourceID string, change
|
||||||
return fmt.Errorf("Validating Secret Data: %w", err)
|
return fmt.Errorf("Validating Secret Data: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if Metadata has not been shared yet then we need to do that
|
||||||
|
// we assume that if MetadataKeyType is not null that this is a v5 Resource and that the other field are fine
|
||||||
|
if resource.MetadataKeyType == api.MetadataKeyTypeUserKey {
|
||||||
|
metadata, err := GetResourceMetadata(ctx, c, resource, rType)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Get Metadata: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
metadataKeyID, metadataKeyType, publicMetadataKey, err := GetMetadataKey(ctx, c, true)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Get Metadata Key: %w", err)
|
||||||
|
}
|
||||||
|
resource.MetadataKeyID = metadataKeyID
|
||||||
|
resource.MetadataKeyType = metadataKeyType
|
||||||
|
|
||||||
|
encMetadata, err := c.EncryptMessageWithKey(publicMetadataKey, string(metadata))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Encrypt Metadata: %w", err)
|
||||||
|
}
|
||||||
|
resource.Metadata = encMetadata
|
||||||
|
|
||||||
|
resource, err = c.UpdateResource(ctx, resource.ID, *resource)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Update Resource Metadata to Shared key: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
simulationResult, err := c.SimulateShareResource(ctx, resourceID, shareRequest)
|
simulationResult, err := c.SimulateShareResource(ctx, resourceID, shareRequest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Simulate Share Resource: %w", err)
|
return fmt.Errorf("Simulate Share Resource: %w", err)
|
||||||
|
|
Loading…
Add table
Reference in a new issue