Skip to content

Commit 077c111

Browse files
#81 use registry-lib key and value types
Introduce new types so that we can refactor the operator step by step.
1 parent 033f9b7 commit 077c111

File tree

9 files changed

+41
-37
lines changed

9 files changed

+41
-37
lines changed

pkg/adapter/config/etcd/doguConfigRepository.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func NewDoguConfigRepository(etcdStore etcdStore) *DoguConfigRepository {
1717
}
1818

1919
func (e DoguConfigRepository) Get(_ context.Context, key common.DoguConfigKey) (*ecosystem.DoguConfigEntry, error) {
20-
entry, err := e.etcdStore.DoguConfig(string(key.DoguName)).Get(key.Key)
20+
entry, err := e.etcdStore.DoguConfig(string(key.DoguName)).Get(string(key.Key))
2121
if registry.IsKeyNotFoundError(err) {
2222
return nil, domainservice.NewNotFoundError(err, "could not find %s in etcd", key)
2323
} else if err != nil {
@@ -33,7 +33,7 @@ func (e DoguConfigRepository) Get(_ context.Context, key common.DoguConfigKey) (
3333
func (e DoguConfigRepository) Save(_ context.Context, entry *ecosystem.DoguConfigEntry) error {
3434
strDoguName := string(entry.Key.DoguName)
3535
strValue := string(entry.Value)
36-
err := setEtcdKey(entry.Key.Key, strValue, e.etcdStore.DoguConfig(strDoguName))
36+
err := setEtcdKey(string(entry.Key.Key), strValue, e.etcdStore.DoguConfig(strDoguName))
3737
if err != nil {
3838
return domainservice.NewInternalError(err, "failed to set %s with value %q in etcd", entry.Key, strValue)
3939
}
@@ -43,7 +43,7 @@ func (e DoguConfigRepository) Save(_ context.Context, entry *ecosystem.DoguConfi
4343

4444
func (e DoguConfigRepository) Delete(_ context.Context, key common.DoguConfigKey) error {
4545
strDoguName := string(key.DoguName)
46-
err := deleteEtcdKey(key.Key, e.etcdStore.DoguConfig(strDoguName))
46+
err := deleteEtcdKey(string(key.Key), e.etcdStore.DoguConfig(strDoguName))
4747
if err != nil && !registry.IsKeyNotFoundError(err) {
4848
return domainservice.NewInternalError(err, "failed to delete %s from etcd", key)
4949
}

pkg/adapter/config/etcd/doguConfigRepository_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func TestEtcdDoguConfigRepository_Delete(t *testing.T) {
2525

2626
key := common.DoguConfigKey{Key: "key", DoguName: testSimpleDoguNameRedmine}
2727
etcdMock.EXPECT().DoguConfig(string(testSimpleDoguNameRedmine)).Return(configurationContextMock)
28-
configurationContextMock.EXPECT().Delete(key.Key).Return(nil)
28+
configurationContextMock.EXPECT().Delete(string(key.Key)).Return(nil)
2929

3030
// when
3131
err := sut.Delete(testCtx, key)
@@ -42,7 +42,7 @@ func TestEtcdDoguConfigRepository_Delete(t *testing.T) {
4242

4343
key := common.DoguConfigKey{Key: "key", DoguName: testSimpleDoguNameRedmine}
4444
etcdMock.EXPECT().DoguConfig(string(testSimpleDoguNameRedmine)).Return(configurationContextMock)
45-
configurationContextMock.EXPECT().Delete(key.Key).Return(etcdNotFoundError)
45+
configurationContextMock.EXPECT().Delete(string(key.Key)).Return(etcdNotFoundError)
4646

4747
// when
4848
err := sut.Delete(testCtx, key)
@@ -59,7 +59,7 @@ func TestEtcdDoguConfigRepository_Delete(t *testing.T) {
5959

6060
key := common.DoguConfigKey{Key: "key", DoguName: testSimpleDoguNameRedmine}
6161
etcdMock.EXPECT().DoguConfig(string(testSimpleDoguNameRedmine)).Return(configurationContextMock)
62-
configurationContextMock.EXPECT().Delete(key.Key).Return(assert.AnError)
62+
configurationContextMock.EXPECT().Delete(string(key.Key)).Return(assert.AnError)
6363

6464
// when
6565
err := sut.Delete(testCtx, key)
@@ -228,7 +228,7 @@ func TestEtcdDoguConfigRepository_Save(t *testing.T) {
228228
PersistenceContext: nil,
229229
}
230230
etcdMock.EXPECT().DoguConfig(string(testSimpleDoguNameRedmine)).Return(configurationContextMock)
231-
configurationContextMock.EXPECT().Set(entry.Key.Key, string(entry.Value)).Return(nil)
231+
configurationContextMock.EXPECT().Set(string(entry.Key.Key), string(entry.Value)).Return(nil)
232232

233233
// when
234234
err := sut.Save(testCtx, entry)
@@ -249,7 +249,7 @@ func TestEtcdDoguConfigRepository_Save(t *testing.T) {
249249
PersistenceContext: nil,
250250
}
251251
etcdMock.EXPECT().DoguConfig(string(testSimpleDoguNameRedmine)).Return(configurationContextMock)
252-
configurationContextMock.EXPECT().Set(entry.Key.Key, string(entry.Value)).Return(assert.AnError)
252+
configurationContextMock.EXPECT().Set(string(entry.Key.Key), string(entry.Value)).Return(assert.AnError)
253253

254254
// when
255255
err := sut.Save(testCtx, entry)

pkg/adapter/config/etcd/sensitiveDoguConfigRepository.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func NewSensitiveDoguConfigRepository(etcdStore etcdStore) *SensitiveDoguConfigR
1818
}
1919

2020
func (e SensitiveDoguConfigRepository) Get(_ context.Context, key common.SensitiveDoguConfigKey) (*ecosystem.SensitiveDoguConfigEntry, error) {
21-
entry, err := e.etcdStore.DoguConfig(string(key.DoguName)).Get(key.Key)
21+
entry, err := e.etcdStore.DoguConfig(string(key.DoguName)).Get(string(key.Key))
2222
if registry.IsKeyNotFoundError(err) {
2323
return nil, domainservice.NewNotFoundError(err, "could not find sensitive %s in etcd", key)
2424
} else if err != nil {
@@ -34,7 +34,7 @@ func (e SensitiveDoguConfigRepository) Get(_ context.Context, key common.Sensiti
3434
func (e SensitiveDoguConfigRepository) Save(_ context.Context, entry *ecosystem.SensitiveDoguConfigEntry) error {
3535
strDoguName := string(entry.Key.DoguName)
3636
strValue := string(entry.Value)
37-
err := setEtcdKey(entry.Key.Key, strValue, e.etcdStore.DoguConfig(strDoguName))
37+
err := setEtcdKey(string(entry.Key.Key), strValue, e.etcdStore.DoguConfig(strDoguName))
3838
if err != nil {
3939
return domainservice.NewInternalError(err, "failed to set encrypted %s with value %q in etcd", entry.Key, strValue)
4040
}
@@ -44,7 +44,7 @@ func (e SensitiveDoguConfigRepository) Save(_ context.Context, entry *ecosystem.
4444

4545
func (e SensitiveDoguConfigRepository) Delete(_ context.Context, key common.SensitiveDoguConfigKey) error {
4646
strDoguName := string(key.DoguName)
47-
err := deleteEtcdKey(key.Key, e.etcdStore.DoguConfig(strDoguName))
47+
err := deleteEtcdKey(string(key.Key), e.etcdStore.DoguConfig(strDoguName))
4848
if err != nil && !registry.IsKeyNotFoundError(err) {
4949
return domainservice.NewInternalError(err, "failed to delete encrypted %s from etcd", key)
5050
}

pkg/adapter/config/etcd/sensitiveDoguConfigRepository_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func TestEtcdSensitiveDoguConfigRepository_Delete(t *testing.T) {
1616
sut := SensitiveDoguConfigRepository{etcdStore: etcdMock}
1717
key := common.SensitiveDoguConfigKey{DoguConfigKey: common.DoguConfigKey{Key: "key", DoguName: testSimpleDoguNameRedmine}}
1818
etcdMock.EXPECT().DoguConfig(string(testSimpleDoguNameRedmine)).Return(configurationContextMock)
19-
configurationContextMock.EXPECT().Delete(key.Key).Return(nil)
19+
configurationContextMock.EXPECT().Delete(string(key.Key)).Return(nil)
2020

2121
// when
2222
err := sut.Delete(testCtx, key)
@@ -32,7 +32,7 @@ func TestEtcdSensitiveDoguConfigRepository_Delete(t *testing.T) {
3232
sut := SensitiveDoguConfigRepository{etcdStore: etcdMock}
3333
key := common.SensitiveDoguConfigKey{DoguConfigKey: common.DoguConfigKey{Key: "key", DoguName: testSimpleDoguNameRedmine}}
3434
etcdMock.EXPECT().DoguConfig(string(testSimpleDoguNameRedmine)).Return(configurationContextMock)
35-
configurationContextMock.EXPECT().Delete(key.Key).Return(etcdNotFoundError)
35+
configurationContextMock.EXPECT().Delete(string(key.Key)).Return(etcdNotFoundError)
3636

3737
// when
3838
err := sut.Delete(testCtx, key)
@@ -48,7 +48,7 @@ func TestEtcdSensitiveDoguConfigRepository_Delete(t *testing.T) {
4848
sut := SensitiveDoguConfigRepository{etcdStore: etcdMock}
4949
key := common.SensitiveDoguConfigKey{DoguConfigKey: common.DoguConfigKey{Key: "key", DoguName: testSimpleDoguNameRedmine}}
5050
etcdMock.EXPECT().DoguConfig(string(testSimpleDoguNameRedmine)).Return(configurationContextMock)
51-
configurationContextMock.EXPECT().Delete(key.Key).Return(assert.AnError)
51+
configurationContextMock.EXPECT().Delete(string(key.Key)).Return(assert.AnError)
5252

5353
// when
5454
err := sut.Delete(testCtx, key)
@@ -216,7 +216,7 @@ func TestEtcdSensitiveDoguConfigRepository_Save(t *testing.T) {
216216
Value: "value",
217217
}
218218
etcdMock.EXPECT().DoguConfig(string(testSimpleDoguNameRedmine)).Return(configurationContextMock)
219-
configurationContextMock.EXPECT().Set(entry.Key.Key, string(entry.Value)).Return(nil)
219+
configurationContextMock.EXPECT().Set(string(entry.Key.Key), string(entry.Value)).Return(nil)
220220

221221
// when
222222
err := sut.Save(testCtx, entry)
@@ -237,7 +237,7 @@ func TestEtcdSensitiveDoguConfigRepository_Save(t *testing.T) {
237237
PersistenceContext: nil,
238238
}
239239
etcdMock.EXPECT().DoguConfig(string(testSimpleDoguNameRedmine)).Return(configurationContextMock)
240-
configurationContextMock.EXPECT().Set(entry.Key.Key, string(entry.Value)).Return(assert.AnError)
240+
configurationContextMock.EXPECT().Set(string(entry.Key.Key), string(entry.Value)).Return(assert.AnError)
241241

242242
// when
243243
err := sut.Save(testCtx, entry)

pkg/adapter/kubernetes/blueprintcr/v1/config.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package v1
33
import (
44
"github.com/cloudogu/k8s-blueprint-operator/pkg/domain"
55
"github.com/cloudogu/k8s-blueprint-operator/pkg/domain/common"
6+
"github.com/cloudogu/k8s-registry-lib/config"
67
)
78

89
type Config struct {
@@ -82,7 +83,7 @@ func convertToDoguConfigDTO(config domain.DoguConfig) DoguConfig {
8283
if len(config.Present) != 0 {
8384
present = make(map[string]string, len(config.Present))
8485
for key, value := range config.Present {
85-
present[key.Key] = string(value)
86+
present[string(key.Key)] = string(value)
8687
}
8788
}
8889

@@ -92,7 +93,7 @@ func convertToDoguConfigDTO(config domain.DoguConfig) DoguConfig {
9293
if len(config.Absent) != 0 {
9394
absent = make([]string, len(config.Absent))
9495
for i, key := range config.Absent {
95-
absent[i] = key.Key
96+
absent[i] = string(key.Key)
9697
}
9798
}
9899

@@ -132,7 +133,7 @@ func convertToDoguConfigDomain(doguName string, config DoguConfig) domain.DoguCo
132133
func convertToDoguConfigKeyDomain(doguName, key string) common.DoguConfigKey {
133134
return common.DoguConfigKey{
134135
DoguName: common.SimpleDoguName(doguName),
135-
Key: key,
136+
Key: config.Key(key),
136137
}
137138
}
138139

@@ -143,7 +144,7 @@ func convertToSensitiveDoguConfigDTO(config domain.SensitiveDoguConfig) Sensitiv
143144
if len(config.Present) != 0 {
144145
present = make(map[string]string, len(config.Present))
145146
for key, value := range config.Present {
146-
present[key.Key] = string(value)
147+
present[string(key.Key)] = string(value)
147148
}
148149
}
149150

@@ -153,7 +154,7 @@ func convertToSensitiveDoguConfigDTO(config domain.SensitiveDoguConfig) Sensitiv
153154
if len(config.Absent) != 0 {
154155
absent = make([]string, len(config.Absent))
155156
for i, key := range config.Absent {
156-
absent[i] = key.Key
157+
absent[i] = string(key.Key)
157158
}
158159
}
159160

@@ -193,7 +194,7 @@ func convertToSensitiveDoguConfigDomain(doguName string, config SensitiveDoguCon
193194
func convertToSensitiveDoguConfigKeyDomain(doguName, key string) common.SensitiveDoguConfigKey {
194195
return common.SensitiveDoguConfigKey{DoguConfigKey: common.DoguConfigKey{
195196
DoguName: common.SimpleDoguName(doguName),
196-
Key: key,
197+
Key: config.Key(key),
197198
},
198199
}
199200
}

pkg/adapter/kubernetes/blueprintcr/v1/doguConfigDiff.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package v1
33
import (
44
"github.com/cloudogu/k8s-blueprint-operator/pkg/domain"
55
"github.com/cloudogu/k8s-blueprint-operator/pkg/domain/common"
6+
"github.com/cloudogu/k8s-registry-lib/config"
67
)
78

89
type CombinedDoguConfigDiff struct {
@@ -56,7 +57,7 @@ func convertToDoguConfigEntryDiffDomain(doguName string, dto DoguConfigEntryDiff
5657
return domain.DoguConfigEntryDiff{
5758
Key: common.DoguConfigKey{
5859
DoguName: common.SimpleDoguName(doguName),
59-
Key: dto.Key,
60+
Key: config.Key(dto.Key),
6061
},
6162
Actual: domain.DoguConfigValueState{
6263
Value: dto.Actual.Value,
@@ -75,7 +76,7 @@ func convertToSensitiveDoguConfigEntryDiffDomain(doguName string, dto SensitiveD
7576
Key: common.SensitiveDoguConfigKey{
7677
DoguConfigKey: common.DoguConfigKey{
7778
DoguName: common.SimpleDoguName(doguName),
78-
Key: dto.Key,
79+
Key: config.Key(dto.Key),
7980
},
8081
},
8182
Actual: domain.DoguConfigValueState{
@@ -116,7 +117,7 @@ func convertToCombinedDoguConfigDiffDTO(domainModel domain.CombinedDoguConfigDif
116117

117118
func convertToDoguConfigEntryDiffDTO(domainModel domain.DoguConfigEntryDiff) DoguConfigEntryDiff {
118119
return DoguConfigEntryDiff{
119-
Key: domainModel.Key.Key,
120+
Key: string(domainModel.Key.Key),
120121
Actual: DoguConfigValueState{
121122
Value: domainModel.Actual.Value,
122123
Exists: domainModel.Actual.Exists,
@@ -131,7 +132,7 @@ func convertToDoguConfigEntryDiffDTO(domainModel domain.DoguConfigEntryDiff) Dog
131132

132133
func convertToSensitiveDoguConfigEntryDiffDTO(domainModel domain.SensitiveDoguConfigEntryDiff) SensitiveDoguConfigEntryDiff {
133134
return SensitiveDoguConfigEntryDiff{
134-
Key: domainModel.Key.Key,
135+
Key: string(domainModel.Key.Key),
135136
Actual: DoguConfigValueState{
136137
Value: domainModel.Actual.Value,
137138
Exists: domainModel.Actual.Exists,

pkg/application/ecosystemConfigUseCase_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"github.com/cloudogu/k8s-blueprint-operator/pkg/domain"
55
"github.com/cloudogu/k8s-blueprint-operator/pkg/domain/common"
66
"github.com/cloudogu/k8s-blueprint-operator/pkg/domain/ecosystem"
7+
"github.com/cloudogu/k8s-registry-lib/config"
78
"github.com/stretchr/testify/assert"
89
"github.com/stretchr/testify/mock"
910
"github.com/stretchr/testify/require"
@@ -532,7 +533,7 @@ func TestNewEcosystemConfigUseCase(t *testing.T) {
532533
func getSetDoguConfigEntryDiff(key, value string, doguName common.SimpleDoguName) domain.DoguConfigEntryDiff {
533534
return domain.DoguConfigEntryDiff{
534535
Key: common.DoguConfigKey{
535-
Key: key,
536+
Key: config.Key(key),
536537
DoguName: doguName,
537538
},
538539
Expected: domain.DoguConfigValueState{
@@ -545,7 +546,7 @@ func getSetDoguConfigEntryDiff(key, value string, doguName common.SimpleDoguName
545546
func getRemoveDoguConfigEntryDiff(key string, doguName common.SimpleDoguName) domain.DoguConfigEntryDiff {
546547
return domain.DoguConfigEntryDiff{
547548
Key: common.DoguConfigKey{
548-
Key: key,
549+
Key: config.Key(key),
549550
DoguName: doguName,
550551
},
551552
NeededAction: domain.ConfigActionRemove,
@@ -556,7 +557,7 @@ func getSensitiveDoguConfigEntryDiffForAction(key, value string, doguName common
556557
return domain.SensitiveDoguConfigEntryDiff{
557558
Key: common.SensitiveDoguConfigKey{
558559
DoguConfigKey: common.DoguConfigKey{
559-
Key: key,
560+
Key: config.Key(key),
560561
DoguName: doguName,
561562
},
562563
},
@@ -571,7 +572,7 @@ func getRemoveSensitiveDoguConfigEntryDiff(key string, doguName common.SimpleDog
571572
return domain.SensitiveDoguConfigEntryDiff{
572573
Key: common.SensitiveDoguConfigKey{
573574
DoguConfigKey: common.DoguConfigKey{
574-
Key: key,
575+
Key: config.Key(key),
575576
DoguName: doguName,
576577
},
577578
},

pkg/domain/common/configNames.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@ package common
33
import (
44
"errors"
55
"fmt"
6+
"github.com/cloudogu/k8s-registry-lib/config"
67
)
78

89
type RegistryConfigKey interface {
910
GlobalConfigKey | DoguConfigKey | SensitiveDoguConfigKey
1011
}
1112

12-
type GlobalConfigKey string
13+
type GlobalConfigKey = config.Key
1314

1415
type DoguConfigKey struct {
1516
DoguName SimpleDoguName
16-
Key string
17+
Key config.Key
1718
}
1819

1920
func (k DoguConfigKey) Validate() error {
@@ -37,10 +38,10 @@ type SensitiveDoguConfigKey struct {
3738
}
3839

3940
// GlobalConfigValue is a single global config value
40-
type GlobalConfigValue string
41+
type GlobalConfigValue = config.Value
4142

4243
// DoguConfigValue is a single dogu config value, which is no sensitive configuration
43-
type DoguConfigValue string
44+
type DoguConfigValue = config.Value
4445

4546
// SensitiveDoguConfigValue is a single unencrypted sensitive dogu config value
46-
type SensitiveDoguConfigValue string
47+
type SensitiveDoguConfigValue = config.Value

pkg/domain/stateDiffConfig_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ func TestCombinedDoguConfigDiff_CensorValues(t *testing.T) {
450450
require.Len(t, result.DoguConfigDiff, 1)
451451

452452
assert.Equal(t, "ldap", string(result.DoguConfigDiff[0].Key.DoguName))
453-
assert.Equal(t, "logging/root", result.DoguConfigDiff[0].Key.Key)
453+
assert.Equal(t, "logging/root", string(result.DoguConfigDiff[0].Key.Key))
454454
assert.Equal(t, "ERROR", result.DoguConfigDiff[0].Actual.Value)
455455
assert.Equal(t, false, result.DoguConfigDiff[0].Actual.Exists)
456456
assert.Equal(t, "DEBUG", result.DoguConfigDiff[0].Expected.Value)
@@ -486,7 +486,7 @@ func TestCombinedDoguConfigDiff_CensorValues(t *testing.T) {
486486
require.Len(t, result.SensitiveDoguConfigDiff, 1)
487487

488488
assert.Equal(t, "ldap", string(result.SensitiveDoguConfigDiff[0].Key.DoguName))
489-
assert.Equal(t, "logging/root", result.SensitiveDoguConfigDiff[0].Key.Key)
489+
assert.Equal(t, "logging/root", string(result.SensitiveDoguConfigDiff[0].Key.Key))
490490
assert.Equal(t, censorValue, result.SensitiveDoguConfigDiff[0].Actual.Value)
491491
assert.Equal(t, false, result.SensitiveDoguConfigDiff[0].Actual.Exists)
492492
assert.Equal(t, censorValue, result.SensitiveDoguConfigDiff[0].Expected.Value)

0 commit comments

Comments
 (0)