Skip to content

feat(manifest): Loaded manifest includes all environment and group names #1897

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/monaco/completion/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func loadEnvironmentsFromManifest(manifestPath string) ([]string, cobra.ShellCom
ManifestPath: manifestPath,
})

return maps.Keys(man.Environments), cobra.ShellCompDirectiveDefault
return maps.Keys(man.Environments.SelectedEnvironments), cobra.ShellCompDirectiveDefault
}

func AccountsByManifestFlag(cmd *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/monaco/delete/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func GetDeleteCommand(fs afero.Fs) (deleteCmd *cobra.Command) {
return fmt.Errorf("encountered errors while parsing %s: %w", deleteFile, err)
}

return Delete(cmd.Context(), manifest.Environments, entriesToDelete)
return Delete(cmd.Context(), manifest.Environments.SelectedEnvironments, entriesToDelete)
},
ValidArgsFunction: completion.DeleteCompletion,
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/monaco/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
// Returns:
// - error: If an error occurs during the deletion process, an error is returned, describing the issue.
// If no errors occur, nil is returned.
func Delete(ctx context.Context, environments manifest.Environments, entriesToDelete delete.DeleteEntries) error {
func Delete(ctx context.Context, environments manifest.EnvironmentDefinitionsByName, entriesToDelete delete.DeleteEntries) error {
var envsWithDeleteErrs []string
for _, env := range environments {
ctx := context.WithValue(ctx, log.CtxKeyEnv{}, log.CtxValEnv{Name: env.Name, Group: env.Group})
Expand Down
18 changes: 9 additions & 9 deletions cmd/monaco/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func deployConfigs(ctx context.Context, fs afero.Fs, manifestPath string, enviro
return err
}

ok := verifyEnvironmentGen(ctx, loadedManifest.Environments, dryRun)
ok := verifyEnvironmentGen(ctx, loadedManifest.Environments.SelectedEnvironments, dryRun)
if !ok {
return fmt.Errorf("unable to verify Dynatrace environment generation")
}
Expand All @@ -61,21 +61,21 @@ func deployConfigs(ctx context.Context, fs afero.Fs, manifestPath string, enviro
return err
}

if err := validateProjectsWithEnvironments(ctx, loadedProjects, loadedManifest.Environments); err != nil {
if err := validateProjectsWithEnvironments(ctx, loadedProjects, loadedManifest.Environments.SelectedEnvironments); err != nil {
return err
}

logging.LogProjectsInfo(loadedProjects)
logging.LogEnvironmentsInfo(loadedManifest.Environments)
logging.LogEnvironmentsInfo(loadedManifest.Environments.SelectedEnvironments)

err = validateAuthenticationWithProjectConfigs(loadedProjects, loadedManifest.Environments)
err = validateAuthenticationWithProjectConfigs(loadedProjects, loadedManifest.Environments.SelectedEnvironments)
if err != nil {
formattedErr := fmt.Errorf("manifest auth field misconfigured: %w", err)
report.GetReporterFromContextOrDiscard(ctx).ReportLoading(report.StateError, formattedErr, "", nil)
return formattedErr
}

clientSets, err := dynatrace.CreateEnvironmentClients(ctx, loadedManifest.Environments, dryRun)
clientSets, err := dynatrace.CreateEnvironmentClients(ctx, loadedManifest.Environments.SelectedEnvironments, dryRun)
if err != nil {
formattedErr := fmt.Errorf("failed to create API clients: %w", err)
report.GetReporterFromContextOrDiscard(ctx).ReportLoading(report.StateError, formattedErr, "", nil)
Expand Down Expand Up @@ -117,7 +117,7 @@ func loadManifest(ctx context.Context, fs afero.Fs, manifestPath string, groups
return &m, nil
}

func verifyEnvironmentGen(ctx context.Context, environments manifest.Environments, dryRun bool) bool {
func verifyEnvironmentGen(ctx context.Context, environments manifest.EnvironmentDefinitionsByName, dryRun bool) bool {
if !dryRun {
return dynatrace.VerifyEnvironmentGeneration(ctx, environments)

Expand Down Expand Up @@ -148,7 +148,7 @@ type KindCoordinates map[string][]coordinate.Coordinate
type KindCoordinatesPerEnvironment map[string]KindCoordinates
type CoordinatesPerEnvironment map[string][]coordinate.Coordinate

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

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

// validateAuthenticationWithProjectConfigs validates each config entry against the manifest if required credentials are set
// it takes into consideration the project, environments and the skip parameter in each config entry
func validateAuthenticationWithProjectConfigs(projects []project.Project, environments manifest.Environments) error {
func validateAuthenticationWithProjectConfigs(projects []project.Project, environments manifest.EnvironmentDefinitionsByName) error {
for _, p := range projects {
for envName, env := range p.Configs {
for _, file := range env {
Expand Down
42 changes: 21 additions & 21 deletions cmd/monaco/deploy/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func Test_checkEnvironments(t *testing.T) {
},
},
},
manifest.Environments{
manifest.EnvironmentDefinitionsByName{
env1Id: env1Definition,
})
assert.NoError(t, err)
Expand All @@ -174,7 +174,7 @@ func Test_checkEnvironments(t *testing.T) {
},
},
},
manifest.Environments{
manifest.EnvironmentDefinitionsByName{
env1Id: env1Definition,
})
assert.ErrorContains(t, err, "undefined environment")
Expand All @@ -193,7 +193,7 @@ func Test_checkEnvironments(t *testing.T) {
},
},
},
manifest.Environments{
manifest.EnvironmentDefinitionsByName{
env1Id: env1Definition,
})
assert.NoError(t, err)
Expand All @@ -212,7 +212,7 @@ func Test_checkEnvironments(t *testing.T) {
},
},
},
manifest.Environments{
manifest.EnvironmentDefinitionsByName{
env1Id: env1DefinitionWithoutPlatform,
})
assert.ErrorContains(t, err, "environment \"env1\" is not configured to access platform")
Expand All @@ -234,7 +234,7 @@ func Test_checkEnvironments(t *testing.T) {
},
},
},
manifest.Environments{env1Id: env1Definition})
manifest.EnvironmentDefinitionsByName{env1Id: env1Definition})
assert.NoError(t, err)
})

