mirror of
https://github.com/passbolt/go-passbolt.git
synced 2025-05-10 01:48:22 +00:00
improve errors
This commit is contained in:
parent
f3e40caa8f
commit
8381328ea9
3 changed files with 47 additions and 14 deletions
|
@ -2,6 +2,7 @@ package helper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/speatzle/go-passbolt/api"
|
"github.com/speatzle/go-passbolt/api"
|
||||||
)
|
)
|
||||||
|
@ -12,27 +13,44 @@ func CreateFolder(ctx context.Context, c *api.Client, folderParentID, name strin
|
||||||
Name: name,
|
Name: name,
|
||||||
FolderParentID: folderParentID,
|
FolderParentID: folderParentID,
|
||||||
})
|
})
|
||||||
return f.ID, err
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("Creating Folder: %w", err)
|
||||||
|
}
|
||||||
|
return f.ID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetFolder Gets a Folder
|
// GetFolder Gets a Folder
|
||||||
func GetFolder(ctx context.Context, c *api.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
|
if err != nil {
|
||||||
|
return "", "", fmt.Errorf("Getting Folder: %w", err)
|
||||||
|
}
|
||||||
|
return f.FolderParentID, f.Name, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateFolder Updates a Folder
|
// UpdateFolder Updates a Folder
|
||||||
func UpdateFolder(ctx context.Context, c *api.Client, folderID, name string) error {
|
func UpdateFolder(ctx context.Context, c *api.Client, folderID, name string) error {
|
||||||
_, err := c.UpdateFolder(ctx, folderID, api.Folder{Name: name})
|
_, err := c.UpdateFolder(ctx, folderID, api.Folder{Name: name})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Updating Folder: %w", err)
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteFolder Deletes a Folder
|
// DeleteFolder Deletes a Folder
|
||||||
func DeleteFolder(ctx context.Context, c *api.Client, folderID string) error {
|
func DeleteFolder(ctx context.Context, c *api.Client, folderID string) error {
|
||||||
return c.DeleteFolder(ctx, folderID)
|
err := c.DeleteFolder(ctx, folderID)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Deleting Folder: %w", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// MoveFolder Moves a Folder into a Folder
|
// MoveFolder Moves a Folder into a Folder
|
||||||
func MoveFolder(ctx context.Context, c *api.Client, folderID, folderParentID string) error {
|
func MoveFolder(ctx context.Context, c *api.Client, folderID, folderParentID string) error {
|
||||||
return c.MoveFolder(ctx, folderID, folderParentID)
|
err := c.MoveFolder(ctx, folderID, folderParentID)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Moving Folder: %w", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -136,7 +136,7 @@ func UpdateResource(ctx context.Context, c *api.Client, resourceID, name, userna
|
||||||
}
|
}
|
||||||
|
|
||||||
opts := &api.GetUsersOptions{
|
opts := &api.GetUsersOptions{
|
||||||
FilterHasAccess: resourceID,
|
FilterHasAccess: []string{resourceID},
|
||||||
}
|
}
|
||||||
users, err := c.GetUsers(ctx, opts)
|
users, err := c.GetUsers(ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -201,10 +201,18 @@ func UpdateResource(ctx context.Context, c *api.Client, resourceID, name, userna
|
||||||
|
|
||||||
// DeleteResource Deletes a Resource
|
// DeleteResource Deletes a Resource
|
||||||
func DeleteResource(ctx context.Context, c *api.Client, resourceID string) error {
|
func DeleteResource(ctx context.Context, c *api.Client, resourceID string) error {
|
||||||
return c.DeleteResource(ctx, resourceID)
|
err := c.DeleteResource(ctx, resourceID)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Deleting Resource: %w", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// MoveResource Moves a Resource into a Folder
|
// MoveResource Moves a Resource into a Folder
|
||||||
func MoveResource(ctx context.Context, c *api.Client, resourceID, folderParentID string) error {
|
func MoveResource(ctx context.Context, c *api.Client, resourceID, folderParentID string) error {
|
||||||
return c.MoveResource(ctx, resourceID, folderParentID)
|
err := c.MoveResource(ctx, resourceID, folderParentID)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Moveing Resource: %w", err)
|
||||||
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ func CreateUser(ctx context.Context, c *api.Client, role, username, firstname, l
|
||||||
}
|
}
|
||||||
|
|
||||||
if roleID == "" {
|
if roleID == "" {
|
||||||
return "", fmt.Errorf("Cannot Find Role %v", role)
|
return "", fmt.Errorf("Cannot Find Role: %v", role)
|
||||||
}
|
}
|
||||||
|
|
||||||
u, err := c.CreateUser(ctx, api.User{
|
u, err := c.CreateUser(ctx, api.User{
|
||||||
|
@ -35,23 +35,26 @@ func CreateUser(ctx context.Context, c *api.Client, role, username, firstname, l
|
||||||
},
|
},
|
||||||
RoleID: roleID,
|
RoleID: roleID,
|
||||||
})
|
})
|
||||||
return u.ID, err
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("Creating User: %w", err)
|
||||||
|
}
|
||||||
|
return u.ID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUser Gets a User
|
// GetUser Gets a User
|
||||||
func GetUser(ctx context.Context, c *api.Client, userID string) (string, string, string, string, error) {
|
func GetUser(ctx context.Context, c *api.Client, userID string) (string, string, string, string, error) {
|
||||||
u, err := c.GetUser(ctx, userID)
|
u, err := c.GetUser(ctx, userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", "", "", fmt.Errorf("Get User %w", err)
|
return "", "", "", "", fmt.Errorf("Getting User: %w", err)
|
||||||
}
|
}
|
||||||
return u.Username, u.Profile.FirstName, u.Profile.LastName, u.Role.Name, nil
|
return u.Role.Name, u.Username, u.Profile.FirstName, u.Profile.LastName, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateUser Updates a User
|
// UpdateUser Updates a User
|
||||||
func UpdateUser(ctx context.Context, c *api.Client, userID, role, firstname, lastname string) error {
|
func UpdateUser(ctx context.Context, c *api.Client, userID, role, firstname, lastname string) error {
|
||||||
user, err := c.GetUser(ctx, userID)
|
user, err := c.GetUser(ctx, userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Get User %w", err)
|
return fmt.Errorf("Getting User: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
new := api.User{
|
new := api.User{
|
||||||
|
@ -79,7 +82,7 @@ func UpdateUser(ctx context.Context, c *api.Client, userID, role, firstname, las
|
||||||
if roleID == "" {
|
if roleID == "" {
|
||||||
return fmt.Errorf("Cannot Find Role %v", role)
|
return fmt.Errorf("Cannot Find Role %v", role)
|
||||||
}
|
}
|
||||||
user.RoleID = roleID
|
new.RoleID = roleID
|
||||||
}
|
}
|
||||||
|
|
||||||
if firstname != "" {
|
if firstname != "" {
|
||||||
|
@ -98,5 +101,9 @@ func UpdateUser(ctx context.Context, c *api.Client, userID, role, firstname, las
|
||||||
|
|
||||||
// DeleteUser Deletes a User
|
// DeleteUser Deletes a User
|
||||||
func DeleteUser(ctx context.Context, c *api.Client, userID string) error {
|
func DeleteUser(ctx context.Context, c *api.Client, userID string) error {
|
||||||
return c.DeleteUser(ctx, userID)
|
err := c.DeleteUser(ctx, userID)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Deleting User: %w", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue