storage

package
v0.0.0-...-45c2084 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2022 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SessionExpirationDuration = 5 * time.Hour
)

Variables

View Source
var (
	// ErrNotFound is an error for cases when requested entity is not found.
	ErrNotFound = errors.New("entity not found")
)

Functions

func Builder

func Builder() sq.StatementBuilderType

Builder returns SQL Builder object

func Connect

func Connect(dsn string) (*sqlx.DB, error)

func NewSavepointStorage

func NewSavepointStorage(db *sqlx.DB, validator validator.IValidator, sseKey []byte) (*Storage, *SavepointDB)

func NewSavepointTX

func NewSavepointTX(db *sqlx.DB) *sqlx.Tx

func SQLErr

func SQLErr(err error) error

SQLErr wraps error from database

Types

type IBuilder

type IBuilder interface {
	ToSql() (string, []interface{}, error)
}

type IConn

type IConn interface {
	SelectContext(ctx context.Context, des interface{}, query string, args ...interface{}) error
	ExecContext(ctx context.Context, query string, args ...interface{}) (Result, error)
	GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
	QueryRowContext(ctx context.Context, query string, args ...interface{}) *Row
}

type IDb

type IDb interface {
	IConn
	SqlDB() *sql.DB
	BeginTxx(ctx context.Context, opts *TxOpts) (ITransaction, error)
}

func NewSqlxDB

func NewSqlxDB(db *sqlx.DB) IDb

type IStore

type IStore interface {
	Ping(ctx context.Context) error
	TruncateAll(ctx context.Context) error

	IssueSession(ctx context.Context, opts jwt.IOts) (domain.Session, string, error)
	RetrieveSession(ctx context.Context, opts jwt.IOts, token string) (session domain.Session, err error)
	NominateSession(ctx context.Context, jti string) error
	CandidateSession(ctx context.Context, jti, candidateID string, srp []byte) error
	DeleteSession(ctx context.Context, jti string) error
	OtpSessionSucceed(ctx context.Context, jti string) error
	DeleteUserSessionExcept(ctx context.Context, userID, jti string) error
	MakeOtpAttempt(ctx context.Context, jti string) error

	CreateUser(ctx context.Context, user *domain.User, uw *domain.UserWorkspace, workspace *domain.Workspace, cards []domain.CardWithItems) error
	FindUserIdentity(ctx context.Context, identity string) (user domain.User, err error)
	FindUser(ctx context.Context, ID string) (user domain.User, err error)
	TerminateUser(ctx context.Context, identity string, userID string) error
	UpdateCredentials(ctx context.Context, ID string, oldIdentity string, user domain.User) error
	IssueUserOtp(ctx context.Context, ID string, secret string) error
	EnableUserOtp(ctx context.Context, ID string, identity string, secret []byte) error
	DisableUserOtp(ctx context.Context, ID string) error

	CreateCardWithItems(ctx context.Context, card *domain.Card, items []domain.CardItem) error
	UpdateCardWithItems(ctx context.Context, card *domain.Card, items []domain.CardItem) error
	ListCardsByWorkspace(ctx context.Context, workspaceID string) (out []domain.Card, err error)
	ListCardItems(ctx context.Context, cardID string) (out []domain.CardItem, err error)
	DeleteCard(ctx context.Context, cardID string) error
	FindCard(ctx context.Context, ID string) (out domain.Card, err error)
	CloneCard(ctx context.Context, oldCardID string, titleEnc []byte) (out domain.Card, err error)
	ArchiveCard(ctx context.Context, ID string) (archived bool, err error)

	ListUserWithWorkspaces(ctx context.Context, userID string) (out []domain.UserWithWorkspace, err error)
	ListSharedUserWorkspaces(ctx context.Context, workspaceID, ownerID string) (out []domain.UserWorkspace, err error)
	DeleteUserWorkspace(ctx context.Context, ID string) error
	FindUserWorkspaceLink(ctx context.Context, userID, workspaceID string) (out domain.UserWorkspace, err error)
	CreateWorkspace(ctx context.Context, uw *domain.UserWorkspace, workspace *domain.Workspace) error
	FindUserWithWorkspace(ctx context.Context, ID string) (out domain.UserWithWorkspace, err error)
	FindUserWorkspace(ctx context.Context, ID string) (out domain.UserWorkspace, err error)
	DeleteWorkspace(ctx context.Context, ID string) error
	UpdateWorkspace(ctx context.Context, ID string, titleEnc []byte) error
	ShareUserWorkspace(ctx context.Context, uw *domain.UserWorkspace) error
}

type ITransaction

type ITransaction interface {
	IConn
	Rollback() error
	Commit() error
}

