diff --git a/go.mod b/go.mod index 4e010a20e..2d8febd38 100644 --- a/go.mod +++ b/go.mod @@ -96,7 +96,7 @@ require ( gopkg.in/warnings.v0 v0.1.2 // indirect ) -replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20240317160615-e419c2a9e723 +replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20240318065424-90669dbbcc54 replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20240225113943-096bf22ca54c diff --git a/go.sum b/go.sum index b61111a8f..909812c3f 100644 --- a/go.sum +++ b/go.sum @@ -87,8 +87,8 @@ github.com/jfrog/build-info-go v1.8.9-0.20240225113943-096bf22ca54c h1:M1QiuCYGC github.com/jfrog/build-info-go v1.8.9-0.20240225113943-096bf22ca54c/go.mod h1:QHcKuesY4MrBVBuEwwBz4uIsX6mwYuMEDV09ng4AvAU= github.com/jfrog/gofrog v1.6.3 h1:F7He0+75HcgCe6SGTSHLFCBDxiE2Ja0tekvvcktW6wc= github.com/jfrog/gofrog v1.6.3/go.mod h1:SZ1EPJUruxrVGndOzHd+LTiwWYKMlHqhKD+eu+v5Hqg= -github.com/jfrog/jfrog-client-go v1.28.1-0.20240317160615-e419c2a9e723 h1:0N/fdI2PXLjdWZieh7ib+6gb87yw3x22V7t1YZJvWOA= -github.com/jfrog/jfrog-client-go v1.28.1-0.20240317160615-e419c2a9e723/go.mod h1:NB8tYFgkWtn+wHsKC+aYC75aLnS6yW81d8JAFTBxsi0= +github.com/jfrog/jfrog-client-go v1.28.1-0.20240318065424-90669dbbcc54 h1:FTrss/ffJPjTHOOhQ8P+8DrkGYkxcaHlxp12nOfeZJQ= +github.com/jfrog/jfrog-client-go v1.28.1-0.20240318065424-90669dbbcc54/go.mod h1:NB8tYFgkWtn+wHsKC+aYC75aLnS6yW81d8JAFTBxsi0= github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4= github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= diff --git a/lifecycle/common.go b/lifecycle/common.go index b5cf6de7d..5e1b2d0a2 100644 --- a/lifecycle/common.go +++ b/lifecycle/common.go @@ -2,10 +2,12 @@ package lifecycle import ( "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils" + "github.com/jfrog/jfrog-cli-core/v2/common/spec" "github.com/jfrog/jfrog-cli-core/v2/utils/config" "github.com/jfrog/jfrog-client-go/lifecycle" "github.com/jfrog/jfrog-client-go/lifecycle/services" clientUtils "github.com/jfrog/jfrog-client-go/utils" + "github.com/jfrog/jfrog-client-go/utils/distribution" ) const minimalLifecycleArtifactoryVersion = "7.63.2" @@ -48,3 +50,21 @@ func validateArtifactoryVersionSupported(serverDetails *config.ServerDetails) er return clientUtils.ValidateMinimumVersion(clientUtils.Artifactory, versionStr, minimalLifecycleArtifactoryVersion) } + +// If distribution rules are empty, distribute to all edges. +func getAggregatedDistRules(distributionRules *spec.DistributionRules) (aggregatedRules []*distribution.DistributionCommonParams) { + if isDistributionRulesEmpty(distributionRules) { + aggregatedRules = append(aggregatedRules, &distribution.DistributionCommonParams{SiteName: "*"}) + } else { + for _, rules := range distributionRules.DistributionRules { + aggregatedRules = append(aggregatedRules, rules.ToDistributionCommonParams()) + } + } + return +} + +func isDistributionRulesEmpty(distributionRules *spec.DistributionRules) bool { + return distributionRules == nil || + len(distributionRules.DistributionRules) == 0 || + len(distributionRules.DistributionRules) == 1 && distributionRules.DistributionRules[0].IsEmpty() +} diff --git a/lifecycle/distribute.go b/lifecycle/distribute.go index 76a187330..76165ef56 100644 --- a/lifecycle/distribute.go +++ b/lifecycle/distribute.go @@ -1,21 +1,19 @@ package lifecycle import ( - "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils" "github.com/jfrog/jfrog-cli-core/v2/common/spec" "github.com/jfrog/jfrog-cli-core/v2/utils/config" "github.com/jfrog/jfrog-client-go/lifecycle/services" - "github.com/jfrog/jfrog-client-go/utils/distribution" ) type ReleaseBundleDistributeCommand struct { - serverDetails *config.ServerDetails - distributeBundlesParams distribution.DistributionParams - distributionRules *spec.DistributionRules - dryRun bool - autoCreateRepo bool - pathMappingPattern string - pathMappingTarget string + releaseBundleCmd + distributionRules *spec.DistributionRules + dryRun bool + autoCreateRepo bool + pathMappingPattern string + pathMappingTarget string + maxWaitMinutes int } func NewReleaseBundleDistributeCommand() *ReleaseBundleDistributeCommand { @@ -27,8 +25,18 @@ func (rbd *ReleaseBundleDistributeCommand) SetServerDetails(serverDetails *confi return rbd } -func (rbd *ReleaseBundleDistributeCommand) SetDistributeBundleParams(params distribution.DistributionParams) *ReleaseBundleDistributeCommand { - rbd.distributeBundlesParams = params +func (rbd *ReleaseBundleDistributeCommand) SetReleaseBundleName(releaseBundleName string) *ReleaseBundleDistributeCommand { + rbd.releaseBundleName = releaseBundleName + return rbd +} + +func (rbd *ReleaseBundleDistributeCommand) SetReleaseBundleVersion(releaseBundleVersion string) *ReleaseBundleDistributeCommand { + rbd.releaseBundleVersion = releaseBundleVersion + return rbd +} + +func (rbd *ReleaseBundleDistributeCommand) SetReleaseBundleProject(rbProjectKey string) *ReleaseBundleDistributeCommand { + rbd.rbProjectKey = rbProjectKey return rbd } @@ -57,33 +65,41 @@ func (rbd *ReleaseBundleDistributeCommand) SetPathMappingTarget(pathMappingTarge return rbd } +func (rbd *ReleaseBundleDistributeCommand) SetSync(sync bool) *ReleaseBundleDistributeCommand { + rbd.sync = sync + return rbd +} + +func (rbd *ReleaseBundleDistributeCommand) SetMaxWaitMinutes(maxWaitMinutes int) *ReleaseBundleDistributeCommand { + rbd.maxWaitMinutes = maxWaitMinutes + return rbd +} + func (rbd *ReleaseBundleDistributeCommand) Run() error { if err := validateArtifactoryVersionSupported(rbd.serverDetails); err != nil { return err } - servicesManager, err := utils.CreateLifecycleServiceManager(rbd.serverDetails, rbd.dryRun) + servicesManager, rbDetails, _, err := rbd.getPrerequisites() if err != nil { return err } - for _, rule := range rbd.distributionRules.DistributionRules { - rbd.distributeBundlesParams.DistributionRules = append(rbd.distributeBundlesParams.DistributionRules, rule.ToDistributionCommonParams()) - } - pathMapping := services.PathMapping{ Pattern: rbd.pathMappingPattern, Target: rbd.pathMappingTarget, } - return servicesManager.DistributeReleaseBundle(services.ReleaseBundleDetails{ - ReleaseBundleName: rbd.distributeBundlesParams.Name, - ReleaseBundleVersion: rbd.distributeBundlesParams.Version, - }, services.DistributeReleaseBundleParams{ + distributeParams := services.DistributeReleaseBundleParams{ + Sync: rbd.sync, AutoCreateRepo: rbd.autoCreateRepo, - DistributionRules: rbd.distributeBundlesParams.DistributionRules, + MaxWaitMinutes: rbd.maxWaitMinutes, + DistributionRules: getAggregatedDistRules(rbd.distributionRules), PathMappings: []services.PathMapping{pathMapping}, - }) + ProjectKey: rbd.rbProjectKey, + } + + return servicesManager.DistributeReleaseBundle(rbDetails, distributeParams) } func (rbd *ReleaseBundleDistributeCommand) ServerDetails() (*config.ServerDetails, error) {