Skip to content

Commit

Permalink
feat(iam): auto-complete permission-set names (#2472)
Browse files Browse the repository at this point in the history
  • Loading branch information
kindermoumoute authored Aug 25, 2022
1 parent 3c23c88 commit e35e8c5
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions internal/namespaces/iam/v1alpha1/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"

"github.com/scaleway/scaleway-cli/v2/internal/core"
iam "github.com/scaleway/scaleway-sdk-go/api/iam/v1alpha1"
"github.com/scaleway/scaleway-sdk-go/scw"
)

func GetCommands() *core.Commands {
Expand All @@ -21,6 +23,27 @@ func GetCommands() *core.Commands {
cmds.MustFind(commandPath...).Override(setOrganizationDefaultValue)
}

// Autocomplete permission set names using IAM API.
cmds.MustFind("iam", "policy", "create").Override(func(c *core.Command) *core.Command {
c.ArgSpecs.GetByName("rules.{index}.permission-set-names.{index}").AutoCompleteFunc = func(ctx context.Context, prefix string) core.AutocompleteSuggestions {
client := core.ExtractClient(ctx)
api := iam.NewAPI(client)
// TODO: store result in a CLI cache
resp, err := api.ListPermissionSets(&iam.ListPermissionSetsRequest{
PageSize: scw.Uint32Ptr(100),
}, scw.WithAllPages())
if err != nil {
return nil
}
suggestions := core.AutocompleteSuggestions{}
for _, ps := range resp.PermissionSets {
suggestions = append(suggestions, ps.Name)
}
return suggestions
}
return c
})

return cmds
}

Expand Down

0 comments on commit e35e8c5

Please sign in to comment.