storage

package
v1.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 5, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound            = errors.New("resource not found")
	ErrDuplicateKey        = errors.New("duplicate key violation")
	ErrForeignKeyViolation = errors.New("foreign key violation")
)

Sentinel errors for storage operations.

Functions

func IsDuplicateKeyError

func IsDuplicateKeyError(err error) bool

IsDuplicateKeyError checks if the error is a PostgreSQL unique constraint violation.

func IsForeignKeyViolation

func IsForeignKeyViolation(err error) bool

IsForeignKeyViolation checks if the error is a PostgreSQL foreign key violation.

func WrapDuplicateKeyError

func WrapDuplicateKeyError(err error, context string) error

WrapDuplicateKeyError wraps a duplicate key error with context about which constraint was violated.

func WrapForeignKeyError

func WrapForeignKeyError(err error, context string) error

WrapForeignKeyError wraps a foreign key violation with context.

Types

type Storage

type Storage struct {
	// contains filtered or unexported fields
}

func (*Storage) AddAllowedApp

func (s *Storage) AddAllowedApp(ctx context.Context, groupID string, appID string) error

AddAllowedApp adds a single application to the allowed list for a group.

func (*Storage) AddAllowedApps

func (s *Storage) AddAllowedApps(ctx context.Context, groupID string, appIDs []string) error

AddAllowedApps adds multiple applications to the allowed list for a group.

func (*Storage) AddAllowedGroupsForApp

func (s *Storage) AddAllowedGroupsForApp(ctx context.Context, appID string, groupIDs []string) error

AddAllowedGroupsForApp adds multiple groups to the allowed list for an application.

func (*Storage) AddUsersToGroup

func (s *Storage) AddUsersToGroup(ctx context.Context, groupID string, userIDs []string) error

AddUsersToGroup adds multiple users to a group.

func (*Storage) CreateGroup

func (s *Storage) CreateGroup(ctx context.Context, group *types.Group) (*types.Group, error)

CreateGroup inserts a new group into the database.

func (*Storage) DeleteGroup

func (s *Storage) DeleteGroup(ctx context.Context, id string) error

DeleteGroup removes a group from the database.

func (*Storage) GetAllowedApps

func (s *Storage) GetAllowedApps(ctx context.Context, groupID string) ([]string, error)

GetAllowedApps retrieves all application IDs allowed for a specific group.

func (*Storage) GetAllowedGroupsForApp

func (s *Storage) GetAllowedGroupsForApp(ctx context.Context, appID string) ([]string, error)

GetAllowedGroupsForApp retrieves all group IDs that are allowed to access a specific application.

func (*Storage) GetGroup

func (s *Storage) GetGroup(ctx context.Context, id string) (*types.Group, error)

GetGroup retrieves a single group by ID.

func (*Storage) GetGroupsForUser

func (s *Storage) GetGroupsForUser(ctx context.Context, userID string) ([]*types.Group, error)

GetGroupsForUser retrieves all groups that a user belongs to.

func (*Storage) ListGroups

func (s *Storage) ListGroups(ctx context.Context) ([]*types.Group, error)

ListGroups retrieves all groups from the database.

func (*Storage) ListUsersInGroup

func (s *Storage) ListUsersInGroup(ctx context.Context, groupID string) ([]string, error)

ListUsersInGroup retrieves all user IDs that are members of a group.

func (*Storage) RemoveAllAllowedGroupsForApp

func (s *Storage) RemoveAllAllowedGroupsForApp(ctx context.Context, appID string) ([]string, error)

RemoveAllAllowedGroupsForApp removes all groups from the allowed list for an application and returns the removed group IDs.

func (*Storage) RemoveAllowedApp

func (s *Storage) RemoveAllowedApp(ctx context.Context, groupID string, appID string) error

RemoveAllowedApp removes a single application from the allowed list for a group.

func (*Storage) RemoveAllowedApps

func (s *Storage) RemoveAllowedApps(ctx context.Context, groupID string) ([]string, error)

RemoveAllowedApps removes all applications from the allowed list for a group and returns the removed app IDs.

func (*Storage) RemoveUsersFromGroup

func (s *Storage) RemoveUsersFromGroup(ctx context.Context, groupID string, users []string) error

RemoveUsersFromGroup removes specific users from a group.

func (*Storage) UpdateGroup

func (s *Storage) UpdateGroup(ctx context.Context, id string, group *types.Group) (*types.Group, error)

UpdateGroup updates an existing group's mutable fields.

func (*Storage) UpdateGroupsForUser

func (s *Storage) UpdateGroupsForUser(ctx context.Context, userID string, groupIDs []string) error

UpdateGroupsForUser replaces all group memberships for a user with the specified groups. It deduplicates the provided group IDs, removes any memberships not in the list, and upserts the remaining memberships to preserve history.

type StorageInterface

type StorageInterface interface {
	// Group CRUD operations
	ListGroups(ctx context.Context) ([]*types.Group, error)
	CreateGroup(ctx context.Context, group *types.Group) (*types.Group, error)
	GetGroup(ctx context.Context, id string) (*types.Group, error)
	UpdateGroup(ctx context.Context, id string, group *types.Group) (*types.Group, error)
	DeleteGroup(ctx context.Context, id string) error

	// Group membership operations
	AddUsersToGroup(ctx context.Context, groupID string, userIDs []string) error
	ListUsersInGroup(ctx context.Context, groupID string) ([]string, error)
	RemoveUsersFromGroup(ctx context.Context, groupID string, users []string) error

	// User-centric group operations
	GetGroupsForUser(ctx context.Context, userID string) ([]*types.Group, error)
	UpdateGroupsForUser(ctx context.Context, userID string, groupIDs []string) error

	// Application authorization operations
	GetAllowedApps(ctx context.Context, groupID string) ([]string, error)
	AddAllowedApp(ctx context.Context, groupID string, appID string) error
	AddAllowedApps(ctx context.Context, groupID string, appIDs []string) error
	RemoveAllowedApp(ctx context.Context, groupID string, appID string) error
	RemoveAllowedApps(ctx context.Context, groupID string) ([]string, error)

	// Group-centric application authorization operations
	AddAllowedGroupsForApp(ctx context.Context, appID string, groupIDs []string) error
	GetAllowedGroupsForApp(ctx context.Context, appID string) ([]string, error)
	RemoveAllAllowedGroupsForApp(ctx context.Context, appID string) ([]string, error)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL