Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

Commit

Permalink
upgrade for breaking changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mikehelmick committed Sep 8, 2020
1 parent 310d248 commit 76e2de8
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
1 change: 1 addition & 0 deletions pkg/database/database-encryption-key/metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"t":"encryption"}
12 changes: 4 additions & 8 deletions pkg/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,17 @@ func (c *Config) Load(ctx context.Context) (*Database, error) {

// If the key manager is in-memory, accept the key as a base64-encoded
// in-memory key.
if c.Keys.KeyManagerType == keys.KeyManagerTypeInMemory {
typ, ok := keyManager.(keys.EncryptionKeyAdder)
if c.Keys.KeyManagerType == keys.KeyManagerTypeFilesystem {
typ, ok := keyManager.(keys.EncryptionKeyManager)
if !ok {
return nil, fmt.Errorf("key manager does not support adding keys")
}

key, err := base64util.DecodeString(c.EncryptionKey)
keyName, err := typ.CreateEncryptionKey(ctx, "", "database-encryption-key")
if err != nil {
return nil, fmt.Errorf("encryption key is invalid: %w", err)
}

if err := typ.AddEncryptionKey("database-encryption-key", key); err != nil {
return nil, fmt.Errorf("failed to add encryption key: %w", err)
}
c.EncryptionKey = "database-encryption-key"
c.EncryptionKey = keyName
}

return &Database{
Expand Down
2 changes: 1 addition & 1 deletion pkg/database/database_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func NewTestDatabaseWithConfig(tb testing.TB) (*Database, *Config) {
},

Keys: keys.Config{
KeyManagerType: keys.KeyManagerTypeInMemory,
KeyManagerType: keys.KeyManagerTypeFilesystem,
},
EncryptionKey: base64.RawStdEncoding.EncodeToString(generateKeys(tb, 1, 32)[0]),
}
Expand Down
1 change: 1 addition & 0 deletions pkg/otp/database-encryption-key/metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"t":"encryption"}

0 comments on commit 76e2de8

Please sign in to comment.