-
Notifications
You must be signed in to change notification settings - Fork 39
feat(resourcemanager): List and describe organizations #1312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9103656
feat(resourcemanager): List and describe organizations
Manuelvaas f4cc9c2
generated docs
Manuelvaas 5bf48d0
changed to outputf
Manuelvaas 52ddff8
table.render -> table.display
Manuelvaas ffd1351
updated examples
Manuelvaas c6a020c
select current profile and not default
Manuelvaas f7884d2
Update internal/cmd/organization/describe/describe.go
Manuelvaas b8dcb26
Update internal/cmd/organization/describe/describe.go
Manuelvaas c0177f3
generated docs
Manuelvaas 0e5218e
check that limit is maximum 100
Manuelvaas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| ## stackit organization describe | ||
|
|
||
| Show a organization | ||
|
|
||
| ### Synopsis | ||
|
|
||
| Show a organization. | ||
|
|
||
| ``` | ||
| stackit organization describe [flags] | ||
| ``` | ||
|
|
||
| ### Examples | ||
|
|
||
| ``` | ||
| Describe the organization with the organization uuid "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" | ||
| $ stackit organization describe xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx | ||
|
|
||
| Describe the organization with the container id "foo-bar-organization" | ||
| $ stackit organization describe foo-bar-organization | ||
| ``` | ||
|
|
||
| ### Options | ||
|
|
||
| ``` | ||
| -h, --help Help for "stackit organization describe" | ||
| ``` | ||
|
|
||
| ### Options inherited from parent commands | ||
|
|
||
| ``` | ||
| -y, --assume-yes If set, skips all confirmation prompts | ||
| --async If set, runs the command asynchronously | ||
| -o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"] | ||
| -p, --project-id string Project ID | ||
| --region string Target region for region-specific requests | ||
| --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") | ||
| ``` | ||
|
|
||
| ### SEE ALSO | ||
|
|
||
| * [stackit organization](./stackit_organization.md) - Manages organizations | ||
|
|
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| ## stackit organization list | ||
|
|
||
| Lists all organizations | ||
|
|
||
| ### Synopsis | ||
|
|
||
| Lists all organizations. | ||
|
|
||
| ``` | ||
| stackit organization list [flags] | ||
| ``` | ||
|
|
||
| ### Examples | ||
|
|
||
| ``` | ||
| Lists organizations for your user | ||
| $ stackit organization list | ||
|
|
||
| Lists the first 10 organizations | ||
| $ stackit organization list --limit 10 | ||
| ``` | ||
|
|
||
| ### Options | ||
|
|
||
| ``` | ||
| -h, --help Help for "stackit organization list" | ||
| --limit int Maximum number of entries to list (default 50) | ||
| ``` | ||
|
|
||
| ### Options inherited from parent commands | ||
|
|
||
| ``` | ||
| -y, --assume-yes If set, skips all confirmation prompts | ||
| --async If set, runs the command asynchronously | ||
| -o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"] | ||
| -p, --project-id string Project ID | ||
| --region string Target region for region-specific requests | ||
| --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") | ||
| ``` | ||
|
|
||
| ### SEE ALSO | ||
|
|
||
| * [stackit organization](./stackit_organization.md) - Manages organizations | ||
|
|
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| package describe | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| "github.com/stackitcloud/stackit-cli/internal/pkg/types" | ||
|
|
||
| "github.com/spf13/cobra" | ||
| "github.com/stackitcloud/stackit-cli/internal/pkg/args" | ||
| "github.com/stackitcloud/stackit-cli/internal/pkg/examples" | ||
| "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" | ||
| "github.com/stackitcloud/stackit-cli/internal/pkg/print" | ||
| "github.com/stackitcloud/stackit-cli/internal/pkg/services/resourcemanager/client" | ||
| "github.com/stackitcloud/stackit-cli/internal/pkg/tables" | ||
| "github.com/stackitcloud/stackit-cli/internal/pkg/utils" | ||
| "github.com/stackitcloud/stackit-sdk-go/services/resourcemanager" | ||
| ) | ||
|
|
||
| const ( | ||
| organizationIdArg = "ORGANIZATION_ID" | ||
| ) | ||
|
|
||
| type inputModel struct { | ||
| *globalflags.GlobalFlagModel | ||
| OrganizationId string | ||
| } | ||
|
|
||
| func NewCmd(params *types.CmdParams) *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "describe", | ||
| Short: "Show a organization", | ||
| Long: "Show a organization.", | ||
|
Manuelvaas marked this conversation as resolved.
Outdated
|
||
| // the arg can be the organization uuid or the container id, which is not a uuid, so no validation needed | ||
| Args: args.SingleArg(organizationIdArg, nil), | ||
| Example: examples.Build( | ||
| examples.NewExample( | ||
| `Describe the organization with the organization uuid "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"`, | ||
| "$ stackit organization describe xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", | ||
| ), | ||
| examples.NewExample( | ||
| `Describe the organization with the container id "foo-bar-organization"`, | ||
| "$ stackit organization describe foo-bar-organization", | ||
| ), | ||
| ), | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| ctx := context.Background() | ||
| model, err := parseInput(params.Printer, cmd, args) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // Configure API client | ||
| apiClient, err := client.ConfigureClient(params.Printer, params.CliVersion) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // Call API | ||
| req := buildRequest(ctx, model, apiClient) | ||
| resp, err := req.Execute() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return outputResult(params.Printer, model.OutputFormat, resp) | ||
| }, | ||
| } | ||
| return cmd | ||
| } | ||
|
|
||
| func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inputModel, error) { | ||
| organizationId := inputArgs[0] | ||
| globalFlags := globalflags.Parse(p, cmd) | ||
|
|
||
| model := inputModel{ | ||
| GlobalFlagModel: globalFlags, | ||
| OrganizationId: organizationId, | ||
| } | ||
|
|
||
| p.DebugInputModel(model) | ||
| return &model, nil | ||
| } | ||
|
|
||
| func buildRequest(ctx context.Context, model *inputModel, apiClient *resourcemanager.APIClient) resourcemanager.ApiGetOrganizationRequest { | ||
| req := apiClient.GetOrganization(ctx, model.OrganizationId) | ||
| return req | ||
| } | ||
|
|
||
| func outputResult(p *print.Printer, outputFormat string, organization *resourcemanager.OrganizationResponse) error { | ||
| return p.OutputResult(outputFormat, organization, func() error { | ||
| if organization == nil { | ||
| p.Outputln("show organization: empty response") | ||
| return nil | ||
| } | ||
|
|
||
| table := tables.NewTable() | ||
|
|
||
| table.AddRow("ORGANIZATION ID", utils.PtrString(organization.OrganizationId)) | ||
| table.AddSeparator() | ||
| table.AddRow("NAME", utils.PtrString(organization.Name)) | ||
| table.AddSeparator() | ||
| table.AddRow("CONTAINER ID", utils.PtrString(organization.ContainerId)) | ||
| table.AddSeparator() | ||
| table.AddRow("STATUS", utils.PtrString(organization.LifecycleState)) | ||
| table.AddSeparator() | ||
| table.AddRow("CREATION TIME", utils.PtrString(organization.CreationTime)) | ||
| table.AddSeparator() | ||
| table.AddRow("UPDATE TIME", utils.PtrString(organization.UpdateTime)) | ||
| table.AddSeparator() | ||
| table.AddRow("LABELS", utils.JoinStringMap(utils.PtrValue(organization.Labels), ": ", ", ")) | ||
|
|
||
| err := table.Display(p) | ||
| if err != nil { | ||
| return fmt.Errorf("render table: %w", err) | ||
| } | ||
| return nil | ||
| }) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.