Skip to content

Commit 3c23c88

Browse files
fix(iam): set organization ID filter on listing commands (#2469)
1 parent 825cb7d commit 3c23c88

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

Diff for: internal/core/context.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,13 @@ func ExtractCommands(ctx context.Context) *Commands {
5353
return extractMeta(ctx).Commands
5454
}
5555

56-
func GetOrganizationIDFromContext(ctx context.Context) (organizationID string) {
56+
func GetOrganizationIDFromContext(ctx context.Context) string {
5757
client := ExtractClient(ctx)
58-
organizationID, exists := client.GetDefaultOrganizationID()
59-
if !exists {
60-
panic("no default organization ID found")
61-
}
58+
organizationID, _ := client.GetDefaultOrganizationID()
6259
return organizationID
6360
}
6461

65-
func GetProjectIDFromContext(ctx context.Context) (projectID string) {
62+
func GetProjectIDFromContext(ctx context.Context) string {
6663
client := ExtractClient(ctx)
6764
projectID, exists := client.GetDefaultProjectID()
6865
if !exists {

Diff for: internal/namespaces/iam/v1alpha1/custom.go

+25-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,33 @@
11
package iam
22

3-
import "github.com/scaleway/scaleway-cli/v2/internal/core"
3+
import (
4+
"context"
5+
6+
"github.com/scaleway/scaleway-cli/v2/internal/core"
7+
)
48

59
func GetCommands() *core.Commands {
610
cmds := GetGeneratedCommands()
711

12+
// These commands have an "optional" organization-id that is required for now.
13+
for _, commandPath := range [][]string{
14+
{"iam", "group", "list"},
15+
{"iam", "api-key", "list"},
16+
{"iam", "ssh-key", "list"},
17+
{"iam", "user", "list"},
18+
{"iam", "policy", "list"},
19+
{"iam", "application", "list"},
20+
} {
21+
cmds.MustFind(commandPath...).Override(setOrganizationDefaultValue)
22+
}
23+
824
return cmds
925
}
26+
27+
func setOrganizationDefaultValue(c *core.Command) *core.Command {
28+
c.ArgSpecs.GetByName("organization-id").Default = func(ctx context.Context) (value string, doc string) {
29+
organizationID := core.GetOrganizationIDFromContext(ctx)
30+
return organizationID, "<retrieved from config>"
31+
}
32+
return c
33+
}

0 commit comments

Comments
 (0)