@@ -118,6 +118,7 @@ import (
118118 buildinfocmd "github.com/jfrog/jfrog-client-go/artifactory/buildinfo"
119119 "github.com/jfrog/jfrog-client-go/artifactory/services"
120120 clientutils "github.com/jfrog/jfrog-client-go/utils"
121+ utilsForLC "github.com/jfrog/jfrog-client-go/utils"
121122 "github.com/jfrog/jfrog-client-go/utils/errorutils"
122123 "github.com/jfrog/jfrog-client-go/utils/log"
123124 "github.com/jszwec/csvutil"
@@ -133,6 +134,7 @@ const (
133134 userCategory = "User Management"
134135 transferCategory = "Transfer Between Artifactory Instances"
135136 otherCategory = "Other"
137+ releaseBundlesV2 = "release-bundles-v2"
136138)
137139
138140func GetCommands () []cli.Command {
@@ -1269,14 +1271,17 @@ func prepareDownloadCommand(c *cli.Context) (*spec.SpecFiles, error) {
12691271
12701272 var downloadSpec * spec.SpecFiles
12711273 var err error
1274+
12721275 if c .IsSet ("spec" ) {
12731276 downloadSpec , err = cliutils .GetSpec (c , true , true )
12741277 } else {
12751278 downloadSpec , err = createDefaultDownloadSpec (c )
12761279 }
1280+
12771281 if err != nil {
12781282 return nil , err
12791283 }
1284+
12801285 setTransitiveInDownloadSpec (downloadSpec )
12811286 err = spec .ValidateSpec (downloadSpec .Files , false , true )
12821287 if err != nil {
@@ -1290,6 +1295,7 @@ func downloadCmd(c *cli.Context) error {
12901295 if err != nil {
12911296 return err
12921297 }
1298+
12931299 fixWinPathsForDownloadCmd (downloadSpec , c )
12941300 configuration , err := cliutils .CreateDownloadConfiguration (c )
12951301 if err != nil {
@@ -1330,6 +1336,54 @@ func downloadCmd(c *cli.Context) error {
13301336 return cliutils .GetCliError (err , result .SuccessCount (), result .FailCount (), cliutils .IsFailNoOp (c ))
13311337}
13321338
1339+ func checkRbExistenceInV2 (c * cli.Context ) (bool , error ) {
1340+ bundleNameAndVersion := c .String ("bundle" )
1341+ parts := strings .Split (bundleNameAndVersion , "/" )
1342+ rbName := parts [0 ]
1343+ rbVersion := parts [1 ]
1344+
1345+ lcDetails , err := createLifecycleDetailsByFlags (c )
1346+ if err != nil {
1347+ return false , err
1348+ }
1349+
1350+ lcServicesManager , err := utils .CreateLifecycleServiceManager (lcDetails , false )
1351+ if err != nil {
1352+ return false , err
1353+ }
1354+
1355+ return lcServicesManager .IsReleaseBundleExist (rbName , rbVersion , c .String ("project" ))
1356+ }
1357+
1358+ func createLifecycleDetailsByFlags (c * cli.Context ) (* coreConfig.ServerDetails , error ) {
1359+ lcDetails , err := cliutils .CreateServerDetailsWithConfigOffer (c , true , commonCliUtils .Platform )
1360+ if err != nil {
1361+ return nil , err
1362+ }
1363+ if lcDetails .Url == "" {
1364+ return nil , errors .New ("platform URL is mandatory for lifecycle commands" )
1365+ }
1366+ PlatformToLifecycleUrls (lcDetails )
1367+ return lcDetails , nil
1368+ }
1369+
1370+ func PlatformToLifecycleUrls (lcDetails * coreConfig.ServerDetails ) {
1371+ // For tests only. in prod - this "if" will always return false
1372+ if strings .Contains (lcDetails .Url , "artifactory/" ) {
1373+ lcDetails .ArtifactoryUrl = utilsForLC .AddTrailingSlashIfNeeded (lcDetails .Url )
1374+ lcDetails .LifecycleUrl = strings .Replace (
1375+ utilsForLC .AddTrailingSlashIfNeeded (lcDetails .Url ),
1376+ "artifactory/" ,
1377+ "lifecycle/" ,
1378+ 1 ,
1379+ )
1380+ } else {
1381+ lcDetails .ArtifactoryUrl = utilsForLC .AddTrailingSlashIfNeeded (lcDetails .Url ) + "artifactory/"
1382+ lcDetails .LifecycleUrl = utilsForLC .AddTrailingSlashIfNeeded (lcDetails .Url ) + "lifecycle/"
1383+ }
1384+ lcDetails .Url = ""
1385+ }
1386+
13331387func uploadCmd (c * cli.Context ) (err error ) {
13341388 if c .NArg () > 0 && c .IsSet ("spec" ) {
13351389 return cliutils .PrintHelpAndReturnError ("No arguments should be sent when the spec option is used." , c )
@@ -2648,8 +2702,9 @@ func createDefaultDownloadSpec(c *cli.Context) (*spec.SpecFiles, error) {
26482702 if err != nil {
26492703 return nil , err
26502704 }
2705+
26512706 return spec .NewBuilder ().
2652- Pattern (strings . TrimPrefix ( c . Args (). Get ( 0 ), "/" )).
2707+ Pattern (getSourcePattern ( c )).
26532708 Props (c .String ("props" )).
26542709 ExcludeProps (c .String ("exclude-props" )).
26552710 Build (c .String ("build" )).
@@ -2674,6 +2729,53 @@ func createDefaultDownloadSpec(c *cli.Context) (*spec.SpecFiles, error) {
26742729 BuildSpec (), nil
26752730}
26762731
2732+ func getSourcePattern (c * cli.Context ) string {
2733+ var source string
2734+ var isRbv2 bool
2735+ var err error
2736+
2737+ if c .IsSet ("bundle" ) {
2738+ // If the bundle flag is set, we need to check if the bundle exists in rbv2
2739+ isRbv2 , err = checkRbExistenceInV2 (c )
2740+ if err != nil {
2741+ log .Error ("Error occurred while checking if the bundle exists in rbv2:" , err .Error ())
2742+ }
2743+ }
2744+
2745+ if isRbv2 {
2746+ // RB2 will be downloaded like a regular artifact, path: projectKey-release-bundles-v2/rbName/rbVersion
2747+ source , err = buildSourceForRbv2 (c )
2748+ if err != nil {
2749+ log .Error ("Error occurred while building source path for rbv2:" , err .Error ())
2750+ return ""
2751+ }
2752+ } else {
2753+ source = strings .TrimPrefix (c .Args ().Get (0 ), "/" )
2754+ }
2755+
2756+ return source
2757+ }
2758+
2759+ func buildSourceForRbv2 (c * cli.Context ) (string , error ) {
2760+ bundleNameAndVersion := c .String ("bundle" )
2761+ projectKey := c .String ("project" )
2762+ source := projectKey
2763+
2764+ // Reset bundle flag
2765+ err := c .Set ("bundle" , "" )
2766+ if err != nil {
2767+ return "" , err
2768+ }
2769+
2770+ // If projectKey is not empty, append "-" to it
2771+ if projectKey != "" {
2772+ source += "-"
2773+ }
2774+ // Build RB path: projectKey-release-bundles-v2/rbName/rbVersion/
2775+ source += releaseBundlesV2 + "/" + bundleNameAndVersion + "/"
2776+ return source , nil
2777+ }
2778+
26772779func setTransitiveInDownloadSpec (downloadSpec * spec.SpecFiles ) {
26782780 transitive := os .Getenv (coreutils .TransitiveDownload )
26792781 if transitive == "" {
0 commit comments