Documentation
¶
Index ¶
- type PGStore
- func (s *PGStore) AddPermissionToGroup(ctx context.Context, groupID string, permissionKey string) error
- func (s *PGStore) AssignPermission(ctx context.Context, userID string, permissionKey string) error
- func (s *PGStore) AssignUserToGroup(ctx context.Context, userID string, groupID string) error
- func (s *PGStore) Bootstrap(ctx context.Context, superAdminEmail string) error
- func (s *PGStore) CreateGroup(ctx context.Context, name string) (*auth.Group, error)
- func (s *PGStore) CreateOTP(ctx context.Context, email string) (*auth.OTP, error)
- func (s *PGStore) CreatePermission(ctx context.Context, key string, description string) (*auth.Permission, error)
- func (s *PGStore) CreateSchema(ctx context.Context) error
- func (s *PGStore) CreateUser(ctx context.Context, email string) (*auth.User, error)
- func (s *PGStore) DeleteGroup(ctx context.Context, id string) error
- func (s *PGStore) DeletePermission(ctx context.Context, id string) error
- func (s *PGStore) DropSchema(ctx context.Context) error
- func (s *PGStore) GetGroup(ctx context.Context, id string) (*auth.Group, error)
- func (s *PGStore) GetPermission(ctx context.Context, key string) (*auth.Permission, error)
- func (s *PGStore) GetResolvedPermissions(ctx context.Context, userID string) ([]auth.Permission, error)
- func (s *PGStore) GetUserByEmail(ctx context.Context, email string) (*auth.User, error)
- func (s *PGStore) GetUserByID(ctx context.Context, id string) (*auth.User, error)
- func (s *PGStore) GetUserGroups(ctx context.Context, userID string) ([]auth.Group, error)
- func (s *PGStore) GetUserPermissions(ctx context.Context, userID string) ([]auth.Permission, error)
- func (s *PGStore) HasPermission(ctx context.Context, userID string, permissionKey string) (bool, error)
- func (s *PGStore) HasResolvedPermission(ctx context.Context, userID string, permissionKey string) (bool, error)
- func (s *PGStore) ListGroups(ctx context.Context) ([]auth.Group, error)
- func (s *PGStore) ListPermissions(ctx context.Context) ([]auth.Permission, error)
- func (s *PGStore) ListUsers(ctx context.Context) ([]auth.User, error)
- func (s *PGStore) Migrate(ctx context.Context) error
- func (s *PGStore) MigrationStatus(ctx context.Context) ([]auth.MigrationRecord, error)
- func (s *PGStore) RemovePermissionFromGroup(ctx context.Context, groupID string, permissionID string) error
- func (s *PGStore) RemoveUserFromGroup(ctx context.Context, userID string, groupID string) error
- func (s *PGStore) RevokePermission(ctx context.Context, userID string, permissionKey string) error
- func (s *PGStore) Rollback(ctx context.Context) error
- func (s *PGStore) VerifyOTP(ctx context.Context, email string, code string) (*auth.User, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PGStore ¶
type PGStore struct {
// contains filtered or unexported fields
}
PGStore implements auth.Store using PostgreSQL via pgx.
func (*PGStore) AddPermissionToGroup ¶
func (s *PGStore) AddPermissionToGroup(ctx context.Context, groupID string, permissionKey string) error
AddPermissionToGroup adds a permission to a group.
func (*PGStore) AssignPermission ¶
AssignPermission assigns a permission directly to a user.
func (*PGStore) AssignUserToGroup ¶
AssignUserToGroup adds a user to a group.
func (*PGStore) Bootstrap ¶
Bootstrap creates the schema, seeds default permissions, and ensures the super admin user exists with all permissions. Safe to call on every server start (idempotent).
func (*PGStore) CreateGroup ¶
CreateGroup creates a new permission group.
func (*PGStore) CreateOTP ¶
CreateOTP generates a random OTP code for the given email and stores it.
func (*PGStore) CreatePermission ¶
func (s *PGStore) CreatePermission(ctx context.Context, key string, description string) (*auth.Permission, error)
CreatePermission creates a new permission with the given key and description.
func (*PGStore) CreateSchema ¶
CreateSchema applies all pending migrations. Delegates to Migrate for migration-based schema management.
func (*PGStore) CreateUser ¶
CreateUser creates a new user with the given email.
func (*PGStore) DeleteGroup ¶
DeleteGroup deletes a group by ID. Cascades to group_permissions and user_groups.
func (*PGStore) DeletePermission ¶
DeletePermission deletes a permission by its ID. Cascades to user_permissions and group_permissions.
func (*PGStore) DropSchema ¶
DropSchema drops all auth tables and the migrations tracking table.
func (*PGStore) GetPermission ¶
GetPermission fetches a permission by its key.
func (*PGStore) GetResolvedPermissions ¶
func (s *PGStore) GetResolvedPermissions(ctx context.Context, userID string) ([]auth.Permission, error)
GetResolvedPermissions returns all permissions for a user (direct + from groups), deduplicated.
func (*PGStore) GetUserByEmail ¶
GetUserByEmail fetches a user by their email. Returns nil, nil if not found.
func (*PGStore) GetUserByID ¶
GetUserByID fetches a user by their ID. Returns nil, nil if not found.
func (*PGStore) GetUserGroups ¶
GetUserGroups returns all groups a user belongs to.
func (*PGStore) GetUserPermissions ¶
GetUserPermissions returns all direct permissions for a user.
func (*PGStore) HasPermission ¶
func (s *PGStore) HasPermission(ctx context.Context, userID string, permissionKey string) (bool, error)
HasPermission checks if a user has a specific direct permission.
func (*PGStore) HasResolvedPermission ¶
func (s *PGStore) HasResolvedPermission(ctx context.Context, userID string, permissionKey string) (bool, error)
HasResolvedPermission checks if a user has a permission (direct or via group).
func (*PGStore) ListGroups ¶
ListGroups returns all groups (without permissions).
func (*PGStore) ListPermissions ¶
ListPermissions returns all permissions.
func (*PGStore) MigrationStatus ¶
MigrationStatus returns all migrations with their applied status.
func (*PGStore) RemovePermissionFromGroup ¶
func (s *PGStore) RemovePermissionFromGroup(ctx context.Context, groupID string, permissionID string) error
RemovePermissionFromGroup removes a permission from a group.
func (*PGStore) RemoveUserFromGroup ¶
RemoveUserFromGroup removes a user from a group.
func (*PGStore) RevokePermission ¶
RevokePermission removes a direct permission from a user.