Skip to content

Commit

Permalink
fix: changes related to PR
Browse files Browse the repository at this point in the history
  • Loading branch information
jskelin committed Dec 10, 2024
1 parent 8763d1a commit 4bfc7a9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 25 deletions.
2 changes: 1 addition & 1 deletion cmd/monaco/download/download_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
32 changes: 16 additions & 16 deletions cmd/monaco/download/download_configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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")
}
Expand Down
20 changes: 12 additions & 8 deletions cmd/monaco/download/download_configs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
},
},
{
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
}
Expand Down
1 change: 1 addition & 0 deletions pkg/download/grailfiltersegment/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 4bfc7a9

Please sign in to comment.