postgres

package
v0.0.1-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var InitialSchema string

Functions

func MapTenantRole

func MapTenantRole(role string) string

MapTenantRole maps internal tenant role names to seeded RBAC role IDs

Types

type AccessTokenRepository

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

AccessTokenRepository implements oauth2.AccessTokenRepository

func NewAccessTokenRepository

func NewAccessTokenRepository(db *DB) *AccessTokenRepository

NewAccessTokenRepository creates a new access token repository

func (*AccessTokenRepository) Create

func (r *AccessTokenRepository) Create(token *oauth2.AccessToken) error

Create creates a new access token

func (*AccessTokenRepository) DeleteExpired

func (r *AccessTokenRepository) DeleteExpired() error

DeleteExpired deletes all expired access tokens

func (*AccessTokenRepository) GetByTokenHash

func (r *AccessTokenRepository) GetByTokenHash(tokenHash string) (*oauth2.AccessToken, error)

GetByTokenHash retrieves an access token

func (*AccessTokenRepository) Revoke

func (r *AccessTokenRepository) Revoke(tokenHash string) error

Revoke revokes an access token

type AssignmentRepository

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

AssignmentRepository implements authz.AssignmentRepository

func NewAssignmentRepository

func NewAssignmentRepository(db *DB) *AssignmentRepository

NewAssignmentRepository creates a new assignment repository

func (*AssignmentRepository) CheckExists

func (r *AssignmentRepository) CheckExists(roleID string, scope authz.Scope, scopeContextID *string) (bool, error)

CheckExists checks if a specific assignment exists

func (*AssignmentRepository) Grant

func (r *AssignmentRepository) Grant(assignment *authz.Assignment) error

Grant assigns a role to a user

func (*AssignmentRepository) ListByRole

func (r *AssignmentRepository) ListByRole(roleID string, scope authz.Scope, scopeContextID *string) ([]string, error)

ListByRole retrieves all users assigned a specific role at a scope

func (*AssignmentRepository) ListForUser

func (r *AssignmentRepository) ListForUser(userID string) ([]*authz.Assignment, error)

ListForUser retrieves all assignments for a user

func (*AssignmentRepository) Revoke

func (r *AssignmentRepository) Revoke(userID, roleID string, scope authz.Scope, scopeContextID *string) error

Revoke removes a role assignment

type AuthorizationCodeRepository

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

AuthorizationCodeRepository implements oauth2.AuthorizationCodeRepository

func NewAuthorizationCodeRepository

func NewAuthorizationCodeRepository(db *DB) *AuthorizationCodeRepository

NewAuthorizationCodeRepository creates a new authorization code repository

func (*AuthorizationCodeRepository) Create

Create creates a new authorization code

func (*AuthorizationCodeRepository) Delete

func (r *AuthorizationCodeRepository) Delete(code string) error

Delete deletes an authorization code

func (*AuthorizationCodeRepository) DeleteExpired

func (r *AuthorizationCodeRepository) DeleteExpired() error

DeleteExpired deletes all expired authorization codes

func (*AuthorizationCodeRepository) GetByCode

GetByCode retrieves an authorization code

func (*AuthorizationCodeRepository) MarkAsUsed

func (r *AuthorizationCodeRepository) MarkAsUsed(code string) error

MarkAsUsed marks the code as used

type ClientRepository

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

ClientRepository implements oauth2.ClientRepository

func NewClientRepository

func NewClientRepository(db *DB) *ClientRepository

NewClientRepository creates a new client repository

func (*ClientRepository) Create

func (r *ClientRepository) Create(client *oauth2.Client) error

Create creates a new OAuth2 client

func (*ClientRepository) Delete

func (r *ClientRepository) Delete(id string) error

Delete soft-deletes a client

func (*ClientRepository) GetByClientID

func (r *ClientRepository) GetByClientID(clientID string) (*oauth2.Client, error)

GetByClientID retrieves a client by client_id

func (*ClientRepository) GetByID

func (r *ClientRepository) GetByID(id string) (*oauth2.Client, error)

GetByID retrieves a client by internal ID

func (*ClientRepository) ListByOwner

func (r *ClientRepository) ListByOwner(ownerID string) ([]*oauth2.Client, error)

ListByOwner retrieves all clients for an owner

func (*ClientRepository) Update

func (r *ClientRepository) Update(client *oauth2.Client) error

Update updates client information

type Config

type Config struct {
	Host         string
	Port         string
	User         string
	Password     string
	Database     string
	SSLMode      string
	MaxOpenConns int
	MaxIdleConns int
}

Config holds database configuration

type DB

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

