github.com/jfrog/jfrog-cli-core/v2@v2.52.0/distribution/commands/distributebundle.go (about)

     1  package commands
     2  
     3  import (
     4  	"github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
     5  	"github.com/jfrog/jfrog-cli-core/v2/common/spec"
     6  	"github.com/jfrog/jfrog-cli-core/v2/utils/config"
     7  	"github.com/jfrog/jfrog-client-go/utils/distribution"
     8  )
     9  
    10  type DistributeReleaseBundleV1Command struct {
    11  	serverDetails           *config.ServerDetails
    12  	distributeBundlesParams distribution.DistributionParams
    13  	distributionRules       *spec.DistributionRules
    14  	sync                    bool
    15  	maxWaitMinutes          int
    16  	dryRun                  bool
    17  	autoCreateRepo          bool
    18  }
    19  
    20  func NewReleaseBundleDistributeV1Command() *DistributeReleaseBundleV1Command {
    21  	return &DistributeReleaseBundleV1Command{}
    22  }
    23  
    24  func (db *DistributeReleaseBundleV1Command) SetServerDetails(serverDetails *config.ServerDetails) *DistributeReleaseBundleV1Command {
    25  	db.serverDetails = serverDetails
    26  	return db
    27  }
    28  
    29  func (db *DistributeReleaseBundleV1Command) SetDistributeBundleParams(params distribution.DistributionParams) *DistributeReleaseBundleV1Command {
    30  	db.distributeBundlesParams = params
    31  	return db
    32  }
    33  
    34  func (db *DistributeReleaseBundleV1Command) SetDistributionRules(distributionRules *spec.DistributionRules) *DistributeReleaseBundleV1Command {
    35  	db.distributionRules = distributionRules
    36  	return db
    37  }
    38  
    39  func (db *DistributeReleaseBundleV1Command) SetSync(sync bool) *DistributeReleaseBundleV1Command {
    40  	db.sync = sync
    41  	return db
    42  }
    43  
    44  func (db *DistributeReleaseBundleV1Command) SetMaxWaitMinutes(maxWaitMinutes int) *DistributeReleaseBundleV1Command {
    45  	db.maxWaitMinutes = maxWaitMinutes
    46  	return db
    47  }
    48  
    49  func (db *DistributeReleaseBundleV1Command) SetDryRun(dryRun bool) *DistributeReleaseBundleV1Command {
    50  	db.dryRun = dryRun
    51  	return db
    52  }
    53  
    54  func (db *DistributeReleaseBundleV1Command) SetAutoCreateRepo(autoCreateRepo bool) *DistributeReleaseBundleV1Command {
    55  	db.autoCreateRepo = autoCreateRepo
    56  	return db
    57  }
    58  
    59  func (db *DistributeReleaseBundleV1Command) Run() error {
    60  	servicesManager, err := utils.CreateDistributionServiceManager(db.serverDetails, db.dryRun)
    61  	if err != nil {
    62  		return err
    63  	}
    64  
    65  	for _, rule := range db.distributionRules.DistributionRules {
    66  		db.distributeBundlesParams.DistributionRules = append(db.distributeBundlesParams.DistributionRules, rule.ToDistributionCommonParams())
    67  	}
    68  
    69  	if db.sync {
    70  		return servicesManager.DistributeReleaseBundleSync(db.distributeBundlesParams, db.maxWaitMinutes, db.autoCreateRepo)
    71  	}
    72  	return servicesManager.DistributeReleaseBundle(db.distributeBundlesParams, db.autoCreateRepo)
    73  }
    74  
    75  func (db *DistributeReleaseBundleV1Command) ServerDetails() (*config.ServerDetails, error) {
    76  	return db.serverDetails, nil
    77  }
    78  
    79  func (db *DistributeReleaseBundleV1Command) CommandName() string {
    80  	return "rt_distribute_bundle"
    81  }