Skip to content

Commit e35e8c5

Browse files
feat(iam): auto-complete permission-set names (#2472)
1 parent 3c23c88 commit e35e8c5

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

internal/namespaces/iam/v1alpha1/custom.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
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

911
func 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

0 commit comments

Comments
 (0)