storage

package
Version: v4.33.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2021 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")

	// ErrNoU2FDeviceHandle error thrown when no U2F device handle has been found in DB.
	ErrNoU2FDeviceHandle = errors.New("no U2F device handle 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)
	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)

	SaveU2FDevice(ctx context.Context, device models.U2FDevice) (err error)
	LoadU2FDevice(ctx context.Context, username string) (device *models.U2FDevice, err error)
	LoadU2FDevices(ctx context.Context, limit, page int) (devices []models.U2FDevice, 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) LoadU2FDevice added in v4.33.0

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

LoadU2FDevice loads a U2F device registration for a given username.

func (*SQLProvider) LoadU2FDevices added in v4.33.0

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

LoadU2FDevices loads U2F device registrations.

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) 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) SaveU2FDevice added in v4.33.0

func (p *SQLProvider) SaveU2FDevice(ctx context.Context, device models.U2FDevice) (err error)

SaveU2FDevice saves a registered U2F 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.

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