diff --git a/pkg/adapter/config/etcd/doguConfigRepository.go b/pkg/adapter/config/etcd/doguConfigRepository.go index 6bfc8836..1ee31542 100644 --- a/pkg/adapter/config/etcd/doguConfigRepository.go +++ b/pkg/adapter/config/etcd/doguConfigRepository.go @@ -17,7 +17,7 @@ func NewDoguConfigRepository(etcdStore etcdStore) *DoguConfigRepository { } func (e DoguConfigRepository) Get(_ context.Context, key common.DoguConfigKey) (*ecosystem.DoguConfigEntry, error) { - entry, err := e.etcdStore.DoguConfig(string(key.DoguName)).Get(key.Key) + entry, err := e.etcdStore.DoguConfig(string(key.DoguName)).Get(string(key.Key)) if registry.IsKeyNotFoundError(err) { return nil, domainservice.NewNotFoundError(err, "could not find %s in etcd", key) } else if err != nil { @@ -33,7 +33,7 @@ func (e DoguConfigRepository) Get(_ context.Context, key common.DoguConfigKey) ( func (e DoguConfigRepository) Save(_ context.Context, entry *ecosystem.DoguConfigEntry) error { strDoguName := string(entry.Key.DoguName) strValue := string(entry.Value) - err := setEtcdKey(entry.Key.Key, strValue, e.etcdStore.DoguConfig(strDoguName)) + err := setEtcdKey(string(entry.Key.Key), strValue, e.etcdStore.DoguConfig(strDoguName)) if err != nil { return domainservice.NewInternalError(err, "failed to set %s with value %q in etcd", entry.Key, strValue) } @@ -43,7 +43,7 @@ func (e DoguConfigRepository) Save(_ context.Context, entry *ecosystem.DoguConfi func (e DoguConfigRepository) Delete(_ context.Context, key common.DoguConfigKey) error { strDoguName := string(key.DoguName) - err := deleteEtcdKey(key.Key, e.etcdStore.DoguConfig(strDoguName)) + err := deleteEtcdKey(string(key.Key), e.etcdStore.DoguConfig(strDoguName)) if err != nil && !registry.IsKeyNotFoundError(err) { return domainservice.NewInternalError(err, "failed to delete %s from etcd", key) } diff --git a/pkg/adapter/config/etcd/doguConfigRepository_test.go b/pkg/adapter/config/etcd/doguConfigRepository_test.go index 7a1fdbb0..943b8f13 100644 --- a/pkg/adapter/config/etcd/doguConfigRepository_test.go +++ b/pkg/adapter/config/etcd/doguConfigRepository_test.go @@ -25,7 +25,7 @@ func TestEtcdDoguConfigRepository_Delete(t *testing.T) { key := common.DoguConfigKey{Key: "key", DoguName: testSimpleDoguNameRedmine} etcdMock.EXPECT().DoguConfig(string(testSimpleDoguNameRedmine)).Return(configurationContextMock) - configurationContextMock.EXPECT().Delete(key.Key).Return(nil) + configurationContextMock.EXPECT().Delete(string(key.Key)).Return(nil) // when err := sut.Delete(testCtx, key) @@ -42,7 +42,7 @@ func TestEtcdDoguConfigRepository_Delete(t *testing.T) { key := common.DoguConfigKey{Key: "key", DoguName: testSimpleDoguNameRedmine} etcdMock.EXPECT().DoguConfig(string(testSimpleDoguNameRedmine)).Return(configurationContextMock) - configurationContextMock.EXPECT().Delete(key.Key).Return(etcdNotFoundError) + configurationContextMock.EXPECT().Delete(string(key.Key)).Return(etcdNotFoundError) // when err := sut.Delete(testCtx, key) @@ -59,7 +59,7 @@ func TestEtcdDoguConfigRepository_Delete(t *testing.T) { key := common.DoguConfigKey{Key: "key", DoguName: testSimpleDoguNameRedmine} etcdMock.EXPECT().DoguConfig(string(testSimpleDoguNameRedmine)).Return(configurationContextMock) - configurationContextMock.EXPECT().Delete(key.Key).Return(assert.AnError) + configurationContextMock.EXPECT().Delete(string(key.Key)).Return(assert.AnError) // when err := sut.Delete(testCtx, key) @@ -228,7 +228,7 @@ func TestEtcdDoguConfigRepository_Save(t *testing.T) { PersistenceContext: nil, } etcdMock.EXPECT().DoguConfig(string(testSimpleDoguNameRedmine)).Return(configurationContextMock) - configurationContextMock.EXPECT().Set(entry.Key.Key, string(entry.Value)).Return(nil) + configurationContextMock.EXPECT().Set(string(entry.Key.Key), string(entry.Value)).Return(nil) // when err := sut.Save(testCtx, entry) @@ -249,7 +249,7 @@ func TestEtcdDoguConfigRepository_Save(t *testing.T) { PersistenceContext: nil, } etcdMock.EXPECT().DoguConfig(string(testSimpleDoguNameRedmine)).Return(configurationContextMock) - configurationContextMock.EXPECT().Set(entry.Key.Key, string(entry.Value)).Return(assert.AnError) + configurationContextMock.EXPECT().Set(string(entry.Key.Key), string(entry.Value)).Return(assert.AnError) // when err := sut.Save(testCtx, entry) diff --git a/pkg/adapter/config/etcd/sensitiveDoguConfigRepository.go b/pkg/adapter/config/etcd/sensitiveDoguConfigRepository.go index d3de8a23..93f5beb3 100644 --- a/pkg/adapter/config/etcd/sensitiveDoguConfigRepository.go +++ b/pkg/adapter/config/etcd/sensitiveDoguConfigRepository.go @@ -18,7 +18,7 @@ func NewSensitiveDoguConfigRepository(etcdStore etcdStore) *SensitiveDoguConfigR } func (e SensitiveDoguConfigRepository) Get(_ context.Context, key common.SensitiveDoguConfigKey) (*ecosystem.SensitiveDoguConfigEntry, error) { - entry, err := e.etcdStore.DoguConfig(string(key.DoguName)).Get(key.Key) + entry, err := e.etcdStore.DoguConfig(string(key.DoguName)).Get(string(key.Key)) if registry.IsKeyNotFoundError(err) { return nil, domainservice.NewNotFoundError(err, "could not find sensitive %s in etcd", key) } else if err != nil { @@ -34,7 +34,7 @@ func (e SensitiveDoguConfigRepository) Get(_ context.Context, key common.Sensiti func (e SensitiveDoguConfigRepository) Save(_ context.Context, entry *ecosystem.SensitiveDoguConfigEntry) error { strDoguName := string(entry.Key.DoguName) strValue := string(entry.Value) - err := setEtcdKey(entry.Key.Key, strValue, e.etcdStore.DoguConfig(strDoguName)) + err := setEtcdKey(string(entry.Key.Key), strValue, e.etcdStore.DoguConfig(strDoguName)) if err != nil { return domainservice.NewInternalError(err, "failed to set encrypted %s with value %q in etcd", entry.Key, strValue) } @@ -44,7 +44,7 @@ func (e SensitiveDoguConfigRepository) Save(_ context.Context, entry *ecosystem. func (e SensitiveDoguConfigRepository) Delete(_ context.Context, key common.SensitiveDoguConfigKey) error { strDoguName := string(key.DoguName) - err := deleteEtcdKey(key.Key, e.etcdStore.DoguConfig(strDoguName)) + err := deleteEtcdKey(string(key.Key), e.etcdStore.DoguConfig(strDoguName)) if err != nil && !registry.IsKeyNotFoundError(err) { return domainservice.NewInternalError(err, "failed to delete encrypted %s from etcd", key) } diff --git a/pkg/adapter/config/etcd/sensitiveDoguConfigRepository_test.go b/pkg/adapter/config/etcd/sensitiveDoguConfigRepository_test.go index 3c280aab..4d4a631a 100644 --- a/pkg/adapter/config/etcd/sensitiveDoguConfigRepository_test.go +++ b/pkg/adapter/config/etcd/sensitiveDoguConfigRepository_test.go @@ -16,7 +16,7 @@ func TestEtcdSensitiveDoguConfigRepository_Delete(t *testing.T) { sut := SensitiveDoguConfigRepository{etcdStore: etcdMock} key := common.SensitiveDoguConfigKey{DoguConfigKey: common.DoguConfigKey{Key: "key", DoguName: testSimpleDoguNameRedmine}} etcdMock.EXPECT().DoguConfig(string(testSimpleDoguNameRedmine)).Return(configurationContextMock) - configurationContextMock.EXPECT().Delete(key.Key).Return(nil) + configurationContextMock.EXPECT().Delete(string(key.Key)).Return(nil) // when err := sut.Delete(testCtx, key) @@ -32,7 +32,7 @@ func TestEtcdSensitiveDoguConfigRepository_Delete(t *testing.T) { sut := SensitiveDoguConfigRepository{etcdStore: etcdMock} key := common.SensitiveDoguConfigKey{DoguConfigKey: common.DoguConfigKey{Key: "key", DoguName: testSimpleDoguNameRedmine}} etcdMock.EXPECT().DoguConfig(string(testSimpleDoguNameRedmine)).Return(configurationContextMock) - configurationContextMock.EXPECT().Delete(key.Key).Return(etcdNotFoundError) + configurationContextMock.EXPECT().Delete(string(key.Key)).Return(etcdNotFoundError) // when err := sut.Delete(testCtx, key) @@ -48,7 +48,7 @@ func TestEtcdSensitiveDoguConfigRepository_Delete(t *testing.T) { sut := SensitiveDoguConfigRepository{etcdStore: etcdMock} key := common.SensitiveDoguConfigKey{DoguConfigKey: common.DoguConfigKey{Key: "key", DoguName: testSimpleDoguNameRedmine}} etcdMock.EXPECT().DoguConfig(string(testSimpleDoguNameRedmine)).Return(configurationContextMock) - configurationContextMock.EXPECT().Delete(key.Key).Return(assert.AnError) + configurationContextMock.EXPECT().Delete(string(key.Key)).Return(assert.AnError) // when err := sut.Delete(testCtx, key) @@ -216,7 +216,7 @@ func TestEtcdSensitiveDoguConfigRepository_Save(t *testing.T) { Value: "value", } etcdMock.EXPECT().DoguConfig(string(testSimpleDoguNameRedmine)).Return(configurationContextMock) - configurationContextMock.EXPECT().Set(entry.Key.Key, string(entry.Value)).Return(nil) + configurationContextMock.EXPECT().Set(string(entry.Key.Key), string(entry.Value)).Return(nil) // when err := sut.Save(testCtx, entry) @@ -237,7 +237,7 @@ func TestEtcdSensitiveDoguConfigRepository_Save(t *testing.T) { PersistenceContext: nil, } etcdMock.EXPECT().DoguConfig(string(testSimpleDoguNameRedmine)).Return(configurationContextMock) - configurationContextMock.EXPECT().Set(entry.Key.Key, string(entry.Value)).Return(assert.AnError) + configurationContextMock.EXPECT().Set(string(entry.Key.Key), string(entry.Value)).Return(assert.AnError) // when err := sut.Save(testCtx, entry) diff --git a/pkg/adapter/kubernetes/blueprintcr/v1/config.go b/pkg/adapter/kubernetes/blueprintcr/v1/config.go index 7fc282c5..f0fc6656 100644 --- a/pkg/adapter/kubernetes/blueprintcr/v1/config.go +++ b/pkg/adapter/kubernetes/blueprintcr/v1/config.go @@ -3,6 +3,7 @@ package v1 import ( "github.com/cloudogu/k8s-blueprint-operator/pkg/domain" "github.com/cloudogu/k8s-blueprint-operator/pkg/domain/common" + "github.com/cloudogu/k8s-registry-lib/config" ) type Config struct { @@ -82,7 +83,7 @@ func convertToDoguConfigDTO(config domain.DoguConfig) DoguConfig { if len(config.Present) != 0 { present = make(map[string]string, len(config.Present)) for key, value := range config.Present { - present[key.Key] = string(value) + present[string(key.Key)] = string(value) } } @@ -92,7 +93,7 @@ func convertToDoguConfigDTO(config domain.DoguConfig) DoguConfig { if len(config.Absent) != 0 { absent = make([]string, len(config.Absent)) for i, key := range config.Absent { - absent[i] = key.Key + absent[i] = string(key.Key) } } @@ -132,7 +133,7 @@ func convertToDoguConfigDomain(doguName string, config DoguConfig) domain.DoguCo func convertToDoguConfigKeyDomain(doguName, key string) common.DoguConfigKey { return common.DoguConfigKey{ DoguName: common.SimpleDoguName(doguName), - Key: key, + Key: config.Key(key), } } @@ -143,7 +144,7 @@ func convertToSensitiveDoguConfigDTO(config domain.SensitiveDoguConfig) Sensitiv if len(config.Present) != 0 { present = make(map[string]string, len(config.Present)) for key, value := range config.Present { - present[key.Key] = string(value) + present[string(key.Key)] = string(value) } } @@ -153,7 +154,7 @@ func convertToSensitiveDoguConfigDTO(config domain.SensitiveDoguConfig) Sensitiv if len(config.Absent) != 0 { absent = make([]string, len(config.Absent)) for i, key := range config.Absent { - absent[i] = key.Key + absent[i] = string(key.Key) } } @@ -193,7 +194,7 @@ func convertToSensitiveDoguConfigDomain(doguName string, config SensitiveDoguCon func convertToSensitiveDoguConfigKeyDomain(doguName, key string) common.SensitiveDoguConfigKey { return common.SensitiveDoguConfigKey{DoguConfigKey: common.DoguConfigKey{ DoguName: common.SimpleDoguName(doguName), - Key: key, + Key: config.Key(key), }, } } diff --git a/pkg/adapter/kubernetes/blueprintcr/v1/doguConfigDiff.go b/pkg/adapter/kubernetes/blueprintcr/v1/doguConfigDiff.go index 6fbac276..a4264868 100644 --- a/pkg/adapter/kubernetes/blueprintcr/v1/doguConfigDiff.go +++ b/pkg/adapter/kubernetes/blueprintcr/v1/doguConfigDiff.go @@ -3,6 +3,7 @@ package v1 import ( "github.com/cloudogu/k8s-blueprint-operator/pkg/domain" "github.com/cloudogu/k8s-blueprint-operator/pkg/domain/common" + "github.com/cloudogu/k8s-registry-lib/config" ) type CombinedDoguConfigDiff struct { @@ -56,7 +57,7 @@ func convertToDoguConfigEntryDiffDomain(doguName string, dto DoguConfigEntryDiff return domain.DoguConfigEntryDiff{ Key: common.DoguConfigKey{ DoguName: common.SimpleDoguName(doguName), - Key: dto.Key, + Key: config.Key(dto.Key), }, Actual: domain.DoguConfigValueState{ Value: dto.Actual.Value, @@ -75,7 +76,7 @@ func convertToSensitiveDoguConfigEntryDiffDomain(doguName string, dto SensitiveD Key: common.SensitiveDoguConfigKey{ DoguConfigKey: common.DoguConfigKey{ DoguName: common.SimpleDoguName(doguName), - Key: dto.Key, + Key: config.Key(dto.Key), }, }, Actual: domain.DoguConfigValueState{ @@ -116,7 +117,7 @@ func convertToCombinedDoguConfigDiffDTO(domainModel domain.CombinedDoguConfigDif func convertToDoguConfigEntryDiffDTO(domainModel domain.DoguConfigEntryDiff) DoguConfigEntryDiff { return DoguConfigEntryDiff{ - Key: domainModel.Key.Key, + Key: string(domainModel.Key.Key), Actual: DoguConfigValueState{ Value: domainModel.Actual.Value, Exists: domainModel.Actual.Exists, @@ -131,7 +132,7 @@ func convertToDoguConfigEntryDiffDTO(domainModel domain.DoguConfigEntryDiff) Dog func convertToSensitiveDoguConfigEntryDiffDTO(domainModel domain.SensitiveDoguConfigEntryDiff) SensitiveDoguConfigEntryDiff { return SensitiveDoguConfigEntryDiff{ - Key: domainModel.Key.Key, + Key: string(domainModel.Key.Key), Actual: DoguConfigValueState{ Value: domainModel.Actual.Value, Exists: domainModel.Actual.Exists, diff --git a/pkg/application/ecosystemConfigUseCase_test.go b/pkg/application/ecosystemConfigUseCase_test.go index c3a07344..46503f4a 100644 --- a/pkg/application/ecosystemConfigUseCase_test.go +++ b/pkg/application/ecosystemConfigUseCase_test.go @@ -4,6 +4,7 @@ import ( "github.com/cloudogu/k8s-blueprint-operator/pkg/domain" "github.com/cloudogu/k8s-blueprint-operator/pkg/domain/common" "github.com/cloudogu/k8s-blueprint-operator/pkg/domain/ecosystem" + "github.com/cloudogu/k8s-registry-lib/config" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" @@ -532,7 +533,7 @@ func TestNewEcosystemConfigUseCase(t *testing.T) { func getSetDoguConfigEntryDiff(key, value string, doguName common.SimpleDoguName) domain.DoguConfigEntryDiff { return domain.DoguConfigEntryDiff{ Key: common.DoguConfigKey{ - Key: key, + Key: config.Key(key), DoguName: doguName, }, Expected: domain.DoguConfigValueState{ @@ -545,7 +546,7 @@ func getSetDoguConfigEntryDiff(key, value string, doguName common.SimpleDoguName func getRemoveDoguConfigEntryDiff(key string, doguName common.SimpleDoguName) domain.DoguConfigEntryDiff { return domain.DoguConfigEntryDiff{ Key: common.DoguConfigKey{ - Key: key, + Key: config.Key(key), DoguName: doguName, }, NeededAction: domain.ConfigActionRemove, @@ -556,7 +557,7 @@ func getSensitiveDoguConfigEntryDiffForAction(key, value string, doguName common return domain.SensitiveDoguConfigEntryDiff{ Key: common.SensitiveDoguConfigKey{ DoguConfigKey: common.DoguConfigKey{ - Key: key, + Key: config.Key(key), DoguName: doguName, }, }, @@ -571,7 +572,7 @@ func getRemoveSensitiveDoguConfigEntryDiff(key string, doguName common.SimpleDog return domain.SensitiveDoguConfigEntryDiff{ Key: common.SensitiveDoguConfigKey{ DoguConfigKey: common.DoguConfigKey{ - Key: key, + Key: config.Key(key), DoguName: doguName, }, }, diff --git a/pkg/domain/common/configNames.go b/pkg/domain/common/configNames.go index ec9d92ec..85569a3e 100644 --- a/pkg/domain/common/configNames.go +++ b/pkg/domain/common/configNames.go @@ -3,17 +3,18 @@ package common import ( "errors" "fmt" + "github.com/cloudogu/k8s-registry-lib/config" ) type RegistryConfigKey interface { GlobalConfigKey | DoguConfigKey | SensitiveDoguConfigKey } -type GlobalConfigKey string +type GlobalConfigKey = config.Key type DoguConfigKey struct { DoguName SimpleDoguName - Key string + Key config.Key } func (k DoguConfigKey) Validate() error { @@ -37,10 +38,10 @@ type SensitiveDoguConfigKey struct { } // GlobalConfigValue is a single global config value -type GlobalConfigValue string +type GlobalConfigValue = config.Value // DoguConfigValue is a single dogu config value, which is no sensitive configuration -type DoguConfigValue string +type DoguConfigValue = config.Value // SensitiveDoguConfigValue is a single unencrypted sensitive dogu config value -type SensitiveDoguConfigValue string +type SensitiveDoguConfigValue = config.Value diff --git a/pkg/domain/stateDiffConfig_test.go b/pkg/domain/stateDiffConfig_test.go index cc4ddbc5..713fbe06 100644 --- a/pkg/domain/stateDiffConfig_test.go +++ b/pkg/domain/stateDiffConfig_test.go @@ -450,7 +450,7 @@ func TestCombinedDoguConfigDiff_CensorValues(t *testing.T) { require.Len(t, result.DoguConfigDiff, 1) assert.Equal(t, "ldap", string(result.DoguConfigDiff[0].Key.DoguName)) - assert.Equal(t, "logging/root", result.DoguConfigDiff[0].Key.Key) + assert.Equal(t, "logging/root", string(result.DoguConfigDiff[0].Key.Key)) assert.Equal(t, "ERROR", result.DoguConfigDiff[0].Actual.Value) assert.Equal(t, false, result.DoguConfigDiff[0].Actual.Exists) assert.Equal(t, "DEBUG", result.DoguConfigDiff[0].Expected.Value) @@ -486,7 +486,7 @@ func TestCombinedDoguConfigDiff_CensorValues(t *testing.T) { require.Len(t, result.SensitiveDoguConfigDiff, 1) assert.Equal(t, "ldap", string(result.SensitiveDoguConfigDiff[0].Key.DoguName)) - assert.Equal(t, "logging/root", result.SensitiveDoguConfigDiff[0].Key.Key) + assert.Equal(t, "logging/root", string(result.SensitiveDoguConfigDiff[0].Key.Key)) assert.Equal(t, censorValue, result.SensitiveDoguConfigDiff[0].Actual.Value) assert.Equal(t, false, result.SensitiveDoguConfigDiff[0].Actual.Exists) assert.Equal(t, censorValue, result.SensitiveDoguConfigDiff[0].Expected.Value)