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

     1  package lifecycle
     2  
     3  import (
     4  	"github.com/jfrog/jfrog-cli-core/v2/common/spec"
     5  	"github.com/jfrog/jfrog-cli-core/v2/utils/config"
     6  	"github.com/jfrog/jfrog-client-go/lifecycle/services"
     7  )
     8  
     9  type ReleaseBundleDistributeCommand struct {
    10  	releaseBundleCmd
    11  	distributionRules  *spec.DistributionRules
    12  	dryRun             bool
    13  	autoCreateRepo     bool
    14  	pathMappingPattern string
    15  	pathMappingTarget  string
    16  	maxWaitMinutes     int
    17  }
    18  
    19  func NewReleaseBundleDistributeCommand() *ReleaseBundleDistributeCommand {
    20  	return &ReleaseBundleDistributeCommand{}
    21  }
    22  
    23  func (rbd *ReleaseBundleDistributeCommand) SetServerDetails(serverDetails *config.ServerDetails) *ReleaseBundleDistributeCommand {
    24  	rbd.serverDetails = serverDetails
    25  	return rbd
    26  }
    27  
    28  func (rbd *ReleaseBundleDistributeCommand) SetReleaseBundleName(releaseBundleName string) *ReleaseBundleDistributeCommand {
    29  	rbd.releaseBundleName = releaseBundleName
    30  	return rbd
    31  }
    32  
    33  func (rbd *ReleaseBundleDistributeCommand) SetReleaseBundleVersion(releaseBundleVersion string) *ReleaseBundleDistributeCommand {
    34  	rbd.releaseBundleVersion = releaseBundleVersion
    35  	return rbd
    36  }
    37  
    38  func (rbd *ReleaseBundleDistributeCommand) SetReleaseBundleProject(rbProjectKey string) *ReleaseBundleDistributeCommand {
    39  	rbd.rbProjectKey = rbProjectKey
    40  	return rbd
    41  }
    42  
    43  func (rbd *ReleaseBundleDistributeCommand) SetDistributionRules(distributionRules *spec.DistributionRules) *ReleaseBundleDistributeCommand {
    44  	rbd.distributionRules = distributionRules
    45  	return rbd
    46  }
    47  
    48  func (rbd *ReleaseBundleDistributeCommand) SetDryRun(dryRun bool) *ReleaseBundleDistributeCommand {
    49  	rbd.dryRun = dryRun
    50  	return rbd
    51  }
    52  
    53  func (rbd *ReleaseBundleDistributeCommand) SetAutoCreateRepo(autoCreateRepo bool) *ReleaseBundleDistributeCommand {
    54  	rbd.autoCreateRepo = autoCreateRepo
    55  	return rbd
    56  }
    57  
    58  func (rbd *ReleaseBundleDistributeCommand) SetPathMappingPattern(pathMappingPattern string) *ReleaseBundleDistributeCommand {
    59  	rbd.pathMappingPattern = pathMappingPattern
    60  	return rbd
    61  }
    62  
    63  func (rbd *ReleaseBundleDistributeCommand) SetPathMappingTarget(pathMappingTarget string) *ReleaseBundleDistributeCommand {
    64  	rbd.pathMappingTarget = pathMappingTarget
    65  	return rbd
    66  }
    67  
    68  func (rbd *ReleaseBundleDistributeCommand) SetSync(sync bool) *ReleaseBundleDistributeCommand {
    69  	rbd.sync = sync
    70  	return rbd
    71  }
    72  
    73  func (rbd *ReleaseBundleDistributeCommand) SetMaxWaitMinutes(maxWaitMinutes int) *ReleaseBundleDistributeCommand {
    74  	rbd.maxWaitMinutes = maxWaitMinutes
    75  	return rbd
    76  }
    77  
    78  func (rbd *ReleaseBundleDistributeCommand) Run() error {
    79  	if err := validateArtifactoryVersionSupported(rbd.serverDetails); err != nil {
    80  		return err
    81  	}
    82  
    83  	servicesManager, rbDetails, _, err := rbd.getPrerequisites()
    84  	if err != nil {
    85  		return err
    86  	}
    87  
    88  	pathMapping := services.PathMapping{
    89  		Pattern: rbd.pathMappingPattern,
    90  		Target:  rbd.pathMappingTarget,
    91  	}
    92  
    93  	distributeParams := services.DistributeReleaseBundleParams{
    94  		Sync:              rbd.sync,
    95  		AutoCreateRepo:    rbd.autoCreateRepo,
    96  		MaxWaitMinutes:    rbd.maxWaitMinutes,
    97  		DistributionRules: getAggregatedDistRules(rbd.distributionRules),
    98  		PathMappings:      []services.PathMapping{pathMapping},
    99  		ProjectKey:        rbd.rbProjectKey,
   100  	}
   101  
   102  	return servicesManager.DistributeReleaseBundle(rbDetails, distributeParams)
   103  }
   104  
   105  func (rbd *ReleaseBundleDistributeCommand) ServerDetails() (*config.ServerDetails, error) {
   106  	return rbd.serverDetails, nil
   107  }
   108  
   109  func (rbd *ReleaseBundleDistributeCommand) CommandName() string {
   110  	return "rb_distribute"
   111  }