Skip to content

Commit

Permalink
Artifactory Release Lifecycle Management - Add Export bundle function (
Browse files Browse the repository at this point in the history
  • Loading branch information
EyalDelarea authored Mar 20, 2024
1 parent b631e3d commit b5807fd
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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.20240319160327-95a883923e0b
replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20240320102352-af2f392bb490

replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20240319160313-0093dee91fc1

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ github.com/jfrog/build-info-go v1.8.9-0.20240319160313-0093dee91fc1 h1:au9aqxUQI
github.com/jfrog/build-info-go v1.8.9-0.20240319160313-0093dee91fc1/go.mod h1:doFB4bFDVHeGulD6GF9LzsrRaIOrSoklV9DgIAEqHgc=
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.20240319160327-95a883923e0b h1:pNrQakO24/lNCK8LuBC9FxbfbSO1G8de8n9/FKPGbVc=
github.com/jfrog/jfrog-client-go v1.28.1-0.20240319160327-95a883923e0b/go.mod h1:/crrK2T2rXlJxBQdmw67i91W37/1R+ZM6xxAwVpm16M=
github.com/jfrog/jfrog-client-go v1.28.1-0.20240320102352-af2f392bb490 h1:oGgwRJatirSNZyqO3e4FtHCe5W30VNgULCW/GYhHdao=
github.com/jfrog/jfrog-client-go v1.28.1-0.20240320102352-af2f392bb490/go.mod h1:8z6in1qalzL1DqchUCrDKVgz2gKoPRhJpzm2Ww+VWYI=
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=
Expand Down
133 changes: 133 additions & 0 deletions lifecycle/export.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package lifecycle

import (
artUtils "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
"github.com/jfrog/jfrog-cli-core/v2/utils/config"
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
"github.com/jfrog/jfrog-client-go/artifactory"
artServices "github.com/jfrog/jfrog-client-go/artifactory/services"
"github.com/jfrog/jfrog-client-go/artifactory/services/utils"
clientConfig "github.com/jfrog/jfrog-client-go/config"
"github.com/jfrog/jfrog-client-go/lifecycle/services"
"github.com/jfrog/jfrog-client-go/utils/errorutils"
"github.com/jfrog/jfrog-client-go/utils/log"
"strings"
)

type ReleaseBundleExportCommand struct {
releaseBundleCmd
modifications services.Modifications
downloadConfigurations artUtils.DownloadConfiguration
targetPath string
}

func (rbe *ReleaseBundleExportCommand) Run() (err error) {
if err = validateArtifactoryVersionSupported(rbe.serverDetails); err != nil {
return
}
servicesManager, rbDetails, queryParams, err := rbe.getPrerequisites()
if err != nil {
return errorutils.CheckErrorf("Failed getting prerequisites for exporting command, error: '%s'", err.Error())
}
// Start the Export process and wait for completion
log.Info("Exporting Release Bundle archive...")
exportResponse, err := servicesManager.ExportReleaseBundle(rbDetails, rbe.modifications, queryParams)
if err != nil {
return errorutils.CheckErrorf("Failed exporting release bundle, error: '%s'", err.Error())
}
// Download the exported bundle
log.Debug("Downloading the exported bundle...")
downloaded, failed, err := rbe.downloadReleaseBundle(exportResponse, rbe.downloadConfigurations)
if err != nil || failed > 0 || downloaded < 1 {
return
}
log.Info("Successfully Downloaded Release Bundle archive")
return
}

// Download the exported release bundle using artifactory service manager
func (rbe *ReleaseBundleExportCommand) downloadReleaseBundle(exportResponse services.ReleaseBundleExportedStatusResponse, downloadConfiguration artUtils.DownloadConfiguration) (downloaded int, failed int, err error) {
downloadParams := artServices.DownloadParams{
CommonParams: &utils.CommonParams{
Pattern: strings.TrimPrefix(exportResponse.RelativeUrl, "/"),
Target: rbe.targetPath,
},
MinSplitSize: downloadConfiguration.MinSplitSize,
SplitCount: downloadConfiguration.SplitCount,
}
artifactoryServiceManager, err := createArtifactoryServiceManager(rbe.serverDetails)
if err != nil {
return
}
return artifactoryServiceManager.DownloadFiles(downloadParams)

}
func (rbe *ReleaseBundleExportCommand) ServerDetails() (*config.ServerDetails, error) {
return rbe.serverDetails, nil
}

func (rbe *ReleaseBundleExportCommand) CommandName() string {
return "rb_export"
}

func NewReleaseBundleExportCommand() *ReleaseBundleExportCommand {
return &ReleaseBundleExportCommand{}
}
func (rbe *ReleaseBundleExportCommand) SetServerDetails(serverDetails *config.ServerDetails) *ReleaseBundleExportCommand {
rbe.serverDetails = serverDetails
return rbe
}

func (rbe *ReleaseBundleExportCommand) SetReleaseBundleExportModifications(modifications services.Modifications) *ReleaseBundleExportCommand {
rbe.modifications = modifications
return rbe
}
func (rbe *ReleaseBundleExportCommand) SetReleaseBundleName(releaseBundleName string) *ReleaseBundleExportCommand {
rbe.releaseBundleName = releaseBundleName
return rbe
}

func (rbe *ReleaseBundleExportCommand) SetReleaseBundleVersion(releaseBundleVersion string) *ReleaseBundleExportCommand {
rbe.releaseBundleVersion = releaseBundleVersion
return rbe
}

func (rbe *ReleaseBundleExportCommand) SetProject(project string) *ReleaseBundleExportCommand {
rbe.rbProjectKey = project
return rbe
}

func (rbe *ReleaseBundleExportCommand) SetDownloadConfiguration(downloadConfig artUtils.DownloadConfiguration) *ReleaseBundleExportCommand {
rbe.downloadConfigurations = downloadConfig
return rbe
}

func (rbe *ReleaseBundleExportCommand) SetTargetPath(target string) *ReleaseBundleExportCommand {
if target == "" {
// Default value as current dir
target += "./"
}
rbe.targetPath = target
return rbe
}

func createArtifactoryServiceManager(artDetails *config.ServerDetails) (artifactory.ArtifactoryServicesManager, error) {
certsPath, err := coreutils.GetJfrogCertsDir()
if err != nil {
return nil, err
}
artAuth, err := artDetails.CreateArtAuthConfig()
if err != nil {
return nil, err
}
serviceConfig, err := clientConfig.NewConfigBuilder().
SetServiceDetails(artAuth).
SetCertificatesPath(certsPath).
SetInsecureTls(artDetails.InsecureTls).
SetDryRun(false).
Build()
if err != nil {
return nil, err
}
return artifactory.New(serviceConfig)
}

0 comments on commit b5807fd

Please sign in to comment.