@@ -2,10 +2,6 @@ package distribution
2
2
3
3
import (
4
4
"errors"
5
- "os"
6
- "path/filepath"
7
- "strings"
8
-
9
5
"github.com/jfrog/jfrog-cli-core/v2/common/commands"
10
6
"github.com/jfrog/jfrog-cli-core/v2/common/spec"
11
7
distributionCommands "github.com/jfrog/jfrog-cli-core/v2/distribution/commands"
@@ -18,10 +14,14 @@ import (
18
14
"github.com/jfrog/jfrog-cli/docs/artifactory/releasebundleupdate"
19
15
"github.com/jfrog/jfrog-cli/docs/common"
20
16
"github.com/jfrog/jfrog-cli/utils/cliutils"
17
+ "github.com/jfrog/jfrog-cli/utils/distribution"
21
18
distributionServices "github.com/jfrog/jfrog-client-go/distribution/services"
22
19
distributionServicesUtils "github.com/jfrog/jfrog-client-go/distribution/services/utils"
23
20
"github.com/jfrog/jfrog-client-go/utils/errorutils"
24
21
"github.com/urfave/cli"
22
+ "os"
23
+ "path/filepath"
24
+ "strings"
25
25
)
26
26
27
27
func GetCommands () []cli.Command {
@@ -111,11 +111,11 @@ func releaseBundleCreateCmd(c *cli.Context) error {
111
111
return err
112
112
}
113
113
releaseBundleCreateCmd := distributionCommands .NewReleaseBundleCreateCommand ()
114
- rtDetails , err := createArtifactoryDetailsByFlags (c )
114
+ dsDetails , err := createDistributionDetailsByFlags (c )
115
115
if err != nil {
116
116
return err
117
117
}
118
- releaseBundleCreateCmd .SetServerDetails (rtDetails ).SetReleaseBundleCreateParams (params ).SetSpec (releaseBundleCreateSpec ).SetDryRun (c .Bool ("dry-run" )).SetDetailedSummary (c .Bool ("detailed-summary" ))
118
+ releaseBundleCreateCmd .SetServerDetails (dsDetails ).SetReleaseBundleCreateParams (params ).SetSpec (releaseBundleCreateSpec ).SetDryRun (c .Bool ("dry-run" )).SetDetailedSummary (c .Bool ("detailed-summary" ))
119
119
120
120
err = commands .Exec (releaseBundleCreateCmd )
121
121
if releaseBundleCreateCmd .IsDetailedSummary () {
@@ -153,11 +153,11 @@ func releaseBundleUpdateCmd(c *cli.Context) error {
153
153
return err
154
154
}
155
155
releaseBundleUpdateCmd := distributionCommands .NewReleaseBundleUpdateCommand ()
156
- rtDetails , err := createArtifactoryDetailsByFlags (c )
156
+ dsDetails , err := createDistributionDetailsByFlags (c )
157
157
if err != nil {
158
158
return err
159
159
}
160
- releaseBundleUpdateCmd .SetServerDetails (rtDetails ).SetReleaseBundleUpdateParams (params ).SetSpec (releaseBundleUpdateSpec ).SetDryRun (c .Bool ("dry-run" )).SetDetailedSummary (c .Bool ("detailed-summary" ))
160
+ releaseBundleUpdateCmd .SetServerDetails (dsDetails ).SetReleaseBundleUpdateParams (params ).SetSpec (releaseBundleUpdateSpec ).SetDryRun (c .Bool ("dry-run" )).SetDetailedSummary (c .Bool ("detailed-summary" ))
161
161
162
162
err = commands .Exec (releaseBundleUpdateCmd )
163
163
if releaseBundleUpdateCmd .IsDetailedSummary () {
@@ -177,11 +177,11 @@ func releaseBundleSignCmd(c *cli.Context) error {
177
177
params .StoringRepository = c .String ("repo" )
178
178
params .GpgPassphrase = c .String ("passphrase" )
179
179
releaseBundleSignCmd := distributionCommands .NewReleaseBundleSignCommand ()
180
- rtDetails , err := createArtifactoryDetailsByFlags (c )
180
+ dsDetails , err := createDistributionDetailsByFlags (c )
181
181
if err != nil {
182
182
return err
183
183
}
184
- releaseBundleSignCmd .SetServerDetails (rtDetails ).SetReleaseBundleSignParams (params ).SetDetailedSummary (c .Bool ("detailed-summary" ))
184
+ releaseBundleSignCmd .SetServerDetails (dsDetails ).SetReleaseBundleSignParams (params ).SetDetailedSummary (c .Bool ("detailed-summary" ))
185
185
err = commands .Exec (releaseBundleSignCmd )
186
186
if releaseBundleSignCmd .IsDetailedSummary () {
187
187
if summary := releaseBundleSignCmd .GetSummary (); summary != nil {
@@ -192,45 +192,29 @@ func releaseBundleSignCmd(c *cli.Context) error {
192
192
}
193
193
194
194
func releaseBundleDistributeCmd (c * cli.Context ) error {
195
- if c .NArg () != 2 {
196
- return cliutils .WrongNumberOfArgumentsHandler (c )
197
- }
198
- if c .IsSet ("max-wait-minutes" ) && ! c .IsSet ("sync" ) {
199
- return cliutils .PrintHelpAndReturnError ("The --max-wait-minutes option can't be used without --sync" , c )
200
- }
201
- var distributionRules * spec.DistributionRules
202
- if c .IsSet ("dist-rules" ) {
203
- if c .IsSet ("site" ) || c .IsSet ("city" ) || c .IsSet ("country-code" ) {
204
- return cliutils .PrintHelpAndReturnError ("The --dist-rules option can't be used with --site, --city or --country-code" , c )
205
- }
206
- var err error
207
- distributionRules , err = spec .CreateDistributionRulesFromFile (c .String ("dist-rules" ))
208
- if err != nil {
209
- return err
210
- }
211
- } else {
212
- distributionRules = createDefaultDistributionRules (c )
195
+ if err := distribution .ValidateReleaseBundleDistributeCmd (c ); err != nil {
196
+ return err
213
197
}
214
198
215
- params := distributionServices .NewDistributeReleaseBundleParams (c .Args ().Get (0 ), c .Args ().Get (1 ))
216
- releaseBundleDistributeCmd := distributionCommands .NewReleaseBundleDistributeCommand ()
217
- rtDetails , err := createArtifactoryDetailsByFlags (c )
199
+ dsDetails , err := createDistributionDetailsByFlags (c )
218
200
if err != nil {
219
201
return err
220
202
}
221
- maxWaitMinutes , err := cliutils . GetIntFlagValue ( c , "max-wait-minutes" , 60 )
203
+ distributionRules , maxWaitMinutes , params , err := distribution . InitReleaseBundleDistributeCmd ( c )
222
204
if err != nil {
223
205
return err
224
206
}
225
- releaseBundleDistributeCmd .SetServerDetails (rtDetails ).
207
+
208
+ distributeCmd := distributionCommands .NewReleaseBundleDistributeV1Command ()
209
+ distributeCmd .SetServerDetails (dsDetails ).
226
210
SetDistributeBundleParams (params ).
227
211
SetDistributionRules (distributionRules ).
228
212
SetDryRun (c .Bool ("dry-run" )).
229
213
SetSync (c .Bool ("sync" )).
230
214
SetMaxWaitMinutes (maxWaitMinutes ).
231
215
SetAutoCreateRepo (c .Bool ("create-repo" ))
232
216
233
- return commands .Exec (releaseBundleDistributeCmd )
217
+ return commands .Exec (distributeCmd )
234
218
}
235
219
236
220
func releaseBundleDeleteCmd (c * cli.Context ) error {
@@ -248,7 +232,7 @@ func releaseBundleDeleteCmd(c *cli.Context) error {
248
232
return err
249
233
}
250
234
} else {
251
- distributionRules = createDefaultDistributionRules (c )
235
+ distributionRules = distribution . CreateDefaultDistributionRules (c )
252
236
}
253
237
254
238
params := distributionServices .NewDeleteReleaseBundleParams (c .Args ().Get (0 ), c .Args ().Get (1 ))
@@ -260,11 +244,11 @@ func releaseBundleDeleteCmd(c *cli.Context) error {
260
244
}
261
245
params .MaxWaitMinutes = maxWaitMinutes
262
246
distributeBundleCmd := distributionCommands .NewReleaseBundleDeleteParams ()
263
- rtDetails , err := createArtifactoryDetailsByFlags (c )
247
+ dsDetails , err := createDistributionDetailsByFlags (c )
264
248
if err != nil {
265
249
return err
266
250
}
267
- distributeBundleCmd .SetQuiet (cliutils .GetQuietValue (c )).SetServerDetails (rtDetails ).SetDistributeBundleParams (params ).SetDistributionRules (distributionRules ).SetDryRun (c .Bool ("dry-run" ))
251
+ distributeBundleCmd .SetQuiet (cliutils .GetQuietValue (c )).SetServerDetails (dsDetails ).SetDistributeBundleParams (params ).SetDistributionRules (distributionRules ).SetDryRun (c .Bool ("dry-run" ))
268
252
269
253
return commands .Exec (distributeBundleCmd )
270
254
}
@@ -283,16 +267,6 @@ func createDefaultReleaseBundleSpec(c *cli.Context) *spec.SpecFiles {
283
267
BuildSpec ()
284
268
}
285
269
286
- func createDefaultDistributionRules (c * cli.Context ) * spec.DistributionRules {
287
- return & spec.DistributionRules {
288
- DistributionRules : []spec.DistributionRule {{
289
- SiteName : c .String ("site" ),
290
- CityName : c .String ("city" ),
291
- CountryCodes : cliutils .GetStringsArrFlagValue (c , "country-codes" ),
292
- }},
293
- }
294
- }
295
-
296
270
func createReleaseBundleCreateUpdateParams (c * cli.Context , bundleName , bundleVersion string ) (distributionServicesUtils.ReleaseBundleParams , error ) {
297
271
releaseBundleParams := distributionServicesUtils .NewReleaseBundleParams (bundleName , bundleVersion )
298
272
releaseBundleParams .SignImmediately = c .Bool ("sign" )
@@ -336,13 +310,13 @@ func populateReleaseNotesSyntax(c *cli.Context) (distributionServicesUtils.Relea
336
310
return distributionServicesUtils .PlainText , nil
337
311
}
338
312
339
- func createArtifactoryDetailsByFlags (c * cli.Context ) (* coreConfig.ServerDetails , error ) {
340
- artDetails , err := cliutils .CreateServerDetailsWithConfigOffer (c , true , cliutils .Ds )
313
+ func createDistributionDetailsByFlags (c * cli.Context ) (* coreConfig.ServerDetails , error ) {
314
+ dsDetails , err := cliutils .CreateServerDetailsWithConfigOffer (c , true , cliutils .Ds )
341
315
if err != nil {
342
316
return nil , err
343
317
}
344
- if artDetails .DistributionUrl == "" {
318
+ if dsDetails .DistributionUrl == "" {
345
319
return nil , errors .New ("the --dist-url option is mandatory" )
346
320
}
347
- return artDetails , nil
321
+ return dsDetails , nil
348
322
}
0 commit comments