summaryrefslogtreecommitdiff
path: root/internal/commands/context.go
diff options
context:
space:
mode:
authorJames Elliott <james-d-elliott@users.noreply.github.com>2022-12-23 15:00:23 +1100
committerGitHub <noreply@github.com>2022-12-23 15:00:23 +1100
commitd7ab3bb6333af2c7bede8c10b99b216bbe215d07 (patch)
tree1e30120a586f7f76a694a91d6f49ae5eca1e2078 /internal/commands/context.go
parent0130edb870137b86ceb686505616796bd20c9b1a (diff)
feat(commands): storage import/export commands (#4545)
This adds commands to export and import TOTP configurations and Webauthn devices as YAML.
Diffstat (limited to 'internal/commands/context.go')
-rw-r--r--internal/commands/context.go21
1 files changed, 20 insertions, 1 deletions
diff --git a/internal/commands/context.go b/internal/commands/context.go
index edb79bc1e..ea3026759 100644
--- a/internal/commands/context.go
+++ b/internal/commands/context.go
@@ -24,6 +24,7 @@ import (
"github.com/authelia/authelia/v4/internal/oidc"
"github.com/authelia/authelia/v4/internal/regulation"
"github.com/authelia/authelia/v4/internal/session"
+ "github.com/authelia/authelia/v4/internal/storage"
"github.com/authelia/authelia/v4/internal/templates"
"github.com/authelia/authelia/v4/internal/totp"
"github.com/authelia/authelia/v4/internal/utils"
@@ -80,7 +81,6 @@ type CmdCtxConfig struct {
// CobraRunECmd describes a function that can be used as a *cobra.Command RunE, PreRunE, or PostRunE.
type CobraRunECmd func(cmd *cobra.Command, args []string) (err error)
-// CheckSchemaVersion is a utility function which checks the schema version.
func (ctx *CmdCtx) CheckSchemaVersion() (err error) {
if ctx.providers.StorageProvider == nil {
return fmt.Errorf("storage not loaded")
@@ -106,6 +106,25 @@ func (ctx *CmdCtx) CheckSchemaVersion() (err error) {
}
}
+// CheckSchema is a utility function which checks the schema version and encryption key.
+func (ctx *CmdCtx) CheckSchema() (err error) {
+ if err = ctx.CheckSchemaVersion(); err != nil {
+ return err
+ }
+
+ var result storage.EncryptionValidationResult
+
+ if result, err = ctx.providers.StorageProvider.SchemaEncryptionCheckKey(ctx, false); !result.Checked() || !result.Success() {
+ if err != nil {
+ return fmt.Errorf("failed to check the schema encryption key: %w", err)
+ }
+
+ return fmt.Errorf("failed to check the schema encryption key: the key is not valid for the schema")
+ }
+
+ return nil
+}
+
// LoadTrustedCertificates loads the trusted certificates into the CmdCtx.
func (ctx *CmdCtx) LoadTrustedCertificates() (warns, errs []error) {
ctx.trusted, warns, errs = utils.NewX509CertPool(ctx.config.CertificatesDirectory)