mirror of
https://github.com/passbolt/go-passbolt.git
synced 2025-05-09 09:48:20 +00:00
move api package to sub folder
This commit is contained in:
parent
ff29c83d56
commit
ff1be787f2
23 changed files with 61 additions and 61 deletions
|
@ -1,4 +1,4 @@
|
||||||
package passbolt
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
|
@ -1,4 +1,4 @@
|
||||||
package passbolt
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
|
@ -1,4 +1,4 @@
|
||||||
package passbolt
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
|
@ -1,4 +1,4 @@
|
||||||
package passbolt
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
|
@ -1,4 +1,4 @@
|
||||||
package passbolt
|
package api
|
||||||
|
|
||||||
import "github.com/ProtonMail/gopenpgp/v2/helper"
|
import "github.com/ProtonMail/gopenpgp/v2/helper"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package passbolt
|
package api
|
||||||
|
|
||||||
import "errors"
|
import "errors"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package passbolt
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
|
@ -1,4 +1,4 @@
|
||||||
package passbolt
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
|
@ -1,4 +1,4 @@
|
||||||
package passbolt
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
|
@ -1,4 +1,4 @@
|
||||||
package passbolt
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
|
@ -1,4 +1,4 @@
|
||||||
package passbolt
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
|
@ -1,4 +1,4 @@
|
||||||
package passbolt
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
|
@ -1,4 +1,4 @@
|
||||||
package passbolt
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
|
@ -1,4 +1,4 @@
|
||||||
package passbolt
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
|
@ -1,4 +1,4 @@
|
||||||
package passbolt
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
|
@ -1,4 +1,4 @@
|
||||||
package passbolt
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
|
@ -1,4 +1,4 @@
|
||||||
package passbolt
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
|
@ -1,4 +1,4 @@
|
||||||
package passbolt
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
|
@ -1,4 +1,4 @@
|
||||||
package passbolt
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
|
@ -1,4 +1,4 @@
|
||||||
package passbolt
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
|
@ -3,31 +3,31 @@ package helper
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/speatzle/go-passbolt"
|
"github.com/speatzle/go-passbolt/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CreateFolder(ctx context.Context, c *passbolt.Client, folderParentID, name string) (string, error) {
|
func CreateFolder(ctx context.Context, c *api.Client, folderParentID, name string) (string, error) {
|
||||||
f, err := c.CreateFolder(ctx, passbolt.Folder{
|
f, err := c.CreateFolder(ctx, api.Folder{
|
||||||
Name: name,
|
Name: name,
|
||||||
FolderParentID: folderParentID,
|
FolderParentID: folderParentID,
|
||||||
})
|
})
|
||||||
return f.ID, err
|
return f.ID, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetFolder(ctx context.Context, c *passbolt.Client, folderID string) (string, string, error) {
|
func GetFolder(ctx context.Context, c *api.Client, folderID string) (string, string, error) {
|
||||||
f, err := c.GetFolder(ctx, folderID)
|
f, err := c.GetFolder(ctx, folderID)
|
||||||
return f.FolderParentID, f.Name, err
|
return f.FolderParentID, f.Name, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateFolder(ctx context.Context, c *passbolt.Client, folderID, name string) error {
|
func UpdateFolder(ctx context.Context, c *api.Client, folderID, name string) error {
|
||||||
_, err := c.UpdateFolder(ctx, folderID, passbolt.Folder{Name: name})
|
_, err := c.UpdateFolder(ctx, folderID, api.Folder{Name: name})
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeleteFolder(ctx context.Context, c *passbolt.Client, folderID string) error {
|
func DeleteFolder(ctx context.Context, c *api.Client, folderID string) error {
|
||||||
return c.DeleteFolder(ctx, folderID)
|
return c.DeleteFolder(ctx, folderID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func MoveFolder(ctx context.Context, c *passbolt.Client, folderID, folderParentID string) error {
|
func MoveFolder(ctx context.Context, c *api.Client, folderID, folderParentID string) error {
|
||||||
return c.MoveFolder(ctx, folderID, folderParentID)
|
return c.MoveFolder(ctx, folderID, folderParentID)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,16 +5,16 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/speatzle/go-passbolt"
|
"github.com/speatzle/go-passbolt/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CreateResource Creates a Resource where the Password and Description are Encrypted and Returns the Resources ID
|
// CreateResource Creates a Resource where the Password and Description are Encrypted and Returns the Resources ID
|
||||||
func CreateResource(ctx context.Context, c *passbolt.Client, folderParentID, name, username, uri, password, description string) (string, error) {
|
func CreateResource(ctx context.Context, c *api.Client, folderParentID, name, username, uri, password, description string) (string, error) {
|
||||||
types, err := c.GetResourceTypes(ctx, nil)
|
types, err := c.GetResourceTypes(ctx, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("Getting ResourceTypes: %w", err)
|
return "", fmt.Errorf("Getting ResourceTypes: %w", err)
|
||||||
}
|
}
|
||||||
var rType *passbolt.ResourceType
|
var rType *api.ResourceType
|
||||||
for _, tmp := range types {
|
for _, tmp := range types {
|
||||||
if tmp.Slug == "password-and-description" {
|
if tmp.Slug == "password-and-description" {
|
||||||
rType = &tmp
|
rType = &tmp
|
||||||
|
@ -24,7 +24,7 @@ func CreateResource(ctx context.Context, c *passbolt.Client, folderParentID, nam
|
||||||
return "", fmt.Errorf("Cannot find Resource type password-and-description")
|
return "", fmt.Errorf("Cannot find Resource type password-and-description")
|
||||||
}
|
}
|
||||||
|
|
||||||
resource := passbolt.Resource{
|
resource := api.Resource{
|
||||||
ResourceTypeID: rType.ID,
|
ResourceTypeID: rType.ID,
|
||||||
FolderParentID: folderParentID,
|
FolderParentID: folderParentID,
|
||||||
Name: name,
|
Name: name,
|
||||||
|
@ -32,7 +32,7 @@ func CreateResource(ctx context.Context, c *passbolt.Client, folderParentID, nam
|
||||||
URI: uri,
|
URI: uri,
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp := passbolt.SecretDataTypePasswordAndDescription{
|
tmp := api.SecretDataTypePasswordAndDescription{
|
||||||
Password: password,
|
Password: password,
|
||||||
Description: description,
|
Description: description,
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ func CreateResource(ctx context.Context, c *passbolt.Client, folderParentID, nam
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("Encrypting Secret Data for User me: %w", err)
|
return "", fmt.Errorf("Encrypting Secret Data for User me: %w", err)
|
||||||
}
|
}
|
||||||
resource.Secrets = []passbolt.Secret{{Data: encSecretData}}
|
resource.Secrets = []api.Secret{{Data: encSecretData}}
|
||||||
|
|
||||||
newresource, err := c.CreateResource(ctx, resource)
|
newresource, err := c.CreateResource(ctx, resource)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -55,19 +55,19 @@ func CreateResource(ctx context.Context, c *passbolt.Client, folderParentID, nam
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateResourceSimple Creates a Legacy Resource where only the Password is Encrypted and Returns the Resources ID
|
// CreateResourceSimple Creates a Legacy Resource where only the Password is Encrypted and Returns the Resources ID
|
||||||
func CreateResourceSimple(ctx context.Context, c *passbolt.Client, folderParentID, name, username, uri, password, description string) (string, error) {
|
func CreateResourceSimple(ctx context.Context, c *api.Client, folderParentID, name, username, uri, password, description string) (string, error) {
|
||||||
enc, err := c.EncryptMessage(password)
|
enc, err := c.EncryptMessage(password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("Encrypting Password: %w", err)
|
return "", fmt.Errorf("Encrypting Password: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
res := passbolt.Resource{
|
res := api.Resource{
|
||||||
Name: name,
|
Name: name,
|
||||||
URI: uri,
|
URI: uri,
|
||||||
Username: username,
|
Username: username,
|
||||||
FolderParentID: folderParentID,
|
FolderParentID: folderParentID,
|
||||||
Description: description,
|
Description: description,
|
||||||
Secrets: []passbolt.Secret{
|
Secrets: []api.Secret{
|
||||||
{Data: enc},
|
{Data: enc},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ func CreateResourceSimple(ctx context.Context, c *passbolt.Client, folderParentI
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetResource Gets a Resource by ID
|
// GetResource Gets a Resource by ID
|
||||||
func GetResource(ctx context.Context, c *passbolt.Client, resourceID string) (folderParentID, name, username, uri, password, description string, err error) {
|
func GetResource(ctx context.Context, c *api.Client, resourceID string) (folderParentID, name, username, uri, password, description string, err error) {
|
||||||
resource, err := c.GetResource(ctx, resourceID)
|
resource, err := c.GetResource(ctx, resourceID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", "", "", "", "", fmt.Errorf("Getting Resource: %w", err)
|
return "", "", "", "", "", "", fmt.Errorf("Getting Resource: %w", err)
|
||||||
|
@ -109,7 +109,7 @@ func GetResource(ctx context.Context, c *passbolt.Client, resourceID string) (fo
|
||||||
return "", "", "", "", "", "", fmt.Errorf("Decrypting Secret Data: %w", err)
|
return "", "", "", "", "", "", fmt.Errorf("Decrypting Secret Data: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var secretData passbolt.SecretDataTypePasswordAndDescription
|
var secretData api.SecretDataTypePasswordAndDescription
|
||||||
err = json.Unmarshal([]byte(rawSecretData), &secretData)
|
err = json.Unmarshal([]byte(rawSecretData), &secretData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", "", "", "", "", fmt.Errorf("Parsing Decrypted Secret Data: %w", err)
|
return "", "", "", "", "", "", fmt.Errorf("Parsing Decrypted Secret Data: %w", err)
|
||||||
|
@ -124,7 +124,7 @@ func GetResource(ctx context.Context, c *passbolt.Client, resourceID string) (fo
|
||||||
|
|
||||||
// UpdateResource Updates all Fields.
|
// UpdateResource Updates all Fields.
|
||||||
// Note if you want to Change the FolderParentID please use the MoveResource Function
|
// Note if you want to Change the FolderParentID please use the MoveResource Function
|
||||||
func UpdateResource(ctx context.Context, c *passbolt.Client, resourceID, name, username, uri, password, description string) error {
|
func UpdateResource(ctx context.Context, c *api.Client, resourceID, name, username, uri, password, description string) error {
|
||||||
resource, err := c.GetResource(ctx, resourceID)
|
resource, err := c.GetResource(ctx, resourceID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Getting Resource: %w", err)
|
return fmt.Errorf("Getting Resource: %w", err)
|
||||||
|
@ -135,7 +135,7 @@ func UpdateResource(ctx context.Context, c *passbolt.Client, resourceID, name, u
|
||||||
return fmt.Errorf("Getting ResourceType: %w", err)
|
return fmt.Errorf("Getting ResourceType: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
opts := &passbolt.GetUsersOptions{
|
opts := &api.GetUsersOptions{
|
||||||
FilterHasAccess: resourceID,
|
FilterHasAccess: resourceID,
|
||||||
}
|
}
|
||||||
users, err := c.GetUsers(ctx, opts)
|
users, err := c.GetUsers(ctx, opts)
|
||||||
|
@ -143,7 +143,7 @@ func UpdateResource(ctx context.Context, c *passbolt.Client, resourceID, name, u
|
||||||
return fmt.Errorf("Getting Users: %w", err)
|
return fmt.Errorf("Getting Users: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
newResource := passbolt.Resource{
|
newResource := api.Resource{
|
||||||
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,
|
||||||
|
@ -158,7 +158,7 @@ func UpdateResource(ctx context.Context, c *passbolt.Client, resourceID, name, u
|
||||||
newResource.Description = description
|
newResource.Description = description
|
||||||
secretData = password
|
secretData = password
|
||||||
case "password-and-description":
|
case "password-and-description":
|
||||||
tmp := passbolt.SecretDataTypePasswordAndDescription{
|
tmp := api.SecretDataTypePasswordAndDescription{
|
||||||
Password: password,
|
Password: password,
|
||||||
Description: description,
|
Description: description,
|
||||||
}
|
}
|
||||||
|
@ -171,7 +171,7 @@ func UpdateResource(ctx context.Context, c *passbolt.Client, resourceID, name, u
|
||||||
return fmt.Errorf("Unknown ResourceType: %v", rType.Slug)
|
return fmt.Errorf("Unknown ResourceType: %v", rType.Slug)
|
||||||
}
|
}
|
||||||
|
|
||||||
newResource.Secrets = []passbolt.Secret{}
|
newResource.Secrets = []api.Secret{}
|
||||||
for _, user := range users {
|
for _, user := range users {
|
||||||
var encSecretData string
|
var encSecretData string
|
||||||
// if this is our user use our stored and verified public key instead
|
// if this is our user use our stored and verified public key instead
|
||||||
|
@ -186,7 +186,7 @@ func UpdateResource(ctx context.Context, c *passbolt.Client, resourceID, name, u
|
||||||
return fmt.Errorf("Encrypting Secret Data for User %v: %w", user.ID, err)
|
return fmt.Errorf("Encrypting Secret Data for User %v: %w", user.ID, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
newResource.Secrets = append(newResource.Secrets, passbolt.Secret{
|
newResource.Secrets = append(newResource.Secrets, api.Secret{
|
||||||
UserID: user.ID,
|
UserID: user.ID,
|
||||||
Data: encSecretData,
|
Data: encSecretData,
|
||||||
})
|
})
|
||||||
|
@ -199,10 +199,10 @@ func UpdateResource(ctx context.Context, c *passbolt.Client, resourceID, name, u
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeleteResource(ctx context.Context, c *passbolt.Client, resourceID string) error {
|
func DeleteResource(ctx context.Context, c *api.Client, resourceID string) error {
|
||||||
return c.DeleteResource(ctx, resourceID)
|
return c.DeleteResource(ctx, resourceID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func MoveResource(ctx context.Context, c *passbolt.Client, resourceID, folderParentID string) error {
|
func MoveResource(ctx context.Context, c *api.Client, resourceID, folderParentID string) error {
|
||||||
return c.MoveResource(ctx, resourceID, folderParentID)
|
return c.MoveResource(ctx, resourceID, folderParentID)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/speatzle/go-passbolt"
|
"github.com/speatzle/go-passbolt/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ShareOperation defines how Resources are to be Shared With Users/Groups
|
// ShareOperation defines how Resources are to be Shared With Users/Groups
|
||||||
|
@ -20,7 +20,7 @@ type ShareOperation struct {
|
||||||
|
|
||||||
// ShareResourceWithUsersAndGroups Shares a Resource With The Users and Groups with the Specified Permission Type,
|
// ShareResourceWithUsersAndGroups Shares a Resource With The Users and Groups with the Specified Permission Type,
|
||||||
// if the Resource has already been shared With the User/Group the Permission Type will be Adjusted/Deleted
|
// if the Resource has already been shared With the User/Group the Permission Type will be Adjusted/Deleted
|
||||||
func ShareResourceWithUsersAndGroups(ctx context.Context, c *passbolt.Client, resourceID string, Users []string, Groups []string, permissionType int) error {
|
func ShareResourceWithUsersAndGroups(ctx context.Context, c *api.Client, resourceID string, Users []string, Groups []string, permissionType int) error {
|
||||||
changes := []ShareOperation{}
|
changes := []ShareOperation{}
|
||||||
for _, userID := range Users {
|
for _, userID := range Users {
|
||||||
changes = append(changes, ShareOperation{
|
changes = append(changes, ShareOperation{
|
||||||
|
@ -40,7 +40,7 @@ func ShareResourceWithUsersAndGroups(ctx context.Context, c *passbolt.Client, re
|
||||||
}
|
}
|
||||||
|
|
||||||
// ShareResource Shares a Resource as Specified in the Passed ShareOperation Struct Slice
|
// ShareResource Shares a Resource as Specified in the Passed ShareOperation Struct Slice
|
||||||
func ShareResource(ctx context.Context, c *passbolt.Client, resourceID string, changes []ShareOperation) error {
|
func ShareResource(ctx context.Context, c *api.Client, resourceID string, changes []ShareOperation) error {
|
||||||
oldPermissions, err := c.GetResourcePermissions(ctx, resourceID)
|
oldPermissions, err := c.GetResourcePermissions(ctx, resourceID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Getting Resource Permissions: %w", err)
|
return fmt.Errorf("Getting Resource Permissions: %w", err)
|
||||||
|
@ -51,7 +51,7 @@ func ShareResource(ctx context.Context, c *passbolt.Client, resourceID string, c
|
||||||
return fmt.Errorf("Generating Resource Permission Changes: %w", err)
|
return fmt.Errorf("Generating Resource Permission Changes: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
shareRequest := passbolt.ResourceShareRequest{Permissions: permissionChanges}
|
shareRequest := api.ResourceShareRequest{Permissions: permissionChanges}
|
||||||
|
|
||||||
secret, err := c.GetSecret(ctx, resourceID)
|
secret, err := c.GetSecret(ctx, resourceID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -73,7 +73,7 @@ func ShareResource(ctx context.Context, c *passbolt.Client, resourceID string, c
|
||||||
return fmt.Errorf("Get Users: %w", err)
|
return fmt.Errorf("Get Users: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
shareRequest.Secrets = []passbolt.Secret{}
|
shareRequest.Secrets = []api.Secret{}
|
||||||
for _, user := range simulationResult.Changes.Added {
|
for _, user := range simulationResult.Changes.Added {
|
||||||
pubkey, err := getPublicKeyByUserID(user.User.ID, users)
|
pubkey, err := getPublicKeyByUserID(user.User.ID, users)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -84,7 +84,7 @@ func ShareResource(ctx context.Context, c *passbolt.Client, resourceID string, c
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Encrypting Secret for User %v: %w", user.User.ID, err)
|
return fmt.Errorf("Encrypting Secret for User %v: %w", user.User.ID, err)
|
||||||
}
|
}
|
||||||
shareRequest.Secrets = append(shareRequest.Secrets, passbolt.Secret{
|
shareRequest.Secrets = append(shareRequest.Secrets, api.Secret{
|
||||||
UserID: user.User.ID,
|
UserID: user.User.ID,
|
||||||
Data: encSecretData,
|
Data: encSecretData,
|
||||||
})
|
})
|
||||||
|
@ -100,7 +100,7 @@ func ShareResource(ctx context.Context, c *passbolt.Client, resourceID string, c
|
||||||
// ShareFolderWithUsersAndGroups Shares a Folder With The Users and Groups with the Specified Type,
|
// ShareFolderWithUsersAndGroups Shares a Folder With The Users and Groups with the Specified Type,
|
||||||
// if the Folder has already been shared With the User/Group the Permission Type will be Adjusted/Deleted.
|
// if the Folder has already been shared With the User/Group the Permission Type will be Adjusted/Deleted.
|
||||||
// Note: Resources Permissions in the Folder are not Adjusted (Like the Extention does)
|
// Note: Resources Permissions in the Folder are not Adjusted (Like the Extention does)
|
||||||
func ShareFolderWithUsersAndGroups(ctx context.Context, c *passbolt.Client, folderID string, Users []string, Groups []string, permissionType int) error {
|
func ShareFolderWithUsersAndGroups(ctx context.Context, c *api.Client, folderID string, Users []string, Groups []string, permissionType int) error {
|
||||||
changes := []ShareOperation{}
|
changes := []ShareOperation{}
|
||||||
for _, userID := range Users {
|
for _, userID := range Users {
|
||||||
changes = append(changes, ShareOperation{
|
changes = append(changes, ShareOperation{
|
||||||
|
@ -121,7 +121,7 @@ func ShareFolderWithUsersAndGroups(ctx context.Context, c *passbolt.Client, fold
|
||||||
|
|
||||||
// ShareFolder Shares a Folder as Specified in the Passed ShareOperation Struct Slice.
|
// ShareFolder Shares a Folder as Specified in the Passed ShareOperation Struct Slice.
|
||||||
// Note Resources Permissions in the Folder are not Adjusted
|
// Note Resources Permissions in the Folder are not Adjusted
|
||||||
func ShareFolder(ctx context.Context, c *passbolt.Client, folderID string, changes []ShareOperation) error {
|
func ShareFolder(ctx context.Context, c *api.Client, folderID string, changes []ShareOperation) error {
|
||||||
oldPermissions, err := c.GetFolderPermissions(ctx, folderID)
|
oldPermissions, err := c.GetFolderPermissions(ctx, folderID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Getting Folder Permissions: %w", err)
|
return fmt.Errorf("Getting Folder Permissions: %w", err)
|
||||||
|
@ -140,7 +140,7 @@ func ShareFolder(ctx context.Context, c *passbolt.Client, folderID string, chang
|
||||||
}
|
}
|
||||||
|
|
||||||
// GeneratePermissionChanges Generates the Permission Changes for a Resource/Folder nessesary for a single Share Operation
|
// GeneratePermissionChanges Generates the Permission Changes for a Resource/Folder nessesary for a single Share Operation
|
||||||
func GeneratePermissionChanges(oldPermissions []passbolt.Permission, changes []ShareOperation) ([]passbolt.Permission, error) {
|
func GeneratePermissionChanges(oldPermissions []api.Permission, changes []ShareOperation) ([]api.Permission, error) {
|
||||||
// Check for Duplicate Users/Groups as that would break stuff
|
// Check for Duplicate Users/Groups as that would break stuff
|
||||||
for i, changeA := range changes {
|
for i, changeA := range changes {
|
||||||
for j, changeB := range changes {
|
for j, changeB := range changes {
|
||||||
|
@ -157,10 +157,10 @@ func GeneratePermissionChanges(oldPermissions []passbolt.Permission, changes []S
|
||||||
ACO := oldPermissions[0].ACO
|
ACO := oldPermissions[0].ACO
|
||||||
ACOID := oldPermissions[0].ACOForeignKey
|
ACOID := oldPermissions[0].ACOForeignKey
|
||||||
|
|
||||||
permissionChanges := []passbolt.Permission{}
|
permissionChanges := []api.Permission{}
|
||||||
for _, change := range changes {
|
for _, change := range changes {
|
||||||
// Find Permission thats invloves the Same ARO as Requested in the change
|
// Find Permission thats invloves the Same ARO as Requested in the change
|
||||||
var oldPermission *passbolt.Permission
|
var oldPermission *api.Permission
|
||||||
for _, oldPerm := range oldPermissions {
|
for _, oldPerm := range oldPermissions {
|
||||||
if oldPerm.ARO == change.ARO && oldPerm.AROForeignKey == change.AROID {
|
if oldPerm.ARO == change.ARO && oldPerm.AROForeignKey == change.AROID {
|
||||||
oldPermission = &oldPerm
|
oldPermission = &oldPerm
|
||||||
|
@ -169,7 +169,7 @@ func GeneratePermissionChanges(oldPermissions []passbolt.Permission, changes []S
|
||||||
// Check Wheter Matching Permission Already Exists and needs to be adjusted or is a new one can be created
|
// Check Wheter Matching Permission Already Exists and needs to be adjusted or is a new one can be created
|
||||||
if oldPermission == nil {
|
if oldPermission == nil {
|
||||||
if change.Type == 15 || change.Type == 7 || change.Type == 1 {
|
if change.Type == 15 || change.Type == 7 || change.Type == 1 {
|
||||||
permissionChanges = append(permissionChanges, passbolt.Permission{
|
permissionChanges = append(permissionChanges, api.Permission{
|
||||||
IsNew: true,
|
IsNew: true,
|
||||||
Type: change.Type,
|
Type: change.Type,
|
||||||
ARO: change.ARO,
|
ARO: change.ARO,
|
||||||
|
@ -183,7 +183,7 @@ func GeneratePermissionChanges(oldPermissions []passbolt.Permission, changes []S
|
||||||
return nil, fmt.Errorf("Unknown Permission Type: %v", change.Type)
|
return nil, fmt.Errorf("Unknown Permission Type: %v", change.Type)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
tmp := passbolt.Permission{
|
tmp := api.Permission{
|
||||||
ID: oldPermission.ID,
|
ID: oldPermission.ID,
|
||||||
ARO: change.ARO,
|
ARO: change.ARO,
|
||||||
AROForeignKey: change.AROID,
|
AROForeignKey: change.AROID,
|
||||||
|
@ -208,7 +208,7 @@ func GeneratePermissionChanges(oldPermissions []passbolt.Permission, changes []S
|
||||||
return permissionChanges, nil
|
return permissionChanges, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPublicKeyByUserID(userID string, Users []passbolt.User) (string, error) {
|
func getPublicKeyByUserID(userID string, Users []api.User) (string, error) {
|
||||||
for _, user := range Users {
|
for _, user := range Users {
|
||||||
if user.ID == userID {
|
if user.ID == userID {
|
||||||
return user.GPGKey.ArmoredKey, nil
|
return user.GPGKey.ArmoredKey, nil
|
||||||
|
|
Loading…
Add table
Reference in a new issue