github.com/jfrog/jfrog-cli-core@v1.12.1/artifactory/commands/distribution/createbundle.go (about)

     1  package distribution
     2  
     3  import (
     4  	"github.com/jfrog/jfrog-cli-core/artifactory/spec"
     5  	"github.com/jfrog/jfrog-cli-core/artifactory/utils"
     6  	"github.com/jfrog/jfrog-cli-core/utils/config"
     7  	"github.com/jfrog/jfrog-client-go/distribution/services"
     8  	distributionServicesUtils "github.com/jfrog/jfrog-client-go/distribution/services/utils"
     9  	clientutils "github.com/jfrog/jfrog-client-go/utils"
    10  )
    11  
    12  type CreateBundleCommand struct {
    13  	serverDetails        *config.ServerDetails
    14  	releaseBundlesParams distributionServicesUtils.ReleaseBundleParams
    15  	spec                 *spec.SpecFiles
    16  	dryRun               bool
    17  	detailedSummary      bool
    18  	summary              *clientutils.Sha256Summary
    19  }
    20  
    21  func NewReleaseBundleCreateCommand() *CreateBundleCommand {
    22  	return &CreateBundleCommand{}
    23  }
    24  
    25  func (cb *CreateBundleCommand) SetServerDetails(serverDetails *config.ServerDetails) *CreateBundleCommand {
    26  	cb.serverDetails = serverDetails
    27  	return cb
    28  }
    29  
    30  func (cb *CreateBundleCommand) SetReleaseBundleCreateParams(params distributionServicesUtils.ReleaseBundleParams) *CreateBundleCommand {
    31  	cb.releaseBundlesParams = params
    32  	return cb
    33  }
    34  
    35  func (cb *CreateBundleCommand) SetSpec(spec *spec.SpecFiles) *CreateBundleCommand {
    36  	cb.spec = spec
    37  	return cb
    38  }
    39  
    40  func (cb *CreateBundleCommand) SetDryRun(dryRun bool) *CreateBundleCommand {
    41  	cb.dryRun = dryRun
    42  	return cb
    43  }
    44  
    45  func (cb *CreateBundleCommand) Run() error {
    46  	servicesManager, err := utils.CreateDistributionServiceManager(cb.serverDetails, cb.dryRun)
    47  	if err != nil {
    48  		return err
    49  	}
    50  
    51  	for _, spec := range cb.spec.Files {
    52  		params, err := spec.ToArtifactoryCommonParams()
    53  		if err != nil {
    54  			return err
    55  		}
    56  		cb.releaseBundlesParams.SpecFiles = append(cb.releaseBundlesParams.SpecFiles, params)
    57  	}
    58  
    59  	params := services.CreateReleaseBundleParams{ReleaseBundleParams: cb.releaseBundlesParams}
    60  	summary, err := servicesManager.CreateReleaseBundle(params)
    61  	if cb.detailedSummary {
    62  		cb.summary = summary
    63  	}
    64  	return err
    65  }
    66  
    67  func (cb *CreateBundleCommand) ServerDetails() (*config.ServerDetails, error) {
    68  	return cb.serverDetails, nil
    69  }
    70  
    71  func (cb *CreateBundleCommand) CommandName() string {
    72  	return "rt_bundle_create"
    73  }
    74  
    75  func (cb *CreateBundleCommand) SetSummary(summary *clientutils.Sha256Summary) *CreateBundleCommand {
    76  	cb.summary = summary
    77  	return cb
    78  }
    79  
    80  func (cb *CreateBundleCommand) GetSummary() *clientutils.Sha256Summary {
    81  	return cb.summary
    82  }
    83  
    84  func (cb *CreateBundleCommand) SetDetailedSummary(detailedSummary bool) *CreateBundleCommand {
    85  	cb.detailedSummary = detailedSummary
    86  	return cb
    87  }
    88  
    89  func (cb *CreateBundleCommand) IsDetailedSummary() bool {
    90  	return cb.detailedSummary
    91  }
    92  
    93  func (cb *CreateBundleCommand) IsSignImmediately() bool {
    94  	return cb.releaseBundlesParams.SignImmediately
    95  }