@@ -12,6 +12,7 @@ import (
1212
1313 "github.com/ovh/cds/cli"
1414 "github.com/ovh/cds/sdk"
15+ "github.com/ovh/cds/sdk/cdsclient"
1516 "github.com/ovh/cds/sdk/exportentities"
1617)
1718
@@ -387,6 +388,8 @@ func templateBulkRun(v cli.Values) error {
387388 mprojects [wti .Project .Key ] = wti .Project
388389 }
389390 projectRepositories := make (map [string ][]string )
391+ projectSSHKeys := make (map [string ][]string )
392+ projectPGPKeys := make (map [string ][]string )
390393
391394 for operationKey , operation := range moperations {
392395 // check if some params are missing for current operation
@@ -400,14 +403,14 @@ func templateBulkRun(v cli.Values) error {
400403
401404 if paramMissing {
402405 // 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 () )
405408 if err != nil {
406409 return err
407410 }
408411 mprojects [p .Key ] = p
409412 }
410- project := mprojects [operationKey ]
413+ project := mprojects [operation . Request . ProjectKey ]
411414
412415 // for each param not already in previous request ask for the value
413416 for _ , p := range wt .Parameters {
@@ -416,40 +419,62 @@ func templateBulkRun(v cli.Values) error {
416419
417420 var value string
418421 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+ }
426436 }
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+ }
430457 }
458+ projectPGPKeys [project .Key ] = pgpKeys
431459 }
460+ options = projectPGPKeys [project .Key ]
432461 }
433462
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 {
441466 return err
442467 }
443- } else if lengthRepo == 1 {
468+ } else if len ( options ) == 1 {
444469 var result bool
445470 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 ),
447472 Default : true ,
448473 }, & result , nil ); err != nil {
449474 return err
450475 }
451476 if result {
452- value = projectRepositories [ project . Key ] [0 ]
477+ value = options [0 ]
453478 }
454479 }
455480 if value == "" {
0 commit comments