DB wraps the PostgreSQL connection pool

func New

func New(ctx context.Context, cfg Config) (*DB, error)

New creates a new database connection

func (*DB) Close

func (db *DB) Close()

Close closes the database connection

func (*DB) Migrate

func (db *DB) Migrate(ctx context.Context, script string) error

Migrate runs a SQL script

func (*DB) Pool

func (db *DB) Pool() *pgxpool.Pool

Pool returns the underlying connection pool

type KeyRepository

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

KeyRepository implements oauth2.KeyRepository

func NewKeyRepository

func NewKeyRepository(db *DB) *KeyRepository

NewKeyRepository creates a new key repository

func (*KeyRepository) Create

func (r *KeyRepository) Create(ctx context.Context, key *oauth2.Key) error

Create stores a new key

func (*KeyRepository) GetActiveKey

func (r *KeyRepository) GetActiveKey(ctx context.Context) (*oauth2.Key, error)

GetActiveKey retrieves the most recent valid key

func (*KeyRepository) ListValidKeys

func (r *KeyRepository) ListValidKeys(ctx context.Context) ([]*oauth2.Key, error)

ListValidKeys retrieves all valid keys

type ProjectRepository

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

ProjectRepository implements authz.ProjectRepository

func NewProjectRepository

func NewProjectRepository(db *DB) *ProjectRepository

NewProjectRepository creates a new project repository

func (*ProjectRepository) Create

func (r *ProjectRepository) Create(project *authz.Project) error

Create creates a new project

func (*ProjectRepository) Delete

func (r *ProjectRepository) Delete(id string) error

Delete soft-deletes a project

func (*ProjectRepository) GetByID

func (r *ProjectRepository) GetByID(id string) (*authz.Project, error)

GetByID retrieves a project by ID

func (*ProjectRepository) GetByName

func (r *ProjectRepository) GetByName(name string) (*authz.Project, error)

GetByName retrieves a project by name

func (*ProjectRepository) ListByOwner

func (r *ProjectRepository) ListByOwner(ownerID string) ([]*authz.Project, error)

ListByOwner retrieves all projects owned by a user

func (*ProjectRepository) ListByUser

func (r *ProjectRepository) ListByUser(userID string) ([]*authz.Project, error)

ListByUser retrieves all projects a user has access to

func (*ProjectRepository) Update

func (r *ProjectRepository) Update(project *authz.Project) error

Update updates project information

type RefreshTokenRepository

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

RefreshTokenRepository implements oauth2.RefreshTokenRepository

func NewRefreshTokenRepository

func NewRefreshTokenRepository(db *DB) *RefreshTokenRepository

NewRefreshTokenRepository creates a new refresh token repository

func (*RefreshTokenRepository) Create

func (r *RefreshTokenRepository) Create(token *oauth2.RefreshToken) error

Create creates a new refresh token

func (*RefreshTokenRepository) DeleteExpired

func (r *RefreshTokenRepository) DeleteExpired() error

DeleteExpired deletes all expired refresh tokens

func (*RefreshTokenRepository) GetByTokenHash

func (r *RefreshTokenRepository) GetByTokenHash(tokenHash string) (*oauth2.RefreshToken, error)

GetByTokenHash retrieves a refresh token

func (*RefreshTokenRepository) Revoke

func (r *RefreshTokenRepository) Revoke(tokenHash string) error

Revoke revokes a refresh token

type RoleRepository

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

RoleRepository implements authz.RoleRepository

func NewRoleRepository

func NewRoleRepository(db *DB) *RoleRepository

NewRoleRepository creates a new role repository

func (*RoleRepository) Create

func (r *RoleRepository) Create(role *authz.Role) error

Create creates a new role

func (*RoleRepository) Delete

func (r *RoleRepository) Delete(id string) error

Delete deletes a role

func (*RoleRepository) GetByID

func (r *RoleRepository) GetByID(id string) (*authz.Role, error)

GetByID retrieves a role by ID

func (*RoleRepository) GetByName

func (r *RoleRepository) GetByName(name string, scope authz.Scope) (*authz.Role, error)

GetByName retrieves a role by name and scope

func (*RoleRepository) List

func (r *RoleRepository) List(scope *authz.Scope) ([]*authz.Role, error)

List retrieves all roles, optionally filtered by scope

func (*RoleRepository) Update

func (r *RoleRepository) Update(role *authz.Role) error

Update updates role information

type SessionRepository

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

SessionRepository implements session.Repository

func NewSessionRepository

func NewSessionRepository(db *DB) *SessionRepository

NewSessionRepository creates a new session repository

func (*SessionRepository) Create

