mirror of
https://github.com/passbolt/go-passbolt.git
synced 2025-09-13 14:29:09 +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
|
@ -4,7 +4,7 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/speatzle/go-passbolt"
|
||||
"github.com/speatzle/go-passbolt/api"
|
||||
)
|
||||
|
||||
// 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,
|
||||
// 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{}
|
||||
for _, userID := range Users {
|
||||
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
|
||||
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)
|
||||
if err != nil {
|
||||
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)
|
||||
}
|
||||
|
||||
shareRequest := passbolt.ResourceShareRequest{Permissions: permissionChanges}
|
||||
shareRequest := api.ResourceShareRequest{Permissions: permissionChanges}
|
||||
|
||||
secret, err := c.GetSecret(ctx, resourceID)
|
||||
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)
|
||||
}
|
||||
|
||||
shareRequest.Secrets = []passbolt.Secret{}
|
||||
shareRequest.Secrets = []api.Secret{}
|
||||
for _, user := range simulationResult.Changes.Added {
|
||||
pubkey, err := getPublicKeyByUserID(user.User.ID, users)
|
||||
if err != nil {
|
||||
|
@ -84,7 +84,7 @@ func ShareResource(ctx context.Context, c *passbolt.Client, resourceID string, c
|
|||
if err != nil {
|
||||
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,
|
||||
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,
|
||||
// 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)
|
||||
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{}
|
||||
for _, userID := range Users {
|
||||
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.
|
||||
// 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)
|
||||
if err != nil {
|
||||
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
|
||||
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
|
||||
for i, changeA := range changes {
|
||||
for j, changeB := range changes {
|
||||
|
@ -157,10 +157,10 @@ func GeneratePermissionChanges(oldPermissions []passbolt.Permission, changes []S
|
|||
ACO := oldPermissions[0].ACO
|
||||
ACOID := oldPermissions[0].ACOForeignKey
|
||||
|
||||
permissionChanges := []passbolt.Permission{}
|
||||
permissionChanges := []api.Permission{}
|
||||
for _, change := range changes {
|
||||
// Find Permission thats invloves the Same ARO as Requested in the change
|
||||
var oldPermission *passbolt.Permission
|
||||
var oldPermission *api.Permission
|
||||
for _, oldPerm := range oldPermissions {
|
||||
if oldPerm.ARO == change.ARO && oldPerm.AROForeignKey == change.AROID {
|
||||
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
|
||||
if oldPermission == nil {
|
||||
if change.Type == 15 || change.Type == 7 || change.Type == 1 {
|
||||
permissionChanges = append(permissionChanges, passbolt.Permission{
|
||||
permissionChanges = append(permissionChanges, api.Permission{
|
||||
IsNew: true,
|
||||
Type: change.Type,
|
||||
ARO: change.ARO,
|
||||
|
@ -183,7 +183,7 @@ func GeneratePermissionChanges(oldPermissions []passbolt.Permission, changes []S
|
|||
return nil, fmt.Errorf("Unknown Permission Type: %v", change.Type)
|
||||
}
|
||||
} else {
|
||||
tmp := passbolt.Permission{
|
||||
tmp := api.Permission{
|
||||
ID: oldPermission.ID,
|
||||
ARO: change.ARO,
|
||||
AROForeignKey: change.AROID,
|
||||
|
@ -208,7 +208,7 @@ func GeneratePermissionChanges(oldPermissions []passbolt.Permission, changes []S
|
|||
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 {
|
||||
if user.ID == userID {
|
||||
return user.GPGKey.ArmoredKey, nil
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue