github.com/jfrog/jfrog-cli-core/v2@v2.51.0/lifecycle/import.go (about)

     1  package lifecycle
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
     6  	"github.com/jfrog/jfrog-cli-core/v2/utils/config"
     7  	"github.com/jfrog/jfrog-client-go/utils/io/fileutils"
     8  	"github.com/jfrog/jfrog-client-go/utils/log"
     9  )
    10  
    11  type ReleaseBundleImportCommand struct {
    12  	releaseBundleCmd
    13  	filePath string
    14  }
    15  
    16  func (rbi *ReleaseBundleImportCommand) ServerDetails() (*config.ServerDetails, error) {
    17  	return rbi.serverDetails, nil
    18  }
    19  
    20  func (rbi *ReleaseBundleImportCommand) CommandName() string {
    21  	return "rb_import"
    22  }
    23  
    24  func NewReleaseBundleImportCommand() *ReleaseBundleImportCommand {
    25  	return &ReleaseBundleImportCommand{}
    26  }
    27  func (rbi *ReleaseBundleImportCommand) SetServerDetails(serverDetails *config.ServerDetails) *ReleaseBundleImportCommand {
    28  	rbi.serverDetails = serverDetails
    29  	return rbi
    30  }
    31  
    32  func (rbi *ReleaseBundleImportCommand) SetFilepath(filePath string) *ReleaseBundleImportCommand {
    33  	rbi.filePath = filePath
    34  	return rbi
    35  }
    36  
    37  func (rbi *ReleaseBundleImportCommand) Run() (err error) {
    38  	if err = validateArtifactoryVersionSupported(rbi.serverDetails); err != nil {
    39  		return
    40  	}
    41  	artService, err := utils.CreateServiceManager(rbi.serverDetails, 3, 0, false)
    42  	if err != nil {
    43  		return
    44  	}
    45  
    46  	exists, err := fileutils.IsFileExists(rbi.filePath, false)
    47  	if err != nil {
    48  		return
    49  	}
    50  	if !exists {
    51  		return fmt.Errorf("file not found: %s", rbi.filePath)
    52  	}
    53  
    54  	log.Info("Importing the release bundle archive...")
    55  	if err = artService.ImportReleaseBundle(rbi.filePath); err != nil {
    56  		return
    57  	}
    58  	log.Info("Successfully imported the release bundle archive")
    59  	return
    60  }