Documentation ¶
Index ¶
- Constants
- Variables
- func AddCredential(ctx context.Context, db sqlx.ExtContext, c *types.Credential) error
- func AsGRPCError(err error) error
- func CheckAndUpdateSignCount(ctx context.Context, tx *sqlx.Tx, c *types.Credential) error
- func GetUserCredentials(ctx context.Context, db sqlx.ExtContext, u *types.User) ([]*types.Credential, error)
- func IsErrEmpty(err error) bool
- func LookupSession(ctx context.Context, db sqlx.ExtContext, id []byte) (*types.Session, error)
- func LookupUser(ctx context.Context, db sqlx.ExtContext, user *types.User) error
- func RevokeSession(ctx context.Context, tx *sqlx.Tx, id []byte, reason string) error
- func UpdateSession(ctx context.Context, db sqlx.ExtContext, s *types.Session) error
- func UpdateUser(ctx context.Context, db sqlx.ExtContext, user *types.User) error
- func ValidSession(t *testing.T, e *jtesting.E, c *Connection) *types.Session
- func WrapRetryable(err error) error
- type Config
- type Connection
- type EmptyDB
- func (EmptyDB) BindNamed(_ string, _ interface{}) (string, []interface{}, error)
- func (EmptyDB) DriverName() string
- func (EmptyDB) ExecContext(_ context.Context, _ string, _ ...interface{}) (sql.Result, error)
- func (EmptyDB) QueryContext(_ context.Context, _ string, _ ...interface{}) (*sql.Rows, error)
- func (EmptyDB) QueryRowxContext(_ context.Context, _ string, _ ...interface{}) *sqlx.Row
- func (EmptyDB) QueryxContext(_ context.Context, _ string, _ ...interface{}) (*sqlx.Rows, error)
- func (EmptyDB) Rebind(_ string) string
- type EmptyResult
- type ErrEmpty
- type Retryable
Constants ¶
const ( MaxRetries = 3 TxDelay = 10 * time.Millisecond )
Variables ¶
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") )
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 ¶
AsGRPCError converts a store error to one with a gRPC status code. Is is valid to call with a nil error.
func CheckAndUpdateSignCount ¶
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 LookupSession ¶
LookupSession will return the session object for a provided session ID, if the session is still valid.
func LookupUser ¶
LookupUser fills in the provided user object, searching by ID or Username.
func RevokeSession ¶
RevokeSession will revoke the provided session.
func UpdateSession ¶
UpdateSession writes a session to the database.
func UpdateUser ¶
UpdateUser edits the provided user, creating it if it doesn't exist.
func ValidSession ¶
func WrapRetryable ¶
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 (*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.
type EmptyDB ¶
type EmptyDB struct{}
func (EmptyDB) DriverName ¶
func (EmptyDB) ExecContext ¶
func (EmptyDB) QueryContext ¶
func (EmptyDB) QueryRowxContext ¶
func (EmptyDB) QueryxContext ¶
type EmptyResult ¶
type EmptyResult struct{}
func (EmptyResult) LastInsertId ¶
func (EmptyResult) LastInsertId() (int64, error)
func (EmptyResult) RowsAffected ¶
func (EmptyResult) RowsAffected() (int64, error)