From 9ab7903de71ba733716a9f7c686ff66d95e2da96 Mon Sep 17 00:00:00 2001 From: yardene Date: Tue, 14 Nov 2023 16:15:17 +0200 Subject: [PATCH] Add distribution path mappings --- distribution_test.go | 24 ++++++++++++++++++- schema/filespec-schema.json | 14 +++++++++++ .../filespecs/dist_create_with_mapping.json | 18 +++++++++++--- .../dist_create_with_pattern_and_target.json | 8 +++++++ .../projectmissingdependecy.go | 2 +- utils/cliutils/utils.go | 2 +- utils/tests/consts.go | 1 + 7 files changed, 63 insertions(+), 6 deletions(-) create mode 100644 testdata/filespecs/dist_create_with_pattern_and_target.json diff --git a/distribution_test.go b/distribution_test.go index 62cbea526..5c5d12869 100644 --- a/distribution_test.go +++ b/distribution_test.go @@ -445,7 +445,7 @@ func TestUpdateBundleProps(t *testing.T) { cleanDistributionTest(t) } -func TestBundlePathMapping(t *testing.T) { +func TestBundlePathMappingFromPatternAndTarget(t *testing.T) { initDistributionTest(t) // Upload files @@ -465,6 +465,28 @@ func TestBundlePathMapping(t *testing.T) { cleanDistributionTest(t) } +func TestBundlePathMappingFromPatternAndTargetUsingSpec(t *testing.T) { + initDistributionTest(t) + + // Upload files + specFile, err := tests.CreateSpec(tests.DistributionUploadSpecB) + assert.NoError(t, err) + runRt(t, "u", "--spec="+specFile) + + // Create and distribute release bundle with path mapping from /data/ to /target/ + spec, err := tests.CreateSpec(tests.DistributionCreateWithPatternAndTarget) + assert.NoError(t, err) + runDs(t, "rbc", tests.BundleName, bundleVersion, "--sign", "--spec="+spec) + runDs(t, "rbd", tests.BundleName, bundleVersion, "--site=*", "--sync") + + // Validate files are distributed to the target mapping + spec, err = tests.CreateSpec(tests.DistributionMappingDownload) + assert.NoError(t, err) + inttestutils.VerifyExistInArtifactory(tests.GetBundleMappingExpected(), spec, serverDetails, t) + + cleanDistributionTest(t) +} + func TestBundlePathMappingUsingSpec(t *testing.T) { initDistributionTest(t) diff --git a/schema/filespec-schema.json b/schema/filespec-schema.json index ef325c155..474bcfbab 100644 --- a/schema/filespec-schema.json +++ b/schema/filespec-schema.json @@ -42,6 +42,19 @@ } } }, + "pathMapping": { + "description": "If specified, determines release-bundle source and target paths for artifacts that had been fetched using aql", + "properties": { + "input": { + "type": "string", + "description": "The input path for mapping." + }, + "output": { + "type": "string", + "description": "The output path for mapping." + } + } + }, "archive": { "type": "string", "enum": ["zip"], @@ -227,6 +240,7 @@ ] } }, + "pathMapping": { "required": ["aql"] }, "build": { "not": { "required": ["bundle", "limit", "offset"] } }, "bundle": { "not": { "required": ["build", "limit", "offset"] } }, "excludeArtifacts": { "required": ["build"] }, diff --git a/testdata/filespecs/dist_create_with_mapping.json b/testdata/filespecs/dist_create_with_mapping.json index 98502d1d9..72b6075de 100644 --- a/testdata/filespecs/dist_create_with_mapping.json +++ b/testdata/filespecs/dist_create_with_mapping.json @@ -1,8 +1,20 @@ { "files": [ { - "pattern": "${DIST_REPO1}/data/(*)", - "target": "${DIST_REPO2}/target/{1}" + "aql": { + "items.find": { + "repo": "${DIST_REPO1}", + "path": "data", + "$or": [ + { + "name": { + "$match": "*" + } + } + ] + } + }, + "pathMapping": { "input": "${DIST_REPO1}/data/(.*)", "output": "${DIST_REPO2}/target/$1" } } ] -} +} \ No newline at end of file diff --git a/testdata/filespecs/dist_create_with_pattern_and_target.json b/testdata/filespecs/dist_create_with_pattern_and_target.json new file mode 100644 index 000000000..98502d1d9 --- /dev/null +++ b/testdata/filespecs/dist_create_with_pattern_and_target.json @@ -0,0 +1,8 @@ +{ + "files": [ + { + "pattern": "${DIST_REPO1}/data/(*)", + "target": "${DIST_REPO2}/target/{1}" + } + ] +} diff --git a/testdata/go/projectmissingdependency/projectmissingdependecy.go b/testdata/go/projectmissingdependency/projectmissingdependecy.go index 30c5ed4ce..b59c02118 100644 --- a/testdata/go/projectmissingdependency/projectmissingdependecy.go +++ b/testdata/go/projectmissingdependency/projectmissingdependecy.go @@ -12,4 +12,4 @@ func execDependency() { func Exec() { fmt.Println("Executing ") execDependency() -} \ No newline at end of file +} diff --git a/utils/cliutils/utils.go b/utils/cliutils/utils.go index e101b863c..94d888400 100644 --- a/utils/cliutils/utils.go +++ b/utils/cliutils/utils.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "github.com/jfrog/gofrog/version" + "github.com/jfrog/jfrog-client-go/utils/log" "io" "net/http" "os" @@ -26,7 +27,6 @@ import ( clientutils "github.com/jfrog/jfrog-client-go/utils" "github.com/jfrog/jfrog-client-go/utils/errorutils" "github.com/jfrog/jfrog-client-go/utils/io/content" - "github.com/jfrog/jfrog-client-go/utils/log" "github.com/urfave/cli" ) diff --git a/utils/tests/consts.go b/utils/tests/consts.go index 576b39cba..8b3b93a6b 100644 --- a/utils/tests/consts.go +++ b/utils/tests/consts.go @@ -42,6 +42,7 @@ const ( DelSpecExclusions = "delete_spec_exclusions.json" DistributionCreateByAql = "dist_create_by_aql.json" DistributionCreateWithMapping = "dist_create_with_mapping.json" + DistributionCreateWithPatternAndTarget = "dist_create_with_pattern_and_target.json" DistributionMappingDownload = "dist_mapping_download_spec.json" DistributionRepoConfig1 = "dist_repository_config1.json" DistributionRepoConfig2 = "dist_repository_config2.json"