Skip to content

Commit ce86a4a

Browse files
committed
refactor(manifest): Rename Environments to EnvironmentDefinitionsByName
`Environments` is not a great name doesn't add value compared to `map[string]EnvironmentDefinition`, but allows us to define `(e EnvironmentDefinitionsByName) Names()`. In most cases, this method also brings no value, as iterating over the map gives us the names anyway. But it simplifies some tests, as then no actual `EnvironmentDefinition` objects are required. By renaming, we can reuse the name `Environments` in the next commit.
1 parent 696a1a2 commit ce86a4a

File tree

11 files changed

+67
-63
lines changed

11 files changed

+67
-63
lines changed

cmd/monaco/delete/delete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import (
3535
// Returns:
3636
// - error: If an error occurs during the deletion process, an error is returned, describing the issue.
3737
// If no errors occur, nil is returned.
38-
func Delete(ctx context.Context, environments manifest.Environments, entriesToDelete delete.DeleteEntries) error {
38+
func Delete(ctx context.Context, environments manifest.EnvironmentDefinitionsByName, entriesToDelete delete.DeleteEntries) error {
3939
var envsWithDeleteErrs []string
4040
for _, env := range environments {
4141
ctx := context.WithValue(ctx, log.CtxKeyEnv{}, log.CtxValEnv{Name: env.Name, Group: env.Group})

cmd/monaco/deploy/deploy.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func loadManifest(ctx context.Context, fs afero.Fs, manifestPath string, groups
117117
return &m, nil
118118
}
119119

120-
func verifyEnvironmentGen(ctx context.Context, environments manifest.Environments, dryRun bool) bool {
120+
func verifyEnvironmentGen(ctx context.Context, environments manifest.EnvironmentDefinitionsByName, dryRun bool) bool {
121121
if !dryRun {
122122
return dynatrace.VerifyEnvironmentGeneration(ctx, environments)
123123

@@ -148,7 +148,7 @@ type KindCoordinates map[string][]coordinate.Coordinate
148148
type KindCoordinatesPerEnvironment map[string]KindCoordinates
149149
type CoordinatesPerEnvironment map[string][]coordinate.Coordinate
150150

151-
func validateProjectsWithEnvironments(ctx context.Context, projects []project.Project, envs manifest.Environments) error {
151+
func validateProjectsWithEnvironments(ctx context.Context, projects []project.Project, envs manifest.EnvironmentDefinitionsByName) error {
152152
undefinedEnvironments := map[string]struct{}{}
153153
openPipelineKindCoordinatesPerEnvironment := KindCoordinatesPerEnvironment{}
154154
platformCoordinatesPerEnvironment := CoordinatesPerEnvironment{}
@@ -249,7 +249,7 @@ func coordinateSliceAsString(coordinates []coordinate.Coordinate) string {
249249
return strings.Join(coordinateStrings, ", ")
250250
}
251251

252-
func collectRequiresPlatformErrors(platformCoordinatesPerEnvironment CoordinatesPerEnvironment, envs manifest.Environments) []error {
252+
func collectRequiresPlatformErrors(platformCoordinatesPerEnvironment CoordinatesPerEnvironment, envs manifest.EnvironmentDefinitionsByName) []error {
253253
errs := []error{}
254254
for envName, coordinates := range platformCoordinatesPerEnvironment {
255255
env, found := envs[envName]
@@ -271,7 +271,7 @@ func platformEnvironment(e manifest.EnvironmentDefinition) bool {
271271

272272
// validateAuthenticationWithProjectConfigs validates each config entry against the manifest if required credentials are set
273273
// it takes into consideration the project, environments and the skip parameter in each config entry
274-
func validateAuthenticationWithProjectConfigs(projects []project.Project, environments manifest.Environments) error {
274+
func validateAuthenticationWithProjectConfigs(projects []project.Project, environments manifest.EnvironmentDefinitionsByName) error {
275275
for _, p := range projects {
276276
for envName, env := range p.Configs {
277277
for _, file := range env {

cmd/monaco/deploy/deploy_test.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func Test_checkEnvironments(t *testing.T) {
157157
},
158158
},
159159
},
160-
manifest.Environments{
160+
manifest.EnvironmentDefinitionsByName{
161161
env1Id: env1Definition,
162162
})
163163
assert.NoError(t, err)
@@ -174,7 +174,7 @@ func Test_checkEnvironments(t *testing.T) {
174174
},
175175
},
176176
},
177-
manifest.Environments{
177+
manifest.EnvironmentDefinitionsByName{
178178
env1Id: env1Definition,
179179
})
180180
assert.ErrorContains(t, err, "undefined environment")
@@ -193,7 +193,7 @@ func Test_checkEnvironments(t *testing.T) {
193193
},
194194
},
195195
},
196-
manifest.Environments{
196+
manifest.EnvironmentDefinitionsByName{
197197
env1Id: env1Definition,
198198
})
199199
assert.NoError(t, err)
@@ -212,7 +212,7 @@ func Test_checkEnvironments(t *testing.T) {
212212
},
213213
},
214214
},
215-
manifest.Environments{
215+
manifest.EnvironmentDefinitionsByName{
216216
env1Id: env1DefinitionWithoutPlatform,
217217
})
218218
assert.ErrorContains(t, err, "environment \"env1\" is not configured to access platform")
@@ -234,7 +234,7 @@ func Test_checkEnvironments(t *testing.T) {
234234
},
235235
},
236236
},
237-
manifest.Environments{env1Id: env1Definition})
237+
manifest.EnvironmentDefinitionsByName{env1Id: env1Definition})
238238
assert.NoError(t, err)
239239
})
240240

@@ -263,7 +263,7 @@ func Test_checkEnvironments(t *testing.T) {
263263
},
264264
},
265265
},
266-
manifest.Environments{env1Id: env1Definition})
266+
manifest.EnvironmentDefinitionsByName{env1Id: env1Definition})
267267
assert.NoError(t, err)
268268
})
269269

