Documentation ¶
Index ¶
- Constants
- Variables
- func Builder() sq.StatementBuilderType
- func Connect(dsn string) (*sqlx.DB, error)
- func NewSavepointStorage(db *sqlx.DB, validator validator.IValidator, sseKey []byte) (*Storage, *SavepointDB)
- func NewSavepointTX(db *sqlx.DB) *sqlx.Tx
- func SQLErr(err error) error
- type IBuilder
- type IConn
- type IDb
- type IStore
- type ITransaction
- type Result
- type Row
- type SavepointDB
- func (s *SavepointDB) BeginTxx(ctx context.Context, opts *TxOpts) (ITransaction, error)
- func (s *SavepointDB) Commit() error
- func (s *SavepointDB) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (s *SavepointDB) Flush()
- func (s *SavepointDB) GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
- func (s *SavepointDB) QueryRowContext(ctx context.Context, query string, args ...interface{}) *Row
- func (s *SavepointDB) Rollback() error
- func (s *SavepointDB) SelectContext(ctx context.Context, des interface{}, query string, args ...interface{}) error
- func (s *SavepointDB) SqlDB() *sql.DB
- type SelectBuilder
- type Sqlizer
- type SqlxDB
- type Storage
- func (s *Storage) ArchiveCard(ctx context.Context, ID string) (archived bool, err error)
- func (s *Storage) CandidateSession(ctx context.Context, jti, candidateID string, srp []byte) error
- func (s *Storage) CloneCard(ctx context.Context, oldCardID string, titleEnc []byte) (out domain.Card, err error)
- func (s *Storage) CreateCardWithItems(ctx context.Context, card *domain.Card, items []domain.CardItem) error
- func (s *Storage) CreateUser(ctx context.Context, user *domain.User, uw *domain.UserWorkspace, ...) error
- func (s *Storage) CreateWorkspace(ctx context.Context, uw *domain.UserWorkspace, workspace *domain.Workspace) error
- func (s *Storage) DeleteCard(ctx context.Context, cardID string) error
- func (s *Storage) DeleteSession(ctx context.Context, jti string) error
- func (s *Storage) DeleteUserSessionExcept(ctx context.Context, userID, jti string) error
- func (s *Storage) DeleteUserWorkspace(ctx context.Context, ID string) error
- func (s *Storage) DeleteWorkspace(ctx context.Context, ID string) error
- func (s *Storage) DisableUserOtp(ctx context.Context, ID string) error
- func (s *Storage) EnableUserOtp(ctx context.Context, ID string, identity string, secret []byte) error
- func (s *Storage) Exec(ctx context.Context, conn IConn, query IBuilder) (Result, error)
- func (s *Storage) Exec1(ctx context.Context, conn IConn, query IBuilder) error
- func (s *Storage) FindCard(ctx context.Context, ID string) (out domain.Card, err error)
- func (s *Storage) FindSession(ctx context.Context, jti string) (out domain.Session, err error)
- func (s *Storage) FindUser(ctx context.Context, ID string) (user domain.User, err error)
- func (s *Storage) FindUserIdentity(ctx context.Context, identity string) (user domain.User, err error)
- func (s *Storage) FindUserWithWorkspace(ctx context.Context, ID string) (out domain.UserWithWorkspace, err error)
- 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 (s *Storage) FindWorkspace(ctx context.Context, ID string) (out domain.Workspace, err error)
- func (s *Storage) Get(ctx context.Context, conn IConn, dest interface{}, query IBuilder) error
- func (s *Storage) IssueSession(ctx context.Context, opts jwt.IOts) (domain.Session, string, error)
- func (s *Storage) IssueUserOtp(ctx context.Context, ID string, secret string) error
- func (s *Storage) ListCardItems(ctx context.Context, cardID string) (out []domain.CardItem, err error)
- func (s *Storage) ListCardsByWorkspace(ctx context.Context, workspaceID string) (out []domain.Card, err error)
- func (s *Storage) ListSharedUserWorkspaces(ctx context.Context, workspaceID, ownerID string) (out []domain.UserWorkspace, err error)
- func (s *Storage) ListUserWithWorkspaces(ctx context.Context, userID string) (out []domain.UserWithWorkspace, err error)
- func (s *Storage) MakeOtpAttempt(ctx context.Context, jti string) error
- func (s *Storage) NominateSession(ctx context.Context, jti string) error
- func (s *Storage) OtpSessionSucceed(ctx context.Context, jti string) error
- func (s *Storage) Ping(ctx context.Context) error
- func (s *Storage) QueryRow(ctx context.Context, conn IConn, query IBuilder) *Row
- func (s *Storage) RetrieveSession(ctx context.Context, opts jwt.IOts, token string) (session domain.Session, err error)
- func (s *Storage) Select(ctx context.Context, conn IConn, dest interface{}, query IBuilder) error
- func (s *Storage) SetValidator(validator validator.IValidator) *Storage
- func (s *Storage) ShareUserWorkspace(ctx context.Context, uw *domain.UserWorkspace) error
- func (s *Storage) SqlDB() *sql.DB
- func (s *Storage) TerminateUser(ctx context.Context, identity string, userID string) error
- func (s *Storage) Truncate(ctx context.Context, tables ...string) error
- func (s *Storage) TruncateAll(ctx context.Context) error
- func (s *Storage) Tx(ctx context.Context, opts *TxOpts, fn TxFunc) (err error)
- func (s *Storage) UpdateCardWithItems(ctx context.Context, card *domain.Card, items []domain.CardItem) error
- func (s *Storage) UpdateCredentials(ctx context.Context, ID string, oldIdentity string, newUser domain.User) error
- func (s *Storage) UpdateWorkspace(ctx context.Context, ID string, titleEnc []byte) error
- type Tx
- type TxFunc
- type TxOpts
Constants ¶
const (
SessionExpirationDuration = 5 * time.Hour
)
Variables ¶
var ( // ErrNotFound is an error for cases when requested entity is not found. ErrNotFound = errors.New("entity not found") )
Functions ¶
func NewSavepointStorage ¶
func NewSavepointStorage(db *sqlx.DB, validator validator.IValidator, sseKey []byte) (*Storage, *SavepointDB)
Types ¶
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 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) 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 }
type ITransaction ¶
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 (*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 SqlxDB ¶
SqlxDB wrapper around sqlx database
func (*SqlxDB) GetContext ¶
type Storage ¶
type Storage struct {
// contains filtered or unexported fields
}
func NewStorage ¶
func (*Storage) ArchiveCard ¶
func (*Storage) CandidateSession ¶
func (*Storage) CreateCardWithItems ¶
func (*Storage) CreateUser ¶
func (*Storage) CreateWorkspace ¶
func (*Storage) DeleteSession ¶
func (*Storage) DeleteUserSessionExcept ¶
DeleteUserSessionExcept deletes all issued sessions for specific user except the current one useful in password change or OTP enable
func (*Storage) DeleteUserWorkspace ¶
func (*Storage) DeleteWorkspace ¶
func (*Storage) DisableUserOtp ¶
func (*Storage) EnableUserOtp ¶
func (*Storage) FindSession ¶
FindSession test case usage only, for regular usage, please use RetrieveSession
func (*Storage) FindUserIdentity ¶
func (*Storage) FindUserWithWorkspace ¶
func (*Storage) FindUserWorkspace ¶
func (*Storage) FindUserWorkspaceLink ¶
func (*Storage) FindWorkspace ¶
func (*Storage) IssueSession ¶
IssueSession creates a session for anonymous and generates JWT token
func (*Storage) IssueUserOtp ¶
func (*Storage) ListCardItems ¶
func (*Storage) ListCardsByWorkspace ¶
func (*Storage) ListSharedUserWorkspaces ¶
func (*Storage) ListUserWithWorkspaces ¶
func (*Storage) MakeOtpAttempt ¶
MakeOtpAttempt do several thinks: 1) validates id user does not reach max OTP attempts per minute 1) increments OTP attempts counter
func (*Storage) NominateSession ¶
NominateSession moves candidateID to userID, from now it means that user is authorized
func (*Storage) OtpSessionSucceed ¶
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) SetValidator ¶
func (s *Storage) SetValidator(validator validator.IValidator) *Storage
func (*Storage) ShareUserWorkspace ¶
func (*Storage) TerminateUser ¶
func (*Storage) TruncateAll ¶
TruncateAll empty whole database