File tree Expand file tree Collapse file tree
internal/namespaces/iam/v1alpha1 Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44 "context"
55
66 "github.com/scaleway/scaleway-cli/v2/internal/core"
7+ iam "github.com/scaleway/scaleway-sdk-go/api/iam/v1alpha1"
8+ "github.com/scaleway/scaleway-sdk-go/scw"
79)
810
911func GetCommands () * core.Commands {
@@ -21,6 +23,27 @@ func GetCommands() *core.Commands {
2123 cmds .MustFind (commandPath ... ).Override (setOrganizationDefaultValue )
2224 }
2325
26+ // Autocomplete permission set names using IAM API.
27+ cmds .MustFind ("iam" , "policy" , "create" ).Override (func (c * core.Command ) * core.Command {
28+ c .ArgSpecs .GetByName ("rules.{index}.permission-set-names.{index}" ).AutoCompleteFunc = func (ctx context.Context , prefix string ) core.AutocompleteSuggestions {
29+ client := core .ExtractClient (ctx )
30+ api := iam .NewAPI (client )
31+ // TODO: store result in a CLI cache
32+ resp , err := api .ListPermissionSets (& iam.ListPermissionSetsRequest {
33+ PageSize : scw .Uint32Ptr (100 ),
34+ }, scw .WithAllPages ())
35+ if err != nil {
36+ return nil
37+ }
38+ suggestions := core.AutocompleteSuggestions {}
39+ for _ , ps := range resp .PermissionSets {
40+ suggestions = append (suggestions , ps .Name )
41+ }
42+ return suggestions
43+ }
44+ return c
45+ })
46+
2447 return cmds
2548}
2649
You can’t perform that action at this time.
0 commit comments