storage

package
v4.34.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2022 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrFmtMigrateUpTargetLessThanCurrent      = "schema up migration target version %d is less then the current version %d"
	ErrFmtMigrateUpTargetGreaterThanLatest    = "schema up migration target version %d is greater then the latest version %d which indicates it doesn't exist"
	ErrFmtMigrateDownTargetGreaterThanCurrent = "schema down migration target version %d is greater than the current version %d"
	ErrFmtMigrateDownTargetLessThanMinimum    = "schema down migration target version %d is less than the minimum version"
	ErrFmtMigrateAlreadyOnTargetVersion       = "schema migration target version %d is the same current version %d"
)

Error formats for the storage provider.

View Source
const (
	// SchemaLatest represents the value expected for a "migrate to latest" migration. It's the maximum 32bit signed integer.
	SchemaLatest = 2147483647
)

Variables

View Source
var (
	// ErrNoAuthenticationLogs error thrown when no matching authentication logs hve been found in DB.
	ErrNoAuthenticationLogs = errors.New("no matching authentication logs found")

	// ErrNoTOTPConfiguration error thrown when no TOTP configuration has been found in DB.
	ErrNoTOTPConfiguration = errors.New("no TOTP configuration for user")

	// ErrNoWebauthnDevice error thrown when no Webauthn device handle has been found in DB.
	ErrNoWebauthnDevice = errors.New("no Webauthn device found")

	// ErrNoDuoDevice error thrown when no Duo device and method has been found in DB.
	ErrNoDuoDevice = errors.New("no Duo device and method saved")

	// ErrNoAvailableMigrations is returned when no available migrations can be found.
	ErrNoAvailableMigrations = errors.New("no available migrations")

	// ErrMigrateCurrentVersionSameAsTarget is returned when the target version is the same as the current.
	ErrMigrateCurrentVersionSameAsTarget = errors.New("current version is same as migration target, no action being taken")

	// ErrSchemaAlreadyUpToDate is returned when the schema is already up to date.
	ErrSchemaAlreadyUpToDate = errors.New("schema already up to date")

	// ErrNoMigrationsFound is returned when no migrations were found.
	ErrNoMigrationsFound = errors.New("no schema migrations found")

	// ErrSchemaEncryptionVersionUnsupported is returned when the schema is checked if the encryption key is valid for
	// the database but the schema doesn't support encryption.
	ErrSchemaEncryptionVersionUnsupported = errors.New("schema version doesn't support encryption")

	// ErrSchemaEncryptionInvalidKey is returned when the schema is checked if the encryption key is valid for
	// the database but the key doesn't appear to be valid.
	ErrSchemaEncryptionInvalidKey = errors.New("the encryption key is not valid against the schema check value")
)

Functions

func SchemaVersionToString added in v4.33.0

func SchemaVersionToString(version int) (versionStr string)

SchemaVersionToString returns a version string given a version number.

Types

type MySQLProvider

type MySQLProvider struct {
	SQLProvider
}

MySQLProvider is a MySQL provider.

func NewMySQLProvider

func NewMySQLProvider(config *schema.Configuration) (provider *MySQLProvider)

NewMySQLProvider a MySQL provider.

type PostgreSQLProvider

type PostgreSQLProvider struct {
	SQLProvider
}

PostgreSQLProvider is a PostgreSQL provider.

func NewPostgreSQLProvider

func NewPostgreSQLProvider(config *schema.Configuration) (provider *PostgreSQLProvider)

NewPostgreSQLProvider a PostgreSQL provider.

type Provider

