db

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2022 License: BSD-2-Clause Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound indicates the requested entity was not found
	ErrNotFound = errors.New("the requested entry was not found")
	// ErrAlreadyExists indicates the entity already exists within the store
	ErrAlreadyExists = errors.New("this entity already exists")
	// ErrInUse signals a foreign key violation
	ErrInUse = errors.New("this entity is needed for another entity")
)

Functions

func BootstrapListeners

func BootstrapListeners(store Auditor, log *zap.Logger) []events.EventListener

BootstrapListeners registers all the event listeners from this package

Types

type ApplicationInvite

type ApplicationInvite struct {
	ApplicationID int    `db:"application_id"`
	Scopes        string `db:"scopes"`
}

type Auditor

type Auditor interface {
	// contains filtered or unexported methods
}

Auditor is a way to write audit log events into a persistent store

type CommonTokenDetails

type CommonTokenDetails struct {
	ID              int                 `db:"id"`
	AuthorizationId uuid.UUID           `db:"authorization_id"`
	UserID          uuid.UUID           `db:"user_id"`
	TokenType       string              `db:"token_type"`
	Token           string              `db:"token"`
	Properties      tables.MapStructure `db:"properties"`
	RedeemedAt      *time.Time          `db:"redeemed_at"`
	RevokedAt       *time.Time          `db:"revoked_at"`
	ExpiresAt       time.Time           `db:"expires_at"`
	ClientID        string              `db:"client_id"`
	IssuedAt        time.Time           `db:"created_at"`
}

func (*CommonTokenDetails) CodeChallenge

func (c *CommonTokenDetails) CodeChallenge() string

func (*CommonTokenDetails) CodeChallengeMethod

func (c *CommonTokenDetails) CodeChallengeMethod() string

type DataStore

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

func NewMysqlStore

func NewMysqlStore(logger *zap.Logger, cfg *config.DatabaseConfiguration) (*DataStore, error)

func NewPostgrestore

func NewPostgrestore(logger *zap.Logger, cfg *config.DatabaseConfiguration) (*DataStore, error)

func NewSqliteStore

func NewSqliteStore(logger *zap.Logger, cfg *config.DatabaseConfiguration) (*DataStore, error)

func (*DataStore) ActiveApplicationsWithUserAuthorizations

func (d *DataStore) ActiveApplicationsWithUserAuthorizations(
	ctx context.Context,
	userID uuid.UUID,
) ([]*tables.ApplicationTable, error)

func (*DataStore) ActiveAuthorizationByCommonToken

func (d *DataStore) ActiveAuthorizationByCommonToken(
	ctx context.Context,
	tokenType string,
	token string,
) (*tables.AuthorizationTable, error)

func (*DataStore) ActiveAuthorizationByUserAndClientID

func (d *DataStore) ActiveAuthorizationByUserAndClientID(
	ctx context.Context,
	clientID string,
	userID uuid.UUID,
) (*tables.AuthorizationTable, error)

func (*DataStore) ActiveAuthorizationsByUserID

func (d *DataStore) ActiveAuthorizationsByUserID(
	ctx context.Context,
	userID uuid.UUID,
) ([]*tables.AuthorizationTable, error)

func (*DataStore) AddRole

func (d *DataStore) AddRole(ctx context.Context, role string) (int, error)

func (*DataStore) AddUserToRole

func (d *DataStore) AddUserToRole(ctx context.Context, id uuid.UUID, role string) error

func (*DataStore) ApplicationByClientID

func (d *DataStore) ApplicationByClientID(
	ctx context.Context,
	clientID string,
) (*tables.ApplicationTable, error)

func (*DataStore) ApplicationByID

func (d *DataStore) ApplicationByID(ctx context.Context, id int) (*tables.ApplicationTable, error)

func (*DataStore) Applications

func (d *DataStore) Applications(
	ctx context.Context,
	opts ListOptions,
) ([]*tables.ApplicationTable, int, error)

func (*DataStore) Auditor

func (d *DataStore) Auditor() Auditor

func (*DataStore) AuthorizationByID

func (d *DataStore) AuthorizationByID(
	ctx context.Context,
	id uuid.UUID,
) (*tables.AuthorizationTable, error)

func (*DataStore) Authorizations