func (r *SessionRepository) Create(sess *session.Session) error

Create creates a new session

func (*SessionRepository) Delete

func (r *SessionRepository) Delete(sessionID string) error

Delete deletes a session

func (*SessionRepository) DeleteByUserID

func (r *SessionRepository) DeleteByUserID(userID string) error

DeleteByUserID deletes all sessions for a user

func (*SessionRepository) DeleteExpired

func (r *SessionRepository) DeleteExpired() error

DeleteExpired deletes all expired sessions

func (*SessionRepository) Get

func (r *SessionRepository) Get(sessionID string) (*session.Session, error)

Get retrieves a session by ID

func (*SessionRepository) Update

func (r *SessionRepository) Update(sess *session.Session) error

Update updates session last seen time

type TenantRepository

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

TenantRepository implements tenant.Repository

func NewTenantRepository

func NewTenantRepository(db *DB) *TenantRepository

NewTenantRepository creates a new tenant repository

func (*TenantRepository) Create

func (r *TenantRepository) Create(ctx context.Context, t *tenant.Tenant) error

Create creates a new tenant

func (*TenantRepository) Delete

func (r *TenantRepository) Delete(ctx context.Context, id string) error

Delete soft-deletes a tenant

func (*TenantRepository) GetByID

func (r *TenantRepository) GetByID(ctx context.Context, id string) (*tenant.Tenant, error)

GetByID retrieves a tenant by ID

func (*TenantRepository) GetByName

func (r *TenantRepository) GetByName(ctx context.Context, name string) (*tenant.Tenant, error)

GetByName retrieves a tenant by name

func (*TenantRepository) List

func (r *TenantRepository) List(ctx context.Context, limit, offset int) ([]*tenant.Tenant, error)

List lists tenants

func (*TenantRepository) Update

func (r *TenantRepository) Update(ctx context.Context, t *tenant.Tenant) error

Update updates a tenant

type TenantRoleRepository

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

TenantRoleRepository implements tenant.RoleRepository

func NewTenantRoleRepository

func NewTenantRoleRepository(db *DB) *TenantRoleRepository

NewTenantRoleRepository creates a new tenant role repository

func (*TenantRoleRepository) AssignRole

func (r *TenantRoleRepository) AssignRole(ctx context.Context, role *tenant.TenantUserRole) error

AssignRole assigns a role to a user in a tenant

func (*TenantRoleRepository) GetTenantUsers

func (r *TenantRoleRepository) GetTenantUsers(ctx context.Context, tenantID string) ([]*tenant.TenantUserRole, error)

GetTenantUsers retrieves all users with roles in a tenant

func (*TenantRoleRepository) GetUserRoles

func (r *TenantRoleRepository) GetUserRoles(ctx context.Context, tenantID, userID string) ([]*tenant.TenantUserRole, error)

GetUserRoles retrieves all roles a user has in a tenant

func (*TenantRoleRepository) RevokeRole

func (r *TenantRoleRepository) RevokeRole(ctx context.Context, tenantID, userID, role string) error

RevokeRole revokes a role from a user in a tenant

type UserRepository

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

UserRepository implements identity.UserRepository

func NewUserRepository

func NewUserRepository(db *DB) *UserRepository

NewUserRepository creates a new user repository

func (*UserRepository) AddCredentials

func (r *UserRepository) AddCredentials(credentials *identity.Credentials) error

AddCredentials adds credentials for a user

func (*UserRepository) Create

func (r *UserRepository) Create(user *identity.User) error

Create creates a new user identity

func (*UserRepository) Delete

func (r *UserRepository) Delete(id string) error

Delete soft-deletes a user

func (*UserRepository) GetByEmail

func (r *UserRepository) GetByEmail(tenantID *string, email string) (*identity.User, error)

GetByEmail retrieves a user by email within a tenant (or no tenant for Platform Admins)

func (*UserRepository) GetByID

func (r *UserRepository) GetByID(id string) (*identity.User, error)

GetByID retrieves a user by ID

func (*UserRepository) GetCredentials

func (r *UserRepository) GetCredentials(userID string) (*identity.Credentials, error)

GetCredentials retrieves user credentials

func (*UserRepository) Update

func (r *UserRepository) Update(user *identity.User) error

Update updates user information

func (*UserRepository) UpdateLockout

func (r *UserRepository) UpdateLockout(userID string, failedAttempts int, lockedUntil *time.Time) error

UpdateLockout updates user lockout status

func (*UserRepository) UpdatePassword

func (r *UserRepository) UpdatePassword(userID string, passwordHash string) error

UpdatePassword updates user password

Jump to

Keyboard shortcuts

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