type Provider interface {
	models.StartupCheck

	RegulatorProvider

	SavePreferred2FAMethod(ctx context.Context, username string, method string) (err error)
	LoadPreferred2FAMethod(ctx context.Context, username string) (method string, err error)
	LoadUserInfo(ctx context.Context, username string) (info models.UserInfo, err error)

	SaveIdentityVerification(ctx context.Context, verification models.IdentityVerification) (err error)
	ConsumeIdentityVerification(ctx context.Context, jti string, ip models.NullIP) (err error)
	FindIdentityVerification(ctx context.Context, jti string) (found bool, err error)

	SaveTOTPConfiguration(ctx context.Context, config models.TOTPConfiguration) (err error)
	UpdateTOTPConfigurationSignIn(ctx context.Context, id int, lastUsedAt *time.Time) (err error)
	DeleteTOTPConfiguration(ctx context.Context, username string) (err error)
	LoadTOTPConfiguration(ctx context.Context, username string) (config *models.TOTPConfiguration, err error)
	LoadTOTPConfigurations(ctx context.Context, limit, page int) (configs []models.TOTPConfiguration, err error)

	SaveWebauthnDevice(ctx context.Context, device models.WebauthnDevice) (err error)
	UpdateWebauthnDeviceSignIn(ctx context.Context, id int, rpid string, lastUsedAt *time.Time, signCount uint32, cloneWarning bool) (err error)
	LoadWebauthnDevices(ctx context.Context, limit, page int) (devices []models.WebauthnDevice, err error)
	LoadWebauthnDevicesByUsername(ctx context.Context, username string) (devices []models.WebauthnDevice, err error)

	SavePreferredDuoDevice(ctx context.Context, device models.DuoDevice) (err error)
	DeletePreferredDuoDevice(ctx context.Context, username string) (err error)
	LoadPreferredDuoDevice(ctx context.Context, username string) (device *models.DuoDevice, err error)

	SchemaTables(ctx context.Context) (tables []string, err error)
	SchemaVersion(ctx context.Context) (version int, err error)
	SchemaLatestVersion() (version int, err error)

	SchemaMigrate(ctx context.Context, up bool, version int) (err error)
	SchemaMigrationHistory(ctx context.Context) (migrations []models.Migration, err error)
	SchemaMigrationsUp(ctx context.Context, version int) (migrations []models.SchemaMigration, err error)
	SchemaMigrationsDown(ctx context.Context, version int) (migrations []models.SchemaMigration, err error)

	SchemaEncryptionChangeKey(ctx context.Context, encryptionKey string) (err error)
	SchemaEncryptionCheckKey(ctx context.Context, verbose bool) (err error)

	Close() (err error)
}

Provider is an interface providing storage capabilities for persisting any kind of data related to Authelia.

type RegulatorProvider added in v4.33.0

type RegulatorProvider interface {
	AppendAuthenticationLog(ctx context.Context, attempt models.AuthenticationAttempt) (err error)
	LoadAuthenticationLogs(ctx context.Context, username string, fromDate time.Time, limit, page int) (attempts []models.AuthenticationAttempt, err error)
}

RegulatorProvider is an interface providing storage capabilities for persisting any kind of data related to the regulator.

type SQLProvider

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

SQLProvider is a storage provider persisting data in a SQL database.

func NewSQLProvider added in v4.33.0

func NewSQLProvider(config *schema.Configuration, name, driverName, dataSourceName string) (provider SQLProvider)

NewSQLProvider generates a generic SQLProvider to be used with other SQL provider NewUp's.

func (*SQLProvider) AppendAuthenticationLog

func (p *SQLProvider) AppendAuthenticationLog(ctx context.Context, attempt models.AuthenticationAttempt) (err error)

AppendAuthenticationLog append a mark to the authentication log.

func (*SQLProvider) Close added in v4.33.0

func (p *SQLProvider) Close() (err error)

Close the underlying database connection.

func (*SQLProvider) ConsumeIdentityVerification added in v4.33.0

func (p *SQLProvider) ConsumeIdentityVerification(ctx context.Context, jti string, ip models.NullIP) (err error)

ConsumeIdentityVerification marks an identity verification record in the database as consumed.