func (d *DataStore) Authorizations(
	ctx context.Context,
	opts ListOptions,
) ([]*tables.AuthorizationTable, int, error)

func (*DataStore) BanUser

func (d *DataStore) BanUser(ctx context.Context, id uuid.UUID) error

func (*DataStore) Close

func (d *DataStore) Close()

func (*DataStore) CommonTokenDetails

func (d *DataStore) CommonTokenDetails(
	ctx context.Context,
	tokenType string,
	token string,
) (*CommonTokenDetails, error)

func (*DataStore) ConfirmTokenExists

func (d *DataStore) ConfirmTokenExists(ctx context.Context, token string) (bool, error)

func (*DataStore) ConfirmUser

func (d *DataStore) ConfirmUser(ctx context.Context, confirmToken string) (bool, uuid.UUID, error)

func (*DataStore) ConsumeInvite

func (d *DataStore) ConsumeInvite(ctx context.Context, inviteCode string) error

func (*DataStore) ConsumeRecoveryToken

func (d *DataStore) ConsumeRecoveryToken(
	ctx context.Context,
	id uuid.UUID,
	recoveryToken string,
) (bool, error)

func (*DataStore) CreateApplication

func (d *DataStore) CreateApplication(ctx context.Context,
	appType int,
	clientID string,
	clientSecret *string,
	name string,
	confidentiality string,
	properties tables.MapStructure) (int, error)

func (*DataStore) DeleteAllRetiredApplications

func (d *DataStore) DeleteAllRetiredApplications(ctx context.Context) ([]string, error)

func (*DataStore) DeleteRole

func (d *DataStore) DeleteRole(ctx context.Context, role string) error

func (*DataStore) DisableMFA

func (d *DataStore) DisableMFA(ctx context.Context, id uuid.UUID) (bool, error)

func (*DataStore) EnableMFA

func (d *DataStore) EnableMFA(
	ctx context.Context,
	id uuid.UUID,
	userSecret string,
	userRecoveryKey string,
) (bool, error)

func (*DataStore) EnsureUsable

func (d *DataStore) EnsureUsable() error

func (*DataStore) GrantAuthorization

func (d *DataStore) GrantAuthorization(
	ctx context.Context,
	applicationId int,
	userID uuid.UUID,
	properties tables.MapStructure,
) (uuid.UUID, error)

func (*DataStore) IDFromEmail

func (d *DataStore) IDFromEmail(ctx context.Context, email string) (bool, uuid.UUID, error)

func (*DataStore) InsertCommonToken

func (d *DataStore) InsertCommonToken(
	ctx context.Context,
	authorizationID uuid.UUID,
	tokenType string,
	token string,
	expires time.Time,
	properties tables.MapStructure,
) (int, error)

func (*DataStore) InsertUser

func (d *DataStore) InsertUser(
	ctx context.Context,
	email string,
	passwordHash string,
	phone *string,
	confirmToken *string,
) (uuid.UUID, error)

func (*DataStore) InviteCodeExists

func (d *DataStore) InviteCodeExists(ctx context.Context, code string) (bool, error)

func (*DataStore) InviteData

func (d *DataStore) InviteData(ctx context.Context, inviteCode string) (*UserInviteData, error)

func (*DataStore) InviteUser

func (d *DataStore) InviteUser(
	ctx context.Context,
	expires time.Time,
	email *string,
	code string,
	roles []string,
	applications ...int,
) error

func (*DataStore) Invites

func (d *DataStore) Invites(
	ctx context.Context,
	opts ListOptions,
) ([]*tables.UserInviteTable, int, error)

func (*DataStore) IsInviteable

func (d *DataStore) IsInviteable(ctx context.Context, email string) (bool, error)

func (*DataStore) IsRegistred

func (d *DataStore) IsRegistred(ctx context.Context, email string) (bool, error)

func (*DataStore) IsUserInRole

func (d *DataStore) IsUserInRole(ctx context.Context, id uuid.UUID, role string) (bool, error)

func (*DataStore) LockUser

func (d *DataStore) LockUser(ctx context.Context, id uuid.UUID, lockTime time.Time) (bool, error)

func (*DataStore) ManualConfirmUser

func (d *DataStore) ManualConfirmUser(ctx context.Context, id uuid.UUID) error

func (*DataStore) RedeemCommonToken

