Documentation
¶
Overview ¶
Package helper provides high-level operations for the Passbolt API.
Index ¶
- Variables
- func AddMFACallbackTOTP(c *api.Client, retrys uint, retryDelay, offset time.Duration, token string)
- func CreateFolder(ctx context.Context, c *api.Client, folderParentID, name string) (string, error)
- func CreateGroup(ctx context.Context, c *api.Client, name string, ...) (string, error)
- func CreateResource(ctx context.Context, c *api.Client, ...) (string, error)
- func CreateResourceGeneric(ctx context.Context, c *api.Client, slug string, folderParentID string, ...) (string, error)
- func CreateResourceSimple(ctx context.Context, c *api.Client, ...) (string, error)deprecated
- func CreateResourceV4(ctx context.Context, c *api.Client, ...) (string, error)deprecated
- func CreateResourceV5(ctx context.Context, c *api.Client, ...) (string, error)deprecated
- func CreateUser(ctx context.Context, c *api.Client, role, username, firstname, lastname string) (string, error)
- func DeleteFolder(ctx context.Context, c *api.Client, folderID string) error
- func DeleteGroup(ctx context.Context, c *api.Client, groupID string) error
- func DeleteResource(ctx context.Context, c *api.Client, resourceID string) error
- func DeleteUser(ctx context.Context, c *api.Client, userID string) error
- func GenerateOTPCode(token string, when time.Time) (string, error)
- func GeneratePermissionChanges(oldPermissions []api.Permission, changes []ShareOperation) ([]api.Permission, error)
- func GetFolder(ctx context.Context, c *api.Client, folderID string) (string, string, error)
- func GetResource(ctx context.Context, c *api.Client, resourceID string) (folderParentID, name, username, uri, password, description string, err error)
- func GetResourceFieldMaps(c *api.Client, resource api.Resource, secret api.Secret, ...) (folderParentID string, metadataFields, secretFields map[string]any, err error)
- func GetResourceFromData(c *api.Client, resource api.Resource, secret api.Secret, ...) (string, string, string, string, string, string, error)
- func GetResourceFromDataWithOptions(c *api.Client, resource api.Resource, secret api.Secret, ...) (string, string, string, string, string, string, error)
- func GetResourceMetadata(ctx context.Context, c *api.Client, resource *api.Resource, ...) (string, error)
- func GetStringField(m map[string]any, key string) string
- func GetUser(ctx context.Context, c *api.Client, userID string) (string, string, string, string, error)
- func MoveFolder(ctx context.Context, c *api.Client, folderID, folderParentID string) error
- func MoveResource(ctx context.Context, c *api.Client, resourceID, folderParentID string) error
- func ParseInviteURL(url string) (string, string, error)
- func SetupAccount(ctx context.Context, c *api.Client, userID, token, password string) (string, error)
- func ShareFolder(ctx context.Context, c *api.Client, folderID string, changes []ShareOperation) error
- func ShareFolderWithUsersAndGroups(ctx context.Context, c *api.Client, folderID string, Users []string, ...) error
- func ShareResource(ctx context.Context, c *api.Client, resourceID string, ...) error
- func ShareResourceWithUsersAndGroups(ctx context.Context, c *api.Client, resourceID string, Users []string, ...) error
- func UpdateFolder(ctx context.Context, c *api.Client, folderID, name string) error
- func UpdateGroup(ctx context.Context, c *api.Client, groupID, name string, ...) error
- func UpdateResource(ctx context.Context, c *api.Client, ...) error
- func UpdateResourceGeneric(ctx context.Context, c *api.Client, resourceID string, ...) error
- func UpdateUser(ctx context.Context, c *api.Client, userID, role, firstname, lastname string) error
- type GroupMembership
- type GroupMembershipOperation
- type ShareOperation
Constants ¶
This section is empty.
Variables ¶
var ( // Resource creation errors ErrV5CreationDisabled = errors.New("creation of V5 passwords is disabled on this server") ErrV4CreationDisabled = errors.New("creation of V4 passwords is disabled on this server") ErrResourceTypeSlugNotFound = errors.New("cannot find resource type") ErrPasswordTooLong = errors.New("password exceeds maximum length") // Lookup errors ErrKeyNotFound = errors.New("cannot find key for user") ErrMembershipNotFound = errors.New("cannot find membership for user") ErrSecretNotFound = errors.New("cannot find secret for resource") // Custom field validation errors ErrCustomFieldInvalidID = errors.New("custom field id must be a valid UUID") ErrCustomFieldMissingKey = errors.New("custom field in metadata must have metadata_key") ErrCustomFieldMissingValue = errors.New("custom field in secret must have secret_value") ErrCustomFieldCrossField = errors.New("custom field key/value must be defined in only one of metadata or secret") ErrCustomFieldIDMismatch = errors.New("custom field ids must match in metadata and secret arrays") )
var ErrUnsupportedResourceType = errors.New("unsupported resource type")
ErrUnsupportedResourceType is returned when a resource has an unknown resource type slug that cannot be decoded by the helper functions.
Functions ¶
func AddMFACallbackTOTP ¶
AddMFACallbackTOTP adds a MFA callback to the client that generates OTP Codes on demand using a Token with configurable retries and delay
func CreateFolder ¶
CreateFolder Creates a new Folder
func CreateGroup ¶
func CreateGroup(ctx context.Context, c *api.Client, name string, operations []GroupMembershipOperation) (string, error)
CreateGroup creates a Groups with Name and Memberships
func CreateResource ¶
func CreateResource(ctx context.Context, c *api.Client, folderParentID, name, username, uri, password, description string) (string, error)
CreateResource creates a resource using the server's preferred format (v4 or v5). For more control, use CreateResourceGeneric.
func CreateResourceGeneric ¶ added in v0.8.0
func CreateResourceGeneric(ctx context.Context, c *api.Client, slug string, folderParentID string, metadataFields map[string]any, secretFields map[string]any) (string, error)
CreateResourceGeneric creates a resource of any type using dynamic field maps. The slug determines the resource type. Metadata and secret fields are validated against the resource type's JSON schema before submission.
func CreateResourceSimple
deprecated
func CreateResourceV4
deprecated
added in
v0.8.0
func CreateResourceV5
deprecated
added in
v0.8.0
func CreateUser ¶
func CreateUser(ctx context.Context, c *api.Client, role, username, firstname, lastname string) (string, error)
CreateUser Creates a new User
func DeleteFolder ¶
DeleteFolder Deletes a Folder
func DeleteGroup ¶
DeleteGroup Deletes a Group
func DeleteResource ¶
DeleteResource Deletes a Resource
func DeleteUser ¶
DeleteUser Deletes a User
func GenerateOTPCode ¶
GenerateOTPCode generates a 6 digit TOTP from the secret Token.
func GeneratePermissionChanges ¶
func GeneratePermissionChanges(oldPermissions []api.Permission, changes []ShareOperation) ([]api.Permission, error)
GeneratePermissionChanges Generates the Permission Changes for a Resource/Folder nessesary for a single Share Operation
func GetResource ¶
func GetResource(ctx context.Context, c *api.Client, resourceID string) (folderParentID, name, username, uri, password, description string, err error)
GetResource gets a resource by ID and returns its decrypted fields.
func GetResourceFieldMaps ¶ added in v0.8.0
func GetResourceFieldMaps(c *api.Client, resource api.Resource, secret api.Secret, rType api.ResourceType, decryptSecret bool) (folderParentID string, metadataFields, secretFields map[string]any, err error)
GetResourceFieldMaps decrypts a resource and returns the metadata and secret field maps. This is useful for callers that need access to custom fields beyond the standard name/username/uri/password/description; those standard fields can be read from the returned maps with GetStringField.
func GetResourceFromData ¶
func GetResourceFromData(c *api.Client, resource api.Resource, secret api.Secret, rType api.ResourceType) (string, string, string, string, string, string, error)
GetResourceFromData decrypts resources using only local data. The Resource object must include the secret. With v5 this needs network calls for metadata of v5 resources.
func GetResourceFromDataWithOptions ¶ added in v0.8.0
func GetResourceFromDataWithOptions(c *api.Client, resource api.Resource, secret api.Secret, rType api.ResourceType, decryptSecret bool) (string, string, string, string, string, string, error)
GetResourceFromDataWithOptions decrypts resources with option to skip secret decryption. For v5 resources, metadata (name, username, uri) can be decrypted without the secret. Set decryptSecret=false to skip secret decryption (password/description will be empty).
func GetResourceMetadata ¶ added in v0.8.0
func GetStringField ¶ added in v0.8.0
GetStringField safely extracts a string from a map. Returns "" if the key is missing or the value isn't a string.
func GetUser ¶
func GetUser(ctx context.Context, c *api.Client, userID string) (string, string, string, string, error)
GetUser Gets a User
func MoveFolder ¶
MoveFolder Moves a Folder into a Folder
func MoveResource ¶
MoveResource Moves a Resource into a Folder
func ParseInviteURL ¶ added in v0.8.0
ParseInviteURL parses a Passbolt Invite URL into a user id and token.
func SetupAccount ¶
func SetupAccount(ctx context.Context, c *api.Client, userID, token, password string) (string, error)
SetupAccount Setup a Account for a Invited User. (Use ParseInviteURL to get the userid and token from a Invite URL)
func ShareFolder ¶
func ShareFolder(ctx context.Context, c *api.Client, folderID string, changes []ShareOperation) error
ShareFolder Shares a Folder as Specified in the Passed ShareOperation Struct Slice. Note Resources Permissions in the Folder are not Adjusted
func ShareFolderWithUsersAndGroups ¶
func ShareFolderWithUsersAndGroups(ctx context.Context, c *api.Client, folderID string, Users []string, Groups []string, permissionType int) error
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 Extension does)
func ShareResource ¶
func ShareResource(ctx context.Context, c *api.Client, resourceID string, changes []ShareOperation) error
ShareResource Shares a Resource as Specified in the Passed ShareOperation Struct Slice
func ShareResourceWithUsersAndGroups ¶
func ShareResourceWithUsersAndGroups(ctx context.Context, c *api.Client, resourceID string, Users []string, Groups []string, permissionType int) error
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 UpdateFolder ¶
UpdateFolder Updates a Folder
func UpdateGroup ¶
func UpdateGroup(ctx context.Context, c *api.Client, groupID, name string, operations []GroupMembershipOperation) error
UpdateGroup Updates a Groups Name and Memberships
func UpdateResource ¶
func UpdateResource(ctx context.Context, c *api.Client, resourceID, name, username, uri, password, description string) error
UpdateResource updates resource fields. Empty strings are not applied (partial update). Note: to change FolderParentID, use MoveResource instead.
func UpdateResourceGeneric ¶ added in v0.8.0
func UpdateResourceGeneric(ctx context.Context, c *api.Client, resourceID string, metadataUpdates map[string]any, secretUpdates map[string]any) error
UpdateResourceGeneric updates a resource using dynamic field maps. Only provided keys are updated; existing values are preserved for keys not in the update maps.
Types ¶
type GroupMembership ¶
type GroupMembership struct {
UserID string
Username string
UserFirstName string
UserLastName string
IsGroupManager bool
}
GroupMembership contains who and what kind of membership they have with a group
type GroupMembershipOperation ¶
GroupMembershipOperation creates/modifies/deletes a group membership
type ShareOperation ¶
type ShareOperation struct {
// Note: Setting this to -1 Will delete this Permission if it already Exists, errors if this Permission Dosen't Already Exists
Type int
ARO string
AROID string
}
ShareOperation defines how Resources are to be Shared With Users/Groups