File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed
internal/namespaces/iam/v1alpha1 Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change 4
4
"context"
5
5
6
6
"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"
7
9
)
8
10
9
11
func GetCommands () * core.Commands {
@@ -21,6 +23,27 @@ func GetCommands() *core.Commands {
21
23
cmds .MustFind (commandPath ... ).Override (setOrganizationDefaultValue )
22
24
}
23
25
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
+
24
47
return cmds
25
48
}
26
49
You can’t perform that action at this time.
0 commit comments