database

package
v0.0.0-...-db8f46d Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	Subject         string
	Name            string
	OperatorSubject string
	OperatorName    string
}

type MigrationHook

type MigrationHook func(from, to uint) error

MigrationHook is a function which runs before/after each migration.

type MigrationHooks

type MigrationHooks struct {
	// Hooks to run before each migration.
	Before []MigrationHook
	// Hooks to run after each migration.
	After []MigrationHook
}

MigrationHooks contains hooks to run before/after each migration.

type Operator

type Operator struct {
	Subject string
	Name    string
}

type PaginatedAccounts

type PaginatedAccounts struct {
	Pagination
	Accounts []Account
}

type PaginatedOperators

type PaginatedOperators struct {
	Pagination
	Operators []Operator
}

type PaginatedUsers

type PaginatedUsers struct {
	Pagination
	Users []User
}

type Pagination

type Pagination struct {
	Total int
	Limit int
}

type TxWrapper

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

TxWrapper is a database wrapper, with each call running in the same transaction.

func (*TxWrapper) Commit

func (w *TxWrapper) Commit() error

Commit commits the transaction if it has not already been rolled back.

func (*TxWrapper) GetAccountSubject

func (w *TxWrapper) GetAccountSubject(ctx context.Context, name, operatorName string) (subj string, err error)

func (*TxWrapper) GetJWTMigrationVersion

func (w *TxWrapper) GetJWTMigrationVersion(ctx context.Context) (int, error)

func (*TxWrapper) GetOperatorSubject

func (w *TxWrapper) GetOperatorSubject(ctx context.Context, name string) (subj string, err error)

func (*TxWrapper) GetUserSubject

func (w *TxWrapper) GetUserSubject(ctx context.Context, name, accountName, operatorName string) (subj string, err error)

func (*TxWrapper) ListAccountsRe

func (w *TxWrapper) ListAccountsRe(
	ctx context.Context,
	offset int,
	nameRegex,
	operatorNameRegex string,
) (p PaginatedAccounts, err error)

func (*TxWrapper) ListJWTs

func (w *TxWrapper) ListJWTs(ctx context.Context, offset int) (p paginatedJWTs, err error)

func (*TxWrapper) ListOperatorsRe

func (w *TxWrapper) ListOperatorsRe(ctx context.Context, offset int, regex string) (p PaginatedOperators, err error)

func (*TxWrapper) ListUsersRe

func (w *TxWrapper) ListUsersRe(
	ctx context.Context,
	offset int,
	nameRegex,
	accountNameRegex,
	operatorNameRegex string,
) (p PaginatedUsers, err error)

func (*TxWrapper) Rollback

func (w *TxWrapper) Rollback() error

Rollback rolls back the transaction if it has not already been committed.

func (*TxWrapper) WalkAccountSubjectsRe

func (w *TxWrapper) WalkAccountSubjectsRe(
	ctx context.Context,
	nameRegex,
	operatorNameRegex string,
	f func(a Account) bool,
) error

func (*TxWrapper) WalkJWTs

func (w *TxWrapper) WalkJWTs(ctx context.Context, f func(subj string) bool) error

func (*TxWrapper) WalkOperatorSubjectsRe

func (w *TxWrapper) WalkOperatorSubjectsRe(ctx context.Context, regex string, f func(o Operator) bool) error

func (*TxWrapper) WalkUserSubjectsRe

func (w *TxWrapper) WalkUserSubjectsRe(
	ctx context.Context,
	nameRegex,
	accountNameRegex,
	operatorNameRegex string,
	f func(u User) bool,
) error

type User

type User struct {
	Subject         string
	Name            string
	AccountSubject  string
	AccountName     string
	OperatorSubject string
	OperatorName    string
}

type Wrapper

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

Wrapper wraps the PostgreSQL database (connection pool). It can start transactions.

func New

func New(url string, log logr.Logger, opts ...WrapperOpt) (*Wrapper, error)

New opens the database and creates a new database wrapper.

func (*Wrapper) BeginTxx

func (w *Wrapper) BeginTxx(ctx context.Context, opts *sql.TxOptions) (*TxWrapper, error)

BeginTxx creates a new TxWrapper. opts can be specified as nil to use default options.

func (*Wrapper) Close

func (w *Wrapper) Close() error

Close closes the Wrapper.

func (*Wrapper) CreateAccount

func (w *Wrapper) CreateAccount(ctx context.Context, name, subject, operatorSubject string) error

func (*Wrapper) CreateOperator

func (w *Wrapper) CreateOperator(ctx context.Context, name, subject string) error

func (*Wrapper) CreateUser

func (w *Wrapper) CreateUser(ctx context.Context, name, subject, accountSubject string) error

func (*Wrapper) GetAccountSubject

func (w *Wrapper) GetAccountSubject(ctx context.Context, name, operatorName string) (subj string, err error)

func (*Wrapper) GetJWTMigrationVersion

func (w *Wrapper) GetJWTMigrationVersion(ctx context.Context) (int, error)

func (*Wrapper) GetOperatorSubject

func (w *Wrapper) GetOperatorSubject(ctx context.Context, name string) (subj string, err error)

func (*Wrapper) GetUserSubject

func (w *Wrapper) GetUserSubject(ctx context.Context, name, accountName, operatorName string) (subj string, err error)

func (*Wrapper) ListAccountsRe

func (w *Wrapper) ListAccountsRe(
	ctx context.Context,
	offset int,
	nameRegex,
	operatorNameRegex string,
) (p PaginatedAccounts, err error)

func (*Wrapper) ListJWTs

func (w *Wrapper) ListJWTs(ctx context.Context, offset int) (p paginatedJWTs, err error)

func (*Wrapper) ListOperatorsRe

func (w *Wrapper) ListOperatorsRe(ctx context.Context, offset int, regex string) (p PaginatedOperators, err error)

func (*Wrapper) ListUsersRe

func (w *Wrapper) ListUsersRe(
	ctx context.Context,
	offset int,
	nameRegex,
	accountNameRegex,
	operatorNameRegex string,
) (p PaginatedUsers, err error)

func (*Wrapper) SetJWTMigrationVersion

func (w *Wrapper) SetJWTMigrationVersion(ctx context.Context, to int) error

func (*Wrapper) WalkAccountSubjectsRe

func (w *Wrapper) WalkAccountSubjectsRe(
	ctx context.Context,
	nameRegex,
	operatorNameRegex string,
	f func(a Account) bool,
) error

func (*Wrapper) WalkJWTs

func (w *Wrapper) WalkJWTs(ctx context.Context, f func(subj string) bool) error

func (*Wrapper) WalkOperatorSubjectsRe

func (w *Wrapper) WalkOperatorSubjectsRe(ctx context.Context, regex string, f func(o Operator) bool) error

func (*Wrapper) WalkUserSubjectsRe

func (w *Wrapper) WalkUserSubjectsRe(
	ctx context.Context,
	nameRegex,
	accountNameRegex,
	operatorNameRegex string,
	f func(u User) bool,
) error

type WrapperOpt

type WrapperOpt func(w wrapperOpts) wrapperOpts

WrapperOpt is a function which configures the options for the Wrapper.

func WithMigrationHooks

func WithMigrationHooks(h MigrationHooks) WrapperOpt

WithMigrationHooks adds migration hooks.

func WithMigrationsURL

func WithMigrationsURL(url string) WrapperOpt

WithMigrationsURL sets the URL at which the migrations can be found.

Jump to

Keyboard shortcuts

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