github.com/jfrog/jfrog-cli-core/v2@v2.52.0/distribution/commands/createbundle.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/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.ToCommonParams() 53 if err != nil { 54 return err 55 } 56 recursive, err := spec.IsRecursive(true) 57 if err != nil { 58 return err 59 } 60 params.Recursive = recursive 61 cb.releaseBundlesParams.SpecFiles = append(cb.releaseBundlesParams.SpecFiles, params) 62 } 63 64 params := services.CreateReleaseBundleParams{ReleaseBundleParams: cb.releaseBundlesParams} 65 summary, err := servicesManager.CreateReleaseBundle(params) 66 if cb.detailedSummary { 67 cb.summary = summary 68 } 69 return err 70 } 71 72 func (cb *CreateBundleCommand) ServerDetails() (*config.ServerDetails, error) { 73 return cb.serverDetails, nil 74 } 75 76 func (cb *CreateBundleCommand) CommandName() string { 77 return "rt_bundle_create" 78 } 79 80 func (cb *CreateBundleCommand) SetSummary(summary *clientutils.Sha256Summary) *CreateBundleCommand { 81 cb.summary = summary 82 return cb 83 } 84 85 func (cb *CreateBundleCommand) GetSummary() *clientutils.Sha256Summary { 86 return cb.summary 87 } 88 89 func (cb *CreateBundleCommand) SetDetailedSummary(detailedSummary bool) *CreateBundleCommand { 90 cb.detailedSummary = detailedSummary 91 return cb 92 } 93 94 func (cb *CreateBundleCommand) IsDetailedSummary() bool { 95 return cb.detailedSummary 96 } 97 98 func (cb *CreateBundleCommand) IsSignImmediately() bool { 99 return cb.releaseBundlesParams.SignImmediately 100 }