From f7d1a5862d2f83463786244482bfda1102294a8a Mon Sep 17 00:00:00 2001 From: Pieter Noordhuis Date: Thu, 8 Feb 2024 13:23:14 +0100 Subject: [PATCH] Use allowlist for Git-related fields to include in metadata (#1187) ## Changes When new fields are added they should not automatically propagate to the bundle metadata. ## Tests Test passes. --- bundle/deploy/metadata/compute.go | 10 ++++++++-- bundle/deploy/metadata/compute_test.go | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/bundle/deploy/metadata/compute.go b/bundle/deploy/metadata/compute.go index 460a81c9..c612d33a 100644 --- a/bundle/deploy/metadata/compute.go +++ b/bundle/deploy/metadata/compute.go @@ -6,6 +6,7 @@ import ( "path/filepath" "github.com/databricks/cli/bundle" + "github.com/databricks/cli/bundle/config" "github.com/databricks/cli/bundle/metadata" ) @@ -25,8 +26,13 @@ func (m *compute) Apply(_ context.Context, b *bundle.Bundle) error { Config: metadata.Config{}, } - // Set git details in metadata - b.Metadata.Config.Bundle.Git = b.Config.Bundle.Git + // Set Git details in metadata + b.Metadata.Config.Bundle.Git = config.Git{ + Branch: b.Config.Bundle.Git.Branch, + OriginURL: b.Config.Bundle.Git.OriginURL, + Commit: b.Config.Bundle.Git.Commit, + BundleRootPath: b.Config.Bundle.Git.BundleRootPath, + } // Set job config paths in metadata jobsMetadata := make(map[string]*metadata.Job) diff --git a/bundle/deploy/metadata/compute_test.go b/bundle/deploy/metadata/compute_test.go index c3cb029d..a1a97aab 100644 --- a/bundle/deploy/metadata/compute_test.go +++ b/bundle/deploy/metadata/compute_test.go @@ -30,6 +30,7 @@ func TestComputeMetadataMutator(t *testing.T) { OriginURL: "www.host.com", Commit: "abcd", BundleRootPath: "a/b/c/d", + Inferred: true, }, }, Resources: config.Resources{ @@ -76,6 +77,9 @@ func TestComputeMetadataMutator(t *testing.T) { OriginURL: "www.host.com", Commit: "abcd", BundleRootPath: "a/b/c/d", + + // Test that this field doesn't carry over into the metadata. + Inferred: false, }, }, Resources: metadata.Resources{