Skip to content

Commit

Permalink
Artifactory Release Lifecycle Management - Add Export bundle command (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
EyalDelarea committed Mar 20, 2024
1 parent 56e8cf8 commit 2b5da11
Show file tree
Hide file tree
Showing 9 changed files with 190 additions and 114 deletions.
84 changes: 2 additions & 82 deletions artifactory/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -948,37 +948,6 @@ func GetCommands() []cli.Command {
})
}

func getSplitCount(c *cli.Context, defaultSplitCount, maxSplitCount int) (splitCount int, err error) {
splitCount = defaultSplitCount
err = nil
if c.String("split-count") != "" {
splitCount, err = strconv.Atoi(c.String("split-count"))
if err != nil {
err = errors.New("The '--split-count' option should have a numeric value. " + cliutils.GetDocumentationMessage())
}
if splitCount > maxSplitCount {
err = errors.New("The '--split-count' option value is limited to a maximum of " + strconv.Itoa(maxSplitCount) + ".")
}
if splitCount < 0 {
err = errors.New("the '--split-count' option cannot have a negative value")
}
}
return
}

func getMinSplit(c *cli.Context, defaultMinSplit int64) (minSplitSize int64, err error) {
minSplitSize = defaultMinSplit
if c.String(cliutils.MinSplit) != "" {
minSplitSize, err = strconv.ParseInt(c.String(cliutils.MinSplit), 10, 64)
if err != nil {
err = errors.New("The '--min-split' option should have a numeric value. " + cliutils.GetDocumentationMessage())
return 0, err
}
}

return minSplitSize, nil
}

func getRetries(c *cli.Context) (retries int, err error) {
retries = cliutils.Retries
if c.String("retries") != "" {
Expand Down Expand Up @@ -1238,7 +1207,7 @@ func downloadCmd(c *cli.Context) error {
return err
}
fixWinPathsForDownloadCmd(downloadSpec, c)
configuration, err := createDownloadConfiguration(c)
configuration, err := cliutils.CreateDownloadConfiguration(c)
if err != nil {
return err
}
Expand Down Expand Up @@ -1299,7 +1268,7 @@ func uploadCmd(c *cli.Context) (err error) {
return
}
cliutils.FixWinPathsForFileSystemSourcedCmds(uploadSpec, c)
configuration, err := createUploadConfiguration(c)
configuration, err := cliutils.CreateUploadConfiguration(c)
if err != nil {
return
}
Expand Down Expand Up @@ -2416,15 +2385,6 @@ func transferSettingsCmd(_ *cli.Context) error {
return commands.Exec(transferSettingsCmd)
}

func getDebFlag(c *cli.Context) (deb string, err error) {
deb = c.String("deb")
slashesCount := strings.Count(deb, "/") - strings.Count(deb, "\\/")
if deb != "" && slashesCount != 2 {
return "", errors.New("the --deb option should be in the form of distribution/component/architecture")
}
return deb, nil
}

func createDefaultCopyMoveSpec(c *cli.Context) (*spec.SpecFiles, error) {
offset, limit, err := getOffsetAndLimitValues(c)
if err != nil {
Expand Down Expand Up @@ -2630,25 +2590,6 @@ func createDefaultDownloadSpec(c *cli.Context) (*spec.SpecFiles, error) {
BuildSpec(), nil
}

func createDownloadConfiguration(c *cli.Context) (downloadConfiguration *utils.DownloadConfiguration, err error) {
downloadConfiguration = new(utils.DownloadConfiguration)
downloadConfiguration.MinSplitSize, err = getMinSplit(c, cliutils.DownloadMinSplitKb)
if err != nil {
return nil, err
}
downloadConfiguration.SplitCount, err = getSplitCount(c, cliutils.DownloadSplitCount, cliutils.DownloadMaxSplitCount)
if err != nil {
return nil, err
}
downloadConfiguration.Threads, err = cliutils.GetThreadsCount(c)
if err != nil {
return nil, err
}
downloadConfiguration.SkipChecksum = c.Bool("skip-checksum")
downloadConfiguration.Symlink = true
return
}

func setTransitiveInDownloadSpec(downloadSpec *spec.SpecFiles) {
transitive := os.Getenv(coreutils.TransitiveDownload)
if transitive == "" {
Expand Down Expand Up @@ -2708,27 +2649,6 @@ func fixWinPathsForDownloadCmd(uploadSpec *spec.SpecFiles, c *cli.Context) {
}
}

func createUploadConfiguration(c *cli.Context) (uploadConfiguration *utils.UploadConfiguration, err error) {
uploadConfiguration = new(utils.UploadConfiguration)
uploadConfiguration.MinSplitSizeMB, err = getMinSplit(c, cliutils.UploadMinSplitMb)
if err != nil {
return nil, err
}
uploadConfiguration.SplitCount, err = getSplitCount(c, cliutils.UploadSplitCount, cliutils.UploadMaxSplitCount)
if err != nil {
return nil, err
}
uploadConfiguration.Threads, err = cliutils.GetThreadsCount(c)
if err != nil {
return nil, err
}
uploadConfiguration.Deb, err = getDebFlag(c)
if err != nil {
return
}
return
}

func getOffsetAndLimitValues(c *cli.Context) (offset, limit int, err error) {
offset, err = cliutils.GetIntFlagValue(c, "offset", 0)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion artifactory/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func TestCreateUploadConfiguration(t *testing.T) {
for _, testCase := range createUploadConfigurationCases {
t.Run(testCase.name, func(t *testing.T) {
context, _ := tests.CreateContext(t, testCase.flags, []string{})
uploadConfiguration, err := createUploadConfiguration(context)
uploadConfiguration, err := cliutils.CreateUploadConfiguration(context)
assert.NoError(t, err)
assert.Equal(t, testCase.expectedMinSplit, uploadConfiguration.MinSplitSizeMB)
assert.Equal(t, testCase.expectedSplitCount, uploadConfiguration.SplitCount)
Expand Down
22 changes: 22 additions & 0 deletions docs/lifecycle/export/help.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package export

var Usage = []string{"rbe <release bundle name> <release bundle version> [target pattern]"}

func GetDescription() string {
return "Triggers the Export process and downloads the Release Bundle archive"
}

func GetArguments() string {
return ` release bundle name
Name of the Release Bundle to export.
release bundle version
Version of the Release Bundle to export.
target pattern
The third argument is optional and specifies the local file system target path.
If the target path ends with a slash, the path is assumed to be a directory.
For example, if you specify the target as "repo-name/a/b/", then "b" is assumed to be a directory into which files should be downloaded.
If there is no terminal slash, the target path is assumed to be a file to which the downloaded file should be renamed.
For example, if you specify the target as "a/b", the downloaded file is renamed to "b". `
}
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ require (
github.com/gookit/color v1.5.4 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/jedib0t/go-pretty/v6 v6.5.4 // indirect
github.com/jedib0t/go-pretty/v6 v6.5.5 // indirect
github.com/jfrog/jfrog-apps-config v1.0.1 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/klauspost/compress v1.17.4 // indirect
Expand Down Expand Up @@ -137,9 +137,9 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)

// replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 dev
replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20240320104952-b5807fd0102d

// replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go dev
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 dev

Expand Down
Loading

0 comments on commit 2b5da11

Please sign in to comment.