Expand Down Expand Up @@ -263,7 +263,7 @@ func Test_checkEnvironments(t *testing.T) {
},
},
},
manifest.Environments{env1Id: env1Definition})
manifest.EnvironmentDefinitionsByName{env1Id: env1Definition})
assert.NoError(t, err)
})

Expand All @@ -287,7 +287,7 @@ func Test_checkEnvironments(t *testing.T) {
},
},
},
manifest.Environments{
manifest.EnvironmentDefinitionsByName{
env1Id: env1Definition,
env2Id: env2Definition,
})
Expand Down Expand Up @@ -319,7 +319,7 @@ func Test_checkEnvironments(t *testing.T) {
},
},
},
manifest.Environments{
manifest.EnvironmentDefinitionsByName{
env1Id: env1Definition,
env2Id: env2Definition,
})
Expand All @@ -342,7 +342,7 @@ func Test_checkEnvironments(t *testing.T) {
},
},
},
manifest.Environments{
manifest.EnvironmentDefinitionsByName{
env1Id: env1Definition,
env2Id: env2Definition,
})
Expand Down Expand Up @@ -374,7 +374,7 @@ func Test_checkEnvironments(t *testing.T) {
},
},
},
manifest.Environments{
manifest.EnvironmentDefinitionsByName{
env1Id: env1Definition,
})
assert.ErrorContains(t, err, "has multiple openpipeline configurations of kind")
Expand Down Expand Up @@ -422,13 +422,13 @@ func Test_ValidateAuthenticationWithProjectConfigs(t *testing.T) {

success_tests := []struct {
name string
environments manifest.Environments
environments manifest.EnvironmentDefinitionsByName
configs project.ConfigsPerType
expectedErrorMessage string
}{
{
"oAuth manifest with document api",
manifest.Environments{
manifest.EnvironmentDefinitionsByName{
envId: manifest.EnvironmentDefinition{
Name: envId,
Auth: manifest.Auth{
Expand All @@ -440,7 +440,7 @@ func Test_ValidateAuthenticationWithProjectConfigs(t *testing.T) {
},
{
"token manifest with classic api",
manifest.Environments{
manifest.EnvironmentDefinitionsByName{
envId: manifest.EnvironmentDefinition{
Name: envId,
Auth: manifest.Auth{
Expand All @@ -452,7 +452,7 @@ func Test_ValidateAuthenticationWithProjectConfigs(t *testing.T) {
},
{
"token and oAuth manifest with classic and document api",
manifest.Environments{
manifest.EnvironmentDefinitionsByName{
envId: manifest.EnvironmentDefinition{
Name: envId,
Auth: manifest.Auth{
Expand All @@ -468,7 +468,7 @@ func Test_ValidateAuthenticationWithProjectConfigs(t *testing.T) {
},
{
"token manifest with document api expect validation error",
manifest.Environments{
manifest.EnvironmentDefinitionsByName{
envId: manifest.EnvironmentDefinition{
Name: envId,
Auth: manifest.Auth{
Expand All @@ -480,7 +480,7 @@ func Test_ValidateAuthenticationWithProjectConfigs(t *testing.T) {
},
{
"oAuth manifest with document and classic api expect validation error",
manifest.Environments{
manifest.EnvironmentDefinitionsByName{
envId: manifest.EnvironmentDefinition{
Name: envId,
Auth: manifest.Auth{
Expand All @@ -494,7 +494,7 @@ func Test_ValidateAuthenticationWithProjectConfigs(t *testing.T) {
},
{
"oAuth manifest with document and classic api classic api with skip true, expect no error",
manifest.Environments{
manifest.EnvironmentDefinitionsByName{
envId: manifest.EnvironmentDefinition{
Name: envId,
Auth: manifest.Auth{
Expand All @@ -506,7 +506,7 @@ func Test_ValidateAuthenticationWithProjectConfigs(t *testing.T) {
},
{
"token manifest with document and classic api document api with skip true, expect no error",
manifest.Environments{
manifest.EnvironmentDefinitionsByName{
envId: manifest.EnvironmentDefinition{
Name: envId,
Auth: manifest.Auth{
Expand All @@ -520,7 +520,7 @@ func Test_ValidateAuthenticationWithProjectConfigs(t *testing.T) {
},
{
"OAuth manifest with settings api",
manifest.Environments{
manifest.EnvironmentDefinitionsByName{
envId: manifest.EnvironmentDefinition{
Name: envId,
Auth: manifest.Auth{
Expand All @@ -533,7 +533,7 @@ func Test_ValidateAuthenticationWithProjectConfigs(t *testing.T) {
},
{
"OAuth manifest with settings api and permissions",
manifest.Environments{
manifest.EnvironmentDefinitionsByName{
envId: manifest.EnvironmentDefinition{
Name: envId,
Auth: manifest.Auth{
Expand All @@ -546,7 +546,7 @@ func Test_ValidateAuthenticationWithProjectConfigs(t *testing.T) {
},
{
"token manifest with settings api and permissions",
manifest.Environments{
manifest.EnvironmentDefinitionsByName{
envId: manifest.EnvironmentDefinition{
Name: envId,
Auth: manifest.Auth{
Expand Down
2 changes: 1 addition & 1 deletion cmd/monaco/deploy/internal/logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func logConfigInfo(projects []project.Project) {
}
}

func LogEnvironmentsInfo(environments manifest.Environments) {
func LogEnvironmentsInfo(environments manifest.EnvironmentDefinitionsByName) {
log.Info("Environments to deploy to (%d):", len(environments))
for _, name := range environments.Names() {
log.Info(" - %s", name)
Expand Down
4 changes: 2 additions & 2 deletions cmd/monaco/download/download_configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ func (d DefaultCommand) DownloadConfigsBasedOnManifest(ctx context.Context, fs a
return err
}

env, found := m.Environments[cmdOptions.specificEnvironmentName]
env, found := m.Environments.SelectedEnvironments[cmdOptions.specificEnvironmentName]
if !found {
return fmt.Errorf("environment %q was not available in manifest %q", cmdOptions.specificEnvironmentName, cmdOptions.manifestFile)
}

ok := dynatrace.VerifyEnvironmentGeneration(ctx, manifest.Environments{env.Name: env})
ok := dynatrace.VerifyEnvironmentGeneration(ctx, manifest.EnvironmentDefinitionsByName{env.Name: env})
if !ok {
return fmt.Errorf("unable to verify Dynatrace environment generation")
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/monaco/dynatrace/dynatrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import (

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

// CreateEnvironmentClients gives back clients to use for specific environments
func CreateEnvironmentClients(ctx context.Context, environments manifest.Environments, dryRun bool) (EnvironmentClients, error) {
func CreateEnvironmentClients(ctx context.Context, environments manifest.EnvironmentDefinitionsByName, dryRun bool) (EnvironmentClients, error) {
clients := make(EnvironmentClients, len(environments))
for _, env := range environments {
if dryRun {
Expand Down
Loading