rbd: Handle encryption type default at a more meaningful place

Different places have different meaningful fallback. When parsing
from user we should default to block, when parsing stored config we
should default to invalid and handle that as an error.

Signed-off-by: Marcel Lauhoff <marcel.lauhoff@suse.com>
This commit is contained in:
Marcel Lauhoff 2022-08-04 17:15:52 +02:00 committed by mergify[bot]
parent 1fa842277a
commit a7ea12eb8e
2 changed files with 5 additions and 4 deletions

View File

@ -109,7 +109,7 @@ func (ri *rbdImage) isFileEncrypted() bool {
}
func IsFileEncrypted(ctx context.Context, volOptions map[string]string) (bool, error) {
_, encType, err := ParseEncryptionOpts(ctx, volOptions)
_, encType, err := ParseEncryptionOpts(ctx, volOptions, util.EncryptionTypeInvalid)
if err != nil {
return false, err
}
@ -306,7 +306,7 @@ func (rv *rbdVolume) openEncryptedDevice(ctx context.Context, devicePath string)
}
func (ri *rbdImage) initKMS(ctx context.Context, volOptions, credentials map[string]string) error {
kmsID, encType, err := ParseEncryptionOpts(ctx, volOptions)
kmsID, encType, err := ParseEncryptionOpts(ctx, volOptions, rbdDefaultEncryptionType)
if err != nil {
return err
} else if kmsID == "" {
@ -333,6 +333,7 @@ func (ri *rbdImage) initKMS(ctx context.Context, volOptions, credentials map[str
func ParseEncryptionOpts(
ctx context.Context,
volOptions map[string]string,
fallbackEncType util.EncryptionType,
) (string, util.EncryptionType, error) {
var (
err error
@ -348,7 +349,7 @@ func ParseEncryptionOpts(
return "", util.EncryptionTypeInvalid, err
}
encType := util.FetchEncryptionType(volOptions, rbdDefaultEncryptionType)
encType := util.FetchEncryptionType(volOptions, fallbackEncType)
return kmsID, encType, nil
}

View File

@ -568,7 +568,7 @@ func RegenerateJournal(
rbdVol.Owner = owner
kmsID, _, err = ParseEncryptionOpts(ctx, volumeAttributes)
kmsID, encryptionType, err = ParseEncryptionOpts(ctx, volumeAttributes, util.EncryptionTypeInvalid)
if err != nil {
return "", err
}