func (d *DataStore) RedeemCommonToken(ctx context.Context, tokenType string, token string) error

func (*DataStore) RemoveUserFromRole

func (d *DataStore) RemoveUserFromRole(ctx context.Context, id uuid.UUID, role string) error

func (*DataStore) RetireApplication

func (d *DataStore) RetireApplication(ctx context.Context, id int) (int64, int64, error)

func (*DataStore) RevokeAuthorization

func (d *DataStore) RevokeAuthorization(ctx context.Context, id uuid.UUID) (int64, error)

func (*DataStore) RevokeCommonToken

func (d *DataStore) RevokeCommonToken(ctx context.Context, tokenType string, token string) error

func (*DataStore) RevokeCommonTokensForAuthorization

func (d *DataStore) RevokeCommonTokensForAuthorization(
	ctx context.Context,
	authorizationID uuid.UUID,
) (int, error)

func (*DataStore) Roles

func (d *DataStore) Roles(ctx context.Context, opts ListOptions) ([]*tables.RoleTable, int, error)

func (*DataStore) SetApplicationSecret

func (d *DataStore) SetApplicationSecret(
	ctx context.Context,
	clientID string,
	secret string,
) error

func (*DataStore) SetEmail

func (d *DataStore) SetEmail(ctx context.Context, id uuid.UUID, email string) (bool, error)

func (*DataStore) SetFailureCount

func (d *DataStore) SetFailureCount(ctx context.Context, id uuid.UUID, count int) error

func (*DataStore) SetInviteSent

func (d *DataStore) SetInviteSent(ctx context.Context, email string, code string) error

func (*DataStore) SetOTPPending

func (d *DataStore) SetOTPPending(ctx context.Context, id uuid.UUID, pending bool) error

func (*DataStore) SetPassword

func (d *DataStore) SetPassword(
	ctx context.Context,
	id uuid.UUID,
	passwordHash string,
) (bool, error)

func (*DataStore) SetRecoveryToken

func (d *DataStore) SetRecoveryToken(
	ctx context.Context,
	id uuid.UUID,
	recoveryToken string,
) (bool, error)

func (*DataStore) UnbanUser

func (d *DataStore) UnbanUser(ctx context.Context, id uuid.UUID) error

func (*DataStore) UnlockUser

func (d *DataStore) UnlockUser(ctx context.Context, id uuid.UUID) (bool, error)

func (*DataStore) UpdateApplicationProperties

func (d *DataStore) UpdateApplicationProperties(
	ctx context.Context,
	clientID string,
	properties tables.MapStructure,
) error

func (*DataStore) User

func (d *DataStore) User(ctx context.Context, userID uuid.UUID) (*tables.UserTable, error)

func (*DataStore) UserByEmail

func (d *DataStore) UserByEmail(ctx context.Context, email string) (*UserData, error)

func (*DataStore) UserByID

func (d *DataStore) UserByID(ctx context.Context, id uuid.UUID) (*UserData, error)

func (*DataStore) UserRoles

func (d *DataStore) UserRoles(ctx context.Context, id uuid.UUID) ([]*tables.RoleTable, error)

func (*DataStore) Users

func (d *DataStore) Users(ctx context.Context, opts ListOptions) ([]*tables.UserTable, int, error)

type ListOptions

type ListOptions struct {
	PageSize int
	Page     int
	Sort     string
	Query    string
}

type UserAuthorization

type UserAuthorization struct {
	ID              uuid.UUID           `db:"id"`
	ClientID        string              `db:"client_id"`
	RevokedAt       *time.Time          `db:"revoked_at"`
	Properties      tables.MapStructure `db:"properties"`
	ApplicationType string              `db:"type"`
}

type UserData

type UserData struct {
	ID                  uuid.UUID
	Email               string
	EmailConfirmed      *time.Time
	Phone               *string
	PhoneConfirmed      *time.Time
	TwoFactor           bool
	TwoFactorSecret     string
	OtpPending          bool
	BannedOn            *time.Time
	LockoutTill         *time.Time
	PasswordHash        []byte
	CurrentFailureCount int
	LastSignIn          *time.Time
	Roles               []string
	Authorizations      []*UserAuthorization
}

type UserInviteData

type UserInviteData struct {
	Roles                       []string
	Expires                     time.Time
	PreApplicationAuthorization []ApplicationInvite
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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