postgres

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

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 New

func New(db *pgxpool.Pool, cfg auth.Config) *PGStore

New creates a new PGStore backed by the given pgx connection pool.

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

func (s *PGStore) AssignPermission(ctx context.Context, userID string, permissionKey string) error

AssignPermission assigns a permission directly to a user.

func (*PGStore) AssignUserToGroup

func (s *PGStore) AssignUserToGroup(ctx context.Context, userID string, groupID string) error

AssignUserToGroup adds a user to a group.

func (*PGStore) Bootstrap

func (s *PGStore) Bootstrap(ctx context.Context, superAdminEmail string) error

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

func (s *PGStore) CreateGroup(ctx context.Context, name string) (*auth.Group, error)

CreateGroup creates a new permission group.

func (*PGStore) CreateOTP

func (s *PGStore) CreateOTP(ctx context.Context, email string) (*auth.OTP, error)

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

func (s *PGStore) CreateSchema(ctx context.Context) error

CreateSchema applies all pending migrations. Delegates to Migrate for migration-based schema management.

func (*PGStore) CreateUser

func (s *PGStore) CreateUser(ctx context.Context, email string) (*auth.User, error)

CreateUser creates a new user with the given email.

func (*PGStore) DeleteGroup

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

DeleteGroup deletes a group by ID. Cascades to group_permissions and user_groups.

func (*PGStore) DeletePermission

func (s *PGStore) DeletePermission(ctx context.Context, id string) error

DeletePermission deletes a permission by its ID. Cascades to user_permissions and group_permissions.

func (*PGStore) DropSchema

func (s *PGStore) DropSchema(ctx context.Context) error

DropSchema drops all auth tables and the migrations tracking table.

func (*PGStore) GetGroup

func (s *PGStore) GetGroup(ctx context.Context, id string) (*auth.Group, error)

GetGroup fetches a group by ID, including its permissions.

func (*PGStore) GetPermission

func (s *PGStore) GetPermission(ctx context.Context, key string) (*auth.Permission, error)

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

func (s *PGStore) GetUserByEmail(ctx context.Context, email string) (*auth.User, error)

GetUserByEmail fetches a user by their email. Returns nil, nil if not found.

func (*PGStore) GetUserByID

func (s *PGStore) GetUserByID(ctx context.Context, id string) (*auth.User, error)

GetUserByID fetches a user by their ID. Returns nil, nil if not found.

func (*PGStore) GetUserGroups

func (s *PGStore) GetUserGroups(ctx context.Context, userID string) ([]auth.Group, error)

GetUserGroups returns all groups a user belongs to.

func (*PGStore) GetUserPermissions

func (s *PGStore) GetUserPermissions(ctx context.Context, userID string) ([]auth.Permission, error)

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

func (s *PGStore) ListGroups(ctx context.Context) ([]auth.Group, error)

ListGroups returns all groups (without permissions).

func (*PGStore) ListPermissions

func (s *PGStore) ListPermissions(ctx context.Context) ([]auth.Permission, error)

ListPermissions returns all permissions.

func (*PGStore) ListUsers

func (s *PGStore) ListUsers(ctx context.Context) ([]auth.User, error)

ListUsers returns all users.

func (*PGStore) Migrate

func (s *PGStore) Migrate(ctx context.Context) error

Migrate applies all pending migrations in order, within transactions.

func (*PGStore) MigrationStatus

func (s *PGStore) MigrationStatus(ctx context.Context) ([]auth.MigrationRecord, error)

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

func (s *PGStore) RemoveUserFromGroup(ctx context.Context, userID string, groupID string) error

RemoveUserFromGroup removes a user from a group.

func (*PGStore) RevokePermission

func (s *PGStore) RevokePermission(ctx context.Context, userID string, permissionKey string) error

RevokePermission removes a direct permission from a user.

func (*PGStore) Rollback

func (s *PGStore) Rollback(ctx context.Context) error

Rollback rolls back the last applied migration.

func (*PGStore) VerifyOTP

func (s *PGStore) VerifyOTP(ctx context.Context, email string, code string) (*auth.User, error)

VerifyOTP validates the OTP code for the given email. If valid, it marks the OTP as verified and returns the user (auto-creating if needed).

Jump to

Keyboard shortcuts

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