@@ -12,6 +12,7 @@ import (
12
12
13
13
"github.com/ovh/cds/cli"
14
14
"github.com/ovh/cds/sdk"
15
+ "github.com/ovh/cds/sdk/cdsclient"
15
16
"github.com/ovh/cds/sdk/exportentities"
16
17
)
17
18
@@ -387,6 +388,8 @@ func templateBulkRun(v cli.Values) error {
387
388
mprojects [wti .Project .Key ] = wti .Project
388
389
}
389
390
projectRepositories := make (map [string ][]string )
391
+ projectSSHKeys := make (map [string ][]string )
392
+ projectPGPKeys := make (map [string ][]string )
390
393
391
394
for operationKey , operation := range moperations {
392
395
// check if some params are missing for current operation
@@ -400,14 +403,14 @@ func templateBulkRun(v cli.Values) error {
400
403
401
404
if paramMissing {
402
405
// get project from map if exists else from api
403
- if _ , ok := mprojects [operationKey ]; ! ok {
404
- p , err := client .ProjectGet (operation .Request .ProjectKey )
406
+ if _ , ok := mprojects [operation . Request . ProjectKey ]; ! ok {
407
+ p , err := client .ProjectGet (operation .Request .ProjectKey , cdsclient . WithKeys () )
405
408
if err != nil {
406
409
return err
407
410
}
408
411
mprojects [p .Key ] = p
409
412
}
410
- project := mprojects [operationKey ]
413
+ project := mprojects [operation . Request . ProjectKey ]
411
414
412
415
// for each param not already in previous request ask for the value
413
416
for _ , p := range wt .Parameters {
@@ -416,40 +419,62 @@ func templateBulkRun(v cli.Values) error {
416
419
417
420
var value string
418
421
switch p .Type {
419
- case sdk .ParameterTypeRepository :
420
- // get the project and its repositories if not already loaded
421
- if _ , ok := projectRepositories [project .Key ]; ! ok {
422
- for _ , vcs := range project .VCSServers {
423
- rs , err := client .RepositoriesList (project .Key , vcs .Name , false )
424
- if err != nil {
425
- return err
422
+ case sdk .ParameterTypeRepository , sdk .ParameterTypeSSHKey , sdk .ParameterTypePGPKey :
423
+ var options []string
424
+ if p .Type == sdk .ParameterTypeRepository {
425
+ // get the project and its repositories if not already loaded
426
+ if _ , ok := projectRepositories [project .Key ]; ! ok {
427
+ for _ , vcs := range project .VCSServers {
428
+ rs , err := client .RepositoriesList (project .Key , vcs .Name , false )
429
+ if err != nil {
430
+ return err
431
+ }
432
+ for _ , r := range rs {
433
+ projectRepositories [project .Key ] = append (projectRepositories [project .Key ],
434
+ fmt .Sprintf ("%s/%s" , vcs .Name , r .Slug ))
435
+ }
426
436
}
427
- for _ , r := range rs {
428
- projectRepositories [project .Key ] = append (projectRepositories [project .Key ],
429
- fmt .Sprintf ("%s/%s" , vcs .Name , r .Slug ))
437
+ }
438
+ options = projectRepositories [project .Key ]
439
+ } else if p .Type == sdk .ParameterTypeSSHKey {
440
+ if _ , ok := projectSSHKeys [project .Key ]; ! ok {
441
+ var sshKeys []string
442
+ for _ , k := range project .Keys {
443
+ if k .Type == sdk .KeyTypeSSH {
444
+ sshKeys = append (sshKeys , k .Name )
445
+ }
446
+ }
447
+ projectSSHKeys [project .Key ] = sshKeys
448
+ }
449
+ options = projectSSHKeys [project .Key ]
450
+ } else if p .Type == sdk .ParameterTypePGPKey {
451
+ if _ , ok := projectPGPKeys [project .Key ]; ! ok {
452
+ var pgpKeys []string
453
+ for _ , k := range project .Keys {
454
+ if k .Type == sdk .KeyTypePGP {
455
+ pgpKeys = append (pgpKeys , k .Name )
456
+ }
430
457
}
458
+ projectPGPKeys [project .Key ] = pgpKeys
431
459
}
460
+ options = projectPGPKeys [project .Key ]
432
461
}
433
462
434
- // ask to choose a repository, if only one ask to, if no repo found ask for value
435
- lengthRepo := len (projectRepositories [project .Key ])
436
- if lengthRepo > 1 {
437
- if err := survey .AskOne (& survey.Select {
438
- Message : label ,
439
- Options : projectRepositories [project .Key ],
440
- }, & value , nil ); err != nil {
463
+ // ask to choose an option, if only one ask to, if no options found ask for value
464
+ if len (options ) > 1 {
465
+ if err := survey .AskOne (& survey.Select {Message : label , Options : options }, & value , nil ); err != nil {
441
466
return err
442
467
}
443
- } else if lengthRepo == 1 {
468
+ } else if len ( options ) == 1 {
444
469
var result bool
445
470
if err := survey .AskOne (& survey.Confirm {
446
- Message : fmt .Sprintf ("Set value to '%s' for param '%s' on '%s'" , projectRepositories [ project . Key ] [0 ], p .Key , operationKey ),
471
+ Message : fmt .Sprintf ("Set value to '%s' for param '%s' on '%s'" , options [0 ], p .Key , operationKey ),
447
472
Default : true ,
448
473
}, & result , nil ); err != nil {
449
474
return err
450
475
}
451
476
if result {
452
- value = projectRepositories [ project . Key ] [0 ]
477
+ value = options [0 ]
453
478
}
454
479
}
455
480
if value == "" {
0 commit comments