diff --git a/go.mod b/go.mod index c7f5382ac..4bee0e1b0 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.20240403100335-8292671b7cc4 +replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20240408071430-62ee0279ac58 // replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go dev diff --git a/go.sum b/go.sum index 7aa3a37b6..2ffd059e2 100644 --- a/go.sum +++ b/go.sum @@ -87,8 +87,8 @@ github.com/jfrog/build-info-go v1.9.25 h1:IkjydGQA/HjOWjRaoKq1hOEgCCyBEJwQgXJSo4 github.com/jfrog/build-info-go v1.9.25/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.20240403100335-8292671b7cc4 h1:A67yoFRYjRzg+xhLYhH0QN7b4/wggRa/lSQKSjzOwNQ= -github.com/jfrog/jfrog-client-go v1.28.1-0.20240403100335-8292671b7cc4/go.mod h1:tUyEmxznphh0nwAGo6xz9Sps7RRW/TBMxIJZteo+j2k= +github.com/jfrog/jfrog-client-go v1.28.1-0.20240408071430-62ee0279ac58 h1:yyhOfECY3WGs6MsnJQWm/U7DYNIzxBiVlEwQ3RvqxwQ= +github.com/jfrog/jfrog-client-go v1.28.1-0.20240408071430-62ee0279ac58/go.mod h1:tUyEmxznphh0nwAGo6xz9Sps7RRW/TBMxIJZteo+j2k= 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/import.go b/lifecycle/import.go new file mode 100644 index 000000000..084ca6205 --- /dev/null +++ b/lifecycle/import.go @@ -0,0 +1,60 @@ +package lifecycle + +import ( + "fmt" + "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils" + "github.com/jfrog/jfrog-cli-core/v2/utils/config" + "github.com/jfrog/jfrog-client-go/utils/io/fileutils" + "github.com/jfrog/jfrog-client-go/utils/log" +) + +type ReleaseBundleImportCommand struct { + releaseBundleCmd + filePath string +} + +func (rbi *ReleaseBundleImportCommand) ServerDetails() (*config.ServerDetails, error) { + return rbi.serverDetails, nil +} + +func (rbi *ReleaseBundleImportCommand) CommandName() string { + return "rb_import" +} + +func NewReleaseBundleImportCommand() *ReleaseBundleImportCommand { + return &ReleaseBundleImportCommand{} +} +func (rbi *ReleaseBundleImportCommand) SetServerDetails(serverDetails *config.ServerDetails) *ReleaseBundleImportCommand { + rbi.serverDetails = serverDetails + return rbi +} + +func (rbi *ReleaseBundleImportCommand) SetFilepath(filePath string) *ReleaseBundleImportCommand { + rbi.filePath = filePath + return rbi +} + +func (rbi *ReleaseBundleImportCommand) Run() (err error) { + if err = validateArtifactoryVersionSupported(rbi.serverDetails); err != nil { + return + } + artService, err := utils.CreateServiceManager(rbi.serverDetails, 3, 0, false) + if err != nil { + return + } + + exists, err := fileutils.IsFileExists(rbi.filePath, false) + if err != nil { + return + } + if !exists { + return fmt.Errorf("file not found: %s", rbi.filePath) + } + + log.Info("Importing the release bundle archive...") + if err = artService.ImportReleaseBundle(rbi.filePath); err != nil { + return + } + log.Info("Successfully imported the release bundle archive") + return +}