type Result

type Result = sql.Result

type Row

type Row = sql.Row

type SavepointDB

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

SavepointDB wrapper around sqlx database

func NewSavepointDB

func NewSavepointDB(db *sqlx.DB) *SavepointDB

func (*SavepointDB) BeginTxx

func (s *SavepointDB) BeginTxx(ctx context.Context, opts *TxOpts) (ITransaction, error)

func (*SavepointDB) Commit

func (s *SavepointDB) Commit() error

func (*SavepointDB) ExecContext

func (s *SavepointDB) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

func (*SavepointDB) Flush

func (s *SavepointDB) Flush()

Flush will roll back parent transaction (all save points inside will be destroyed)

func (*SavepointDB) GetContext

func (s *SavepointDB) GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error

func (*SavepointDB) QueryRowContext

func (s *SavepointDB) QueryRowContext(ctx context.Context, query string, args ...interface{}) *Row

func (*SavepointDB) Rollback

func (s *SavepointDB) Rollback() error

func (*SavepointDB) SelectContext

func (s *SavepointDB) SelectContext(ctx context.Context, des interface{}, query string, args ...interface{}) error

func (*SavepointDB) SqlDB

func (s *SavepointDB) SqlDB() *sql.DB

type SelectBuilder

type SelectBuilder = sq.SelectBuilder

type Sqlizer

type Sqlizer = sq.Sqlizer

func Expr

func Expr(sql string, args ...interface{}) Sqlizer

type SqlxDB

type SqlxDB struct {
	*sqlx.DB
}

SqlxDB wrapper around sqlx database

func (*SqlxDB) BeginTxx

func (s *SqlxDB) BeginTxx(ctx context.Context, opts *TxOpts) (ITransaction, error)

func (*SqlxDB) GetContext

func (s *SqlxDB) GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error

func (*SqlxDB) SqlDB

func (s *SqlxDB) SqlDB() *sql.DB

type Storage

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

func NewStorage

func NewStorage(db *sqlx.DB, validator validator.IValidator, sseKey []byte) *Storage

func (*Storage) ArchiveCard

func (s *Storage) ArchiveCard(ctx context.Context, ID string) (archived bool, err error)

func (*Storage) CandidateSession

func (s *Storage) CandidateSession(ctx context.Context, jti, candidateID string, srp []byte) error

func (*Storage) CloneCard

func (s *Storage) CloneCard(ctx context.Context, oldCardID string, titleEnc []byte) (out domain.Card, err error)

func (*Storage) CreateCardWithItems

func (s *Storage) CreateCardWithItems(ctx context.Context, card *domain.Card, items []domain.CardItem) error

func (*Storage) CreateUser

func (s *Storage) CreateUser(ctx context.Context, user *domain.User, uw *domain.UserWorkspace,
	workspace *domain.Workspace, cardsWithItems []domain.CardWithItems) error

func (*Storage) CreateWorkspace

func (s *Storage) CreateWorkspace(ctx context.Context, uw *domain.UserWorkspace, workspace *domain.Workspace) error

func (*Storage) DeleteCard

func (s *Storage) DeleteCard(ctx context.Context, cardID string) error

func (*Storage) DeleteSession

func (s *Storage) DeleteSession(ctx context.Context, jti string) error

func (*Storage) DeleteUserSessionExcept

func (s *Storage) DeleteUserSessionExcept(ctx context.Context, userID, jti string) error

DeleteUserSessionExcept deletes all issued sessions for specific user except the current one useful in password change or OTP enable

func (*Storage) DeleteUserWorkspace

func (s *Storage) DeleteUserWorkspace(ctx context.Context, ID string) error

func (*Storage) DeleteWorkspace

func (s *Storage) DeleteWorkspace(ctx context.Context, ID string) error

func (*Storage) DisableUserOtp

func (s *Storage) DisableUserOtp(ctx context.Context, ID string) error

func (*Storage) EnableUserOtp

func (s *Storage) EnableUserOtp(ctx context.Context, ID string, identity string, secret []byte) error

func (*Storage) Exec

func (s *Storage) Exec(ctx context.Context, conn IConn, query IBuilder) (Result, error)

func (*Storage) Exec1

func (s *Storage) Exec1(ctx context.Context, conn IConn, query IBuilder) error

func (*Storage) FindCard

func (s *Storage) FindCard(ctx context.Context, ID string) (out domain.Card, err error)

func (*Storage) FindSession

func (s *Storage) FindSession(ctx context.Context, jti string) (out domain.Session, err error)

FindSession test case usage only, for regular usage, please use RetrieveSession

func (*Storage) FindUser

func (s *Storage) FindUser(ctx context.Context, ID string) (user domain.User, err error)

