Skip to content

Commit

Permalink
cleanup: rename EncryptionTypeString() to EncryptionType.String()
Browse files Browse the repository at this point in the history
This makes it easier to log the EncryptionType as string, or int,
whatever is preferred. Standard fmt formatting notations like %s or %d
can be used now.

Signed-off-by: Niels de Vos <[email protected]>
  • Loading branch information
nixpanic authored and mergify[bot] committed Apr 2, 2024
1 parent 5a6556c commit 86b5db9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
36 changes: 18 additions & 18 deletions e2e/rbd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2006,7 +2006,7 @@ var _ = Describe("RBD", func() {
"mapOptions": nbdMapOptions,
"cephLogStrategy": e2eDefaultCephLogStrategy,
"encrypted": "true",
"encryptionType": util.EncryptionTypeString(encType),
"encryptionType": encType.String(),
},
deletePolicy)
if err != nil {
Expand Down Expand Up @@ -2041,7 +2041,7 @@ var _ = Describe("RBD", func() {
f,
defaultSCName,
nil,
map[string]string{"encrypted": "true", "encryptionType": util.EncryptionTypeString(encType)},
map[string]string{"encrypted": "true", "encryptionType": encType.String()},
deletePolicy)
if err != nil {
framework.Failf("failed to create storageclass: %v", err)
Expand Down Expand Up @@ -2075,7 +2075,7 @@ var _ = Describe("RBD", func() {
f,
defaultSCName,
nil,
map[string]string{"encrypted": "true", "encryptionType": util.EncryptionTypeString(encType)},
map[string]string{"encrypted": "true", "encryptionType": encType.String()},
deletePolicy)
if err != nil {
framework.Failf("failed to create storageclass: %v", err)
Expand Down Expand Up @@ -2120,7 +2120,7 @@ var _ = Describe("RBD", func() {
scOpts := map[string]string{
"encrypted": "true",
"encryptionKMSID": "vault-test",
"encryptionType": util.EncryptionTypeString(encType),
"encryptionType": encType.String(),
}
err = createRBDStorageClass(f.ClientSet, f, defaultSCName, nil, scOpts, deletePolicy)
if err != nil {
Expand Down Expand Up @@ -2153,7 +2153,7 @@ var _ = Describe("RBD", func() {
scOpts := map[string]string{
"encrypted": "true",
"encryptionKMSID": "vault-tokens-test",
"encryptionType": util.EncryptionTypeString(encType),
"encryptionType": encType.String(),
}
err = createRBDStorageClass(f.ClientSet, f, defaultSCName, nil, scOpts, deletePolicy)
if err != nil {
Expand Down Expand Up @@ -2207,7 +2207,7 @@ var _ = Describe("RBD", func() {
scOpts := map[string]string{
"encrypted": "true",
"encryptionKMSID": "vault-tenant-sa-test",
"encryptionType": util.EncryptionTypeString(encType),
"encryptionType": encType.String(),
}
err = createRBDStorageClass(f.ClientSet, f, defaultSCName, nil, scOpts, deletePolicy)
if err != nil {
Expand Down Expand Up @@ -2246,7 +2246,7 @@ var _ = Describe("RBD", func() {
scOpts := map[string]string{
"encrypted": "true",
"encryptionKMSID": "secrets-metadata-test",
"encryptionType": util.EncryptionTypeString(encType),
"encryptionType": encType.String(),
}
err = createRBDStorageClass(f.ClientSet, f, defaultSCName, nil, scOpts, deletePolicy)
if err != nil {
Expand Down Expand Up @@ -2279,7 +2279,7 @@ var _ = Describe("RBD", func() {
scOpts := map[string]string{
"encrypted": "true",
"encryptionKMSID": "user-ns-secrets-metadata-test",
"encryptionType": util.EncryptionTypeString(encType),
"encryptionType": encType.String(),
}
err = createRBDStorageClass(f.ClientSet, f, defaultSCName, nil, scOpts, deletePolicy)
if err != nil {
Expand Down Expand Up @@ -2333,7 +2333,7 @@ var _ = Describe("RBD", func() {
scOpts := map[string]string{
"encrypted": "true",
"encryptionKMSID": "user-secrets-metadata-test",
"encryptionType": util.EncryptionTypeString(encType),
"encryptionType": encType.String(),
}
err = createRBDStorageClass(f.ClientSet, f, defaultSCName, nil, scOpts, deletePolicy)
if err != nil {
Expand Down Expand Up @@ -2460,7 +2460,7 @@ var _ = Describe("RBD", func() {
scOpts := map[string]string{
"encrypted": "true",
"encryptionKMSID": "vault-test",
"encryptionType": util.EncryptionTypeString(encType),
"encryptionType": encType.String(),
}
err = createRBDStorageClass(f.ClientSet, f, defaultSCName, nil, scOpts, deletePolicy)
if err != nil {
Expand Down Expand Up @@ -2494,7 +2494,7 @@ var _ = Describe("RBD", func() {
scOpts := map[string]string{
"encrypted": "true",
"encryptionKMSID": "vault-test",
"encryptionType": util.EncryptionTypeString(encType),
"encryptionType": encType.String(),
}
err = createRBDStorageClass(f.ClientSet, f, defaultSCName, nil, scOpts, deletePolicy)
if err != nil {
Expand All @@ -2504,7 +2504,7 @@ var _ = Describe("RBD", func() {
scOpts = map[string]string{
"encrypted": "true",
"encryptionKMSID": "vault-tenant-sa-test",
"encryptionType": util.EncryptionTypeString(encType),
"encryptionType": encType.String(),
}
err = createRBDStorageClass(f.ClientSet, f, restoreSCName, nil, scOpts, deletePolicy)
if err != nil {
Expand Down Expand Up @@ -2554,7 +2554,7 @@ var _ = Describe("RBD", func() {
scOpts := map[string]string{
"encrypted": "true",
"encryptionKMSID": "vault-test",
"encryptionType": util.EncryptionTypeString(encType),
"encryptionType": encType.String(),
}
err = createRBDStorageClass(f.ClientSet, f, defaultSCName, nil, scOpts, deletePolicy)
if err != nil {
Expand All @@ -2564,7 +2564,7 @@ var _ = Describe("RBD", func() {
scOpts = map[string]string{
"encrypted": "true",
"encryptionKMSID": "vault-tenant-sa-test",
"encryptionType": util.EncryptionTypeString(encType),
"encryptionType": encType.String(),
}
err = createRBDStorageClass(f.ClientSet, f, restoreSCName, nil, scOpts, deletePolicy)
if err != nil {
Expand Down Expand Up @@ -2617,7 +2617,7 @@ var _ = Describe("RBD", func() {
scOpts := map[string]string{
"encrypted": "true",
"encryptionKMSID": "secrets-metadata-test",
"encryptionType": util.EncryptionTypeString(encType),
"encryptionType": encType.String(),
}
err = createRBDStorageClass(f.ClientSet, f, defaultSCName, nil, scOpts, deletePolicy)
if err != nil {
Expand Down Expand Up @@ -2655,7 +2655,7 @@ var _ = Describe("RBD", func() {
scOpts := map[string]string{
"encrypted": "true",
"encryptionKMSID": "vault-test",
"encryptionType": util.EncryptionTypeString(encType),
"encryptionType": encType.String(),
}
err = createRBDStorageClass(f.ClientSet, f, defaultSCName, nil, scOpts, deletePolicy)
if err != nil {
Expand Down Expand Up @@ -4202,7 +4202,7 @@ var _ = Describe("RBD", func() {
scOpts := map[string]string{
"encrypted": "true",
"encryptionKMSID": "vault-test",
"encryptionType": util.EncryptionTypeString(encType),
"encryptionType": encType.String(),
}
err := createRBDStorageClass(f.ClientSet, f, defaultSCName, nil, scOpts, deletePolicy)
if err != nil {
Expand Down Expand Up @@ -4264,7 +4264,7 @@ var _ = Describe("RBD", func() {
) {
scOpts := map[string]string{
"encrypted": "true",
"encryptionType": util.EncryptionTypeString(encType),
"encryptionType": encType.String(),
"encryptionKMSID": "vault-test",
}
err := createRBDStorageClass(f.ClientSet, f, defaultSCName, nil, scOpts, deletePolicy)
Expand Down
8 changes: 4 additions & 4 deletions internal/journal/voljournal.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,8 @@ func (conn *Connection) CheckReservation(ctx context.Context,
if savedImageAttributes.EncryptionType != encryptionType {
return nil, fmt.Errorf("internal state inconsistent, omap encryption type"+
" mismatch, request type %q(%d) volume UUID (%s) volume omap encryption type %q (%d)",
util.EncryptionTypeString(encryptionType), encryptionType,
objUUID, util.EncryptionTypeString(savedImageAttributes.EncryptionType),
encryptionType, encryptionType,
objUUID, savedImageAttributes.EncryptionType,
savedImageAttributes.EncryptionType)
}
}
Expand Down Expand Up @@ -561,7 +561,7 @@ func (conn *Connection) ReserveName(ctx context.Context,
imagePool string, imagePoolID int64,
reqName, namePrefix, parentName, kmsConf, volUUID, owner,
backingSnapshotID string,
encryptionType util.EncryptionType,
encryptionType util.EncryptionType, //nolint:interfacer // prefer util.EncryptionType over fmt.Stringer
) (string, string, error) {
// TODO: Take in-arg as ImageAttributes?
var (
Expand Down Expand Up @@ -642,7 +642,7 @@ func (conn *Connection) ReserveName(ctx context.Context,
// Update UUID directory to store encryption values
if kmsConf != "" {
omapValues[cj.encryptKMSKey] = kmsConf
omapValues[cj.encryptionType] = util.EncryptionTypeString(encryptionType)
omapValues[cj.encryptionType] = encryptionType.String()
}

// if owner is passed, set it in the UUID directory too
Expand Down
2 changes: 1 addition & 1 deletion internal/util/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func ParseEncryptionType(typeStr string) EncryptionType {
}
}

func EncryptionTypeString(encType EncryptionType) string {
func (encType EncryptionType) String() string {
switch encType {
case EncryptionTypeBlock:
return encryptionTypeBlockString
Expand Down
2 changes: 1 addition & 1 deletion internal/util/crypto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func TestEncryptionType(t *testing.T) {
assert.EqualValues(t, EncryptionTypeNone, ParseEncryptionType(""))

for _, s := range []string{"file", "block", ""} {
assert.EqualValues(t, s, EncryptionTypeString(ParseEncryptionType(s)))
assert.EqualValues(t, s, ParseEncryptionType(s).String())
}
}

Expand Down

0 comments on commit 86b5db9

Please sign in to comment.