From 4bfc7a911d7dbdcba24f8d2c9c60c05744a63393 Mon Sep 17 00:00:00 2001 From: Jure Skelin Date: Tue, 10 Dec 2024 17:00:34 +0100 Subject: [PATCH] fix: changes related to PR --- cmd/monaco/download/download_command.go | 2 +- cmd/monaco/download/download_configs.go | 32 ++++++++++---------- cmd/monaco/download/download_configs_test.go | 20 +++++++----- pkg/download/grailfiltersegment/download.go | 1 + 4 files changed, 30 insertions(+), 25 deletions(-) diff --git a/cmd/monaco/download/download_command.go b/cmd/monaco/download/download_command.go index d02eaf7b0..5d3f335a4 100644 --- a/cmd/monaco/download/download_command.go +++ b/cmd/monaco/download/download_command.go @@ -101,7 +101,7 @@ func GetDownloadCommand(fs afero.Fs, command Command) (cmd *cobra.Command) { } if featureflags.Temporary[featureflags.GrailFilterSegment].Enabled() { - cmd.Flags().BoolVar(&f.onlyGrailFilterSegments, "only-filtersegments", false, "Only download Grail filter-segment configurations, skip all other configuration types") + cmd.Flags().BoolVar(&f.onlyGrailFilterSegments, "only-filter-segments", false, "Only download Grail filter-segment configurations, skip all other configuration types") } err := errors.Join( diff --git a/cmd/monaco/download/download_configs.go b/cmd/monaco/download/download_configs.go index 2fc2091cb..35a87e8dc 100644 --- a/cmd/monaco/download/download_configs.go +++ b/cmd/monaco/download/download_configs.go @@ -235,23 +235,23 @@ func doDownloadConfigs(fs afero.Fs, clientSet *client.ClientSet, apisToDownload } type downloadFn struct { - classicDownload func(client.ConfigClient, string, api.APIs, classic.ContentFilters) (projectv2.ConfigsPerType, error) - settingsDownload func(client.SettingsClient, string, settings.Filters, ...config.SettingsType) (projectv2.ConfigsPerType, error) - automationDownload func(client.AutomationClient, string, ...config.AutomationType) (projectv2.ConfigsPerType, error) - bucketDownload func(client.BucketClient, string) (projectv2.ConfigsPerType, error) - documentDownload func(client.DocumentClient, string) (projectv2.ConfigsPerType, error) - openPipelineDownload func(client.OpenPipelineClient, string) (projectv2.ConfigsPerType, error) - grailFilterSegment func(client.GrailFilterSegmentClient, string) (projectv2.ConfigsPerType, error) + classicDownload func(client.ConfigClient, string, api.APIs, classic.ContentFilters) (projectv2.ConfigsPerType, error) + settingsDownload func(client.SettingsClient, string, settings.Filters, ...config.SettingsType) (projectv2.ConfigsPerType, error) + automationDownload func(client.AutomationClient, string, ...config.AutomationType) (projectv2.ConfigsPerType, error) + bucketDownload func(client.BucketClient, string) (projectv2.ConfigsPerType, error) + documentDownload func(client.DocumentClient, string) (projectv2.ConfigsPerType, error) + openPipelineDownload func(client.OpenPipelineClient, string) (projectv2.ConfigsPerType, error) + grailFilterSegmentDownload func(client.GrailFilterSegmentClient, string) (projectv2.ConfigsPerType, error) } var defaultDownloadFn = downloadFn{ - classicDownload: classic.Download, - settingsDownload: settings.Download, - automationDownload: automation.Download, - bucketDownload: bucket.Download, - documentDownload: document.Download, - openPipelineDownload: openpipeline.Download, - grailFilterSegment: grailfiltersegment.Download, + classicDownload: classic.Download, + settingsDownload: settings.Download, + automationDownload: automation.Download, + bucketDownload: bucket.Download, + documentDownload: document.Download, + openPipelineDownload: openpipeline.Download, + grailFilterSegmentDownload: grailfiltersegment.Download, } func downloadConfigs(clientSet *client.ClientSet, apisToDownload api.APIs, opts downloadConfigsOptions, fn downloadFn) (project.ConfigsPerType, error) { @@ -329,11 +329,11 @@ func downloadConfigs(clientSet *client.ClientSet, apisToDownload api.APIs, opts if featureflags.Temporary[featureflags.GrailFilterSegment].Enabled() { if shouldDownloadGrailFilterSegments(opts) { - cgfs, err := fn.grailFilterSegment(clientSet.GrailFilterSegmentClient, opts.projectName) + grailFilterSegmentCgfs, err := fn.grailFilterSegmentDownload(clientSet.GrailFilterSegmentClient, opts.projectName) if err != nil { return nil, err } - copyConfigs(configs, cgfs) + copyConfigs(configs, grailFilterSegmentCgfs) } else if opts.onlyGrailFilterSegment { return nil, errors.New("can't download filter-segment resources: no OAuth credentials configured") } diff --git a/cmd/monaco/download/download_configs_test.go b/cmd/monaco/download/download_configs_test.go index a03f0c55d..c5c2e2907 100644 --- a/cmd/monaco/download/download_configs_test.go +++ b/cmd/monaco/download/download_configs_test.go @@ -26,6 +26,7 @@ import ( "github.com/stretchr/testify/assert" "go.uber.org/mock/gomock" + "github.com/dynatrace/dynatrace-configuration-as-code/v2/internal/featureflags" "github.com/dynatrace/dynatrace-configuration-as-code/v2/internal/testutils" "github.com/dynatrace/dynatrace-configuration-as-code/v2/pkg/api" "github.com/dynatrace/dynatrace-configuration-as-code/v2/pkg/client" @@ -195,12 +196,13 @@ func TestDownload_Options(t *testing.T) { }, }, wantDownload{ - config: true, - settings: true, - bucket: true, - automation: true, - document: true, - openpipeline: true, + config: true, + settings: true, + bucket: true, + automation: true, + document: true, + openpipeline: true, + grailFilterSegment: true, }, }, { @@ -238,7 +240,8 @@ func TestDownload_Options(t *testing.T) { auth: manifest.Auth{OAuth: &manifest.OAuth{}}, }}, wantDownload{openpipeline: true}, - }, { + }, + { "only grail filter-segment requested", downloadConfigsOptions{ onlyGrailFilterSegment: true, @@ -289,6 +292,7 @@ func TestDownload_Options(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + t.Setenv(featureflags.Temporary[featureflags.GrailFilterSegment].EnvName(), "true") fn := downloadFn{ classicDownload: func(client.ConfigClient, string, api.APIs, classic.ContentFilters) (projectv2.ConfigsPerType, error) { if !tt.want.config { @@ -326,7 +330,7 @@ func TestDownload_Options(t *testing.T) { } return nil, nil }, - grailFilterSegment: func(b client.GrailFilterSegmentClient, s string) (projectv2.ConfigsPerType, error) { + grailFilterSegmentDownload: func(b client.GrailFilterSegmentClient, s string) (projectv2.ConfigsPerType, error) { if !tt.want.grailFilterSegment { t.Fatalf("grail file-segment download was not meant to be called but was") } diff --git a/pkg/download/grailfiltersegment/download.go b/pkg/download/grailfiltersegment/download.go index 4c7987164..02f93f80c 100644 --- a/pkg/download/grailfiltersegment/download.go +++ b/pkg/download/grailfiltersegment/download.go @@ -65,6 +65,7 @@ func createConfig(projectName string, response openpipeline.Response) (config.Co return config.Config{}, fmt.Errorf("failed to extract id as string from payload") } + // delete fields that prevent a re-upload of the configuration jsonObj.Delete("uid") jsonObj.Delete("version") jsonObj.Delete("externalId")