func (*Storage) FindUserIdentity

func (s *Storage) FindUserIdentity(ctx context.Context, identity string) (user domain.User, err error)

func (*Storage) FindUserWithWorkspace

func (s *Storage) FindUserWithWorkspace(ctx context.Context, ID string) (out domain.UserWithWorkspace, err error)

func (*Storage) FindUserWorkspace

func (s *Storage) FindUserWorkspace(ctx context.Context, ID string) (out domain.UserWorkspace, err error)
func (s *Storage) FindUserWorkspaceLink(ctx context.Context, userID, workspaceID string) (out domain.UserWorkspace, err error)

func (*Storage) FindWorkspace

func (s *Storage) FindWorkspace(ctx context.Context, ID string) (out domain.Workspace, err error)

func (*Storage) Get

func (s *Storage) Get(ctx context.Context, conn IConn, dest interface{}, query IBuilder) error

func (*Storage) IssueSession

func (s *Storage) IssueSession(ctx context.Context, opts jwt.IOts) (domain.Session, string, error)

IssueSession creates a session for anonymous and generates JWT token

func (*Storage) IssueUserOtp

func (s *Storage) IssueUserOtp(ctx context.Context, ID string, secret string) error

func (*Storage) ListCardItems

func (s *Storage) ListCardItems(ctx context.Context, cardID string) (out []domain.CardItem, err error)

func (*Storage) ListCardsByWorkspace

func (s *Storage) ListCardsByWorkspace(ctx context.Context, workspaceID string) (out []domain.Card, err error)

func (*Storage) ListSharedUserWorkspaces

func (s *Storage) ListSharedUserWorkspaces(ctx context.Context, workspaceID, ownerID string) (out []domain.UserWorkspace, err error)

func (*Storage) ListUserWithWorkspaces

func (s *Storage) ListUserWithWorkspaces(ctx context.Context, userID string) (out []domain.UserWithWorkspace, err error)

func (*Storage) MakeOtpAttempt

func (s *Storage) MakeOtpAttempt(ctx context.Context, jti string) error

MakeOtpAttempt do several thinks: 1) validates id user does not reach max OTP attempts per minute 1) increments OTP attempts counter

func (*Storage) NominateSession

func (s *Storage) NominateSession(ctx context.Context, jti string) error

NominateSession moves candidateID to userID, from now it means that user is authorized

func (*Storage) OtpSessionSucceed

func (s *Storage) OtpSessionSucceed(ctx context.Context, jti string) error

func (*Storage) Ping

func (s *Storage) Ping(ctx context.Context) error

func (*Storage) QueryRow

func (s *Storage) QueryRow(ctx context.Context, conn IConn, query IBuilder) *Row

func (*Storage) RetrieveSession

func (s *Storage) RetrieveSession(ctx context.Context, opts jwt.IOts, token string) (session domain.Session, err error)

RetrieveSession find & verify a session by JWT token

func (*Storage) Select

func (s *Storage) Select(ctx context.Context, conn IConn, dest interface{}, query IBuilder) error

func (*Storage) SetValidator

func (s *Storage) SetValidator(validator validator.IValidator) *Storage

func (*Storage) ShareUserWorkspace

func (s *Storage) ShareUserWorkspace(ctx context.Context, uw *domain.UserWorkspace) error

func (*Storage) SqlDB

func (s *Storage) SqlDB() *sql.DB

SqlDB returns raw SQL connection, required for goose migrations

func (*Storage) TerminateUser

func (s *Storage) TerminateUser(ctx context.Context, identity string, userID string) error

func (*Storage) Truncate

func (s *Storage) Truncate(ctx context.Context, tables ...string) error

Truncate empty a table or set of tables

func (*Storage) TruncateAll

func (s *Storage) TruncateAll(ctx context.Context) error

TruncateAll empty whole database

func (*Storage) Tx

func (s *Storage) Tx(ctx context.Context, opts *TxOpts, fn TxFunc) (err error)

func (*Storage) UpdateCardWithItems

func (s *Storage) UpdateCardWithItems(ctx context.Context, card *domain.Card, items []domain.CardItem) error

func (*Storage) UpdateCredentials

func (s *Storage) UpdateCredentials(ctx context.Context, ID string, oldIdentity string, newUser domain.User) error

func (*Storage) UpdateWorkspace

func (s *Storage) UpdateWorkspace(ctx context.Context, ID string, titleEnc []byte) error

type Tx

type Tx = sqlx.Tx

type TxFunc

type TxFunc func(ctx context.Context, tx IConn) error

type TxOpts

type TxOpts = sql.TxOptions

Jump to

Keyboard shortcuts

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