-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(iam): set organization ID filter on listing commands (#2469)
- Loading branch information
1 parent
825cb7d
commit 3c23c88
Showing
2 changed files
with
28 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,33 @@ | ||
package iam | ||
|
||
import "github.com/scaleway/scaleway-cli/v2/internal/core" | ||
import ( | ||
"context" | ||
|
||
"github.com/scaleway/scaleway-cli/v2/internal/core" | ||
) | ||
|
||
func GetCommands() *core.Commands { | ||
cmds := GetGeneratedCommands() | ||
|
||
// These commands have an "optional" organization-id that is required for now. | ||
for _, commandPath := range [][]string{ | ||
{"iam", "group", "list"}, | ||
{"iam", "api-key", "list"}, | ||
{"iam", "ssh-key", "list"}, | ||
{"iam", "user", "list"}, | ||
{"iam", "policy", "list"}, | ||
{"iam", "application", "list"}, | ||
} { | ||
cmds.MustFind(commandPath...).Override(setOrganizationDefaultValue) | ||
} | ||
|
||
return cmds | ||
} | ||
|
||
func setOrganizationDefaultValue(c *core.Command) *core.Command { | ||
c.ArgSpecs.GetByName("organization-id").Default = func(ctx context.Context) (value string, doc string) { | ||
organizationID := core.GetOrganizationIDFromContext(ctx) | ||
return organizationID, "<retrieved from config>" | ||
} | ||
return c | ||
} |