From 8698c266b68d3df28e1f4327a872e4395a287c95 Mon Sep 17 00:00:00 2001 From: Alexander Dammeier Date: Fri, 11 Oct 2024 15:15:25 +0200 Subject: [PATCH] #81 replace sensitiveDoguConfigEntryRepository completely --- .../config/etcd/doguConfigRepository.go | 64 --- .../config/etcd/doguConfigRepository_test.go | 484 ------------------ .../config/etcd/globalConfigRepository.go | 32 ++ .../etcd/globalConfigRepository_test.go | 6 + .../config/etcd/mock_registryEntry_test.go | 33 -- .../config/etcd/mock_registryKey_test.go | 33 -- .../etcd/sensitiveDoguConfigRepository.go | 104 ---- .../sensitiveDoguConfigRepository_test.go | 480 ----------------- .../kubernetes/blueprintcr/v1/config.go | 22 +- .../blueprintcr/v1/doguConfigDiff.go | 6 +- .../blueprintcr/v1/doguConfigDiff_test.go | 16 +- .../blueprintcr/v1/effectiveBlueprint_test.go | 8 +- .../blueprintV2/blueprintV2_test.go | 8 +- .../serializer/blueprintV2/serializer_test.go | 24 +- pkg/application/ecosystemConfigUseCase.go | 77 +-- .../ecosystemConfigUseCase_test.go | 137 +++-- pkg/application/interfaces.go | 5 - .../mock_doguConfigEntryRepository_test.go | 346 ------------- ...sensitiveDoguConfigEntryRepository_test.go | 346 ------------- pkg/application/stateDiffUseCase_test.go | 4 +- pkg/bootstrap.go | 4 +- pkg/domain/blueprintSpec_test.go | 2 +- pkg/domain/blueprint_test.go | 8 +- pkg/domain/common/configNames.go | 6 +- pkg/domain/config_test.go | 34 +- pkg/domain/stateDiffConfig_test.go | 16 +- pkg/domain/stateDiffSensitiveDoguConfig.go | 9 +- pkg/domainservice/adapterInterfaces.go | 62 --- .../mock_DoguConfigEntryRepository_test.go | 346 ------------- .../mock_DoguRestartAdapter_test.go | 82 --- ...SensitiveDoguConfigEntryRepository_test.go | 346 ------------- 31 files changed, 245 insertions(+), 2905 deletions(-) delete mode 100644 pkg/adapter/config/etcd/doguConfigRepository.go delete mode 100644 pkg/adapter/config/etcd/doguConfigRepository_test.go delete mode 100644 pkg/adapter/config/etcd/mock_registryEntry_test.go delete mode 100644 pkg/adapter/config/etcd/mock_registryKey_test.go delete mode 100644 pkg/adapter/config/etcd/sensitiveDoguConfigRepository.go delete mode 100644 pkg/adapter/config/etcd/sensitiveDoguConfigRepository_test.go delete mode 100644 pkg/application/mock_doguConfigEntryRepository_test.go delete mode 100644 pkg/application/mock_sensitiveDoguConfigEntryRepository_test.go delete mode 100644 pkg/domainservice/mock_DoguConfigEntryRepository_test.go delete mode 100644 pkg/domainservice/mock_DoguRestartAdapter_test.go delete mode 100644 pkg/domainservice/mock_SensitiveDoguConfigEntryRepository_test.go diff --git a/pkg/adapter/config/etcd/doguConfigRepository.go b/pkg/adapter/config/etcd/doguConfigRepository.go deleted file mode 100644 index 1ee31542..00000000 --- a/pkg/adapter/config/etcd/doguConfigRepository.go +++ /dev/null @@ -1,64 +0,0 @@ -package etcd - -import ( - "context" - "github.com/cloudogu/cesapp-lib/registry" - "github.com/cloudogu/k8s-blueprint-operator/pkg/domain/common" - "github.com/cloudogu/k8s-blueprint-operator/pkg/domain/ecosystem" - "github.com/cloudogu/k8s-blueprint-operator/pkg/domainservice" -) - -type DoguConfigRepository struct { - etcdStore etcdStore -} - -func NewDoguConfigRepository(etcdStore etcdStore) *DoguConfigRepository { - return &DoguConfigRepository{etcdStore: etcdStore} -} - -func (e DoguConfigRepository) Get(_ context.Context, key common.DoguConfigKey) (*ecosystem.DoguConfigEntry, error) { - 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 { - return nil, domainservice.NewInternalError(err, "failed to get %s from etcd", key) - } - - return &ecosystem.DoguConfigEntry{ - Key: key, - Value: common.DoguConfigValue(entry), - }, nil -} - -func (e DoguConfigRepository) Save(_ context.Context, entry *ecosystem.DoguConfigEntry) error { - strDoguName := string(entry.Key.DoguName) - strValue := string(entry.Value) - 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) - } - - return nil -} - -func (e DoguConfigRepository) Delete(_ context.Context, key common.DoguConfigKey) error { - strDoguName := string(key.DoguName) - 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) - } - - return nil -} - -func (e DoguConfigRepository) GetAllByKey(ctx context.Context, keys []common.DoguConfigKey) (map[common.DoguConfigKey]*ecosystem.DoguConfigEntry, error) { - return getAllByKeyOrEntry(ctx, keys, e.Get) -} - -func (e DoguConfigRepository) SaveAll(ctx context.Context, entries []*ecosystem.DoguConfigEntry) error { - return mapKeyOrEntry(ctx, entries, e.Save, "failed to set given dogu config entries in etcd") -} - -func (e DoguConfigRepository) DeleteAllByKeys(ctx context.Context, keys []common.DoguConfigKey) error { - return mapKeyOrEntry(ctx, keys, e.Delete, "failed to delete given dogu config keys in etcd") -} diff --git a/pkg/adapter/config/etcd/doguConfigRepository_test.go b/pkg/adapter/config/etcd/doguConfigRepository_test.go deleted file mode 100644 index 943b8f13..00000000 --- a/pkg/adapter/config/etcd/doguConfigRepository_test.go +++ /dev/null @@ -1,484 +0,0 @@ -package etcd - -import ( - "context" - "github.com/cloudogu/k8s-blueprint-operator/pkg/domain/common" - "github.com/cloudogu/k8s-blueprint-operator/pkg/domain/ecosystem" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "go.etcd.io/etcd/client/v2" - "testing" -) - -var testCtx = context.Background() - -const testSimpleDoguNameRedmine = common.SimpleDoguName("redmine") - -var etcdNotFoundError = client.Error{Code: client.ErrorCodeKeyNotFound} - -func TestEtcdDoguConfigRepository_Delete(t *testing.T) { - t.Run("success", func(t *testing.T) { - // given - etcdMock := newMockEtcdStore(t) - configurationContextMock := newMockConfigurationContext(t) - sut := &DoguConfigRepository{etcdStore: etcdMock} - - key := common.DoguConfigKey{Key: "key", DoguName: testSimpleDoguNameRedmine} - etcdMock.EXPECT().DoguConfig(string(testSimpleDoguNameRedmine)).Return(configurationContextMock) - configurationContextMock.EXPECT().Delete(string(key.Key)).Return(nil) - - // when - err := sut.Delete(testCtx, key) - - // then - require.NoError(t, err) - }) - - t.Run("should return nil on not found error", func(t *testing.T) { - // given - etcdMock := newMockEtcdStore(t) - configurationContextMock := newMockConfigurationContext(t) - sut := &DoguConfigRepository{etcdStore: etcdMock} - - key := common.DoguConfigKey{Key: "key", DoguName: testSimpleDoguNameRedmine} - etcdMock.EXPECT().DoguConfig(string(testSimpleDoguNameRedmine)).Return(configurationContextMock) - configurationContextMock.EXPECT().Delete(string(key.Key)).Return(etcdNotFoundError) - - // when - err := sut.Delete(testCtx, key) - - // then - require.NoError(t, err) - }) - - t.Run("should return error on delete error", func(t *testing.T) { - // given - etcdMock := newMockEtcdStore(t) - configurationContextMock := newMockConfigurationContext(t) - sut := &DoguConfigRepository{etcdStore: etcdMock} - - key := common.DoguConfigKey{Key: "key", DoguName: testSimpleDoguNameRedmine} - etcdMock.EXPECT().DoguConfig(string(testSimpleDoguNameRedmine)).Return(configurationContextMock) - configurationContextMock.EXPECT().Delete(string(key.Key)).Return(assert.AnError) - - // when - err := sut.Delete(testCtx, key) - - // then - require.Error(t, err) - assert.ErrorContains(t, err, "failed to delete key \"key\" of dogu \"redmine\" from etcd") - assert.ErrorIs(t, err, assert.AnError) - assert.ErrorAs(t, err, &internalErr) - }) -} - -func TestEtcdDoguConfigRepository_GetAllByKey(t *testing.T) { - t.Run("should fail with multiple keys", func(t *testing.T) { - // given - ldapConfigMock := newMockConfigurationContext(t) - ldapConfigMock.EXPECT().Get("container_config/memory_limit").Return("", etcdNotFoundError) - postfixConfigMock := newMockConfigurationContext(t) - postfixConfigMock.EXPECT().Get("container_config/swap_limit").Return("", assert.AnError) - etcdMock := newMockEtcdStore(t) - etcdMock.EXPECT().DoguConfig("ldap").Return(ldapConfigMock) - etcdMock.EXPECT().DoguConfig("postfix").Return(postfixConfigMock) - sut := &DoguConfigRepository{etcdStore: etcdMock} - - keys := []common.DoguConfigKey{ - { - DoguName: "ldap", - Key: "container_config/memory_limit", - }, - { - DoguName: "postfix", - Key: "container_config/swap_limit", - }, - } - - // when - _, err := sut.GetAllByKey(testCtx, keys) - - // then - assert.ErrorIs(t, err, etcdNotFoundError) - assert.ErrorAs(t, err, ¬FoundErr) - - assert.ErrorIs(t, err, assert.AnError) - assert.ErrorAs(t, err, &internalErr) - }) - t.Run("should succeed with multiple keys", func(t *testing.T) { - // given - ldapConfigMock := newMockConfigurationContext(t) - ldapConfigMock.EXPECT().Get("container_config/memory_limit").Return("1024m", nil) - postfixConfigMock := newMockConfigurationContext(t) - postfixConfigMock.EXPECT().Get("container_config/swap_limit").Return("512m", nil) - etcdMock := newMockEtcdStore(t) - etcdMock.EXPECT().DoguConfig("ldap").Return(ldapConfigMock) - etcdMock.EXPECT().DoguConfig("postfix").Return(postfixConfigMock) - sut := &DoguConfigRepository{etcdStore: etcdMock} - - keys := []common.DoguConfigKey{ - { - DoguName: "ldap", - Key: "container_config/memory_limit", - }, - { - DoguName: "postfix", - Key: "container_config/swap_limit", - }, - } - - // when - actualEntries, err := sut.GetAllByKey(testCtx, keys) - - // then - assert.NoError(t, err) - expectedEntries := map[common.DoguConfigKey]*ecosystem.DoguConfigEntry{ - { - DoguName: "ldap", - Key: "container_config/memory_limit", - }: { - Key: common.DoguConfigKey{ - DoguName: "ldap", - Key: "container_config/memory_limit", - }, - Value: "1024m", - }, - { - DoguName: "postfix", - Key: "container_config/swap_limit", - }: { - Key: common.DoguConfigKey{ - DoguName: "postfix", - Key: "container_config/swap_limit", - }, - Value: "512m", - }, - } - assert.Equal(t, expectedEntries, actualEntries) - }) - t.Run("not found errors should produce the other values", func(t *testing.T) { - // given - ldapConfigMock := newMockConfigurationContext(t) - ldapConfigMock.EXPECT().Get("container_config/memory_limit").Return("1024m", nil) - ldapConfigMock.EXPECT().Get("password_change/notification_enabled").Return("", etcdNotFoundError) - postfixConfigMock := newMockConfigurationContext(t) - postfixConfigMock.EXPECT().Get("container_config/swap_limit").Return("512m", nil) - etcdMock := newMockEtcdStore(t) - etcdMock.EXPECT().DoguConfig("ldap").Return(ldapConfigMock) - etcdMock.EXPECT().DoguConfig("postfix").Return(postfixConfigMock) - sut := &DoguConfigRepository{etcdStore: etcdMock} - - keys := []common.DoguConfigKey{ - { - DoguName: "ldap", - Key: "container_config/memory_limit", - }, - { - DoguName: "ldap", - Key: "password_change/notification_enabled", - }, - { - DoguName: "postfix", - Key: "container_config/swap_limit", - }, - } - - // when - actualEntries, err := sut.GetAllByKey(testCtx, keys) - - // then - assert.ErrorIs(t, err, etcdNotFoundError) - assert.ErrorAs(t, err, ¬FoundErr) - - expectedEntries := map[common.DoguConfigKey]*ecosystem.DoguConfigEntry{ - { - DoguName: "ldap", - Key: "container_config/memory_limit", - }: { - Key: common.DoguConfigKey{ - DoguName: "ldap", - Key: "container_config/memory_limit", - }, - Value: "1024m", - }, - { - DoguName: "postfix", - Key: "container_config/swap_limit", - }: { - Key: common.DoguConfigKey{ - DoguName: "postfix", - Key: "container_config/swap_limit", - }, - Value: "512m", - }, - } - assert.Equal(t, expectedEntries, actualEntries) - }) -} - -func TestEtcdDoguConfigRepository_Save(t *testing.T) { - t.Run("success", func(t *testing.T) { - // given - etcdMock := newMockEtcdStore(t) - configurationContextMock := newMockConfigurationContext(t) - sut := &DoguConfigRepository{etcdStore: etcdMock} - entry := &ecosystem.DoguConfigEntry{ - Key: common.DoguConfigKey{Key: "key", DoguName: testSimpleDoguNameRedmine}, - Value: "value", - PersistenceContext: nil, - } - etcdMock.EXPECT().DoguConfig(string(testSimpleDoguNameRedmine)).Return(configurationContextMock) - configurationContextMock.EXPECT().Set(string(entry.Key.Key), string(entry.Value)).Return(nil) - - // when - err := sut.Save(testCtx, entry) - - // then - require.NoError(t, err) - }) - - t.Run("should return error on save error", func(t *testing.T) { - // given - etcdMock := newMockEtcdStore(t) - configurationContextMock := newMockConfigurationContext(t) - sut := &DoguConfigRepository{etcdStore: etcdMock} - - entry := &ecosystem.DoguConfigEntry{ - Key: common.DoguConfigKey{Key: "key", DoguName: testSimpleDoguNameRedmine}, - Value: "value", - PersistenceContext: nil, - } - etcdMock.EXPECT().DoguConfig(string(testSimpleDoguNameRedmine)).Return(configurationContextMock) - configurationContextMock.EXPECT().Set(string(entry.Key.Key), string(entry.Value)).Return(assert.AnError) - - // when - err := sut.Save(testCtx, entry) - - // then - require.Error(t, err) - assert.ErrorContains(t, err, "failed to set key \"key\" of dogu \"redmine\" with value \"value\" in etcd") - assert.ErrorIs(t, err, assert.AnError) - assert.ErrorAs(t, err, &internalErr) - }) -} - -func TestEtcdDoguConfigRepository_SaveAll(t *testing.T) { - t.Run("should fail to save multiple entries", func(t *testing.T) { - // given - ldapConfigMock := newMockConfigurationContext(t) - ldapConfigMock.EXPECT().Set("container_config/memory_limit", "1024m").Return(assert.AnError) - postfixConfigMock := newMockConfigurationContext(t) - postfixConfigMock.EXPECT().Set("container_config/swap_limit", "512m").Return(anotherErr) - etcdMock := newMockEtcdStore(t) - etcdMock.EXPECT().DoguConfig("ldap").Return(ldapConfigMock) - etcdMock.EXPECT().DoguConfig("postfix").Return(postfixConfigMock) - - sut := &DoguConfigRepository{etcdStore: etcdMock} - - entries := []*ecosystem.DoguConfigEntry{ - { - Key: common.DoguConfigKey{ - DoguName: "ldap", - Key: "container_config/memory_limit", - }, - Value: "1024m", - }, - { - Key: common.DoguConfigKey{ - DoguName: "postfix", - Key: "container_config/swap_limit", - }, - Value: "512m", - }, - } - - // when - err := sut.SaveAll(testCtx, entries) - - // then - assert.ErrorIs(t, err, assert.AnError) - assert.ErrorIs(t, err, anotherErr) - assert.ErrorContains(t, err, "failed to set given dogu config entries in etcd") - }) - t.Run("should succeed to save multiple entries", func(t *testing.T) { - // given - ldapConfigMock := newMockConfigurationContext(t) - ldapConfigMock.EXPECT().Set("container_config/memory_limit", "1024m").Return(nil) - postfixConfigMock := newMockConfigurationContext(t) - postfixConfigMock.EXPECT().Set("container_config/swap_limit", "512m").Return(nil) - etcdMock := newMockEtcdStore(t) - etcdMock.EXPECT().DoguConfig("ldap").Return(ldapConfigMock) - etcdMock.EXPECT().DoguConfig("postfix").Return(postfixConfigMock) - - sut := &DoguConfigRepository{etcdStore: etcdMock} - - entries := []*ecosystem.DoguConfigEntry{ - { - Key: common.DoguConfigKey{ - DoguName: "ldap", - Key: "container_config/memory_limit", - }, - Value: "1024m", - }, - { - Key: common.DoguConfigKey{ - DoguName: "postfix", - Key: "container_config/swap_limit", - }, - Value: "512m", - }, - } - - // when - err := sut.SaveAll(testCtx, entries) - - // then - assert.NoError(t, err) - }) -} - -func TestNewEtcdDoguConfigRepository(t *testing.T) { - t.Run("success", func(t *testing.T) { - // given - etcdMock := newMockEtcdStore(t) - - // when - repository := NewDoguConfigRepository(etcdMock) - - // then - assert.Equal(t, etcdMock, repository.etcdStore) - }) -} - -func TestEtcdDoguConfigRepository_Get(t *testing.T) { - t.Run("should not find key", func(t *testing.T) { - // given - configurationContextMock := newMockConfigurationContext(t) - configurationContextMock.EXPECT().Get("container_config/memory_limit").Return("", etcdNotFoundError) - etcdMock := newMockEtcdStore(t) - etcdMock.EXPECT().DoguConfig("ldap").Return(configurationContextMock) - sut := &DoguConfigRepository{etcdStore: etcdMock} - - key := common.DoguConfigKey{ - DoguName: "ldap", - Key: "container_config/memory_limit", - } - - // when - _, err := sut.Get(testCtx, key) - - // then - assert.ErrorIs(t, err, etcdNotFoundError) - assert.ErrorAs(t, err, ¬FoundErr) - assert.ErrorContains(t, err, "could not find key \"container_config/memory_limit\" of dogu \"ldap\" in etcd") - }) - t.Run("should fail to get value for key", func(t *testing.T) { - // given - configurationContextMock := newMockConfigurationContext(t) - configurationContextMock.EXPECT().Get("container_config/swap_limit").Return("", assert.AnError) - etcdMock := newMockEtcdStore(t) - etcdMock.EXPECT().DoguConfig("ldap").Return(configurationContextMock) - sut := &DoguConfigRepository{etcdStore: etcdMock} - - key := common.DoguConfigKey{ - DoguName: "ldap", - Key: "container_config/swap_limit", - } - - // when - _, err := sut.Get(testCtx, key) - - // then - assert.ErrorAs(t, err, &internalErr) - assert.ErrorContains(t, err, "failed to get key \"container_config/swap_limit\" of dogu \"ldap\" from etcd") - }) - t.Run("should succeed to get value for key", func(t *testing.T) { - // given - configurationContextMock := newMockConfigurationContext(t) - configurationContextMock.EXPECT().Get("container_config/swap_limit").Return("512m", nil) - etcdMock := newMockEtcdStore(t) - etcdMock.EXPECT().DoguConfig("ldap").Return(configurationContextMock) - sut := &DoguConfigRepository{etcdStore: etcdMock} - - key := common.DoguConfigKey{ - DoguName: "ldap", - Key: "container_config/swap_limit", - } - - // when - actualEntry, err := sut.Get(testCtx, key) - - // then - assert.NoError(t, err) - assert.Equal(t, &ecosystem.DoguConfigEntry{ - Key: common.DoguConfigKey{ - DoguName: "ldap", - Key: "container_config/swap_limit", - }, - Value: "512m", - }, actualEntry) - }) -} - -func TestEtcdDoguConfigRepository_DeleteAllByKeys(t *testing.T) { - t.Run("success with multiple keys", func(t *testing.T) { - // given - ldapConfigMock := newMockConfigurationContext(t) - ldapConfigMock.EXPECT().Delete("container_config/memory_limit").Return(nil) - postfixConfigMock := newMockConfigurationContext(t) - postfixConfigMock.EXPECT().Delete("container_config/swap_limit").Return(nil) - etcdMock := newMockEtcdStore(t) - etcdMock.EXPECT().DoguConfig("ldap").Return(ldapConfigMock) - etcdMock.EXPECT().DoguConfig("postfix").Return(postfixConfigMock) - - sut := &DoguConfigRepository{etcdStore: etcdMock} - - keys := []common.DoguConfigKey{ - { - DoguName: "ldap", - Key: "container_config/memory_limit", - }, - { - DoguName: "postfix", - Key: "container_config/swap_limit", - }, - } - - // when - err := sut.DeleteAllByKeys(testCtx, keys) - - // then - assert.NoError(t, err) - }) - - t.Run("should return error on delete error", func(t *testing.T) { - // given - ldapConfigMock := newMockConfigurationContext(t) - ldapConfigMock.EXPECT().Delete("container_config/memory_limit").Return(nil) - postfixConfigMock := newMockConfigurationContext(t) - postfixConfigMock.EXPECT().Delete("container_config/swap_limit").Return(assert.AnError) - etcdMock := newMockEtcdStore(t) - etcdMock.EXPECT().DoguConfig("ldap").Return(ldapConfigMock) - etcdMock.EXPECT().DoguConfig("postfix").Return(postfixConfigMock) - - sut := &DoguConfigRepository{etcdStore: etcdMock} - - entries := []common.DoguConfigKey{ - { - DoguName: "ldap", - Key: "container_config/memory_limit", - }, - { - DoguName: "postfix", - Key: "container_config/swap_limit", - }, - } - - // when - err := sut.DeleteAllByKeys(testCtx, entries) - - // then - require.Error(t, err) - assert.ErrorContains(t, err, "failed to delete given dogu config keys in etcd") - }) -} diff --git a/pkg/adapter/config/etcd/globalConfigRepository.go b/pkg/adapter/config/etcd/globalConfigRepository.go index a1b96e3c..04d4fc46 100644 --- a/pkg/adapter/config/etcd/globalConfigRepository.go +++ b/pkg/adapter/config/etcd/globalConfigRepository.go @@ -2,6 +2,7 @@ package etcd import ( "context" + "errors" "github.com/cloudogu/cesapp-lib/registry" "github.com/cloudogu/k8s-blueprint-operator/pkg/domain/common" "github.com/cloudogu/k8s-blueprint-operator/pkg/domain/ecosystem" @@ -62,3 +63,34 @@ func (e GlobalConfigRepository) SaveAll(ctx context.Context, entries []*ecosyste func (e GlobalConfigRepository) DeleteAllByKeys(ctx context.Context, keys []common.GlobalConfigKey) error { return mapKeyOrEntry(ctx, keys, e.Delete, "failed to delete given global config keys in etcd") } + +func getAllByKeyOrEntry[T common.RegistryConfigKey, K ecosystem.RegistryConfigEntry](ctx context.Context, collection []T, fn func(context.Context, T) (K, error)) (map[T]K, error) { + var errs []error + entries := make(map[T]K) + for _, key := range collection { + entry, err := fn(ctx, key) + if err != nil { + errs = append(errs, err) + continue + } + + entries[key] = entry + } + + return entries, errors.Join(errs...) +} + +func mapKeyOrEntry[T common.RegistryConfigKey | ecosystem.RegistryConfigEntry](ctx context.Context, collection []T, fn func(context.Context, T) error, errorMsg string) error { + var errs []error + for _, key := range collection { + err := fn(ctx, key) + errs = append(errs, err) + } + + err := errors.Join(errs...) + if err != nil { + return domainservice.NewInternalError(err, errorMsg) + } + + return nil +} diff --git a/pkg/adapter/config/etcd/globalConfigRepository_test.go b/pkg/adapter/config/etcd/globalConfigRepository_test.go index 77509881..3ee45602 100644 --- a/pkg/adapter/config/etcd/globalConfigRepository_test.go +++ b/pkg/adapter/config/etcd/globalConfigRepository_test.go @@ -1,7 +1,9 @@ package etcd import ( + "context" "fmt" + "go.etcd.io/etcd/client/v2" "testing" "github.com/stretchr/testify/assert" @@ -15,6 +17,10 @@ import ( var internalErr = &domainservice.InternalError{} var notFoundErr = &domainservice.NotFoundError{} var anotherErr = fmt.Errorf("another error for testing") +var testCtx = context.Background() +var etcdNotFoundError = client.Error{Code: client.ErrorCodeKeyNotFound} + +const testSimpleDoguNameRedmine = common.SimpleDoguName("redmine") func TestEtcdGlobalConfigRepository_Delete(t *testing.T) { t.Run("success", func(t *testing.T) { diff --git a/pkg/adapter/config/etcd/mock_registryEntry_test.go b/pkg/adapter/config/etcd/mock_registryEntry_test.go deleted file mode 100644 index 840a8b9c..00000000 --- a/pkg/adapter/config/etcd/mock_registryEntry_test.go +++ /dev/null @@ -1,33 +0,0 @@ -// Code generated by mockery v2.20.0. DO NOT EDIT. - -package etcd - -import mock "github.com/stretchr/testify/mock" - -// mockRegistryEntry is an autogenerated mock type for the registryEntry type -type mockRegistryEntry struct { - mock.Mock -} - -type mockRegistryEntry_Expecter struct { - mock *mock.Mock -} - -func (_m *mockRegistryEntry) EXPECT() *mockRegistryEntry_Expecter { - return &mockRegistryEntry_Expecter{mock: &_m.Mock} -} - -type mockConstructorTestingTnewMockRegistryEntry interface { - mock.TestingT - Cleanup(func()) -} - -// newMockRegistryEntry creates a new instance of mockRegistryEntry. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func newMockRegistryEntry(t mockConstructorTestingTnewMockRegistryEntry) *mockRegistryEntry { - mock := &mockRegistryEntry{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/pkg/adapter/config/etcd/mock_registryKey_test.go b/pkg/adapter/config/etcd/mock_registryKey_test.go deleted file mode 100644 index ae4df546..00000000 --- a/pkg/adapter/config/etcd/mock_registryKey_test.go +++ /dev/null @@ -1,33 +0,0 @@ -// Code generated by mockery v2.20.0. DO NOT EDIT. - -package etcd - -import mock "github.com/stretchr/testify/mock" - -// mockRegistryKey is an autogenerated mock type for the registryKey type -type mockRegistryKey struct { - mock.Mock -} - -type mockRegistryKey_Expecter struct { - mock *mock.Mock -} - -func (_m *mockRegistryKey) EXPECT() *mockRegistryKey_Expecter { - return &mockRegistryKey_Expecter{mock: &_m.Mock} -} - -type mockConstructorTestingTnewMockRegistryKey interface { - mock.TestingT - Cleanup(func()) -} - -// newMockRegistryKey creates a new instance of mockRegistryKey. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func newMockRegistryKey(t mockConstructorTestingTnewMockRegistryKey) *mockRegistryKey { - mock := &mockRegistryKey{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/pkg/adapter/config/etcd/sensitiveDoguConfigRepository.go b/pkg/adapter/config/etcd/sensitiveDoguConfigRepository.go deleted file mode 100644 index 93f5beb3..00000000 --- a/pkg/adapter/config/etcd/sensitiveDoguConfigRepository.go +++ /dev/null @@ -1,104 +0,0 @@ -package etcd - -import ( - "context" - "errors" - "github.com/cloudogu/cesapp-lib/registry" - "github.com/cloudogu/k8s-blueprint-operator/pkg/domain/common" - "github.com/cloudogu/k8s-blueprint-operator/pkg/domain/ecosystem" - "github.com/cloudogu/k8s-blueprint-operator/pkg/domainservice" -) - -type SensitiveDoguConfigRepository struct { - etcdStore etcdStore -} - -func NewSensitiveDoguConfigRepository(etcdStore etcdStore) *SensitiveDoguConfigRepository { - return &SensitiveDoguConfigRepository{etcdStore: etcdStore} -} - -func (e SensitiveDoguConfigRepository) Get(_ context.Context, key common.SensitiveDoguConfigKey) (*ecosystem.SensitiveDoguConfigEntry, error) { - 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 { - return nil, domainservice.NewInternalError(err, "failed to get sensitive %s from etcd", key) - } - - return &ecosystem.SensitiveDoguConfigEntry{ - Key: key, - Value: common.SensitiveDoguConfigValue(entry), - }, nil -} - -func (e SensitiveDoguConfigRepository) Save(_ context.Context, entry *ecosystem.SensitiveDoguConfigEntry) error { - strDoguName := string(entry.Key.DoguName) - strValue := string(entry.Value) - 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) - } - - return nil -} - -func (e SensitiveDoguConfigRepository) Delete(_ context.Context, key common.SensitiveDoguConfigKey) error { - strDoguName := string(key.DoguName) - 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) - } - - return nil -} - -func (e SensitiveDoguConfigRepository) GetAllByKey(ctx context.Context, keys []common.SensitiveDoguConfigKey) (map[common.SensitiveDoguConfigKey]*ecosystem.SensitiveDoguConfigEntry, error) { - return getAllByKeyOrEntry(ctx, keys, e.Get) -} - -func (e SensitiveDoguConfigRepository) SaveAll(ctx context.Context, entries []*ecosystem.SensitiveDoguConfigEntry) error { - return mapKeyOrEntry(ctx, entries, e.Save, "failed to set given sensitive dogu config entries in etcd") -} - -func (e SensitiveDoguConfigRepository) DeleteAllByKeys(ctx context.Context, keys []common.SensitiveDoguConfigKey) error { - return mapKeyOrEntry(ctx, keys, e.Delete, "failed to delete given sensitive dogu config keys in etcd") -} - -func getAllByKeyOrEntry[T common.RegistryConfigKey, K ecosystem.RegistryConfigEntry](ctx context.Context, collection []T, fn func(context.Context, T) (K, error)) (map[T]K, error) { - var errs []error - entries := make(map[T]K) - for _, key := range collection { - entry, err := fn(ctx, key) - if err != nil { - errs = append(errs, err) - continue - } - - entries[key] = entry - } - - return entries, errors.Join(errs...) -} - -func mapKeyOrEntry[T common.RegistryConfigKey | ecosystem.RegistryConfigEntry](ctx context.Context, collection []T, fn func(context.Context, T) error, errorMsg string) error { - var errs []error - for _, key := range collection { - err := fn(ctx, key) - errs = append(errs, err) - } - - err := errors.Join(errs...) - if err != nil { - return domainservice.NewInternalError(err, errorMsg) - } - - return nil -} - -func setEtcdKey(key, value string, config configurationContext) error { - return config.Set(key, value) -} - -func deleteEtcdKey(key string, config configurationContext) error { - return config.Delete(key) -} diff --git a/pkg/adapter/config/etcd/sensitiveDoguConfigRepository_test.go b/pkg/adapter/config/etcd/sensitiveDoguConfigRepository_test.go deleted file mode 100644 index 4d4a631a..00000000 --- a/pkg/adapter/config/etcd/sensitiveDoguConfigRepository_test.go +++ /dev/null @@ -1,480 +0,0 @@ -package etcd - -import ( - "github.com/cloudogu/k8s-blueprint-operator/pkg/domain/common" - "github.com/cloudogu/k8s-blueprint-operator/pkg/domain/ecosystem" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "testing" -) - -func TestEtcdSensitiveDoguConfigRepository_Delete(t *testing.T) { - t.Run("success", func(t *testing.T) { - // given - etcdMock := newMockEtcdStore(t) - configurationContextMock := newMockConfigurationContext(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(string(key.Key)).Return(nil) - - // when - err := sut.Delete(testCtx, key) - - // then - require.NoError(t, err) - }) - - t.Run("should return nil on not found error", func(t *testing.T) { - // given - etcdMock := newMockEtcdStore(t) - configurationContextMock := newMockConfigurationContext(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(string(key.Key)).Return(etcdNotFoundError) - - // when - err := sut.Delete(testCtx, key) - - // then - require.NoError(t, err) - }) - - t.Run("should return error on delete error", func(t *testing.T) { - // given - etcdMock := newMockEtcdStore(t) - configurationContextMock := newMockConfigurationContext(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(string(key.Key)).Return(assert.AnError) - - // when - err := sut.Delete(testCtx, key) - - // then - require.Error(t, err) - assert.ErrorContains(t, err, "failed to delete encrypted key \"key\" of dogu \"redmine\" from etcd") - assert.ErrorIs(t, err, assert.AnError) - assert.ErrorAs(t, err, &internalErr) - }) -} - -func TestEtcdSensitiveDoguConfigRepository_GetAllByKey(t *testing.T) { - t.Run("should fail with multiple keys", func(t *testing.T) { - // given - ldapConfigMock := newMockConfigurationContext(t) - ldapConfigMock.EXPECT().Get("container_config/memory_limit").Return("", etcdNotFoundError) - postfixConfigMock := newMockConfigurationContext(t) - postfixConfigMock.EXPECT().Get("container_config/swap_limit").Return("", assert.AnError) - etcdMock := newMockEtcdStore(t) - etcdMock.EXPECT().DoguConfig("ldap").Return(ldapConfigMock) - etcdMock.EXPECT().DoguConfig("postfix").Return(postfixConfigMock) - sut := &SensitiveDoguConfigRepository{etcdStore: etcdMock} - - keys := []common.SensitiveDoguConfigKey{ - {common.DoguConfigKey{ - DoguName: "ldap", - Key: "container_config/memory_limit", - }}, - {common.DoguConfigKey{ - DoguName: "postfix", - Key: "container_config/swap_limit", - }}, - } - - // when - _, err := sut.GetAllByKey(testCtx, keys) - - // then - assert.ErrorIs(t, err, etcdNotFoundError) - assert.ErrorAs(t, err, ¬FoundErr) - - assert.ErrorIs(t, err, assert.AnError) - assert.ErrorAs(t, err, &internalErr) - }) - t.Run("should succeed with multiple keys", func(t *testing.T) { - // given - ldapConfigMock := newMockConfigurationContext(t) - ldapConfigMock.EXPECT().Get("container_config/memory_limit").Return("1024m", nil) - postfixConfigMock := newMockConfigurationContext(t) - postfixConfigMock.EXPECT().Get("container_config/swap_limit").Return("512m", nil) - etcdMock := newMockEtcdStore(t) - etcdMock.EXPECT().DoguConfig("ldap").Return(ldapConfigMock) - etcdMock.EXPECT().DoguConfig("postfix").Return(postfixConfigMock) - sut := &SensitiveDoguConfigRepository{etcdStore: etcdMock} - - keys := []common.SensitiveDoguConfigKey{ - {common.DoguConfigKey{ - DoguName: "ldap", - Key: "container_config/memory_limit", - }}, - {common.DoguConfigKey{ - DoguName: "postfix", - Key: "container_config/swap_limit", - }}, - } - - // when - actualEntries, err := sut.GetAllByKey(testCtx, keys) - - // then - assert.NoError(t, err) - expectedEntries := map[common.SensitiveDoguConfigKey]*ecosystem.SensitiveDoguConfigEntry{ - {DoguConfigKey: common.DoguConfigKey{ - DoguName: "ldap", - Key: "container_config/memory_limit", - }}: { - Key: common.SensitiveDoguConfigKey{DoguConfigKey: common.DoguConfigKey{ - DoguName: "ldap", - Key: "container_config/memory_limit", - }}, - Value: "1024m", - }, - {DoguConfigKey: common.DoguConfigKey{ - DoguName: "postfix", - Key: "container_config/swap_limit", - }}: { - Key: common.SensitiveDoguConfigKey{DoguConfigKey: common.DoguConfigKey{ - DoguName: "postfix", - Key: "container_config/swap_limit", - }}, - Value: "512m", - }, - } - assert.Equal(t, expectedEntries, actualEntries) - }) - t.Run("not found errors should produce the other values", func(t *testing.T) { - // given - ldapConfigMock := newMockConfigurationContext(t) - ldapConfigMock.EXPECT().Get("container_config/memory_limit").Return("1024m", nil) - ldapConfigMock.EXPECT().Get("password_change/notification_enabled").Return("", etcdNotFoundError) - postfixConfigMock := newMockConfigurationContext(t) - postfixConfigMock.EXPECT().Get("container_config/swap_limit").Return("512m", nil) - etcdMock := newMockEtcdStore(t) - etcdMock.EXPECT().DoguConfig("ldap").Return(ldapConfigMock) - etcdMock.EXPECT().DoguConfig("postfix").Return(postfixConfigMock) - sut := &SensitiveDoguConfigRepository{etcdStore: etcdMock} - - keys := []common.SensitiveDoguConfigKey{ - {common.DoguConfigKey{ - DoguName: "ldap", - Key: "container_config/memory_limit", - }}, - {common.DoguConfigKey{ - DoguName: "ldap", - Key: "password_change/notification_enabled", - }}, - {common.DoguConfigKey{ - DoguName: "postfix", - Key: "container_config/swap_limit", - }}, - } - - // when - actualEntries, err := sut.GetAllByKey(testCtx, keys) - - // then - assert.ErrorIs(t, err, etcdNotFoundError) - assert.ErrorAs(t, err, ¬FoundErr) - - expectedEntries := map[common.SensitiveDoguConfigKey]*ecosystem.SensitiveDoguConfigEntry{ - {DoguConfigKey: common.DoguConfigKey{ - DoguName: "ldap", - Key: "container_config/memory_limit", - }}: { - Key: common.SensitiveDoguConfigKey{DoguConfigKey: common.DoguConfigKey{ - DoguName: "ldap", - Key: "container_config/memory_limit", - }}, - Value: "1024m", - }, - {DoguConfigKey: common.DoguConfigKey{ - DoguName: "postfix", - Key: "container_config/swap_limit", - }}: { - Key: common.SensitiveDoguConfigKey{DoguConfigKey: common.DoguConfigKey{ - DoguName: "postfix", - Key: "container_config/swap_limit", - }}, - Value: "512m", - }, - } - assert.Equal(t, expectedEntries, actualEntries) - }) -} - -func TestEtcdSensitiveDoguConfigRepository_Save(t *testing.T) { - t.Run("success", func(t *testing.T) { - // given - etcdMock := newMockEtcdStore(t) - configurationContextMock := newMockConfigurationContext(t) - sut := SensitiveDoguConfigRepository{etcdStore: etcdMock} - entry := &ecosystem.SensitiveDoguConfigEntry{ - Key: common.SensitiveDoguConfigKey{DoguConfigKey: common.DoguConfigKey{Key: "key", DoguName: testSimpleDoguNameRedmine}}, - Value: "value", - } - etcdMock.EXPECT().DoguConfig(string(testSimpleDoguNameRedmine)).Return(configurationContextMock) - configurationContextMock.EXPECT().Set(string(entry.Key.Key), string(entry.Value)).Return(nil) - - // when - err := sut.Save(testCtx, entry) - - // then - require.NoError(t, err) - }) - - t.Run("should return error on save error", func(t *testing.T) { - // given - etcdMock := newMockEtcdStore(t) - configurationContextMock := newMockConfigurationContext(t) - sut := SensitiveDoguConfigRepository{etcdStore: etcdMock} - - entry := &ecosystem.SensitiveDoguConfigEntry{ - Key: common.SensitiveDoguConfigKey{DoguConfigKey: common.DoguConfigKey{Key: "key", DoguName: testSimpleDoguNameRedmine}}, - Value: "value", - PersistenceContext: nil, - } - etcdMock.EXPECT().DoguConfig(string(testSimpleDoguNameRedmine)).Return(configurationContextMock) - configurationContextMock.EXPECT().Set(string(entry.Key.Key), string(entry.Value)).Return(assert.AnError) - - // when - err := sut.Save(testCtx, entry) - - // then - require.Error(t, err) - assert.ErrorContains(t, err, "failed to set encrypted key \"key\" of dogu \"redmine\" with value \"value\" in etcd") - assert.ErrorIs(t, err, assert.AnError) - assert.ErrorAs(t, err, &internalErr) - }) -} - -func TestEtcdSensitiveDoguConfigRepository_SaveAll(t *testing.T) { - t.Run("should fail to save multiple entries", func(t *testing.T) { - // given - ldapConfigMock := newMockConfigurationContext(t) - ldapConfigMock.EXPECT().Set("container_config/memory_limit", "1024m").Return(assert.AnError) - postfixConfigMock := newMockConfigurationContext(t) - postfixConfigMock.EXPECT().Set("container_config/swap_limit", "512m").Return(anotherErr) - etcdMock := newMockEtcdStore(t) - etcdMock.EXPECT().DoguConfig("ldap").Return(ldapConfigMock) - etcdMock.EXPECT().DoguConfig("postfix").Return(postfixConfigMock) - - sut := &SensitiveDoguConfigRepository{etcdStore: etcdMock} - - entries := []*ecosystem.SensitiveDoguConfigEntry{ - { - Key: common.SensitiveDoguConfigKey{DoguConfigKey: common.DoguConfigKey{ - DoguName: "ldap", - Key: "container_config/memory_limit", - }}, - Value: "1024m", - }, - { - Key: common.SensitiveDoguConfigKey{DoguConfigKey: common.DoguConfigKey{ - DoguName: "postfix", - Key: "container_config/swap_limit", - }}, - Value: "512m", - }, - } - - // when - err := sut.SaveAll(testCtx, entries) - - // then - assert.ErrorIs(t, err, assert.AnError) - assert.ErrorIs(t, err, anotherErr) - assert.ErrorContains(t, err, "failed to set given sensitive dogu config entries in etcd") - }) - t.Run("should succeed to save multiple entries", func(t *testing.T) { - // given - ldapConfigMock := newMockConfigurationContext(t) - ldapConfigMock.EXPECT().Set("container_config/memory_limit", "1024m").Return(nil) - postfixConfigMock := newMockConfigurationContext(t) - postfixConfigMock.EXPECT().Set("container_config/swap_limit", "512m").Return(nil) - etcdMock := newMockEtcdStore(t) - etcdMock.EXPECT().DoguConfig("ldap").Return(ldapConfigMock) - etcdMock.EXPECT().DoguConfig("postfix").Return(postfixConfigMock) - - sut := &SensitiveDoguConfigRepository{etcdStore: etcdMock} - - entries := []*ecosystem.SensitiveDoguConfigEntry{ - { - Key: common.SensitiveDoguConfigKey{DoguConfigKey: common.DoguConfigKey{ - DoguName: "ldap", - Key: "container_config/memory_limit", - }}, - Value: "1024m", - }, - { - Key: common.SensitiveDoguConfigKey{DoguConfigKey: common.DoguConfigKey{ - DoguName: "postfix", - Key: "container_config/swap_limit", - }}, - Value: "512m", - }, - } - - // when - err := sut.SaveAll(testCtx, entries) - - // then - assert.NoError(t, err) - }) -} - -func TestNewEtcdSensitiveDoguConfigRepository(t *testing.T) { - t.Run("success", func(t *testing.T) { - // given - etcdMock := newMockEtcdStore(t) - - // when - repository := NewSensitiveDoguConfigRepository(etcdMock) - - // then - assert.Equal(t, etcdMock, repository.etcdStore) - }) -} - -func TestEtcdSensitiveDoguConfigRepository_Get(t *testing.T) { - t.Run("should not find key", func(t *testing.T) { - // given - configurationContextMock := newMockConfigurationContext(t) - configurationContextMock.EXPECT().Get("container_config/memory_limit").Return("", etcdNotFoundError) - etcdMock := newMockEtcdStore(t) - etcdMock.EXPECT().DoguConfig("ldap").Return(configurationContextMock) - sut := &SensitiveDoguConfigRepository{etcdStore: etcdMock} - - key := common.SensitiveDoguConfigKey{DoguConfigKey: common.DoguConfigKey{ - DoguName: "ldap", - Key: "container_config/memory_limit", - }} - - // when - _, err := sut.Get(testCtx, key) - - // then - assert.ErrorIs(t, err, etcdNotFoundError) - assert.ErrorAs(t, err, ¬FoundErr) - assert.ErrorContains(t, err, "could not find sensitive key \"container_config/memory_limit\" of dogu \"ldap\" in etcd") - }) - t.Run("should fail to get value for key", func(t *testing.T) { - // given - configurationContextMock := newMockConfigurationContext(t) - configurationContextMock.EXPECT().Get("container_config/swap_limit").Return("", assert.AnError) - etcdMock := newMockEtcdStore(t) - etcdMock.EXPECT().DoguConfig("ldap").Return(configurationContextMock) - sut := &SensitiveDoguConfigRepository{etcdStore: etcdMock} - - key := common.SensitiveDoguConfigKey{DoguConfigKey: common.DoguConfigKey{ - DoguName: "ldap", - Key: "container_config/swap_limit", - }} - - // when - _, err := sut.Get(testCtx, key) - - // then - assert.ErrorAs(t, err, &internalErr) - assert.ErrorContains(t, err, "failed to get sensitive key \"container_config/swap_limit\" of dogu \"ldap\" from etcd") - }) - t.Run("should succeed to get value for key", func(t *testing.T) { - // given - configurationContextMock := newMockConfigurationContext(t) - configurationContextMock.EXPECT().Get("container_config/swap_limit").Return("512m", nil) - etcdMock := newMockEtcdStore(t) - etcdMock.EXPECT().DoguConfig("ldap").Return(configurationContextMock) - sut := &SensitiveDoguConfigRepository{etcdStore: etcdMock} - - key := common.SensitiveDoguConfigKey{DoguConfigKey: common.DoguConfigKey{ - DoguName: "ldap", - Key: "container_config/swap_limit", - }} - - // when - actualEntry, err := sut.Get(testCtx, key) - - // then - assert.NoError(t, err) - assert.Equal(t, &ecosystem.SensitiveDoguConfigEntry{ - Key: common.SensitiveDoguConfigKey{DoguConfigKey: common.DoguConfigKey{ - DoguName: "ldap", - Key: "container_config/swap_limit", - }}, - Value: "512m", - }, actualEntry) - }) -} - -func TestEtcdSensitiveDoguConfigRepository_DeleteAllByKeys(t *testing.T) { - t.Run("success with multiple keys", func(t *testing.T) { - // given - ldapConfigMock := newMockConfigurationContext(t) - ldapConfigMock.EXPECT().Delete("container_config/memory_limit").Return(nil) - postfixConfigMock := newMockConfigurationContext(t) - postfixConfigMock.EXPECT().Delete("container_config/swap_limit").Return(nil) - etcdMock := newMockEtcdStore(t) - etcdMock.EXPECT().DoguConfig("ldap").Return(ldapConfigMock) - etcdMock.EXPECT().DoguConfig("postfix").Return(postfixConfigMock) - - sut := &SensitiveDoguConfigRepository{etcdStore: etcdMock} - - entries := []common.SensitiveDoguConfigKey{ - { - DoguConfigKey: common.DoguConfigKey{ - DoguName: "ldap", - Key: "container_config/memory_limit", - }, - }, - { - DoguConfigKey: common.DoguConfigKey{ - DoguName: "postfix", - Key: "container_config/swap_limit", - }, - }, - } - - // when - err := sut.DeleteAllByKeys(testCtx, entries) - - // then - require.NoError(t, err) - }) - - t.Run("should return error on delete error", func(t *testing.T) { - // given - ldapConfigMock := newMockConfigurationContext(t) - ldapConfigMock.EXPECT().Delete("container_config/memory_limit").Return(nil) - postfixConfigMock := newMockConfigurationContext(t) - postfixConfigMock.EXPECT().Delete("container_config/swap_limit").Return(assert.AnError) - etcdMock := newMockEtcdStore(t) - etcdMock.EXPECT().DoguConfig("ldap").Return(ldapConfigMock) - etcdMock.EXPECT().DoguConfig("postfix").Return(postfixConfigMock) - - sut := &SensitiveDoguConfigRepository{etcdStore: etcdMock} - - entries := []common.SensitiveDoguConfigKey{ - { - DoguConfigKey: common.DoguConfigKey{ - DoguName: "ldap", - Key: "container_config/memory_limit", - }, - }, - { - DoguConfigKey: common.DoguConfigKey{ - DoguName: "postfix", - Key: "container_config/swap_limit", - }, - }, - } - - // when - err := sut.DeleteAllByKeys(testCtx, entries) - - // then - require.Error(t, err) - assert.ErrorContains(t, err, "failed to delete given sensitive dogu config keys in etcd") - }) -} diff --git a/pkg/adapter/kubernetes/blueprintcr/v1/config.go b/pkg/adapter/kubernetes/blueprintcr/v1/config.go index 79646258..ba280675 100644 --- a/pkg/adapter/kubernetes/blueprintcr/v1/config.go +++ b/pkg/adapter/kubernetes/blueprintcr/v1/config.go @@ -164,13 +164,13 @@ func convertToSensitiveDoguConfigDTO(config domain.SensitiveDoguConfig) Sensitiv } } -func convertToSensitiveDoguConfigDomain(doguName string, config SensitiveDoguConfig) domain.SensitiveDoguConfig { +func convertToSensitiveDoguConfigDomain(doguName string, doguConfig SensitiveDoguConfig) domain.SensitiveDoguConfig { var present map[common.SensitiveDoguConfigKey]common.SensitiveDoguConfigValue // we check for empty values to make good use of default values // this makes testing easier - if len(config.Present) != 0 { - present = make(map[common.SensitiveDoguConfigKey]common.SensitiveDoguConfigValue, len(config.Present)) - for key, value := range config.Present { + if len(doguConfig.Present) != 0 { + present = make(map[common.SensitiveDoguConfigKey]common.SensitiveDoguConfigValue, len(doguConfig.Present)) + for key, value := range doguConfig.Present { present[convertToSensitiveDoguConfigKeyDomain(doguName, key)] = common.SensitiveDoguConfigValue(value) } } @@ -178,10 +178,13 @@ func convertToSensitiveDoguConfigDomain(doguName string, config SensitiveDoguCon var absent []common.SensitiveDoguConfigKey // we check for empty values to make good use of default values // this makes testing easier - if len(config.Absent) != 0 { - absent = make([]common.SensitiveDoguConfigKey, len(config.Absent)) - for i, key := range config.Absent { - absent[i] = convertToSensitiveDoguConfigKeyDomain(doguName, key) + if len(doguConfig.Absent) != 0 { + absent = make([]common.SensitiveDoguConfigKey, len(doguConfig.Absent)) + for i, key := range doguConfig.Absent { + absent[i] = common.SensitiveDoguConfigKey{ + DoguName: common.SimpleDoguName(doguName), + Key: config.Key(key), + } } } @@ -192,10 +195,9 @@ func convertToSensitiveDoguConfigDomain(doguName string, config SensitiveDoguCon } func convertToSensitiveDoguConfigKeyDomain(doguName, key string) common.SensitiveDoguConfigKey { - return common.SensitiveDoguConfigKey{DoguConfigKey: common.DoguConfigKey{ + return common.SensitiveDoguConfigKey{ DoguName: common.SimpleDoguName(doguName), Key: config.Key(key), - }, } } diff --git a/pkg/adapter/kubernetes/blueprintcr/v1/doguConfigDiff.go b/pkg/adapter/kubernetes/blueprintcr/v1/doguConfigDiff.go index da4a1e0f..8836d78e 100644 --- a/pkg/adapter/kubernetes/blueprintcr/v1/doguConfigDiff.go +++ b/pkg/adapter/kubernetes/blueprintcr/v1/doguConfigDiff.go @@ -73,10 +73,8 @@ func convertToDoguConfigEntryDiffDomain(doguName string, dto DoguConfigEntryDiff func convertToSensitiveDoguConfigEntryDiffDomain(doguName string, dto SensitiveDoguConfigEntryDiff) domain.SensitiveDoguConfigEntryDiff { return domain.SensitiveDoguConfigEntryDiff{ Key: common.SensitiveDoguConfigKey{ - DoguConfigKey: common.DoguConfigKey{ - DoguName: common.SimpleDoguName(doguName), - Key: config.Key(dto.Key), - }, + DoguName: common.SimpleDoguName(doguName), + Key: config.Key(dto.Key), }, Actual: domain.DoguConfigValueState{ Value: dto.Actual.Value, diff --git a/pkg/adapter/kubernetes/blueprintcr/v1/doguConfigDiff_test.go b/pkg/adapter/kubernetes/blueprintcr/v1/doguConfigDiff_test.go index 263d79bc..5299808a 100644 --- a/pkg/adapter/kubernetes/blueprintcr/v1/doguConfigDiff_test.go +++ b/pkg/adapter/kubernetes/blueprintcr/v1/doguConfigDiff_test.go @@ -86,10 +86,10 @@ func Test_convertToCombinedDoguConfigDiffDTO(t *testing.T) { domainModel: domain.CombinedDoguConfigDiffs{ SensitiveDoguConfigDiff: []domain.SensitiveDoguConfigEntryDiff{ { - Key: common.SensitiveDoguConfigKey{DoguConfigKey: common.DoguConfigKey{ + Key: common.SensitiveDoguConfigKey{ DoguName: "ldap", Key: "container_config/memory_limit", - }}, + }, Actual: domain.DoguConfigValueState{ Value: "512m", Exists: true, @@ -101,10 +101,10 @@ func Test_convertToCombinedDoguConfigDiffDTO(t *testing.T) { NeededAction: domain.ConfigActionSet, }, { - Key: common.SensitiveDoguConfigKey{DoguConfigKey: common.DoguConfigKey{ + Key: common.SensitiveDoguConfigKey{ DoguName: "ldap", Key: "container_config/swap_limit", - }}, + }, Actual: domain.DoguConfigValueState{ Exists: false, }, @@ -258,10 +258,10 @@ func Test_convertToCombinedDoguConfigDiffDomain(t *testing.T) { want: domain.CombinedDoguConfigDiffs{ SensitiveDoguConfigDiff: []domain.SensitiveDoguConfigEntryDiff{ { - Key: common.SensitiveDoguConfigKey{DoguConfigKey: common.DoguConfigKey{ + Key: common.SensitiveDoguConfigKey{ DoguName: "ldap", Key: "container_config/memory_limit", - }}, + }, Actual: domain.DoguConfigValueState{ Value: "512m", Exists: true, @@ -273,10 +273,10 @@ func Test_convertToCombinedDoguConfigDiffDomain(t *testing.T) { NeededAction: domain.ConfigActionSet, }, { - Key: common.SensitiveDoguConfigKey{DoguConfigKey: common.DoguConfigKey{ + Key: common.SensitiveDoguConfigKey{ DoguName: "ldap", Key: "container_config/swap_limit", - }}, + }, Actual: domain.DoguConfigValueState{ Exists: false, }, diff --git a/pkg/adapter/kubernetes/blueprintcr/v1/effectiveBlueprint_test.go b/pkg/adapter/kubernetes/blueprintcr/v1/effectiveBlueprint_test.go index db1cfaee..fa4f7c27 100644 --- a/pkg/adapter/kubernetes/blueprintcr/v1/effectiveBlueprint_test.go +++ b/pkg/adapter/kubernetes/blueprintcr/v1/effectiveBlueprint_test.go @@ -54,10 +54,10 @@ func TestConvertToEffectiveBlueprint(t *testing.T) { }, SensitiveConfig: domain.SensitiveDoguConfig{ Present: map[common.SensitiveDoguConfigKey]common.SensitiveDoguConfigValue{ - {DoguConfigKey: common.DoguConfigKey{ + { DoguName: "my-dogu", Key: "config-encrypted", - }}: "42", + }: "42", }, }, }, @@ -181,10 +181,10 @@ func TestConvertToEffectiveBlueprintV1(t *testing.T) { }, SensitiveConfig: domain.SensitiveDoguConfig{ Present: map[common.SensitiveDoguConfigKey]common.SensitiveDoguConfigValue{ - {DoguConfigKey: common.DoguConfigKey{ + { DoguName: "my-dogu", Key: "config-encrypted", - }}: "42", + }: "42", }, }, }, diff --git a/pkg/adapter/serializer/blueprintV2/blueprintV2_test.go b/pkg/adapter/serializer/blueprintV2/blueprintV2_test.go index 3d9e30bd..21484131 100644 --- a/pkg/adapter/serializer/blueprintV2/blueprintV2_test.go +++ b/pkg/adapter/serializer/blueprintV2/blueprintV2_test.go @@ -55,10 +55,10 @@ func Test_ConvertToBlueprintV2(t *testing.T) { }, SensitiveConfig: domain.SensitiveDoguConfig{ Present: map[common.SensitiveDoguConfigKey]common.SensitiveDoguConfigValue{ - {DoguConfigKey: common.DoguConfigKey{ + { DoguName: "my-dogu", Key: "config-encrypted", - }}: "42", + }: "42", }, }, }, @@ -182,10 +182,10 @@ func Test_ConvertToBlueprint(t *testing.T) { }, SensitiveConfig: domain.SensitiveDoguConfig{ Present: map[common.SensitiveDoguConfigKey]common.SensitiveDoguConfigValue{ - {DoguConfigKey: common.DoguConfigKey{ + { DoguName: "my-dogu", Key: "config-encrypted", - }}: "42", + }: "42", }, }, }, diff --git a/pkg/adapter/serializer/blueprintV2/serializer_test.go b/pkg/adapter/serializer/blueprintV2/serializer_test.go index f4dacd84..2d73cf31 100644 --- a/pkg/adapter/serializer/blueprintV2/serializer_test.go +++ b/pkg/adapter/serializer/blueprintV2/serializer_test.go @@ -113,19 +113,19 @@ func TestSerializeBlueprint_ok(t *testing.T) { "redmine": { SensitiveConfig: domain.SensitiveDoguConfig{ Present: map[common.SensitiveDoguConfigKey]common.SensitiveDoguConfigValue{ - {DoguConfigKey: common.DoguConfigKey{ + { DoguName: "redmine", Key: "my-secret-password", - }}: "password-value", - {DoguConfigKey: common.DoguConfigKey{ + }: "password-value", + { DoguName: "redmine", Key: "my-secret-password-2", - }}: "password-value-2", + }: "password-value-2", }, - Absent: []common.SensitiveDoguConfigKey{{DoguConfigKey: common.DoguConfigKey{ + Absent: []common.SensitiveDoguConfigKey{{ DoguName: "redmine", Key: "my-secret-password-3", - }}}, + }}, }, }, }, @@ -285,19 +285,19 @@ func TestDeserializeBlueprint_ok(t *testing.T) { DoguName: "redmine", SensitiveConfig: domain.SensitiveDoguConfig{ Present: map[common.SensitiveDoguConfigKey]common.SensitiveDoguConfigValue{ - {DoguConfigKey: common.DoguConfigKey{ + { DoguName: "redmine", Key: "my-secret-password", - }}: "password-value", - {DoguConfigKey: common.DoguConfigKey{ + }: "password-value", + { DoguName: "redmine", Key: "my-secret-password-2", - }}: "password-value-2", + }: "password-value-2", }, - Absent: []common.SensitiveDoguConfigKey{{DoguConfigKey: common.DoguConfigKey{ + Absent: []common.SensitiveDoguConfigKey{{ DoguName: "redmine", Key: "my-secret-password-3", - }}}, + }}, }, }, }, diff --git a/pkg/application/ecosystemConfigUseCase.go b/pkg/application/ecosystemConfigUseCase.go index 6d491525..698da56b 100644 --- a/pkg/application/ecosystemConfigUseCase.go +++ b/pkg/application/ecosystemConfigUseCase.go @@ -15,20 +15,20 @@ import ( type EcosystemConfigUseCase struct { blueprintRepository blueprintSpecRepository doguConfigRepository doguConfigRepository - doguSensitiveConfigRepository sensitiveDoguConfigEntryRepository + sensitiveDoguConfigRepository sensitiveDoguConfigRepository globalConfigRepository globalConfigRepository } func NewEcosystemConfigUseCase( blueprintRepository blueprintSpecRepository, doguConfigRepository doguConfigRepository, - doguSensitiveConfigRepository sensitiveDoguConfigEntryRepository, + sensitiveDoguConfigRepository sensitiveDoguConfigRepository, globalConfigRepository globalConfigRepository, ) *EcosystemConfigUseCase { return &EcosystemConfigUseCase{ blueprintRepository: blueprintRepository, doguConfigRepository: doguConfigRepository, - doguSensitiveConfigRepository: doguSensitiveConfigRepository, + sensitiveDoguConfigRepository: sensitiveDoguConfigRepository, globalConfigRepository: globalConfigRepository, } } @@ -69,7 +69,7 @@ func (useCase *EcosystemConfigUseCase) ApplyConfig(ctx context.Context, blueprin if err != nil { return useCase.handleFailedApplyRegistryConfig(ctx, blueprintSpec, err) } - err = useCase.applySensitiveDoguConfigDiffs(ctx, blueprintSpec.StateDiff.GetSensitiveDoguConfigDiffsByAction()) + err = useCase.applySensitiveDoguConfigDiffs(ctx, blueprintSpec.StateDiff.DoguConfigDiffs) if err != nil { return useCase.handleFailedApplyRegistryConfig(ctx, blueprintSpec, err) } @@ -151,6 +151,47 @@ func (useCase *EcosystemConfigUseCase) applyDoguConfigDiffs( return errors.Join(errs...) } +func (useCase *EcosystemConfigUseCase) applySensitiveDoguConfigDiffs( + ctx context.Context, + diffsByDogu map[common.SimpleDoguName]domain.CombinedDoguConfigDiffs, +) error { + var errs []error + + var doguNames []common.SimpleDoguName + for dogu, diff := range diffsByDogu { + if diff.SensitiveDoguConfigDiff.HasChangesForDogu(dogu) { + doguNames = append(doguNames, dogu) + } + } + slices.Sort(doguNames) + + if len(doguNames) == 0 { + // no changes to dogu config needed + return nil + } + + configByDogu, err := useCase.sensitiveDoguConfigRepository.GetAll(ctx, doguNames) + if err != nil { + return err + } + + for _, dogu := range doguNames { + updatedConfig, applyError := useCase.applyDiff(configByDogu[dogu], diffsByDogu[dogu].SensitiveDoguConfigDiff) + if applyError != nil { + return applyError + } + _, applyError = useCase.sensitiveDoguConfigRepository.Update(ctx, config.DoguConfig{ + DoguName: dogu, + Config: updatedConfig, + }) + if applyError != nil { + return applyError + } + } + + return errors.Join(errs...) +} + func (useCase *EcosystemConfigUseCase) applyDiff(doguConfig config.DoguConfig, diffs []domain.DoguConfigEntryDiff) (config.Config, error) { var errs []error updatedEntries := doguConfig.Config @@ -171,27 +212,6 @@ func (useCase *EcosystemConfigUseCase) applyDiff(doguConfig config.DoguConfig, d return updatedEntries, errors.Join(errs...) } -func (useCase *EcosystemConfigUseCase) applySensitiveDoguConfigDiffs(ctx context.Context, sensitiveDoguConfigDiffsByAction map[domain.ConfigAction]domain.SensitiveDoguConfigDiffs) error { - var errs []error - - var keysToSet []*ecosystem.SensitiveDoguConfigEntry - var keysToDelete []common.SensitiveDoguConfigKey - - for _, diff := range sensitiveDoguConfigDiffsByAction[domain.ConfigActionSet] { - entry := getSensitiveDoguConfigEntry(diff.Key.DoguName, diff) - keysToSet = append(keysToSet, entry) - } - - for _, diff := range sensitiveDoguConfigDiffsByAction[domain.ConfigActionRemove] { - keysToDelete = append(keysToDelete, common.SensitiveDoguConfigKey{DoguConfigKey: common.DoguConfigKey{DoguName: diff.Key.DoguName, Key: diff.Key.Key}}) - } - - errs = append(errs, callIfNotEmpty(ctx, keysToSet, useCase.doguSensitiveConfigRepository.SaveAll)) - errs = append(errs, callIfNotEmpty(ctx, keysToDelete, useCase.doguSensitiveConfigRepository.DeleteAllByKeys)) - - return errors.Join(errs...) -} - func callIfNotEmpty[T ecosystem.RegistryConfigEntry | common.RegistryConfigKey](ctx context.Context, collection []T, fn func(context.Context, []T) error) error { if len(collection) > 0 { return fn(ctx, collection) @@ -200,13 +220,6 @@ func callIfNotEmpty[T ecosystem.RegistryConfigEntry | common.RegistryConfigKey]( return nil } -func getSensitiveDoguConfigEntry(doguName common.SimpleDoguName, diff domain.SensitiveDoguConfigEntryDiff) *ecosystem.SensitiveDoguConfigEntry { - return &ecosystem.SensitiveDoguConfigEntry{ - Key: common.SensitiveDoguConfigKey{DoguConfigKey: common.DoguConfigKey{DoguName: doguName, Key: diff.Key.Key}}, - Value: common.SensitiveDoguConfigValue(diff.Expected.Value), - } -} - func (useCase *EcosystemConfigUseCase) markApplyConfigStart(ctx context.Context, blueprintSpec *domain.BlueprintSpec) error { blueprintSpec.StartApplyRegistryConfig() err := useCase.blueprintRepository.Update(ctx, blueprintSpec) diff --git a/pkg/application/ecosystemConfigUseCase_test.go b/pkg/application/ecosystemConfigUseCase_test.go index 9c7c1181..b7b9261e 100644 --- a/pkg/application/ecosystemConfigUseCase_test.go +++ b/pkg/application/ecosystemConfigUseCase_test.go @@ -3,7 +3,6 @@ package application 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" @@ -23,11 +22,11 @@ func TestEcosystemConfigUseCase_ApplyConfig(t *testing.T) { // given blueprintRepoMock := newMockBlueprintSpecRepository(t) doguConfigMock := newMockDoguConfigRepository(t) - sensitiveDoguConfigMock := newMockSensitiveDoguConfigEntryRepository(t) + sensitiveDoguConfigMock := newMockSensitiveDoguConfigRepository(t) globalConfigRepoMock := newMockGlobalConfigRepository(t) - redmineDiffToEncrypt := getSensitiveDoguConfigEntryDiffForAction("key", "value", redmine, domain.ConfigActionSet) - casDiffToEncrypt := getSensitiveDoguConfigEntryDiffForAction("key", "value", cas, domain.ConfigActionSet) + sensitiveRedmineDiff := getSensitiveDoguConfigEntryDiffForAction("key", "value", redmine, domain.ConfigActionSet) + sensitiveCasDiff := getSensitiveDoguConfigEntryDiffForAction("key", "value", cas, domain.ConfigActionSet) spec := &domain.BlueprintSpec{ StateDiff: domain.StateDiff{ DoguConfigDiffs: map[common.SimpleDoguName]domain.CombinedDoguConfigDiffs{ @@ -37,7 +36,7 @@ func TestEcosystemConfigUseCase_ApplyConfig(t *testing.T) { getRemoveDoguConfigEntryDiff("key", redmine), }, SensitiveDoguConfigDiff: []domain.SensitiveDoguConfigEntryDiff{ - redmineDiffToEncrypt, + sensitiveRedmineDiff, getRemoveSensitiveDoguConfigEntryDiff("key", redmine), }, }, @@ -47,7 +46,7 @@ func TestEcosystemConfigUseCase_ApplyConfig(t *testing.T) { getRemoveDoguConfigEntryDiff("key", cas), }, SensitiveDoguConfigDiff: []domain.SensitiveDoguConfigEntryDiff{ - casDiffToEncrypt, + sensitiveCasDiff, getRemoveSensitiveDoguConfigEntryDiff("key", cas), }, }, @@ -68,8 +67,13 @@ func TestEcosystemConfigUseCase_ApplyConfig(t *testing.T) { }, nil) doguConfigMock.EXPECT().Update(testCtx, mock.Anything).Return(config.DoguConfig{}, nil).Times(2) - sensitiveDoguConfigMock.EXPECT().SaveAll(testCtx, mock.Anything).Return(nil).Times(1) - sensitiveDoguConfigMock.EXPECT().DeleteAllByKeys(testCtx, mock.Anything).Return(nil).Times(1) + sensitiveDoguConfigMock.EXPECT(). + GetAll(testCtx, []common.SimpleDoguName{cas, redmine}). + Return(map[config.SimpleDoguName]config.DoguConfig{ + redmine: config.CreateDoguConfig(redmine, map[config.Key]config.Value{}), + cas: config.CreateDoguConfig(cas, map[config.Key]config.Value{}), + }, nil) + sensitiveDoguConfigMock.EXPECT().Update(testCtx, mock.Anything).Return(config.DoguConfig{}, nil).Times(2) entries, _ := config.MapToEntries(map[string]any{}) globalConfig := config.CreateGlobalConfig(entries) @@ -160,7 +164,7 @@ func TestEcosystemConfigUseCase_ApplyConfig(t *testing.T) { // given blueprintRepoMock := newMockBlueprintSpecRepository(t) doguConfigMock := newMockDoguConfigRepository(t) - sensitiveDoguConfigMock := newMockSensitiveDoguConfigEntryRepository(t) + sensitiveDoguConfigMock := newMockSensitiveDoguConfigRepository(t) globalConfigMock := newMockGlobalConfigRepository(t) spec := &domain.BlueprintSpec{ @@ -207,7 +211,7 @@ func TestEcosystemConfigUseCase_ApplyConfig(t *testing.T) { // given blueprintRepoMock := newMockBlueprintSpecRepository(t) doguConfigMock := newMockDoguConfigRepository(t) - sensitiveDoguConfigMock := newMockSensitiveDoguConfigEntryRepository(t) + sensitiveDoguConfigMock := newMockSensitiveDoguConfigRepository(t) globalConfigMock := newMockGlobalConfigRepository(t) casDiff := getSensitiveDoguConfigEntryDiffForAction("key", "value", cas, domain.ConfigActionSet) @@ -229,7 +233,13 @@ func TestEcosystemConfigUseCase_ApplyConfig(t *testing.T) { } // Just check if the routine hits the repos. Check values in concrete test of methods. - sensitiveDoguConfigMock.EXPECT().SaveAll(testCtx, mock.Anything).Return(assert.AnError) + sensitiveDoguConfigMock.EXPECT(). + GetAll(testCtx, []common.SimpleDoguName{cas, redmine}). + Return(map[config.SimpleDoguName]config.DoguConfig{ + redmine: config.CreateDoguConfig(redmine, map[config.Key]config.Value{}), + cas: config.CreateDoguConfig(cas, map[config.Key]config.Value{}), + }, nil) + sensitiveDoguConfigMock.EXPECT().Update(testCtx, mock.Anything).Return(config.DoguConfig{}, assert.AnError).Times(1) blueprintRepoMock.EXPECT().GetById(testCtx, testBlueprintID).Return(spec, nil) blueprintRepoMock.EXPECT().Update(testCtx, mock.Anything).Return(nil).Times(2) @@ -249,7 +259,7 @@ func TestEcosystemConfigUseCase_ApplyConfig(t *testing.T) { // given blueprintRepoMock := newMockBlueprintSpecRepository(t) doguConfigMock := newMockDoguConfigRepository(t) - sensitiveDoguConfigMock := newMockSensitiveDoguConfigEntryRepository(t) + sensitiveDoguConfigMock := newMockSensitiveDoguConfigRepository(t) globalConfigMock := newMockGlobalConfigRepository(t) spec := &domain.BlueprintSpec{ @@ -292,10 +302,10 @@ func TestEcosystemConfigUseCase_applyDoguConfigDiffs(t *testing.T) { diff1 := getSetDoguConfigEntryDiff("key1", "update1", redmine) diff2 := getSetDoguConfigEntryDiff("key2", "update2", redmine) diffsByDogu := map[common.SimpleDoguName]domain.CombinedDoguConfigDiffs{ - "redmine": {DoguConfigDiff: []domain.DoguConfigEntryDiff{diff1, diff2}}, + redmine: {DoguConfigDiff: []domain.DoguConfigEntryDiff{diff1, diff2}}, } - redmineConfig := config.CreateDoguConfig("redmine", map[config.Key]config.Value{ + redmineConfig := config.CreateDoguConfig(redmine, map[config.Key]config.Value{ "key1": "val1", "key2": "val2", }) @@ -327,10 +337,10 @@ func TestEcosystemConfigUseCase_applyDoguConfigDiffs(t *testing.T) { diff1 := getRemoveDoguConfigEntryDiff("key1", redmine) diff2 := getRemoveDoguConfigEntryDiff("key2", redmine) diffsByDogu := map[common.SimpleDoguName]domain.CombinedDoguConfigDiffs{ - "redmine": {DoguConfigDiff: []domain.DoguConfigEntryDiff{diff1, diff2}}, + redmine: {DoguConfigDiff: []domain.DoguConfigEntryDiff{diff1, diff2}}, } - redmineConfig := config.CreateDoguConfig("redmine", map[config.Key]config.Value{ + redmineConfig := config.CreateDoguConfig(redmine, map[config.Key]config.Value{ "key1": "val1", "key2": "val2", }) @@ -343,8 +353,8 @@ func TestEcosystemConfigUseCase_applyDoguConfigDiffs(t *testing.T) { Delete("key2") doguConfigMock.EXPECT(). - GetAll(testCtx, []common.SimpleDoguName{"redmine"}). - Return(map[config.SimpleDoguName]config.DoguConfig{"redmine": redmineConfig}, nil) + GetAll(testCtx, []common.SimpleDoguName{redmine}). + Return(map[config.SimpleDoguName]config.DoguConfig{redmine: redmineConfig}, nil) doguConfigMock.EXPECT(). Update(testCtx, config.DoguConfig{DoguName: redmine, Config: updatedConfig}). Return(config.DoguConfig{}, nil) @@ -364,7 +374,7 @@ func TestEcosystemConfigUseCase_applyDoguConfigDiffs(t *testing.T) { NeededAction: domain.ConfigActionNone, } diffsByDogu := map[common.SimpleDoguName]domain.CombinedDoguConfigDiffs{ - "redmine": {DoguConfigDiff: []domain.DoguConfigEntryDiff{diff1}}, + redmine: {DoguConfigDiff: []domain.DoguConfigEntryDiff{diff1}}, } // when @@ -451,25 +461,34 @@ func TestEcosystemConfigUseCase_applyGlobalConfigDiffs(t *testing.T) { func TestEcosystemConfigUseCase_applySensitiveDoguConfigDiffs(t *testing.T) { t.Run("should save diffs with action set", func(t *testing.T) { // given - sensitiveDoguConfigMock := newMockSensitiveDoguConfigEntryRepository(t) + sensitiveDoguConfigMock := newMockSensitiveDoguConfigRepository(t) sut := NewEcosystemConfigUseCase(nil, nil, sensitiveDoguConfigMock, nil) diff1 := getSensitiveDoguConfigEntryDiffForAction("key1", "value1", redmine, domain.ConfigActionSet) diff2 := getSensitiveDoguConfigEntryDiffForAction("key2", "value2", redmine, domain.ConfigActionSet) - byAction := map[domain.ConfigAction]domain.SensitiveDoguConfigDiffs{domain.ConfigActionSet: {diff1, diff2}} - - expectedEntry1 := &ecosystem.SensitiveDoguConfigEntry{ - Key: common.SensitiveDoguConfigKey{DoguConfigKey: common.DoguConfigKey{DoguName: redmine, Key: diff1.Key.Key}}, - Value: common.SensitiveDoguConfigValue("value1"), - } - expectedEntry2 := &ecosystem.SensitiveDoguConfigEntry{ - Key: common.SensitiveDoguConfigKey{DoguConfigKey: common.DoguConfigKey{DoguName: redmine, Key: diff2.Key.Key}}, - Value: common.SensitiveDoguConfigValue("value2"), + diffsByDogu := map[common.SimpleDoguName]domain.CombinedDoguConfigDiffs{ + redmine: {SensitiveDoguConfigDiff: []domain.DoguConfigEntryDiff{diff1, diff2}}, } - sensitiveDoguConfigMock.EXPECT().SaveAll(testCtx, []*ecosystem.SensitiveDoguConfigEntry{expectedEntry1, expectedEntry2}).Return(nil).Times(1) + redmineConfig := config.CreateDoguConfig(redmine, map[config.Key]config.Value{ + "key1": "val1", + "key2": "val2", + }) + + updatedConfig := redmineConfig.Config + updatedConfig, err := updatedConfig.Set(diff1.Key.Key, config.Value(diff1.Expected.Value)) + require.NoError(t, err) + updatedConfig, err = updatedConfig.Set(diff2.Key.Key, config.Value(diff2.Expected.Value)) + require.NoError(t, err) + + sensitiveDoguConfigMock.EXPECT(). + GetAll(testCtx, []common.SimpleDoguName{redmine}). + Return(map[config.SimpleDoguName]config.DoguConfig{redmine: redmineConfig}, nil) + sensitiveDoguConfigMock.EXPECT(). + Update(testCtx, config.DoguConfig{DoguName: redmine, Config: updatedConfig}). + Return(config.DoguConfig{}, nil) // when - err := sut.applySensitiveDoguConfigDiffs(testCtx, byAction) + err = sut.applySensitiveDoguConfigDiffs(testCtx, diffsByDogu) // then require.NoError(t, err) @@ -477,19 +496,35 @@ func TestEcosystemConfigUseCase_applySensitiveDoguConfigDiffs(t *testing.T) { t.Run("should delete diffs with action remove", func(t *testing.T) { // given - sensitiveDoguConfigMock := newMockSensitiveDoguConfigEntryRepository(t) + sensitiveDoguConfigMock := newMockSensitiveDoguConfigRepository(t) sut := NewEcosystemConfigUseCase(nil, nil, sensitiveDoguConfigMock, nil) - diff1 := getRemoveSensitiveDoguConfigEntryDiff("key", redmine) - diff2 := getRemoveSensitiveDoguConfigEntryDiff("key", redmine) - byAction := map[domain.ConfigAction]domain.SensitiveDoguConfigDiffs{domain.ConfigActionRemove: {diff1, diff2}} + diff1 := getRemoveSensitiveDoguConfigEntryDiff("key1", redmine) + diff2 := getRemoveSensitiveDoguConfigEntryDiff("key2", redmine) + diffsByDogu := map[common.SimpleDoguName]domain.CombinedDoguConfigDiffs{ + redmine: {SensitiveDoguConfigDiff: []domain.DoguConfigEntryDiff{diff1, diff2}}, + } - expectedKey1 := common.SensitiveDoguConfigKey{DoguConfigKey: common.DoguConfigKey{DoguName: redmine, Key: diff1.Key.Key}} - expectedKey2 := common.SensitiveDoguConfigKey{DoguConfigKey: common.DoguConfigKey{DoguName: redmine, Key: diff2.Key.Key}} + redmineConfig := config.CreateDoguConfig(redmine, map[config.Key]config.Value{ + "key1": "val1", + "key2": "val2", + }) + + //TODO: this fixes a bug in the lib: Delete modifies redmineConfig and updatedConfig as well. The structs are not really immutable at the moment. + updatedConfig := config.CreateConfig(maps.Clone(redmineConfig.GetAll())) + + updatedConfig = updatedConfig. + Delete("key1"). + Delete("key2") - sensitiveDoguConfigMock.EXPECT().DeleteAllByKeys(testCtx, []common.SensitiveDoguConfigKey{expectedKey1, expectedKey2}).Return(nil).Times(1) + sensitiveDoguConfigMock.EXPECT(). + GetAll(testCtx, []common.SimpleDoguName{redmine}). + Return(map[config.SimpleDoguName]config.DoguConfig{redmine: redmineConfig}, nil) + sensitiveDoguConfigMock.EXPECT(). + Update(testCtx, config.DoguConfig{DoguName: redmine, Config: updatedConfig}). + Return(config.DoguConfig{}, nil) // when - err := sut.applySensitiveDoguConfigDiffs(testCtx, byAction) + err := sut.applySensitiveDoguConfigDiffs(testCtx, diffsByDogu) // then require.NoError(t, err) @@ -497,14 +532,16 @@ func TestEcosystemConfigUseCase_applySensitiveDoguConfigDiffs(t *testing.T) { t.Run("should return nil on action none", func(t *testing.T) { // given - sut := NewEcosystemConfigUseCase(nil, nil, newMockSensitiveDoguConfigEntryRepository(t), nil) + sut := NewEcosystemConfigUseCase(nil, nil, newMockSensitiveDoguConfigRepository(t), nil) diff1 := domain.SensitiveDoguConfigEntryDiff{ NeededAction: domain.ConfigActionNone, } - byAction := map[domain.ConfigAction]domain.SensitiveDoguConfigDiffs{domain.ConfigActionNone: {diff1}} + diffsByDogu := map[common.SimpleDoguName]domain.CombinedDoguConfigDiffs{ + redmine: {SensitiveDoguConfigDiff: []domain.DoguConfigEntryDiff{diff1}}, + } // when - err := sut.applySensitiveDoguConfigDiffs(testCtx, byAction) + err := sut.applySensitiveDoguConfigDiffs(testCtx, diffsByDogu) // then require.NoError(t, err) @@ -638,7 +675,7 @@ func TestNewEcosystemConfigUseCase(t *testing.T) { // given blueprintRepoMock := newMockBlueprintSpecRepository(t) doguConfigMock := newMockDoguConfigRepository(t) - sensitiveDoguConfigMock := newMockSensitiveDoguConfigEntryRepository(t) + sensitiveDoguConfigMock := newMockSensitiveDoguConfigRepository(t) globalConfigMock := newMockGlobalConfigRepository(t) // when @@ -647,7 +684,7 @@ func TestNewEcosystemConfigUseCase(t *testing.T) { // then assert.Equal(t, blueprintRepoMock, useCase.blueprintRepository) assert.Equal(t, doguConfigMock, useCase.doguConfigRepository) - assert.Equal(t, sensitiveDoguConfigMock, useCase.doguSensitiveConfigRepository) + assert.Equal(t, sensitiveDoguConfigMock, useCase.sensitiveDoguConfigRepository) assert.Equal(t, globalConfigMock, useCase.globalConfigRepository) }) } @@ -678,10 +715,8 @@ func getRemoveDoguConfigEntryDiff(key string, doguName common.SimpleDoguName) do func getSensitiveDoguConfigEntryDiffForAction(key, value string, doguName common.SimpleDoguName, action domain.ConfigAction) domain.SensitiveDoguConfigEntryDiff { return domain.SensitiveDoguConfigEntryDiff{ Key: common.SensitiveDoguConfigKey{ - DoguConfigKey: common.DoguConfigKey{ - Key: config.Key(key), - DoguName: doguName, - }, + Key: config.Key(key), + DoguName: doguName, }, Expected: domain.DoguConfigValueState{ Value: value, @@ -693,10 +728,8 @@ func getSensitiveDoguConfigEntryDiffForAction(key, value string, doguName common func getRemoveSensitiveDoguConfigEntryDiff(key string, doguName common.SimpleDoguName) domain.SensitiveDoguConfigEntryDiff { return domain.SensitiveDoguConfigEntryDiff{ Key: common.SensitiveDoguConfigKey{ - DoguConfigKey: common.DoguConfigKey{ - Key: config.Key(key), - DoguName: doguName, - }, + Key: config.Key(key), + DoguName: doguName, }, NeededAction: domain.ConfigActionRemove, } diff --git a/pkg/application/interfaces.go b/pkg/application/interfaces.go index 55c69c9c..5f01217d 100644 --- a/pkg/application/interfaces.go +++ b/pkg/application/interfaces.go @@ -107,11 +107,6 @@ type doguConfigRepository interface { domainservice.DoguConfigRepository } -// TODO: remove this when refactoring is done -type sensitiveDoguConfigEntryRepository interface { - domainservice.SensitiveDoguConfigEntryRepository -} - type sensitiveDoguConfigRepository interface { domainservice.SensitiveDoguConfigRepository } diff --git a/pkg/application/mock_doguConfigEntryRepository_test.go b/pkg/application/mock_doguConfigEntryRepository_test.go deleted file mode 100644 index 366c03d0..00000000 --- a/pkg/application/mock_doguConfigEntryRepository_test.go +++ /dev/null @@ -1,346 +0,0 @@ -// Code generated by mockery v2.42.1. DO NOT EDIT. - -package application - -import ( - context "context" - - common "github.com/cloudogu/k8s-blueprint-operator/pkg/domain/common" - - ecosystem "github.com/cloudogu/k8s-blueprint-operator/pkg/domain/ecosystem" - - mock "github.com/stretchr/testify/mock" -) - -// mockDoguConfigEntryRepository is an autogenerated mock type for the doguConfigEntryRepository type -type mockDoguConfigEntryRepository struct { - mock.Mock -} - -type mockDoguConfigEntryRepository_Expecter struct { - mock *mock.Mock -} - -func (_m *mockDoguConfigEntryRepository) EXPECT() *mockDoguConfigEntryRepository_Expecter { - return &mockDoguConfigEntryRepository_Expecter{mock: &_m.Mock} -} - -// Delete provides a mock function with given fields: _a0, _a1 -func (_m *mockDoguConfigEntryRepository) Delete(_a0 context.Context, _a1 common.DoguConfigKey) error { - ret := _m.Called(_a0, _a1) - - if len(ret) == 0 { - panic("no return value specified for Delete") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, common.DoguConfigKey) error); ok { - r0 = rf(_a0, _a1) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// mockDoguConfigEntryRepository_Delete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Delete' -type mockDoguConfigEntryRepository_Delete_Call struct { - *mock.Call -} - -// Delete is a helper method to define mock.On call -// - _a0 context.Context -// - _a1 common.DoguConfigKey -func (_e *mockDoguConfigEntryRepository_Expecter) Delete(_a0 interface{}, _a1 interface{}) *mockDoguConfigEntryRepository_Delete_Call { - return &mockDoguConfigEntryRepository_Delete_Call{Call: _e.mock.On("Delete", _a0, _a1)} -} - -func (_c *mockDoguConfigEntryRepository_Delete_Call) Run(run func(_a0 context.Context, _a1 common.DoguConfigKey)) *mockDoguConfigEntryRepository_Delete_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(common.DoguConfigKey)) - }) - return _c -} - -func (_c *mockDoguConfigEntryRepository_Delete_Call) Return(_a0 error) *mockDoguConfigEntryRepository_Delete_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *mockDoguConfigEntryRepository_Delete_Call) RunAndReturn(run func(context.Context, common.DoguConfigKey) error) *mockDoguConfigEntryRepository_Delete_Call { - _c.Call.Return(run) - return _c -} - -// DeleteAllByKeys provides a mock function with given fields: _a0, _a1 -func (_m *mockDoguConfigEntryRepository) DeleteAllByKeys(_a0 context.Context, _a1 []common.DoguConfigKey) error { - ret := _m.Called(_a0, _a1) - - if len(ret) == 0 { - panic("no return value specified for DeleteAllByKeys") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, []common.DoguConfigKey) error); ok { - r0 = rf(_a0, _a1) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// mockDoguConfigEntryRepository_DeleteAllByKeys_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteAllByKeys' -type mockDoguConfigEntryRepository_DeleteAllByKeys_Call struct { - *mock.Call -} - -// DeleteAllByKeys is a helper method to define mock.On call -// - _a0 context.Context -// - _a1 []common.DoguConfigKey -func (_e *mockDoguConfigEntryRepository_Expecter) DeleteAllByKeys(_a0 interface{}, _a1 interface{}) *mockDoguConfigEntryRepository_DeleteAllByKeys_Call { - return &mockDoguConfigEntryRepository_DeleteAllByKeys_Call{Call: _e.mock.On("DeleteAllByKeys", _a0, _a1)} -} - -func (_c *mockDoguConfigEntryRepository_DeleteAllByKeys_Call) Run(run func(_a0 context.Context, _a1 []common.DoguConfigKey)) *mockDoguConfigEntryRepository_DeleteAllByKeys_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].([]common.DoguConfigKey)) - }) - return _c -} - -func (_c *mockDoguConfigEntryRepository_DeleteAllByKeys_Call) Return(_a0 error) *mockDoguConfigEntryRepository_DeleteAllByKeys_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *mockDoguConfigEntryRepository_DeleteAllByKeys_Call) RunAndReturn(run func(context.Context, []common.DoguConfigKey) error) *mockDoguConfigEntryRepository_DeleteAllByKeys_Call { - _c.Call.Return(run) - return _c -} - -// Get provides a mock function with given fields: _a0, _a1 -func (_m *mockDoguConfigEntryRepository) Get(_a0 context.Context, _a1 common.DoguConfigKey) (*ecosystem.DoguConfigEntry, error) { - ret := _m.Called(_a0, _a1) - - if len(ret) == 0 { - panic("no return value specified for Get") - } - - var r0 *ecosystem.DoguConfigEntry - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, common.DoguConfigKey) (*ecosystem.DoguConfigEntry, error)); ok { - return rf(_a0, _a1) - } - if rf, ok := ret.Get(0).(func(context.Context, common.DoguConfigKey) *ecosystem.DoguConfigEntry); ok { - r0 = rf(_a0, _a1) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*ecosystem.DoguConfigEntry) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, common.DoguConfigKey) error); ok { - r1 = rf(_a0, _a1) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// mockDoguConfigEntryRepository_Get_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Get' -type mockDoguConfigEntryRepository_Get_Call struct { - *mock.Call -} - -// Get is a helper method to define mock.On call -// - _a0 context.Context -// - _a1 common.DoguConfigKey -func (_e *mockDoguConfigEntryRepository_Expecter) Get(_a0 interface{}, _a1 interface{}) *mockDoguConfigEntryRepository_Get_Call { - return &mockDoguConfigEntryRepository_Get_Call{Call: _e.mock.On("Get", _a0, _a1)} -} - -func (_c *mockDoguConfigEntryRepository_Get_Call) Run(run func(_a0 context.Context, _a1 common.DoguConfigKey)) *mockDoguConfigEntryRepository_Get_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(common.DoguConfigKey)) - }) - return _c -} - -func (_c *mockDoguConfigEntryRepository_Get_Call) Return(_a0 *ecosystem.DoguConfigEntry, _a1 error) *mockDoguConfigEntryRepository_Get_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *mockDoguConfigEntryRepository_Get_Call) RunAndReturn(run func(context.Context, common.DoguConfigKey) (*ecosystem.DoguConfigEntry, error)) *mockDoguConfigEntryRepository_Get_Call { - _c.Call.Return(run) - return _c -} - -// GetAllByKey provides a mock function with given fields: _a0, _a1 -func (_m *mockDoguConfigEntryRepository) GetAllByKey(_a0 context.Context, _a1 []common.DoguConfigKey) (map[common.DoguConfigKey]*ecosystem.DoguConfigEntry, error) { - ret := _m.Called(_a0, _a1) - - if len(ret) == 0 { - panic("no return value specified for GetAllByKey") - } - - var r0 map[common.DoguConfigKey]*ecosystem.DoguConfigEntry - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, []common.DoguConfigKey) (map[common.DoguConfigKey]*ecosystem.DoguConfigEntry, error)); ok { - return rf(_a0, _a1) - } - if rf, ok := ret.Get(0).(func(context.Context, []common.DoguConfigKey) map[common.DoguConfigKey]*ecosystem.DoguConfigEntry); ok { - r0 = rf(_a0, _a1) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(map[common.DoguConfigKey]*ecosystem.DoguConfigEntry) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, []common.DoguConfigKey) error); ok { - r1 = rf(_a0, _a1) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// mockDoguConfigEntryRepository_GetAllByKey_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetAllByKey' -type mockDoguConfigEntryRepository_GetAllByKey_Call struct { - *mock.Call -} - -// GetAllByKey is a helper method to define mock.On call -// - _a0 context.Context -// - _a1 []common.DoguConfigKey -func (_e *mockDoguConfigEntryRepository_Expecter) GetAllByKey(_a0 interface{}, _a1 interface{}) *mockDoguConfigEntryRepository_GetAllByKey_Call { - return &mockDoguConfigEntryRepository_GetAllByKey_Call{Call: _e.mock.On("GetAllByKey", _a0, _a1)} -} - -func (_c *mockDoguConfigEntryRepository_GetAllByKey_Call) Run(run func(_a0 context.Context, _a1 []common.DoguConfigKey)) *mockDoguConfigEntryRepository_GetAllByKey_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].([]common.DoguConfigKey)) - }) - return _c -} - -func (_c *mockDoguConfigEntryRepository_GetAllByKey_Call) Return(_a0 map[common.DoguConfigKey]*ecosystem.DoguConfigEntry, _a1 error) *mockDoguConfigEntryRepository_GetAllByKey_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *mockDoguConfigEntryRepository_GetAllByKey_Call) RunAndReturn(run func(context.Context, []common.DoguConfigKey) (map[common.DoguConfigKey]*ecosystem.DoguConfigEntry, error)) *mockDoguConfigEntryRepository_GetAllByKey_Call { - _c.Call.Return(run) - return _c -} - -// Save provides a mock function with given fields: _a0, _a1 -func (_m *mockDoguConfigEntryRepository) Save(_a0 context.Context, _a1 *ecosystem.DoguConfigEntry) error { - ret := _m.Called(_a0, _a1) - - if len(ret) == 0 { - panic("no return value specified for Save") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, *ecosystem.DoguConfigEntry) error); ok { - r0 = rf(_a0, _a1) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// mockDoguConfigEntryRepository_Save_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Save' -type mockDoguConfigEntryRepository_Save_Call struct { - *mock.Call -} - -// Save is a helper method to define mock.On call -// - _a0 context.Context -// - _a1 *ecosystem.DoguConfigEntry -func (_e *mockDoguConfigEntryRepository_Expecter) Save(_a0 interface{}, _a1 interface{}) *mockDoguConfigEntryRepository_Save_Call { - return &mockDoguConfigEntryRepository_Save_Call{Call: _e.mock.On("Save", _a0, _a1)} -} - -func (_c *mockDoguConfigEntryRepository_Save_Call) Run(run func(_a0 context.Context, _a1 *ecosystem.DoguConfigEntry)) *mockDoguConfigEntryRepository_Save_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(*ecosystem.DoguConfigEntry)) - }) - return _c -} - -func (_c *mockDoguConfigEntryRepository_Save_Call) Return(_a0 error) *mockDoguConfigEntryRepository_Save_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *mockDoguConfigEntryRepository_Save_Call) RunAndReturn(run func(context.Context, *ecosystem.DoguConfigEntry) error) *mockDoguConfigEntryRepository_Save_Call { - _c.Call.Return(run) - return _c -} - -// SaveAll provides a mock function with given fields: _a0, _a1 -func (_m *mockDoguConfigEntryRepository) SaveAll(_a0 context.Context, _a1 []*ecosystem.DoguConfigEntry) error { - ret := _m.Called(_a0, _a1) - - if len(ret) == 0 { - panic("no return value specified for SaveAll") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, []*ecosystem.DoguConfigEntry) error); ok { - r0 = rf(_a0, _a1) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// mockDoguConfigEntryRepository_SaveAll_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SaveAll' -type mockDoguConfigEntryRepository_SaveAll_Call struct { - *mock.Call -} - -// SaveAll is a helper method to define mock.On call -// - _a0 context.Context -// - _a1 []*ecosystem.DoguConfigEntry -func (_e *mockDoguConfigEntryRepository_Expecter) SaveAll(_a0 interface{}, _a1 interface{}) *mockDoguConfigEntryRepository_SaveAll_Call { - return &mockDoguConfigEntryRepository_SaveAll_Call{Call: _e.mock.On("SaveAll", _a0, _a1)} -} - -func (_c *mockDoguConfigEntryRepository_SaveAll_Call) Run(run func(_a0 context.Context, _a1 []*ecosystem.DoguConfigEntry)) *mockDoguConfigEntryRepository_SaveAll_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].([]*ecosystem.DoguConfigEntry)) - }) - return _c -} - -func (_c *mockDoguConfigEntryRepository_SaveAll_Call) Return(_a0 error) *mockDoguConfigEntryRepository_SaveAll_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *mockDoguConfigEntryRepository_SaveAll_Call) RunAndReturn(run func(context.Context, []*ecosystem.DoguConfigEntry) error) *mockDoguConfigEntryRepository_SaveAll_Call { - _c.Call.Return(run) - return _c -} - -// newMockDoguConfigEntryRepository creates a new instance of mockDoguConfigEntryRepository. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func newMockDoguConfigEntryRepository(t interface { - mock.TestingT - Cleanup(func()) -}) *mockDoguConfigEntryRepository { - mock := &mockDoguConfigEntryRepository{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/pkg/application/mock_sensitiveDoguConfigEntryRepository_test.go b/pkg/application/mock_sensitiveDoguConfigEntryRepository_test.go deleted file mode 100644 index c0760586..00000000 --- a/pkg/application/mock_sensitiveDoguConfigEntryRepository_test.go +++ /dev/null @@ -1,346 +0,0 @@ -// Code generated by mockery v2.42.1. DO NOT EDIT. - -package application - -import ( - context "context" - - common "github.com/cloudogu/k8s-blueprint-operator/pkg/domain/common" - - ecosystem "github.com/cloudogu/k8s-blueprint-operator/pkg/domain/ecosystem" - - mock "github.com/stretchr/testify/mock" -) - -// mockSensitiveDoguConfigEntryRepository is an autogenerated mock type for the sensitiveDoguConfigEntryRepository type -type mockSensitiveDoguConfigEntryRepository struct { - mock.Mock -} - -type mockSensitiveDoguConfigEntryRepository_Expecter struct { - mock *mock.Mock -} - -func (_m *mockSensitiveDoguConfigEntryRepository) EXPECT() *mockSensitiveDoguConfigEntryRepository_Expecter { - return &mockSensitiveDoguConfigEntryRepository_Expecter{mock: &_m.Mock} -} - -// Delete provides a mock function with given fields: _a0, _a1 -func (_m *mockSensitiveDoguConfigEntryRepository) Delete(_a0 context.Context, _a1 common.SensitiveDoguConfigKey) error { - ret := _m.Called(_a0, _a1) - - if len(ret) == 0 { - panic("no return value specified for Delete") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, common.SensitiveDoguConfigKey) error); ok { - r0 = rf(_a0, _a1) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// mockSensitiveDoguConfigEntryRepository_Delete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Delete' -type mockSensitiveDoguConfigEntryRepository_Delete_Call struct { - *mock.Call -} - -// Delete is a helper method to define mock.On call -// - _a0 context.Context -// - _a1 common.SensitiveDoguConfigKey -func (_e *mockSensitiveDoguConfigEntryRepository_Expecter) Delete(_a0 interface{}, _a1 interface{}) *mockSensitiveDoguConfigEntryRepository_Delete_Call { - return &mockSensitiveDoguConfigEntryRepository_Delete_Call{Call: _e.mock.On("Delete", _a0, _a1)} -} - -func (_c *mockSensitiveDoguConfigEntryRepository_Delete_Call) Run(run func(_a0 context.Context, _a1 common.SensitiveDoguConfigKey)) *mockSensitiveDoguConfigEntryRepository_Delete_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(common.SensitiveDoguConfigKey)) - }) - return _c -} - -func (_c *mockSensitiveDoguConfigEntryRepository_Delete_Call) Return(_a0 error) *mockSensitiveDoguConfigEntryRepository_Delete_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *mockSensitiveDoguConfigEntryRepository_Delete_Call) RunAndReturn(run func(context.Context, common.SensitiveDoguConfigKey) error) *mockSensitiveDoguConfigEntryRepository_Delete_Call { - _c.Call.Return(run) - return _c -} - -// DeleteAllByKeys provides a mock function with given fields: _a0, _a1 -func (_m *mockSensitiveDoguConfigEntryRepository) DeleteAllByKeys(_a0 context.Context, _a1 []common.SensitiveDoguConfigKey) error { - ret := _m.Called(_a0, _a1) - - if len(ret) == 0 { - panic("no return value specified for DeleteAllByKeys") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, []common.SensitiveDoguConfigKey) error); ok { - r0 = rf(_a0, _a1) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// mockSensitiveDoguConfigEntryRepository_DeleteAllByKeys_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteAllByKeys' -type mockSensitiveDoguConfigEntryRepository_DeleteAllByKeys_Call struct { - *mock.Call -} - -// DeleteAllByKeys is a helper method to define mock.On call -// - _a0 context.Context -// - _a1 []common.SensitiveDoguConfigKey -func (_e *mockSensitiveDoguConfigEntryRepository_Expecter) DeleteAllByKeys(_a0 interface{}, _a1 interface{}) *mockSensitiveDoguConfigEntryRepository_DeleteAllByKeys_Call { - return &mockSensitiveDoguConfigEntryRepository_DeleteAllByKeys_Call{Call: _e.mock.On("DeleteAllByKeys", _a0, _a1)} -} - -func (_c *mockSensitiveDoguConfigEntryRepository_DeleteAllByKeys_Call) Run(run func(_a0 context.Context, _a1 []common.SensitiveDoguConfigKey)) *mockSensitiveDoguConfigEntryRepository_DeleteAllByKeys_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].([]common.SensitiveDoguConfigKey)) - }) - return _c -} - -func (_c *mockSensitiveDoguConfigEntryRepository_DeleteAllByKeys_Call) Return(_a0 error) *mockSensitiveDoguConfigEntryRepository_DeleteAllByKeys_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *mockSensitiveDoguConfigEntryRepository_DeleteAllByKeys_Call) RunAndReturn(run func(context.Context, []common.SensitiveDoguConfigKey) error) *mockSensitiveDoguConfigEntryRepository_DeleteAllByKeys_Call { - _c.Call.Return(run) - return _c -} - -// Get provides a mock function with given fields: _a0, _a1 -func (_m *mockSensitiveDoguConfigEntryRepository) Get(_a0 context.Context, _a1 common.SensitiveDoguConfigKey) (*ecosystem.SensitiveDoguConfigEntry, error) { - ret := _m.Called(_a0, _a1) - - if len(ret) == 0 { - panic("no return value specified for Get") - } - - var r0 *ecosystem.SensitiveDoguConfigEntry - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, common.SensitiveDoguConfigKey) (*ecosystem.SensitiveDoguConfigEntry, error)); ok { - return rf(_a0, _a1) - } - if rf, ok := ret.Get(0).(func(context.Context, common.SensitiveDoguConfigKey) *ecosystem.SensitiveDoguConfigEntry); ok { - r0 = rf(_a0, _a1) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*ecosystem.SensitiveDoguConfigEntry) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, common.SensitiveDoguConfigKey) error); ok { - r1 = rf(_a0, _a1) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// mockSensitiveDoguConfigEntryRepository_Get_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Get' -type mockSensitiveDoguConfigEntryRepository_Get_Call struct { - *mock.Call -} - -// Get is a helper method to define mock.On call -// - _a0 context.Context -// - _a1 common.SensitiveDoguConfigKey -func (_e *mockSensitiveDoguConfigEntryRepository_Expecter) Get(_a0 interface{}, _a1 interface{}) *mockSensitiveDoguConfigEntryRepository_Get_Call { - return &mockSensitiveDoguConfigEntryRepository_Get_Call{Call: _e.mock.On("Get", _a0, _a1)} -} - -func (_c *mockSensitiveDoguConfigEntryRepository_Get_Call) Run(run func(_a0 context.Context, _a1 common.SensitiveDoguConfigKey)) *mockSensitiveDoguConfigEntryRepository_Get_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(common.SensitiveDoguConfigKey)) - }) - return _c -} - -func (_c *mockSensitiveDoguConfigEntryRepository_Get_Call) Return(_a0 *ecosystem.SensitiveDoguConfigEntry, _a1 error) *mockSensitiveDoguConfigEntryRepository_Get_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *mockSensitiveDoguConfigEntryRepository_Get_Call) RunAndReturn(run func(context.Context, common.SensitiveDoguConfigKey) (*ecosystem.SensitiveDoguConfigEntry, error)) *mockSensitiveDoguConfigEntryRepository_Get_Call { - _c.Call.Return(run) - return _c -} - -// GetAllByKey provides a mock function with given fields: _a0, _a1 -func (_m *mockSensitiveDoguConfigEntryRepository) GetAllByKey(_a0 context.Context, _a1 []common.SensitiveDoguConfigKey) (map[common.SensitiveDoguConfigKey]*ecosystem.SensitiveDoguConfigEntry, error) { - ret := _m.Called(_a0, _a1) - - if len(ret) == 0 { - panic("no return value specified for GetAllByKey") - } - - var r0 map[common.SensitiveDoguConfigKey]*ecosystem.SensitiveDoguConfigEntry - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, []common.SensitiveDoguConfigKey) (map[common.SensitiveDoguConfigKey]*ecosystem.SensitiveDoguConfigEntry, error)); ok { - return rf(_a0, _a1) - } - if rf, ok := ret.Get(0).(func(context.Context, []common.SensitiveDoguConfigKey) map[common.SensitiveDoguConfigKey]*ecosystem.SensitiveDoguConfigEntry); ok { - r0 = rf(_a0, _a1) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(map[common.SensitiveDoguConfigKey]*ecosystem.SensitiveDoguConfigEntry) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, []common.SensitiveDoguConfigKey) error); ok { - r1 = rf(_a0, _a1) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// mockSensitiveDoguConfigEntryRepository_GetAllByKey_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetAllByKey' -type mockSensitiveDoguConfigEntryRepository_GetAllByKey_Call struct { - *mock.Call -} - -// GetAllByKey is a helper method to define mock.On call -// - _a0 context.Context -// - _a1 []common.SensitiveDoguConfigKey -func (_e *mockSensitiveDoguConfigEntryRepository_Expecter) GetAllByKey(_a0 interface{}, _a1 interface{}) *mockSensitiveDoguConfigEntryRepository_GetAllByKey_Call { - return &mockSensitiveDoguConfigEntryRepository_GetAllByKey_Call{Call: _e.mock.On("GetAllByKey", _a0, _a1)} -} - -func (_c *mockSensitiveDoguConfigEntryRepository_GetAllByKey_Call) Run(run func(_a0 context.Context, _a1 []common.SensitiveDoguConfigKey)) *mockSensitiveDoguConfigEntryRepository_GetAllByKey_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].([]common.SensitiveDoguConfigKey)) - }) - return _c -} - -func (_c *mockSensitiveDoguConfigEntryRepository_GetAllByKey_Call) Return(_a0 map[common.SensitiveDoguConfigKey]*ecosystem.SensitiveDoguConfigEntry, _a1 error) *mockSensitiveDoguConfigEntryRepository_GetAllByKey_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *mockSensitiveDoguConfigEntryRepository_GetAllByKey_Call) RunAndReturn(run func(context.Context, []common.SensitiveDoguConfigKey) (map[common.SensitiveDoguConfigKey]*ecosystem.SensitiveDoguConfigEntry, error)) *mockSensitiveDoguConfigEntryRepository_GetAllByKey_Call { - _c.Call.Return(run) - return _c -} - -// Save provides a mock function with given fields: _a0, _a1 -func (_m *mockSensitiveDoguConfigEntryRepository) Save(_a0 context.Context, _a1 *ecosystem.SensitiveDoguConfigEntry) error { - ret := _m.Called(_a0, _a1) - - if len(ret) == 0 { - panic("no return value specified for Save") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, *ecosystem.SensitiveDoguConfigEntry) error); ok { - r0 = rf(_a0, _a1) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// mockSensitiveDoguConfigEntryRepository_Save_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Save' -type mockSensitiveDoguConfigEntryRepository_Save_Call struct { - *mock.Call -} - -// Save is a helper method to define mock.On call -// - _a0 context.Context -// - _a1 *ecosystem.SensitiveDoguConfigEntry -func (_e *mockSensitiveDoguConfigEntryRepository_Expecter) Save(_a0 interface{}, _a1 interface{}) *mockSensitiveDoguConfigEntryRepository_Save_Call { - return &mockSensitiveDoguConfigEntryRepository_Save_Call{Call: _e.mock.On("Save", _a0, _a1)} -} - -func (_c *mockSensitiveDoguConfigEntryRepository_Save_Call) Run(run func(_a0 context.Context, _a1 *ecosystem.SensitiveDoguConfigEntry)) *mockSensitiveDoguConfigEntryRepository_Save_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(*ecosystem.SensitiveDoguConfigEntry)) - }) - return _c -} - -func (_c *mockSensitiveDoguConfigEntryRepository_Save_Call) Return(_a0 error) *mockSensitiveDoguConfigEntryRepository_Save_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *mockSensitiveDoguConfigEntryRepository_Save_Call) RunAndReturn(run func(context.Context, *ecosystem.SensitiveDoguConfigEntry) error) *mockSensitiveDoguConfigEntryRepository_Save_Call { - _c.Call.Return(run) - return _c -} - -// SaveAll provides a mock function with given fields: _a0, _a1 -func (_m *mockSensitiveDoguConfigEntryRepository) SaveAll(_a0 context.Context, _a1 []*ecosystem.SensitiveDoguConfigEntry) error { - ret := _m.Called(_a0, _a1) - - if len(ret) == 0 { - panic("no return value specified for SaveAll") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, []*ecosystem.SensitiveDoguConfigEntry) error); ok { - r0 = rf(_a0, _a1) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// mockSensitiveDoguConfigEntryRepository_SaveAll_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SaveAll' -type mockSensitiveDoguConfigEntryRepository_SaveAll_Call struct { - *mock.Call -} - -// SaveAll is a helper method to define mock.On call -// - _a0 context.Context -// - _a1 []*ecosystem.SensitiveDoguConfigEntry -func (_e *mockSensitiveDoguConfigEntryRepository_Expecter) SaveAll(_a0 interface{}, _a1 interface{}) *mockSensitiveDoguConfigEntryRepository_SaveAll_Call { - return &mockSensitiveDoguConfigEntryRepository_SaveAll_Call{Call: _e.mock.On("SaveAll", _a0, _a1)} -} - -func (_c *mockSensitiveDoguConfigEntryRepository_SaveAll_Call) Run(run func(_a0 context.Context, _a1 []*ecosystem.SensitiveDoguConfigEntry)) *mockSensitiveDoguConfigEntryRepository_SaveAll_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].([]*ecosystem.SensitiveDoguConfigEntry)) - }) - return _c -} - -func (_c *mockSensitiveDoguConfigEntryRepository_SaveAll_Call) Return(_a0 error) *mockSensitiveDoguConfigEntryRepository_SaveAll_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *mockSensitiveDoguConfigEntryRepository_SaveAll_Call) RunAndReturn(run func(context.Context, []*ecosystem.SensitiveDoguConfigEntry) error) *mockSensitiveDoguConfigEntryRepository_SaveAll_Call { - _c.Call.Return(run) - return _c -} - -// newMockSensitiveDoguConfigEntryRepository creates a new instance of mockSensitiveDoguConfigEntryRepository. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func newMockSensitiveDoguConfigEntryRepository(t interface { - mock.TestingT - Cleanup(func()) -}) *mockSensitiveDoguConfigEntryRepository { - mock := &mockSensitiveDoguConfigEntryRepository{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/pkg/application/stateDiffUseCase_test.go b/pkg/application/stateDiffUseCase_test.go index 908916e1..c4d9631f 100644 --- a/pkg/application/stateDiffUseCase_test.go +++ b/pkg/application/stateDiffUseCase_test.go @@ -45,8 +45,8 @@ var ( internalTestError = domainservice.NewInternalError(assert.AnError, "internal error") nginxStaticConfigKeyNginxKey1 = common.DoguConfigKey{DoguName: "nginx-static", Key: "nginxKey1"} nginxStaticConfigKeyNginxKey2 = common.DoguConfigKey{DoguName: "nginx-static", Key: "nginxKey2"} - nginxStaticSensitiveConfigKeyNginxKey1 = common.SensitiveDoguConfigKey{DoguConfigKey: nginxStaticConfigKeyNginxKey1} - nginxStaticSensitiveConfigKeyNginxKey2 = common.SensitiveDoguConfigKey{DoguConfigKey: nginxStaticConfigKeyNginxKey2} + nginxStaticSensitiveConfigKeyNginxKey1 = nginxStaticConfigKeyNginxKey1 + nginxStaticSensitiveConfigKeyNginxKey2 = nginxStaticConfigKeyNginxKey2 ) func TestStateDiffUseCase_DetermineStateDiff(t *testing.T) { diff --git a/pkg/bootstrap.go b/pkg/bootstrap.go index 17c30985..14d268d8 100644 --- a/pkg/bootstrap.go +++ b/pkg/bootstrap.go @@ -2,7 +2,6 @@ package pkg import ( "fmt" - adapterconfigetcd "github.com/cloudogu/k8s-blueprint-operator/pkg/adapter/config/etcd" adapterconfigk8s "github.com/cloudogu/k8s-blueprint-operator/pkg/adapter/config/kubernetes" "github.com/cloudogu/k8s-blueprint-operator/pkg/adapter/kubernetes/restartcr" "github.com/cloudogu/k8s-registry-lib/repository" @@ -81,7 +80,6 @@ func Bootstrap(restConfig *rest.Config, eventRecorder record.EventRecorder, name return nil, err } - sensitiveDoguConfigAdapter := adapterconfigetcd.NewSensitiveDoguConfigRepository(configRegistry) k8sDoguConfigRepo := repository.NewDoguConfigRepository(ecosystemClientSet.CoreV1().ConfigMaps(namespace)) doguConfigRepo := adapterconfigk8s.NewDoguConfigRepository(*k8sDoguConfigRepo) k8sSensitiveDoguConfigRepo := repository.NewSensitiveDoguConfigRepository(ecosystemClientSet.CoreV1().Secrets(namespace)) @@ -103,7 +101,7 @@ func Bootstrap(restConfig *rest.Config, eventRecorder record.EventRecorder, name componentInstallationUseCase := application.NewComponentInstallationUseCase(blueprintSpecRepository, componentInstallationRepo, healthConfigRepo) ecosystemHealthUseCase := application.NewEcosystemHealthUseCase(doguInstallationUseCase, componentInstallationUseCase, healthConfigRepo) applyBlueprintSpecUseCase := application.NewApplyBlueprintSpecUseCase(blueprintSpecRepository, doguInstallationUseCase, ecosystemHealthUseCase, componentInstallationUseCase, maintenanceMode) - ConfigUseCase := application.NewEcosystemConfigUseCase(blueprintSpecRepository, doguConfigRepo, sensitiveDoguConfigAdapter, globalConfigRepoAdapter) + ConfigUseCase := application.NewEcosystemConfigUseCase(blueprintSpecRepository, doguConfigRepo, sensitiveDoguConfigRepo, globalConfigRepoAdapter) doguRestartUseCase := application.NewDoguRestartUseCase(doguInstallationRepo, blueprintSpecRepository, restartRepository) selfUpgradeUseCase := application.NewSelfUpgradeUseCase(blueprintSpecRepository, componentInstallationRepo, componentInstallationUseCase, blueprintOperatorName.SimpleName, healthConfigRepo) diff --git a/pkg/domain/blueprintSpec_test.go b/pkg/domain/blueprintSpec_test.go index 28526f67..e73d4643 100644 --- a/pkg/domain/blueprintSpec_test.go +++ b/pkg/domain/blueprintSpec_test.go @@ -712,7 +712,7 @@ func TestBlueprintSpec_MarkBlueprintApplied(t *testing.T) { func TestBlueprintSpec_CensorSensitiveData(t *testing.T) { // given - ldapLoggingKey := common.SensitiveDoguConfigKey{DoguConfigKey: common.DoguConfigKey{DoguName: "ldap", Key: "logging/root"}} + ldapLoggingKey := common.SensitiveDoguConfigKey{DoguName: "ldap", Key: "logging/root"} spec := &BlueprintSpec{ Blueprint: Blueprint{ Config: Config{ diff --git a/pkg/domain/blueprint_test.go b/pkg/domain/blueprint_test.go index be7ebdc4..a16fa082 100644 --- a/pkg/domain/blueprint_test.go +++ b/pkg/domain/blueprint_test.go @@ -220,8 +220,8 @@ func Test_censorConfigValues(t *testing.T) { }, SensitiveConfig: SensitiveDoguConfig{ Present: map[common.SensitiveDoguConfigKey]common.SensitiveDoguConfigValue{ - common.SensitiveDoguConfigKey{DoguConfigKey: ldapLoggingKey}: "ERROR", - common.SensitiveDoguConfigKey{DoguConfigKey: ldapPasswordChangeKey}: "no-reply@itzbund.de", + ldapLoggingKey: "ERROR", + ldapPasswordChangeKey: "no-reply@itzbund.de", }, }, }, @@ -239,8 +239,8 @@ func Test_censorConfigValues(t *testing.T) { assert.Equal(t, "ERROR", string(result.Dogus["ldap"].Config.Present[ldapLoggingKey])) assert.Equal(t, "no-reply@itzbund.de", string(result.Dogus["ldap"].Config.Present[ldapPasswordChangeKey])) - assert.Equal(t, censorValue, string(result.Dogus["ldap"].SensitiveConfig.Present[common.SensitiveDoguConfigKey{DoguConfigKey: ldapLoggingKey}])) - assert.Equal(t, censorValue, string(result.Dogus["ldap"].SensitiveConfig.Present[common.SensitiveDoguConfigKey{DoguConfigKey: ldapPasswordChangeKey}])) + assert.Equal(t, censorValue, string(result.Dogus["ldap"].SensitiveConfig.Present[ldapLoggingKey])) + assert.Equal(t, censorValue, string(result.Dogus["ldap"].SensitiveConfig.Present[ldapPasswordChangeKey])) assert.Equal(t, "true", string(result.Global.Present["block_warpmenu_support_category"])) assert.Equal(t, "14", string(result.Global.Present["password-policy/min_length"])) } diff --git a/pkg/domain/common/configNames.go b/pkg/domain/common/configNames.go index 85569a3e..a84156eb 100644 --- a/pkg/domain/common/configNames.go +++ b/pkg/domain/common/configNames.go @@ -7,7 +7,7 @@ import ( ) type RegistryConfigKey interface { - GlobalConfigKey | DoguConfigKey | SensitiveDoguConfigKey + GlobalConfigKey | DoguConfigKey } type GlobalConfigKey = config.Key @@ -33,9 +33,7 @@ func (k DoguConfigKey) String() string { return fmt.Sprintf("key %q of dogu %q", k.Key, k.DoguName) } -type SensitiveDoguConfigKey struct { - DoguConfigKey -} +type SensitiveDoguConfigKey = DoguConfigKey // GlobalConfigValue is a single global config value type GlobalConfigValue = config.Value diff --git a/pkg/domain/config_test.go b/pkg/domain/config_test.go index 998f0eef..eb4cdfa1 100644 --- a/pkg/domain/config_test.go +++ b/pkg/domain/config_test.go @@ -164,10 +164,10 @@ func TestSensitiveDoguConfig_validate(t *testing.T) { t.Run("config is ok", func(t *testing.T) { config := SensitiveDoguConfig{ Present: map[common.SensitiveDoguConfigKey]common.SensitiveDoguConfigValue{ - common.SensitiveDoguConfigKey{DoguConfigKey: common.DoguConfigKey{DoguName: "dogu1", Key: "my/key1"}}: "value1", + common.SensitiveDoguConfigKey{DoguName: "dogu1", Key: "my/key1"}: "value1", }, Absent: []common.SensitiveDoguConfigKey{ - {DoguConfigKey: common.DoguConfigKey{DoguName: "dogu1", Key: "my/key2"}}, + {DoguName: "dogu1", Key: "my/key2"}, }, } err := config.validate("dogu1") @@ -176,10 +176,10 @@ func TestSensitiveDoguConfig_validate(t *testing.T) { t.Run("not absent and present at the same time", func(t *testing.T) { config := SensitiveDoguConfig{ Present: map[common.SensitiveDoguConfigKey]common.SensitiveDoguConfigValue{ - common.SensitiveDoguConfigKey{DoguConfigKey: common.DoguConfigKey{DoguName: "dogu1", Key: "my/key"}}: "value1", + common.SensitiveDoguConfigKey{DoguName: "dogu1", Key: "my/key"}: "value1", }, Absent: []common.SensitiveDoguConfigKey{ - {DoguConfigKey: common.DoguConfigKey{DoguName: "dogu1", Key: "my/key"}}, + {DoguName: "dogu1", Key: "my/key"}, }, } err := config.validate("dogu1") @@ -188,8 +188,8 @@ func TestSensitiveDoguConfig_validate(t *testing.T) { t.Run("not same key multiple times", func(t *testing.T) { config := SensitiveDoguConfig{ Absent: []common.SensitiveDoguConfigKey{ - {DoguConfigKey: common.DoguConfigKey{DoguName: "dogu1", Key: "my/key"}}, - {DoguConfigKey: common.DoguConfigKey{DoguName: "dogu1", Key: "my/key"}}, + {DoguName: "dogu1", Key: "my/key"}, + {DoguName: "dogu1", Key: "my/key"}, }, } err := config.validate("dogu1") @@ -198,10 +198,10 @@ func TestSensitiveDoguConfig_validate(t *testing.T) { t.Run("only one referenced dogu name", func(t *testing.T) { config := SensitiveDoguConfig{ Present: map[common.SensitiveDoguConfigKey]common.SensitiveDoguConfigValue{ - common.SensitiveDoguConfigKey{DoguConfigKey: common.DoguConfigKey{DoguName: "dogu1", Key: "test"}}: "value1", + common.SensitiveDoguConfigKey{DoguName: "dogu1", Key: "test"}: "value1", }, Absent: []common.SensitiveDoguConfigKey{ - {DoguConfigKey: common.DoguConfigKey{DoguName: "dogu1", Key: "my/key"}}, + {DoguName: "dogu1", Key: "my/key"}, }, } err := config.validate("dogu2") @@ -211,10 +211,10 @@ func TestSensitiveDoguConfig_validate(t *testing.T) { t.Run("combine errors", func(t *testing.T) { config := SensitiveDoguConfig{ Present: map[common.SensitiveDoguConfigKey]common.SensitiveDoguConfigValue{ - common.SensitiveDoguConfigKey{DoguConfigKey: common.DoguConfigKey{DoguName: "dogu1", Key: ""}}: "value1", + common.SensitiveDoguConfigKey{DoguName: "dogu1", Key: ""}: "value1", }, Absent: []common.SensitiveDoguConfigKey{ - {DoguConfigKey: common.DoguConfigKey{DoguName: "dogu1", Key: ""}}, + {DoguName: "dogu1", Key: ""}, }, } err := config.validate("dogu1") @@ -258,7 +258,7 @@ func TestConfig_validate(t *testing.T) { Absent: []common.DoguConfigKey{{DoguName: ""}}, }, SensitiveConfig: SensitiveDoguConfig{ - Absent: []common.SensitiveDoguConfigKey{{common.DoguConfigKey{DoguName: ""}}}, + Absent: []common.SensitiveDoguConfigKey{{DoguName: ""}}, }, }, }, @@ -341,10 +341,10 @@ func TestConfig_GetSensitiveDoguConfigKeys(t *testing.T) { var ( nginx = common.SimpleDoguName("nginx") postfix = common.SimpleDoguName("postfix") - nginxKey1 = common.SensitiveDoguConfigKey{DoguConfigKey: common.DoguConfigKey{DoguName: nginx, Key: "key1"}} - nginxKey2 = common.SensitiveDoguConfigKey{DoguConfigKey: common.DoguConfigKey{DoguName: nginx, Key: "key2"}} - postfixKey1 = common.SensitiveDoguConfigKey{DoguConfigKey: common.DoguConfigKey{DoguName: postfix, Key: "key1"}} - postfixKey2 = common.SensitiveDoguConfigKey{DoguConfigKey: common.DoguConfigKey{DoguName: postfix, Key: "key2"}} + nginxKey1 = common.SensitiveDoguConfigKey{DoguName: nginx, Key: "key1"} + nginxKey2 = common.SensitiveDoguConfigKey{DoguName: nginx, Key: "key2"} + postfixKey1 = common.SensitiveDoguConfigKey{DoguName: postfix, Key: "key1"} + postfixKey2 = common.SensitiveDoguConfigKey{DoguName: postfix, Key: "key2"} ) config := Config{ Dogus: map[common.SimpleDoguName]CombinedDoguConfig{ @@ -389,10 +389,10 @@ func TestCombinedDoguConfig_validate(t *testing.T) { } sensitiveConfig := SensitiveDoguConfig{ Present: map[common.SensitiveDoguConfigKey]common.SensitiveDoguConfigValue{ - common.SensitiveDoguConfigKey{DoguConfigKey: common.DoguConfigKey{DoguName: "dogu1", Key: "my/key1"}}: "value1", + common.SensitiveDoguConfigKey{DoguName: "dogu1", Key: "my/key1"}: "value1", }, Absent: []common.SensitiveDoguConfigKey{ - {DoguConfigKey: common.DoguConfigKey{DoguName: "dogu1", Key: "my/key2"}}, + {DoguName: "dogu1", Key: "my/key2"}, }, } diff --git a/pkg/domain/stateDiffConfig_test.go b/pkg/domain/stateDiffConfig_test.go index eb8f900b..5878e869 100644 --- a/pkg/domain/stateDiffConfig_test.go +++ b/pkg/domain/stateDiffConfig_test.go @@ -10,17 +10,13 @@ import ( var ( dogu1 = common.SimpleDoguName("dogu1") - dogu2 = common.SimpleDoguName("dogu2") dogu1Key1 = common.DoguConfigKey{DoguName: dogu1, Key: "key1"} dogu1Key2 = common.DoguConfigKey{DoguName: dogu1, Key: "key2"} dogu1Key3 = common.DoguConfigKey{DoguName: dogu1, Key: "key3"} dogu1Key4 = common.DoguConfigKey{DoguName: dogu1, Key: "key4"} - dogu2Key1 = common.DoguConfigKey{DoguName: dogu2, Key: "key1"} - sensitiveDogu1Key1 = common.SensitiveDoguConfigKey{DoguConfigKey: dogu1Key1} - sensitiveDogu1Key2 = common.SensitiveDoguConfigKey{DoguConfigKey: dogu1Key2} - sensitiveDogu1Key3 = common.SensitiveDoguConfigKey{DoguConfigKey: dogu1Key3} - sensitiveDogu1Key4 = common.SensitiveDoguConfigKey{DoguConfigKey: dogu1Key4} - sensitiveDogu2Key1 = common.SensitiveDoguConfigKey{DoguConfigKey: dogu2Key1} + sensitiveDogu1Key1 = common.SensitiveDoguConfigKey{DoguName: dogu1, Key: "key1"} + sensitiveDogu1Key2 = common.SensitiveDoguConfigKey{DoguName: dogu1, Key: "key2"} + sensitiveDogu1Key3 = common.SensitiveDoguConfigKey{DoguName: dogu1, Key: "key3"} ) func Test_determineConfigDiff(t *testing.T) { @@ -458,10 +454,10 @@ func TestCombinedDoguConfigDiff_CensorValues(t *testing.T) { configDiff := CombinedDoguConfigDiffs{ SensitiveDoguConfigDiff: []SensitiveDoguConfigEntryDiff{ { - Key: common.SensitiveDoguConfigKey{DoguConfigKey: common.DoguConfigKey{ + Key: common.SensitiveDoguConfigKey{ DoguName: "ldap", Key: "logging/root", - }}, + }, Actual: DoguConfigValueState{ Value: "ERROR", Exists: false, @@ -549,7 +545,7 @@ func TestCombinedDoguConfigDiffs_HasChanges(t *testing.T) { fields: fields{ DoguConfigDiff: []DoguConfigEntryDiff{}, SensitiveDoguConfigDiff: []SensitiveDoguConfigEntryDiff{{ - Key: common.SensitiveDoguConfigKey{common.DoguConfigKey{DoguName: "testdogu", Key: "testkey"}}, + Key: common.SensitiveDoguConfigKey{DoguName: "testdogu", Key: "testkey"}, Actual: DoguConfigValueState{Value: "changed", Exists: true}, Expected: DoguConfigValueState{"initial", true}, NeededAction: ConfigActionSet}}, diff --git a/pkg/domain/stateDiffSensitiveDoguConfig.go b/pkg/domain/stateDiffSensitiveDoguConfig.go index 516cd667..daecca08 100644 --- a/pkg/domain/stateDiffSensitiveDoguConfig.go +++ b/pkg/domain/stateDiffSensitiveDoguConfig.go @@ -6,7 +6,7 @@ import ( "github.com/cloudogu/k8s-registry-lib/config" ) -type SensitiveDoguConfigDiffs []SensitiveDoguConfigEntryDiff +type SensitiveDoguConfigDiffs = DoguConfigDiffs func (diffs SensitiveDoguConfigDiffs) GetSensitiveDoguConfigDiffByAction() map[ConfigAction][]SensitiveDoguConfigEntryDiff { return util.GroupBy(diffs, func(diff SensitiveDoguConfigEntryDiff) ConfigAction { @@ -14,12 +14,7 @@ func (diffs SensitiveDoguConfigDiffs) GetSensitiveDoguConfigDiffByAction() map[C }) } -type SensitiveDoguConfigEntryDiff struct { - Key common.SensitiveDoguConfigKey - Actual DoguConfigValueState - Expected DoguConfigValueState - NeededAction ConfigAction -} +type SensitiveDoguConfigEntryDiff = DoguConfigEntryDiff func newSensitiveDoguConfigEntryDiff( key common.SensitiveDoguConfigKey, diff --git a/pkg/domainservice/adapterInterfaces.go b/pkg/domainservice/adapterInterfaces.go index 47425963..bb88a870 100644 --- a/pkg/domainservice/adapterInterfaces.go +++ b/pkg/domainservice/adapterInterfaces.go @@ -166,68 +166,6 @@ type SensitiveDoguConfigRepository interface { Update(ctx context.Context, config config.DoguConfig) (config.DoguConfig, error) } -type DoguConfigEntryRepository interface { - // Get retrieves a key from the dogu's config. - // It can throw the following errors: - // - NotFoundError if the key is not found. - // - InternalError if any other error happens. - Get(context.Context, common.DoguConfigKey) (*ecosystem.DoguConfigEntry, error) - // GetAllByKey retrieves all ecosystem.DoguConfigEntry's for the given ecosystem.DoguConfigKey's config. - // It can trow the following errors: - // - NotFoundError if there is no config for the dogu. - // - InternalError if any other error happens. - GetAllByKey(context.Context, []common.DoguConfigKey) (map[common.DoguConfigKey]*ecosystem.DoguConfigEntry, error) - // Save persists the config for the given dogu. Config can be set even if the dogu is not yet installed. - // It can throw the following errors: - // - ConflictError if there were concurrent write accesses. - // - InternalError if any other error happens. - Save(context.Context, *ecosystem.DoguConfigEntry) error - // SaveAll persists all given config keys. Configs can be set even if the dogus are not installed. - // It can throw the following errors: - // - ConflictError if there were concurrent write accesses. - // - InternalError if any other error happens. - SaveAll(context.Context, []*ecosystem.DoguConfigEntry) error - // Delete deletes a dogu config key. - // It can throw an InternalError if any error happens. - // If the key is not existent no error will be returned. - Delete(context.Context, common.DoguConfigKey) error - // DeleteAllByKeys deletes all given dogu config keys. - // It can throw an InternalError if any error happens. - // If any key is not existent, no error will be returned for that case. - DeleteAllByKeys(context.Context, []common.DoguConfigKey) error -} - -type SensitiveDoguConfigEntryRepository interface { - // Get retrieves a key from the dogu's sensitive config. - // It can throw the following errors: - // - NotFoundError if the key is not found. - // - InternalError if any other error happens. - Get(context.Context, common.SensitiveDoguConfigKey) (*ecosystem.SensitiveDoguConfigEntry, error) - // GetAllByKey retrieves a dogu's sensitive config for the given keys. - // It can trow the following errors: - // - NotFoundError if there is no config for the dogu. - // - InternalError if any other error happens. - GetAllByKey(context.Context, []common.SensitiveDoguConfigKey) (map[common.SensitiveDoguConfigKey]*ecosystem.SensitiveDoguConfigEntry, error) - // Save persists the sensitive config for the given dogu. Config can be set even if the dogu is not yet installed. - // It can throw the following errors: - // - ConflictError if there were concurrent write accesses. - // - InternalError if any other error happens. - Save(context.Context, *ecosystem.SensitiveDoguConfigEntry) error - // SaveAll persists all given sensitive config keys. sensitive configs can be set even if the dogus are not installed. - // It can throw the following errors: - // - ConflictError if there were concurrent write accesses. - // - InternalError if any other error happens. - SaveAll(context.Context, []*ecosystem.SensitiveDoguConfigEntry) error - // Delete deletes a sensitive dogu config key. - // It can throw an InternalError if any error happens. - // If the key is not existent no error will be returned. - Delete(context.Context, common.SensitiveDoguConfigKey) error - // DeleteAllByKeys deletes all given sensitive dogu config keys. - // It can throw an InternalError if any error happens. - // If any key is not existent, no error will be returned for that case. - DeleteAllByKeys(context.Context, []common.SensitiveDoguConfigKey) error -} - // NewNotFoundError creates a NotFoundError with a given message. The wrapped error may be nil. The error message must // omit the fmt.Errorf verb %w because this is done by NotFoundError.Error(). func NewNotFoundError(wrappedError error, message string, msgArgs ...any) *NotFoundError { diff --git a/pkg/domainservice/mock_DoguConfigEntryRepository_test.go b/pkg/domainservice/mock_DoguConfigEntryRepository_test.go deleted file mode 100644 index eb46668f..00000000 --- a/pkg/domainservice/mock_DoguConfigEntryRepository_test.go +++ /dev/null @@ -1,346 +0,0 @@ -// Code generated by mockery v2.42.1. DO NOT EDIT. - -package domainservice - -import ( - context "context" - - common "github.com/cloudogu/k8s-blueprint-operator/pkg/domain/common" - - ecosystem "github.com/cloudogu/k8s-blueprint-operator/pkg/domain/ecosystem" - - mock "github.com/stretchr/testify/mock" -) - -// MockDoguConfigEntryRepository is an autogenerated mock type for the DoguConfigEntryRepository type -type MockDoguConfigEntryRepository struct { - mock.Mock -} - -type MockDoguConfigEntryRepository_Expecter struct { - mock *mock.Mock -} - -func (_m *MockDoguConfigEntryRepository) EXPECT() *MockDoguConfigEntryRepository_Expecter { - return &MockDoguConfigEntryRepository_Expecter{mock: &_m.Mock} -} - -// Delete provides a mock function with given fields: _a0, _a1 -func (_m *MockDoguConfigEntryRepository) Delete(_a0 context.Context, _a1 common.DoguConfigKey) error { - ret := _m.Called(_a0, _a1) - - if len(ret) == 0 { - panic("no return value specified for Delete") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, common.DoguConfigKey) error); ok { - r0 = rf(_a0, _a1) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// MockDoguConfigEntryRepository_Delete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Delete' -type MockDoguConfigEntryRepository_Delete_Call struct { - *mock.Call -} - -// Delete is a helper method to define mock.On call -// - _a0 context.Context -// - _a1 common.DoguConfigKey -func (_e *MockDoguConfigEntryRepository_Expecter) Delete(_a0 interface{}, _a1 interface{}) *MockDoguConfigEntryRepository_Delete_Call { - return &MockDoguConfigEntryRepository_Delete_Call{Call: _e.mock.On("Delete", _a0, _a1)} -} - -func (_c *MockDoguConfigEntryRepository_Delete_Call) Run(run func(_a0 context.Context, _a1 common.DoguConfigKey)) *MockDoguConfigEntryRepository_Delete_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(common.DoguConfigKey)) - }) - return _c -} - -func (_c *MockDoguConfigEntryRepository_Delete_Call) Return(_a0 error) *MockDoguConfigEntryRepository_Delete_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *MockDoguConfigEntryRepository_Delete_Call) RunAndReturn(run func(context.Context, common.DoguConfigKey) error) *MockDoguConfigEntryRepository_Delete_Call { - _c.Call.Return(run) - return _c -} - -// DeleteAllByKeys provides a mock function with given fields: _a0, _a1 -func (_m *MockDoguConfigEntryRepository) DeleteAllByKeys(_a0 context.Context, _a1 []common.DoguConfigKey) error { - ret := _m.Called(_a0, _a1) - - if len(ret) == 0 { - panic("no return value specified for DeleteAllByKeys") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, []common.DoguConfigKey) error); ok { - r0 = rf(_a0, _a1) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// MockDoguConfigEntryRepository_DeleteAllByKeys_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteAllByKeys' -type MockDoguConfigEntryRepository_DeleteAllByKeys_Call struct { - *mock.Call -} - -// DeleteAllByKeys is a helper method to define mock.On call -// - _a0 context.Context -// - _a1 []common.DoguConfigKey -func (_e *MockDoguConfigEntryRepository_Expecter) DeleteAllByKeys(_a0 interface{}, _a1 interface{}) *MockDoguConfigEntryRepository_DeleteAllByKeys_Call { - return &MockDoguConfigEntryRepository_DeleteAllByKeys_Call{Call: _e.mock.On("DeleteAllByKeys", _a0, _a1)} -} - -func (_c *MockDoguConfigEntryRepository_DeleteAllByKeys_Call) Run(run func(_a0 context.Context, _a1 []common.DoguConfigKey)) *MockDoguConfigEntryRepository_DeleteAllByKeys_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].([]common.DoguConfigKey)) - }) - return _c -} - -func (_c *MockDoguConfigEntryRepository_DeleteAllByKeys_Call) Return(_a0 error) *MockDoguConfigEntryRepository_DeleteAllByKeys_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *MockDoguConfigEntryRepository_DeleteAllByKeys_Call) RunAndReturn(run func(context.Context, []common.DoguConfigKey) error) *MockDoguConfigEntryRepository_DeleteAllByKeys_Call { - _c.Call.Return(run) - return _c -} - -// Get provides a mock function with given fields: _a0, _a1 -func (_m *MockDoguConfigEntryRepository) Get(_a0 context.Context, _a1 common.DoguConfigKey) (*ecosystem.DoguConfigEntry, error) { - ret := _m.Called(_a0, _a1) - - if len(ret) == 0 { - panic("no return value specified for Get") - } - - var r0 *ecosystem.DoguConfigEntry - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, common.DoguConfigKey) (*ecosystem.DoguConfigEntry, error)); ok { - return rf(_a0, _a1) - } - if rf, ok := ret.Get(0).(func(context.Context, common.DoguConfigKey) *ecosystem.DoguConfigEntry); ok { - r0 = rf(_a0, _a1) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*ecosystem.DoguConfigEntry) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, common.DoguConfigKey) error); ok { - r1 = rf(_a0, _a1) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// MockDoguConfigEntryRepository_Get_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Get' -type MockDoguConfigEntryRepository_Get_Call struct { - *mock.Call -} - -// Get is a helper method to define mock.On call -// - _a0 context.Context -// - _a1 common.DoguConfigKey -func (_e *MockDoguConfigEntryRepository_Expecter) Get(_a0 interface{}, _a1 interface{}) *MockDoguConfigEntryRepository_Get_Call { - return &MockDoguConfigEntryRepository_Get_Call{Call: _e.mock.On("Get", _a0, _a1)} -} - -func (_c *MockDoguConfigEntryRepository_Get_Call) Run(run func(_a0 context.Context, _a1 common.DoguConfigKey)) *MockDoguConfigEntryRepository_Get_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(common.DoguConfigKey)) - }) - return _c -} - -func (_c *MockDoguConfigEntryRepository_Get_Call) Return(_a0 *ecosystem.DoguConfigEntry, _a1 error) *MockDoguConfigEntryRepository_Get_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *MockDoguConfigEntryRepository_Get_Call) RunAndReturn(run func(context.Context, common.DoguConfigKey) (*ecosystem.DoguConfigEntry, error)) *MockDoguConfigEntryRepository_Get_Call { - _c.Call.Return(run) - return _c -} - -// GetAllByKey provides a mock function with given fields: _a0, _a1 -func (_m *MockDoguConfigEntryRepository) GetAllByKey(_a0 context.Context, _a1 []common.DoguConfigKey) (map[common.DoguConfigKey]*ecosystem.DoguConfigEntry, error) { - ret := _m.Called(_a0, _a1) - - if len(ret) == 0 { - panic("no return value specified for GetAllByKey") - } - - var r0 map[common.DoguConfigKey]*ecosystem.DoguConfigEntry - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, []common.DoguConfigKey) (map[common.DoguConfigKey]*ecosystem.DoguConfigEntry, error)); ok { - return rf(_a0, _a1) - } - if rf, ok := ret.Get(0).(func(context.Context, []common.DoguConfigKey) map[common.DoguConfigKey]*ecosystem.DoguConfigEntry); ok { - r0 = rf(_a0, _a1) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(map[common.DoguConfigKey]*ecosystem.DoguConfigEntry) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, []common.DoguConfigKey) error); ok { - r1 = rf(_a0, _a1) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// MockDoguConfigEntryRepository_GetAllByKey_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetAllByKey' -type MockDoguConfigEntryRepository_GetAllByKey_Call struct { - *mock.Call -} - -// GetAllByKey is a helper method to define mock.On call -// - _a0 context.Context -// - _a1 []common.DoguConfigKey -func (_e *MockDoguConfigEntryRepository_Expecter) GetAllByKey(_a0 interface{}, _a1 interface{}) *MockDoguConfigEntryRepository_GetAllByKey_Call { - return &MockDoguConfigEntryRepository_GetAllByKey_Call{Call: _e.mock.On("GetAllByKey", _a0, _a1)} -} - -func (_c *MockDoguConfigEntryRepository_GetAllByKey_Call) Run(run func(_a0 context.Context, _a1 []common.DoguConfigKey)) *MockDoguConfigEntryRepository_GetAllByKey_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].([]common.DoguConfigKey)) - }) - return _c -} - -func (_c *MockDoguConfigEntryRepository_GetAllByKey_Call) Return(_a0 map[common.DoguConfigKey]*ecosystem.DoguConfigEntry, _a1 error) *MockDoguConfigEntryRepository_GetAllByKey_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *MockDoguConfigEntryRepository_GetAllByKey_Call) RunAndReturn(run func(context.Context, []common.DoguConfigKey) (map[common.DoguConfigKey]*ecosystem.DoguConfigEntry, error)) *MockDoguConfigEntryRepository_GetAllByKey_Call { - _c.Call.Return(run) - return _c -} - -// Save provides a mock function with given fields: _a0, _a1 -func (_m *MockDoguConfigEntryRepository) Save(_a0 context.Context, _a1 *ecosystem.DoguConfigEntry) error { - ret := _m.Called(_a0, _a1) - - if len(ret) == 0 { - panic("no return value specified for Save") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, *ecosystem.DoguConfigEntry) error); ok { - r0 = rf(_a0, _a1) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// MockDoguConfigEntryRepository_Save_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Save' -type MockDoguConfigEntryRepository_Save_Call struct { - *mock.Call -} - -// Save is a helper method to define mock.On call -// - _a0 context.Context -// - _a1 *ecosystem.DoguConfigEntry -func (_e *MockDoguConfigEntryRepository_Expecter) Save(_a0 interface{}, _a1 interface{}) *MockDoguConfigEntryRepository_Save_Call { - return &MockDoguConfigEntryRepository_Save_Call{Call: _e.mock.On("Save", _a0, _a1)} -} - -func (_c *MockDoguConfigEntryRepository_Save_Call) Run(run func(_a0 context.Context, _a1 *ecosystem.DoguConfigEntry)) *MockDoguConfigEntryRepository_Save_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(*ecosystem.DoguConfigEntry)) - }) - return _c -} - -func (_c *MockDoguConfigEntryRepository_Save_Call) Return(_a0 error) *MockDoguConfigEntryRepository_Save_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *MockDoguConfigEntryRepository_Save_Call) RunAndReturn(run func(context.Context, *ecosystem.DoguConfigEntry) error) *MockDoguConfigEntryRepository_Save_Call { - _c.Call.Return(run) - return _c -} - -// SaveAll provides a mock function with given fields: _a0, _a1 -func (_m *MockDoguConfigEntryRepository) SaveAll(_a0 context.Context, _a1 []*ecosystem.DoguConfigEntry) error { - ret := _m.Called(_a0, _a1) - - if len(ret) == 0 { - panic("no return value specified for SaveAll") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, []*ecosystem.DoguConfigEntry) error); ok { - r0 = rf(_a0, _a1) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// MockDoguConfigEntryRepository_SaveAll_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SaveAll' -type MockDoguConfigEntryRepository_SaveAll_Call struct { - *mock.Call -} - -// SaveAll is a helper method to define mock.On call -// - _a0 context.Context -// - _a1 []*ecosystem.DoguConfigEntry -func (_e *MockDoguConfigEntryRepository_Expecter) SaveAll(_a0 interface{}, _a1 interface{}) *MockDoguConfigEntryRepository_SaveAll_Call { - return &MockDoguConfigEntryRepository_SaveAll_Call{Call: _e.mock.On("SaveAll", _a0, _a1)} -} - -func (_c *MockDoguConfigEntryRepository_SaveAll_Call) Run(run func(_a0 context.Context, _a1 []*ecosystem.DoguConfigEntry)) *MockDoguConfigEntryRepository_SaveAll_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].([]*ecosystem.DoguConfigEntry)) - }) - return _c -} - -func (_c *MockDoguConfigEntryRepository_SaveAll_Call) Return(_a0 error) *MockDoguConfigEntryRepository_SaveAll_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *MockDoguConfigEntryRepository_SaveAll_Call) RunAndReturn(run func(context.Context, []*ecosystem.DoguConfigEntry) error) *MockDoguConfigEntryRepository_SaveAll_Call { - _c.Call.Return(run) - return _c -} - -// NewMockDoguConfigEntryRepository creates a new instance of MockDoguConfigEntryRepository. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func NewMockDoguConfigEntryRepository(t interface { - mock.TestingT - Cleanup(func()) -}) *MockDoguConfigEntryRepository { - mock := &MockDoguConfigEntryRepository{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/pkg/domainservice/mock_DoguRestartAdapter_test.go b/pkg/domainservice/mock_DoguRestartAdapter_test.go deleted file mode 100644 index 3117f344..00000000 --- a/pkg/domainservice/mock_DoguRestartAdapter_test.go +++ /dev/null @@ -1,82 +0,0 @@ -// Code generated by mockery v2.20.0. DO NOT EDIT. - -package domainservice - -import ( - context "context" - - common "github.com/cloudogu/k8s-blueprint-operator/pkg/domain/common" - - mock "github.com/stretchr/testify/mock" -) - -// MockDoguRestartAdapter is an autogenerated mock type for the DoguRestartRepository type -type MockDoguRestartAdapter struct { - mock.Mock -} - -type MockDoguRestartAdapter_Expecter struct { - mock *mock.Mock -} - -func (_m *MockDoguRestartAdapter) EXPECT() *MockDoguRestartAdapter_Expecter { - return &MockDoguRestartAdapter_Expecter{mock: &_m.Mock} -} - -// RestartAll provides a mock function with given fields: _a0, _a1 -func (_m *MockDoguRestartAdapter) RestartAll(_a0 context.Context, _a1 []common.SimpleDoguName) error { - ret := _m.Called(_a0, _a1) - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, []common.SimpleDoguName) error); ok { - r0 = rf(_a0, _a1) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// MockDoguRestartAdapter_RestartAll_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RestartAll' -type MockDoguRestartAdapter_RestartAll_Call struct { - *mock.Call -} - -// RestartAll is a helper method to define mock.On call -// - _a0 context.Context -// - _a1 []common.SimpleDoguName -func (_e *MockDoguRestartAdapter_Expecter) RestartAll(_a0 interface{}, _a1 interface{}) *MockDoguRestartAdapter_RestartAll_Call { - return &MockDoguRestartAdapter_RestartAll_Call{Call: _e.mock.On("RestartAll", _a0, _a1)} -} - -func (_c *MockDoguRestartAdapter_RestartAll_Call) Run(run func(_a0 context.Context, _a1 []common.SimpleDoguName)) *MockDoguRestartAdapter_RestartAll_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].([]common.SimpleDoguName)) - }) - return _c -} - -func (_c *MockDoguRestartAdapter_RestartAll_Call) Return(_a0 error) *MockDoguRestartAdapter_RestartAll_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *MockDoguRestartAdapter_RestartAll_Call) RunAndReturn(run func(context.Context, []common.SimpleDoguName) error) *MockDoguRestartAdapter_RestartAll_Call { - _c.Call.Return(run) - return _c -} - -type mockConstructorTestingTNewMockDoguRestartAdapter interface { - mock.TestingT - Cleanup(func()) -} - -// NewMockDoguRestartAdapter creates a new instance of MockDoguRestartAdapter. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewMockDoguRestartAdapter(t mockConstructorTestingTNewMockDoguRestartAdapter) *MockDoguRestartAdapter { - mock := &MockDoguRestartAdapter{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/pkg/domainservice/mock_SensitiveDoguConfigEntryRepository_test.go b/pkg/domainservice/mock_SensitiveDoguConfigEntryRepository_test.go deleted file mode 100644 index df19647d..00000000 --- a/pkg/domainservice/mock_SensitiveDoguConfigEntryRepository_test.go +++ /dev/null @@ -1,346 +0,0 @@ -// Code generated by mockery v2.42.1. DO NOT EDIT. - -package domainservice - -import ( - context "context" - - common "github.com/cloudogu/k8s-blueprint-operator/pkg/domain/common" - - ecosystem "github.com/cloudogu/k8s-blueprint-operator/pkg/domain/ecosystem" - - mock "github.com/stretchr/testify/mock" -) - -// MockSensitiveDoguConfigEntryRepository is an autogenerated mock type for the SensitiveDoguConfigEntryRepository type -type MockSensitiveDoguConfigEntryRepository struct { - mock.Mock -} - -type MockSensitiveDoguConfigEntryRepository_Expecter struct { - mock *mock.Mock -} - -func (_m *MockSensitiveDoguConfigEntryRepository) EXPECT() *MockSensitiveDoguConfigEntryRepository_Expecter { - return &MockSensitiveDoguConfigEntryRepository_Expecter{mock: &_m.Mock} -} - -// Delete provides a mock function with given fields: _a0, _a1 -func (_m *MockSensitiveDoguConfigEntryRepository) Delete(_a0 context.Context, _a1 common.SensitiveDoguConfigKey) error { - ret := _m.Called(_a0, _a1) - - if len(ret) == 0 { - panic("no return value specified for Delete") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, common.SensitiveDoguConfigKey) error); ok { - r0 = rf(_a0, _a1) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// MockSensitiveDoguConfigEntryRepository_Delete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Delete' -type MockSensitiveDoguConfigEntryRepository_Delete_Call struct { - *mock.Call -} - -// Delete is a helper method to define mock.On call -// - _a0 context.Context -// - _a1 common.SensitiveDoguConfigKey -func (_e *MockSensitiveDoguConfigEntryRepository_Expecter) Delete(_a0 interface{}, _a1 interface{}) *MockSensitiveDoguConfigEntryRepository_Delete_Call { - return &MockSensitiveDoguConfigEntryRepository_Delete_Call{Call: _e.mock.On("Delete", _a0, _a1)} -} - -func (_c *MockSensitiveDoguConfigEntryRepository_Delete_Call) Run(run func(_a0 context.Context, _a1 common.SensitiveDoguConfigKey)) *MockSensitiveDoguConfigEntryRepository_Delete_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(common.SensitiveDoguConfigKey)) - }) - return _c -} - -func (_c *MockSensitiveDoguConfigEntryRepository_Delete_Call) Return(_a0 error) *MockSensitiveDoguConfigEntryRepository_Delete_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *MockSensitiveDoguConfigEntryRepository_Delete_Call) RunAndReturn(run func(context.Context, common.SensitiveDoguConfigKey) error) *MockSensitiveDoguConfigEntryRepository_Delete_Call { - _c.Call.Return(run) - return _c -} - -// DeleteAllByKeys provides a mock function with given fields: _a0, _a1 -func (_m *MockSensitiveDoguConfigEntryRepository) DeleteAllByKeys(_a0 context.Context, _a1 []common.SensitiveDoguConfigKey) error { - ret := _m.Called(_a0, _a1) - - if len(ret) == 0 { - panic("no return value specified for DeleteAllByKeys") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, []common.SensitiveDoguConfigKey) error); ok { - r0 = rf(_a0, _a1) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// MockSensitiveDoguConfigEntryRepository_DeleteAllByKeys_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteAllByKeys' -type MockSensitiveDoguConfigEntryRepository_DeleteAllByKeys_Call struct { - *mock.Call -} - -// DeleteAllByKeys is a helper method to define mock.On call -// - _a0 context.Context -// - _a1 []common.SensitiveDoguConfigKey -func (_e *MockSensitiveDoguConfigEntryRepository_Expecter) DeleteAllByKeys(_a0 interface{}, _a1 interface{}) *MockSensitiveDoguConfigEntryRepository_DeleteAllByKeys_Call { - return &MockSensitiveDoguConfigEntryRepository_DeleteAllByKeys_Call{Call: _e.mock.On("DeleteAllByKeys", _a0, _a1)} -} - -func (_c *MockSensitiveDoguConfigEntryRepository_DeleteAllByKeys_Call) Run(run func(_a0 context.Context, _a1 []common.SensitiveDoguConfigKey)) *MockSensitiveDoguConfigEntryRepository_DeleteAllByKeys_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].([]common.SensitiveDoguConfigKey)) - }) - return _c -} - -func (_c *MockSensitiveDoguConfigEntryRepository_DeleteAllByKeys_Call) Return(_a0 error) *MockSensitiveDoguConfigEntryRepository_DeleteAllByKeys_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *MockSensitiveDoguConfigEntryRepository_DeleteAllByKeys_Call) RunAndReturn(run func(context.Context, []common.SensitiveDoguConfigKey) error) *MockSensitiveDoguConfigEntryRepository_DeleteAllByKeys_Call { - _c.Call.Return(run) - return _c -} - -// Get provides a mock function with given fields: _a0, _a1 -func (_m *MockSensitiveDoguConfigEntryRepository) Get(_a0 context.Context, _a1 common.SensitiveDoguConfigKey) (*ecosystem.SensitiveDoguConfigEntry, error) { - ret := _m.Called(_a0, _a1) - - if len(ret) == 0 { - panic("no return value specified for Get") - } - - var r0 *ecosystem.SensitiveDoguConfigEntry - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, common.SensitiveDoguConfigKey) (*ecosystem.SensitiveDoguConfigEntry, error)); ok { - return rf(_a0, _a1) - } - if rf, ok := ret.Get(0).(func(context.Context, common.SensitiveDoguConfigKey) *ecosystem.SensitiveDoguConfigEntry); ok { - r0 = rf(_a0, _a1) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*ecosystem.SensitiveDoguConfigEntry) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, common.SensitiveDoguConfigKey) error); ok { - r1 = rf(_a0, _a1) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// MockSensitiveDoguConfigEntryRepository_Get_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Get' -type MockSensitiveDoguConfigEntryRepository_Get_Call struct { - *mock.Call -} - -// Get is a helper method to define mock.On call -// - _a0 context.Context -// - _a1 common.SensitiveDoguConfigKey -func (_e *MockSensitiveDoguConfigEntryRepository_Expecter) Get(_a0 interface{}, _a1 interface{}) *MockSensitiveDoguConfigEntryRepository_Get_Call { - return &MockSensitiveDoguConfigEntryRepository_Get_Call{Call: _e.mock.On("Get", _a0, _a1)} -} - -func (_c *MockSensitiveDoguConfigEntryRepository_Get_Call) Run(run func(_a0 context.Context, _a1 common.SensitiveDoguConfigKey)) *MockSensitiveDoguConfigEntryRepository_Get_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(common.SensitiveDoguConfigKey)) - }) - return _c -} - -func (_c *MockSensitiveDoguConfigEntryRepository_Get_Call) Return(_a0 *ecosystem.SensitiveDoguConfigEntry, _a1 error) *MockSensitiveDoguConfigEntryRepository_Get_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *MockSensitiveDoguConfigEntryRepository_Get_Call) RunAndReturn(run func(context.Context, common.SensitiveDoguConfigKey) (*ecosystem.SensitiveDoguConfigEntry, error)) *MockSensitiveDoguConfigEntryRepository_Get_Call { - _c.Call.Return(run) - return _c -} - -// GetAllByKey provides a mock function with given fields: _a0, _a1 -func (_m *MockSensitiveDoguConfigEntryRepository) GetAllByKey(_a0 context.Context, _a1 []common.SensitiveDoguConfigKey) (map[common.SensitiveDoguConfigKey]*ecosystem.SensitiveDoguConfigEntry, error) { - ret := _m.Called(_a0, _a1) - - if len(ret) == 0 { - panic("no return value specified for GetAllByKey") - } - - var r0 map[common.SensitiveDoguConfigKey]*ecosystem.SensitiveDoguConfigEntry - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, []common.SensitiveDoguConfigKey) (map[common.SensitiveDoguConfigKey]*ecosystem.SensitiveDoguConfigEntry, error)); ok { - return rf(_a0, _a1) - } - if rf, ok := ret.Get(0).(func(context.Context, []common.SensitiveDoguConfigKey) map[common.SensitiveDoguConfigKey]*ecosystem.SensitiveDoguConfigEntry); ok { - r0 = rf(_a0, _a1) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(map[common.SensitiveDoguConfigKey]*ecosystem.SensitiveDoguConfigEntry) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, []common.SensitiveDoguConfigKey) error); ok { - r1 = rf(_a0, _a1) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// MockSensitiveDoguConfigEntryRepository_GetAllByKey_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetAllByKey' -type MockSensitiveDoguConfigEntryRepository_GetAllByKey_Call struct { - *mock.Call -} - -// GetAllByKey is a helper method to define mock.On call -// - _a0 context.Context -// - _a1 []common.SensitiveDoguConfigKey -func (_e *MockSensitiveDoguConfigEntryRepository_Expecter) GetAllByKey(_a0 interface{}, _a1 interface{}) *MockSensitiveDoguConfigEntryRepository_GetAllByKey_Call { - return &MockSensitiveDoguConfigEntryRepository_GetAllByKey_Call{Call: _e.mock.On("GetAllByKey", _a0, _a1)} -} - -func (_c *MockSensitiveDoguConfigEntryRepository_GetAllByKey_Call) Run(run func(_a0 context.Context, _a1 []common.SensitiveDoguConfigKey)) *MockSensitiveDoguConfigEntryRepository_GetAllByKey_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].([]common.SensitiveDoguConfigKey)) - }) - return _c -} - -func (_c *MockSensitiveDoguConfigEntryRepository_GetAllByKey_Call) Return(_a0 map[common.SensitiveDoguConfigKey]*ecosystem.SensitiveDoguConfigEntry, _a1 error) *MockSensitiveDoguConfigEntryRepository_GetAllByKey_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *MockSensitiveDoguConfigEntryRepository_GetAllByKey_Call) RunAndReturn(run func(context.Context, []common.SensitiveDoguConfigKey) (map[common.SensitiveDoguConfigKey]*ecosystem.SensitiveDoguConfigEntry, error)) *MockSensitiveDoguConfigEntryRepository_GetAllByKey_Call { - _c.Call.Return(run) - return _c -} - -// Save provides a mock function with given fields: _a0, _a1 -func (_m *MockSensitiveDoguConfigEntryRepository) Save(_a0 context.Context, _a1 *ecosystem.SensitiveDoguConfigEntry) error { - ret := _m.Called(_a0, _a1) - - if len(ret) == 0 { - panic("no return value specified for Save") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, *ecosystem.SensitiveDoguConfigEntry) error); ok { - r0 = rf(_a0, _a1) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// MockSensitiveDoguConfigEntryRepository_Save_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Save' -type MockSensitiveDoguConfigEntryRepository_Save_Call struct { - *mock.Call -} - -// Save is a helper method to define mock.On call -// - _a0 context.Context -// - _a1 *ecosystem.SensitiveDoguConfigEntry -func (_e *MockSensitiveDoguConfigEntryRepository_Expecter) Save(_a0 interface{}, _a1 interface{}) *MockSensitiveDoguConfigEntryRepository_Save_Call { - return &MockSensitiveDoguConfigEntryRepository_Save_Call{Call: _e.mock.On("Save", _a0, _a1)} -} - -func (_c *MockSensitiveDoguConfigEntryRepository_Save_Call) Run(run func(_a0 context.Context, _a1 *ecosystem.SensitiveDoguConfigEntry)) *MockSensitiveDoguConfigEntryRepository_Save_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(*ecosystem.SensitiveDoguConfigEntry)) - }) - return _c -} - -func (_c *MockSensitiveDoguConfigEntryRepository_Save_Call) Return(_a0 error) *MockSensitiveDoguConfigEntryRepository_Save_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *MockSensitiveDoguConfigEntryRepository_Save_Call) RunAndReturn(run func(context.Context, *ecosystem.SensitiveDoguConfigEntry) error) *MockSensitiveDoguConfigEntryRepository_Save_Call { - _c.Call.Return(run) - return _c -} - -// SaveAll provides a mock function with given fields: _a0, _a1 -func (_m *MockSensitiveDoguConfigEntryRepository) SaveAll(_a0 context.Context, _a1 []*ecosystem.SensitiveDoguConfigEntry) error { - ret := _m.Called(_a0, _a1) - - if len(ret) == 0 { - panic("no return value specified for SaveAll") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, []*ecosystem.SensitiveDoguConfigEntry) error); ok { - r0 = rf(_a0, _a1) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// MockSensitiveDoguConfigEntryRepository_SaveAll_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SaveAll' -type MockSensitiveDoguConfigEntryRepository_SaveAll_Call struct { - *mock.Call -} - -// SaveAll is a helper method to define mock.On call -// - _a0 context.Context -// - _a1 []*ecosystem.SensitiveDoguConfigEntry -func (_e *MockSensitiveDoguConfigEntryRepository_Expecter) SaveAll(_a0 interface{}, _a1 interface{}) *MockSensitiveDoguConfigEntryRepository_SaveAll_Call { - return &MockSensitiveDoguConfigEntryRepository_SaveAll_Call{Call: _e.mock.On("SaveAll", _a0, _a1)} -} - -func (_c *MockSensitiveDoguConfigEntryRepository_SaveAll_Call) Run(run func(_a0 context.Context, _a1 []*ecosystem.SensitiveDoguConfigEntry)) *MockSensitiveDoguConfigEntryRepository_SaveAll_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].([]*ecosystem.SensitiveDoguConfigEntry)) - }) - return _c -} - -func (_c *MockSensitiveDoguConfigEntryRepository_SaveAll_Call) Return(_a0 error) *MockSensitiveDoguConfigEntryRepository_SaveAll_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *MockSensitiveDoguConfigEntryRepository_SaveAll_Call) RunAndReturn(run func(context.Context, []*ecosystem.SensitiveDoguConfigEntry) error) *MockSensitiveDoguConfigEntryRepository_SaveAll_Call { - _c.Call.Return(run) - return _c -} - -// NewMockSensitiveDoguConfigEntryRepository creates a new instance of MockSensitiveDoguConfigEntryRepository. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func NewMockSensitiveDoguConfigEntryRepository(t interface { - mock.TestingT - Cleanup(func()) -}) *MockSensitiveDoguConfigEntryRepository { - mock := &MockSensitiveDoguConfigEntryRepository{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -}