store

package
v0.0.0-...-a92fb97 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2020 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxRetries = 3
	TxDelay    = 10 * time.Millisecond
)

Variables

View Source
var (
	ErrNothingToUpdate      = errors.New("nothing to update")
	ErrSessionExpired       = errors.New("session expired")
	ErrSessionNotYetCreated = errors.New("session not yet created?")
	ErrSessionIDInvalid     = errors.New("session id is not valid")
	ErrSignCountDecreased   = errors.New("authenticator's signature counter is not higher than the stored signature counter; possible cloned authenticator")
)
View Source
var ErrUnimplemented = errors.New("unimplemented")

Functions

func AddCredential

func AddCredential(ctx context.Context, db sqlx.ExtContext, c *types.Credential) error

AddCredential adds a credential to the database. The credential object must refer to a valid user and session.

func AsGRPCError

func AsGRPCError(err error) error

AsGRPCError converts a store error to one with a gRPC status code. Is is valid to call with a nil error.

func CheckAndUpdateSignCount

func CheckAndUpdateSignCount(ctx context.Context, tx *sqlx.Tx, c *types.Credential) error

CheckAndUpdateSignCount updates the sign count associated with the credential, and returns an error if it would have decreased.

func GetUserCredentials

func GetUserCredentials(ctx context.Context, db sqlx.ExtContext, u *types.User) ([]*types.Credential, error)

GetUserCredentials returns a list of all currently-valid credentials associated with the provided user.

func IsErrEmpty

func IsErrEmpty(err error) bool

func LookupSession

func LookupSession(ctx context.Context, db sqlx.ExtContext, id []byte) (*types.Session, error)

LookupSession will return the session object for a provided session ID, if the session is still valid.

func LookupUser

func LookupUser(ctx context.Context, db sqlx.ExtContext, user *types.User) error

LookupUser fills in the provided user object, searching by ID or Username.

func RevokeSession

func RevokeSession(ctx context.Context, tx *sqlx.Tx, id []byte, reason string) error

RevokeSession will revoke the provided session.

func UpdateSession

func UpdateSession(ctx context.Context, db sqlx.ExtContext, s *types.Session) error

UpdateSession writes a session to the database.

func UpdateUser

func UpdateUser(ctx context.Context, db sqlx.ExtContext, user *types.User) error

UpdateUser edits the provided user, creating it if it doesn't exist.

func ValidSession

func ValidSession(t *testing.T, e *jtesting.E, c *Connection) *types.Session

func WrapRetryable

func WrapRetryable(err error) error

Types

type Config

type Config struct {
	DatabaseURL   string `long:"database_url" description:"Postgres connection string pointing at the database" env:"DATABASE_URL"`
	RunMigrations bool   `long:"run_migrations" description:"If true, migrate the database after connecting." env:"RUN_MIGRATIONS"`
}

Config is environment/command-line config for storage.

type Connection

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

Connection is a connection to storage for jsso.

func Connect

func Connect(ctx context.Context, dsn string) (*Connection, error)

Connect connects to the database.

func MustGetTestDB

func MustGetTestDB(t *testing.T, e *jtesting.E) *Connection

func Wrap

func Wrap(ctx context.Context, db *sql.DB) (*Connection, error)

Wrap wraps an existing connection to the database.

func (*Connection) AuthenticateUser

func (c *Connection) AuthenticateUser(ctx context.Context, l *zap.Logger, ss []*types.Session, unusedHeaders []*sessions.UnusedHeader, unusedCookies []*sessions.UnusedCookie) (*types.Session, []error)

AuthenticateUser checks the database for a valid session in the provided sessions. The provided sessions need only contain a session ID. Each lookup is done in a separate transaction.

func (*Connection) DoTx

func (c *Connection) DoTx(origCtx context.Context, l *zap.Logger, readOnly bool, f func(tx *sqlx.Tx) error) error

DoTx executes the provied function in a transaction, retrying it if it rolls back. You should not manually commit or roll back the provided transaction; return an error to roll back or return nil to commit.

func (*Connection) MigrateDB

func (c *Connection) MigrateDB(ctx context.Context) error

type EmptyDB

type EmptyDB struct{}

func (EmptyDB) BindNamed

func (EmptyDB) BindNamed(_ string, _ interface{}) (string, []interface{}, error)

func (EmptyDB) DriverName

func (EmptyDB) DriverName() string

func (EmptyDB) ExecContext

func (EmptyDB) ExecContext(_ context.Context, _ string, _ ...interface{}) (sql.Result, error)

func (EmptyDB) QueryContext

func (EmptyDB) QueryContext(_ context.Context, _ string, _ ...interface{}) (*sql.Rows, error)

func (EmptyDB) QueryRowxContext

func (EmptyDB) QueryRowxContext(_ context.Context, _ string, _ ...interface{}) *sqlx.Row

func (EmptyDB) QueryxContext

func (EmptyDB) QueryxContext(_ context.Context, _ string, _ ...interface{}) (*sqlx.Rows, error)

func (EmptyDB) Rebind

func (EmptyDB) Rebind(_ string) string

type EmptyResult

type EmptyResult struct{}

func (EmptyResult) LastInsertId

func (EmptyResult) LastInsertId() (int64, error)

func (EmptyResult) RowsAffected

func (EmptyResult) RowsAffected() (int64, error)

type ErrEmpty

type ErrEmpty struct {
	Field string
}

func (*ErrEmpty) Error

func (e *ErrEmpty) Error() string

type Retryable

type Retryable struct {
	Err error
}

Retryable allows you to explicitly mark an error as retryable.

func (*Retryable) Error

func (r *Retryable) Error() string

func (*Retryable) Unwrap

func (r *Retryable) Unwrap() error

Jump to

Keyboard shortcuts

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