Skip to content

Commit

Permalink
fix: Skip download of ready-made documents
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurpitman committed Jan 22, 2025
1 parent 7603f3b commit 43510ea
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/dynatrace/dynatrace-configuration-as-code/v2

require (
github.com/anknown/ahocorasick v0.0.0-20190904063843-d75dbd5169c0
github.com/dynatrace/dynatrace-configuration-as-code-core v0.7.1-0.20250116092549-011619f1b72c
github.com/dynatrace/dynatrace-configuration-as-code-core v0.7.1-0.20250122070908-49a5e700869b
github.com/go-logr/logr v1.4.2
github.com/go-logr/zapr v1.3.0
github.com/google/go-cmp v0.6.0
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dynatrace/dynatrace-configuration-as-code-core v0.7.1-0.20250116092549-011619f1b72c h1:zgC8EYhbvrefwTa50nC0VKdOHHeVnarv1deVIE5ouIs=
github.com/dynatrace/dynatrace-configuration-as-code-core v0.7.1-0.20250116092549-011619f1b72c/go.mod h1:+X1IcFfICIIq3ZCAYMkHWNL1IQ6ES2IqIaiEDjhIrF4=
github.com/dynatrace/dynatrace-configuration-as-code-core v0.7.1-0.20250121101851-8ea0560d0f67 h1:W3/NfadNGltkcsqxuXK8YoB22P/64DtQI4zCuzXBLmk=
github.com/dynatrace/dynatrace-configuration-as-code-core v0.7.1-0.20250121101851-8ea0560d0f67/go.mod h1:+X1IcFfICIIq3ZCAYMkHWNL1IQ6ES2IqIaiEDjhIrF4=
github.com/dynatrace/dynatrace-configuration-as-code-core v0.7.1-0.20250122064727-56661a734a85 h1:HqbFnP1dqjx1l/kNbdhLLJYqe+czl7ZhIoSIjAwqS78=
github.com/dynatrace/dynatrace-configuration-as-code-core v0.7.1-0.20250122064727-56661a734a85/go.mod h1:+X1IcFfICIIq3ZCAYMkHWNL1IQ6ES2IqIaiEDjhIrF4=
github.com/dynatrace/dynatrace-configuration-as-code-core v0.7.1-0.20250122070908-49a5e700869b h1:KytK4Z9ermPegjCuJXDr0nDT/ecyUEn3xI+s7aq5jy8=
github.com/dynatrace/dynatrace-configuration-as-code-core v0.7.1-0.20250122070908-49a5e700869b/go.mod h1:+X1IcFfICIIq3ZCAYMkHWNL1IQ6ES2IqIaiEDjhIrF4=
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/zapr v1.3.0 h1:XGdV8XW8zdwFiwOA2Dryh1gj2KRQyOOoNmBy4EplIcQ=
Expand Down
9 changes: 9 additions & 0 deletions pkg/download/document/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ func downloadDocumentsOfType(client client.DocumentClient, projectName string, d
}

var configs []config.Config

for _, response := range listResponse.Responses {
// skip downloading ready-made documents - these are presets that cannot be redeployed
if isReadyMadeByAnApp(response.Metadata) {
continue
}

config, err := convertDocumentResponse(client, projectName, response)
if err != nil {
Expand All @@ -83,6 +88,10 @@ func downloadDocumentsOfType(client client.DocumentClient, projectName string, d
return configs
}

func isReadyMadeByAnApp(metadata documents.Metadata) bool {
return (metadata.OriginAppID != nil) && (len(*metadata.OriginAppID) > 0)
}

func convertDocumentResponse(client client.DocumentClient, projectName string, response documents.Response) (config.Config, error) {
documentType, err := validateDocumentType(response.Type)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/download/document/download_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ func TestDownloader_Download(t *testing.T) {
result, err := Download(documentClient, "project")
assert.NoError(t, err)
assert.Len(t, result, 1)
assert.True(t, true)

// expect no dashboards or notebooks
require.Len(t, result["document"], 0)
Expand Down
22 changes: 21 additions & 1 deletion pkg/download/document/testdata/listDashboardDocuments.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,28 @@
"isPrivate": false,
"version": 3,
"owner": "01234567-0123-0123-0123-0123456789ab"
},
{
"modificationInfo": {
"createdBy": "01234567-0123-0123-0123-0123456789ab",
"createdTime": "2024-04-02T11:49:47.726Z",
"lastModifiedBy": "01234567-0123-0123-0123-0123456789ab",
"lastModifiedTime": "2024-04-05T08:20:15.143Z"
},
"access": [
"read",
"delete",
"write"
],
"id": "12345678-1234-1234-1234-0123456789ac",
"name": "Data Ingest Overview",
"type": "dashboard",
"isPrivate": false,
"version": 3,
"owner": "01234567-0123-0123-0123-0123456789ab",
"originAppId": "dynatrace.some.app"
}
],
"nextPageKey": null,
"totalCount": 1
"totalCount": 2
}

0 comments on commit 43510ea

Please sign in to comment.