Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/stackit_organization.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ stackit organization [flags]
### SEE ALSO

* [stackit](./stackit.md) - Manage STACKIT resources using the command line
* [stackit organization describe](./stackit_organization_describe.md) - Show a organization
* [stackit organization list](./stackit_organization_list.md) - Lists all organizations
* [stackit organization member](./stackit_organization_member.md) - Manages organization members
* [stackit organization role](./stackit_organization_role.md) - Manages organization roles

43 changes: 43 additions & 0 deletions docs/stackit_organization_describe.md
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

44 changes: 44 additions & 0 deletions docs/stackit_organization_list.md
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

119 changes: 119 additions & 0 deletions internal/cmd/organization/describe/describe.go
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",
Comment thread
Manuelvaas marked this conversation as resolved.
Outdated
Long: "Show a organization.",
Comment thread
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
})
}
Loading
Loading