@@ -287,7 +287,7 @@ func Test_checkEnvironments(t *testing.T) {
287287
},
288288
},
289289
},
290-
manifest.Environments{
290+
manifest.EnvironmentDefinitionsByName{
291291
env1Id: env1Definition,
292292
env2Id: env2Definition,
293293
})
@@ -319,7 +319,7 @@ func Test_checkEnvironments(t *testing.T) {
319319
},
320320
},
321321
},
322-
manifest.Environments{
322+
manifest.EnvironmentDefinitionsByName{
323323
env1Id: env1Definition,
324324
env2Id: env2Definition,
325325
})
@@ -342,7 +342,7 @@ func Test_checkEnvironments(t *testing.T) {
342342
},
343343
},
344344
},
345-
manifest.Environments{
345+
manifest.EnvironmentDefinitionsByName{
346346
env1Id: env1Definition,
347347
env2Id: env2Definition,
348348
})
@@ -374,7 +374,7 @@ func Test_checkEnvironments(t *testing.T) {
374374
},
375375
},
376376
},
377-
manifest.Environments{
377+
manifest.EnvironmentDefinitionsByName{
378378
env1Id: env1Definition,
379379
})
380380
assert.ErrorContains(t, err, "has multiple openpipeline configurations of kind")
@@ -422,13 +422,13 @@ func Test_ValidateAuthenticationWithProjectConfigs(t *testing.T) {
422422

423423
success_tests := []struct {
424424
name string
425-
environments manifest.Environments
425+
environments manifest.EnvironmentDefinitionsByName
426426
configs project.ConfigsPerType
427427
expectedErrorMessage string
428428
}{
429429
{
430430
"oAuth manifest with document api",
431-
manifest.Environments{
431+
manifest.EnvironmentDefinitionsByName{
432432
envId: manifest.EnvironmentDefinition{
433433
Name: envId,
434434
Auth: manifest.Auth{
@@ -440,7 +440,7 @@ func Test_ValidateAuthenticationWithProjectConfigs(t *testing.T) {
440440
},
441441
{
442442
"token manifest with classic api",
443-
manifest.Environments{
443+
manifest.EnvironmentDefinitionsByName{
444444
envId: manifest.EnvironmentDefinition{
445445
Name: envId,
446446
Auth: manifest.Auth{
@@ -452,7 +452,7 @@ func Test_ValidateAuthenticationWithProjectConfigs(t *testing.T) {
452452
},
453453
{
454454
"token and oAuth manifest with classic and document api",
455-
manifest.Environments{
455+
manifest.EnvironmentDefinitionsByName{
456456
envId: manifest.EnvironmentDefinition{
457457
Name: envId,
458458
Auth: manifest.Auth{
@@ -468,7 +468,7 @@ func Test_ValidateAuthenticationWithProjectConfigs(t *testing.T) {
468468
},
469469
{
470470
"token manifest with document api expect validation error",
471-
manifest.Environments{
471+
manifest.EnvironmentDefinitionsByName{
472472
envId: manifest.EnvironmentDefinition{
473473
Name: envId,
474474
Auth: manifest.Auth{
@@ -480,7 +480,7 @@ func Test_ValidateAuthenticationWithProjectConfigs(t *testing.T) {
480480
},
481481
{
482482
"oAuth manifest with document and classic api expect validation error",
483-
manifest.Environments{
483+
manifest.EnvironmentDefinitionsByName{
484484
envId: manifest.EnvironmentDefinition{
485485
Name: envId,
486486
Auth: manifest.Auth{
@@ -494,7 +494,7 @@ func Test_ValidateAuthenticationWithProjectConfigs(t *testing.T) {
494494
},
495495
{
496496
"oAuth manifest with document and classic api classic api with skip true, expect no error",
497-
manifest.Environments{
497+
manifest.EnvironmentDefinitionsByName{
498498
envId: manifest.EnvironmentDefinition{
499499
Name: envId,
500500
Auth: manifest.Auth{
@@ -506,7 +506,7 @@ func Test_ValidateAuthenticationWithProjectConfigs(t *testing.T) {
506506
},
507507
{
508508
"token manifest with document and classic api document api with skip true, expect no error",
509-
manifest.Environments{
509+
manifest.EnvironmentDefinitionsByName{
510510
envId: manifest.EnvironmentDefinition{
511511
Name: envId,
512512
Auth: manifest.Auth{
@@ -520,7 +520,7 @@ func Test_ValidateAuthenticationWithProjectConfigs(t *testing.T) {
520520
},
521521
{
522522
"OAuth manifest with settings api",
523-
manifest.Environments{
523+
manifest.EnvironmentDefinitionsByName{
524524
envId: manifest.EnvironmentDefinition{
525525
Name: envId,
526526
Auth: manifest.Auth{
@@ -533,7 +533,7 @@ func Test_ValidateAuthenticationWithProjectConfigs(t *testing.T) {
533533
},
534534
{
535535
"OAuth manifest with settings api and permissions",
536-
manifest.Environments{
536+
manifest.EnvironmentDefinitionsByName{
537537
envId: manifest.EnvironmentDefinition{
538538
Name: envId,
539539
Auth: manifest.Auth{
@@ -546,7 +546,7 @@ func Test_ValidateAuthenticationWithProjectConfigs(t *testing.T) {
546546
},
547547
{
548548
"token manifest with settings api and permissions",
549-
manifest.Environments{
549+
manifest.EnvironmentDefinitionsByName{
550550
envId: manifest.EnvironmentDefinition{
551551
Name: envId,
552552
Auth: manifest.Auth{

cmd/monaco/deploy/internal/logging/logging.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func logConfigInfo(projects []project.Project) {
4848
}
4949
}
5050

51-
func LogEnvironmentsInfo(environments manifest.Environments) {
51+
func LogEnvironmentsInfo(environments manifest.EnvironmentDefinitionsByName) {
5252
log.Info("Environments to deploy to (%d):", len(environments))
5353
for _, name := range environments.Names() {
5454
log.Info(" - %s", name)

cmd/monaco/download/download_configs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func (d DefaultCommand) DownloadConfigsBasedOnManifest(ctx context.Context, fs a
9595
return fmt.Errorf("environment %q was not available in manifest %q", cmdOptions.specificEnvironmentName, cmdOptions.manifestFile)
9696
}
9797

98-
ok := dynatrace.VerifyEnvironmentGeneration(ctx, manifest.Environments{env.Name: env})
98+
ok := dynatrace.VerifyEnvironmentGeneration(ctx, manifest.EnvironmentDefinitionsByName{env.Name: env})
9999
if !ok {
100100
return fmt.Errorf("unable to verify Dynatrace environment generation")
101101
}

cmd/monaco/dynatrace/dynatrace.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import (
4646

4747
// VerifyEnvironmentGeneration takes a manifestEnvironments map and tries to verify that each environment can be reached
4848
// using the configured credentials
49-
func VerifyEnvironmentGeneration(ctx context.Context, envs manifest.Environments) bool {
49+
func VerifyEnvironmentGeneration(ctx context.Context, envs manifest.EnvironmentDefinitionsByName) bool {
5050
if !featureflags.VerifyEnvironmentType.Enabled() {
5151
return true
5252
}
@@ -186,7 +186,7 @@ func (e EnvironmentClients) Names() []string {
186186
}
187187

188188
// CreateEnvironmentClients gives back clients to use for specific environments
189-
func CreateEnvironmentClients(ctx context.Context, environments manifest.Environments, dryRun bool) (EnvironmentClients, error) {
189+
func CreateEnvironmentClients(ctx context.Context, environments manifest.EnvironmentDefinitionsByName, dryRun bool) (EnvironmentClients, error) {
190190
clients := make(EnvironmentClients, len(environments))
191191
for _, env := range environments {
192192
if dryRun {

cmd/monaco/dynatrace/dynatrace_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func TestVerifyEnvironmentGeneration_TurnedOffByFF(t *testing.T) {
5353
}))
5454
defer server.Close()
5555

56-
ok := VerifyEnvironmentGeneration(t.Context(), manifest.Environments{
56+
ok := VerifyEnvironmentGeneration(t.Context(), manifest.EnvironmentDefinitionsByName{
5757
"env": manifest.EnvironmentDefinition{
5858
Name: "env",
5959
URL: manifest.URLDefinition{
@@ -79,7 +79,7 @@ func TestVerifyEnvironmentGeneration_OneOfManyFails(t *testing.T) {
7979
}))
8080
defer server.Close()
8181

82-
ok := VerifyEnvironmentGeneration(t.Context(), manifest.Environments{
82+
ok := VerifyEnvironmentGeneration(t.Context(), manifest.EnvironmentDefinitionsByName{
8383
"env": manifest.EnvironmentDefinition{
8484
Name: "env",
8585
URL: manifest.URLDefinition{
@@ -103,7 +103,7 @@ func TestVerifyEnvironmentGeneration_OneOfManyFails(t *testing.T) {
103103

104104
func TestVerifyEnvironmentGen(t *testing.T) {
105105
type args struct {
106-
envs manifest.Environments
106+
envs manifest.EnvironmentDefinitionsByName
107107
}
108108
tests := []struct {
109109
name string
@@ -115,14 +115,14 @@ func TestVerifyEnvironmentGen(t *testing.T) {
115115
{
116116
name: "empty environment - passes",
117117
args: args{
118-
envs: manifest.Environments{},
118+
envs: manifest.EnvironmentDefinitionsByName{},
119119
},
120120
wantErr: false,
121121
},
122122
{
123123
name: "single environment without fields set - fails",
124124
args: args{
125-
envs: manifest.Environments{},
125+
envs: manifest.EnvironmentDefinitionsByName{},
126126
},
127127
wantErr: false,
128128
},
@@ -142,7 +142,7 @@ func TestVerifyEnvironmentGen(t *testing.T) {
142142
}))
143143
defer server.Close()
144144

145-
ok := VerifyEnvironmentGeneration(t.Context(), manifest.Environments{
145+
ok := VerifyEnvironmentGeneration(t.Context(), manifest.EnvironmentDefinitionsByName{
146146
"env": manifest.EnvironmentDefinition{
147147
Name: "env",
148148
URL: manifest.URLDefinition{
@@ -175,7 +175,7 @@ func TestVerifyEnvironmentGen(t *testing.T) {
175175
}))
176176
defer server.Close()
177177

178-
ok := VerifyEnvironmentGeneration(t.Context(), manifest.Environments{
178+
ok := VerifyEnvironmentGeneration(t.Context(), manifest.EnvironmentDefinitionsByName{
179179
"env": manifest.EnvironmentDefinition{
180180
Name: "env",
181181
URL: manifest.URLDefinition{
@@ -214,7 +214,7 @@ func TestVerifyEnvironmentGen(t *testing.T) {
214214
}))
215215
defer server.Close()
216216

217-
ok := VerifyEnvironmentGeneration(t.Context(), manifest.Environments{
217+
ok := VerifyEnvironmentGeneration(t.Context(), manifest.EnvironmentDefinitionsByName{
218218
"env1": manifest.EnvironmentDefinition{
219219
Name: "env1",
220220
URL: manifest.URLDefinition{
@@ -226,7 +226,7 @@ func TestVerifyEnvironmentGen(t *testing.T) {
226226
})
227227
assert.False(t, ok)
228228

229-
ok = VerifyEnvironmentGeneration(t.Context(), manifest.Environments{
229+
ok = VerifyEnvironmentGeneration(t.Context(), manifest.EnvironmentDefinitionsByName{
230230
"env2": manifest.EnvironmentDefinition{
231231
Name: "env2",
232232
URL: manifest.URLDefinition{

pkg/manifest/manifest.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ type AuthSecret struct {
105105

106106
type ProjectDefinitionByProjectID map[string]ProjectDefinition
107107

108-
// Environments is a map of environment-name -> EnvironmentDefinition
109-
type Environments map[string]EnvironmentDefinition
108+
// EnvironmentDefinitionsByName is a map of environment-name -> EnvironmentDefinition
109+
type EnvironmentDefinitionsByName map[string]EnvironmentDefinition
110110

111111
// Names returns the slice of environment names
112-
func (e Environments) Names() []string {
112+
func (e EnvironmentDefinitionsByName) Names() []string {
113113
return maps.Keys(e)
114114
}
115115

@@ -135,7 +135,7 @@ type Manifest struct {
135135
Projects ProjectDefinitionByProjectID
136136

137137
// Environments defined in the manifest, split by environment-name
138-
Environments Environments
138+
Environments EnvironmentDefinitionsByName
139139

140140
// Accounts holds all accounts defined in the manifest. Key is the user-defined account name.
141141
Accounts map[string]Account

0 commit comments

Comments
 (0)