func (*SQLProvider) DeletePreferredDuoDevice added in v4.33.0

func (p *SQLProvider) DeletePreferredDuoDevice(ctx context.Context, username string) (err error)

DeletePreferredDuoDevice deletes a Duo device of a given user.

func (*SQLProvider) DeleteTOTPConfiguration added in v4.33.0

func (p *SQLProvider) DeleteTOTPConfiguration(ctx context.Context, username string) (err error)

DeleteTOTPConfiguration delete a TOTP configuration from the database given a username.

func (*SQLProvider) FindIdentityVerification added in v4.33.0

func (p *SQLProvider) FindIdentityVerification(ctx context.Context, jti string) (found bool, err error)

FindIdentityVerification checks if an identity verification record is in the database and active.

func (*SQLProvider) LoadAuthenticationLogs added in v4.33.0

func (p *SQLProvider) LoadAuthenticationLogs(ctx context.Context, username string, fromDate time.Time, limit, page int) (attempts []models.AuthenticationAttempt, err error)

LoadAuthenticationLogs retrieve the latest failed authentications from the authentication log.

func (*SQLProvider) LoadPreferred2FAMethod

func (p *SQLProvider) LoadPreferred2FAMethod(ctx context.Context, username string) (method string, err error)

LoadPreferred2FAMethod load the preferred method for 2FA from the database.

func (*SQLProvider) LoadPreferredDuoDevice added in v4.33.0

func (p *SQLProvider) LoadPreferredDuoDevice(ctx context.Context, username string) (device *models.DuoDevice, err error)

LoadPreferredDuoDevice loads a Duo device of a given user.

func (*SQLProvider) LoadTOTPConfiguration added in v4.33.0

func (p *SQLProvider) LoadTOTPConfiguration(ctx context.Context, username string) (config *models.TOTPConfiguration, err error)

LoadTOTPConfiguration load a TOTP configuration given a username from the database.

func (*SQLProvider) LoadTOTPConfigurations added in v4.33.0

func (p *SQLProvider) LoadTOTPConfigurations(ctx context.Context, limit, page int) (configs []models.TOTPConfiguration, err error)

LoadTOTPConfigurations load a set of TOTP configurations.

func (*SQLProvider) LoadUserInfo added in v4.33.0

func (p *SQLProvider) LoadUserInfo(ctx context.Context, username string) (info models.UserInfo, err error)

LoadUserInfo loads the models.UserInfo from the database.

func (*SQLProvider) LoadWebauthnDevices added in v4.34.0

func (p *SQLProvider) LoadWebauthnDevices(ctx context.Context, limit, page int) (devices []models.WebauthnDevice, err error)

LoadWebauthnDevices loads Webauthn device registrations.

func (*SQLProvider) LoadWebauthnDevicesByUsername added in v4.34.0

func (p *SQLProvider) LoadWebauthnDevicesByUsername(ctx context.Context, username string) (devices []models.WebauthnDevice, err error)

LoadWebauthnDevicesByUsername loads all webauthn devices registration for a given username.

func (*SQLProvider) SaveIdentityVerification added in v4.33.0

func (p *SQLProvider) SaveIdentityVerification(ctx context.Context, verification models.IdentityVerification) (err error)

SaveIdentityVerification save an identity verification record to the database.

func (*SQLProvider) SavePreferred2FAMethod

func (p *SQLProvider) SavePreferred2FAMethod(ctx context.Context, username string, method string) (err error)

SavePreferred2FAMethod save the preferred method for 2FA to the database.

func (*SQLProvider) SavePreferredDuoDevice added in v4.33.0

func (p *SQLProvider) SavePreferredDuoDevice(ctx context.Context, device models.DuoDevice) (err error)

SavePreferredDuoDevice saves a Duo device.

func (*SQLProvider) SaveTOTPConfiguration added in v4.33.0

func (p *SQLProvider) SaveTOTPConfiguration(ctx context.Context, config models.TOTPConfiguration) (err error)

SaveTOTPConfiguration save a TOTP configuration of a given user in the database.

func (*SQLProvider) SaveWebauthnDevice added in v4.34.0

func (p *SQLProvider) SaveWebauthnDevice(ctx context.Context, device models.WebauthnDevice) (err error)

SaveWebauthnDevice saves a registered Webauthn device.

func (*SQLProvider) SchemaEncryptionChangeKey added in v4.33.0

func (p *SQLProvider) SchemaEncryptionChangeKey(ctx context.Context, encryptionKey string) (err error)

SchemaEncryptionChangeKey uses the currently configured key to decrypt values in the database and the key provided by this command to encrypt the values again and update them using a transaction.

func (*SQLProvider) SchemaEncryptionCheckKey added in v4.33.0

func (p *SQLProvider) SchemaEncryptionCheckKey(ctx context.Context, verbose bool) (err error)

SchemaEncryptionCheckKey checks the encryption key configured is valid for the database.

func (*SQLProvider) SchemaLatestVersion added in v4.33.0

func (p *SQLProvider) SchemaLatestVersion() (version int, err error)

SchemaLatestVersion returns the latest version available for migration.

func (*SQLProvider) SchemaMigrate added in v4.33.0

func (p *SQLProvider) SchemaMigrate(ctx context.Context, up bool, version int) (err error)

SchemaMigrate migrates from the current version to the provided version.

func (*SQLProvider) SchemaMigrationHistory added in v4.33.0

func (p *SQLProvider) SchemaMigrationHistory(ctx context.Context) (migrations []models.Migration, err error)

SchemaMigrationHistory returns migration history rows.

func (*SQLProvider) SchemaMigrationsDown added in v4.33.0

func (p *SQLProvider) SchemaMigrationsDown(ctx context.Context, version int) (migrations []models.SchemaMigration, err error)

SchemaMigrationsDown returns a list of migrations down available between the current version and the provided version.

func (*SQLProvider) SchemaMigrationsUp added in v4.33.0

func (p *SQLProvider) SchemaMigrationsUp(ctx context.Context, version int) (migrations []models.SchemaMigration, err error)

SchemaMigrationsUp returns a list of migrations up available between the current version and the provided version.

func (*SQLProvider) SchemaTables added in v4.33.0

func (p *SQLProvider) SchemaTables(ctx context.Context) (tables []string, err error)

SchemaTables returns a list of tables.

func (*SQLProvider) SchemaVersion added in v4.33.0

func (p *SQLProvider) SchemaVersion(ctx context.Context) (version int, err error)

SchemaVersion returns the version of the schema.

func (*SQLProvider) StartupCheck added in v4.33.0

func (p *SQLProvider) StartupCheck() (err error)

StartupCheck implements the provider startup check interface.

func (*SQLProvider) UpdateTOTPConfigurationSignIn added in v4.34.0

func (p *SQLProvider) UpdateTOTPConfigurationSignIn(ctx context.Context, id int, lastUsedAt *time.Time) (err error)

UpdateTOTPConfigurationSignIn updates a registered Webauthn devices sign in information.

func (*SQLProvider) UpdateWebauthnDeviceSignIn added in v4.34.0

func (p *SQLProvider) UpdateWebauthnDeviceSignIn(ctx context.Context, id int, rpid string, lastUsedAt *time.Time, signCount uint32, cloneWarning bool) (err error)

UpdateWebauthnDeviceSignIn updates a registered Webauthn devices sign in information.

type SQLiteProvider

type SQLiteProvider struct {
	SQLProvider
}

SQLiteProvider is a SQLite3 provider.

func NewSQLiteProvider

func NewSQLiteProvider(config *schema.Configuration) (provider *SQLiteProvider)

NewSQLiteProvider constructs a SQLite provider.

Jump to

Keyboard shortcuts

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