Skip to content

Commit 2fcc3e0

Browse files
feat(scf): onboard scf platform describe/list and scf platform quota describe/list
Relates to STACKITCLI-484
1 parent 33ab07e commit 2fcc3e0

18 files changed

Lines changed: 1713 additions & 0 deletions

‎docs/stackit_beta_scf.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@ stackit beta scf [flags]
3131

3232
* [stackit beta](./stackit_beta.md) - Contains beta STACKIT CLI commands
3333
* [stackit beta scf organization](./stackit_beta_scf_organization.md) - Provides functionality for STACKIT Cloud Foundry organizations
34+
* [stackit beta scf platform](./stackit_beta_scf_platform.md) - Provides functionality for STACKIT Cloud Foundry platforms
3435

‎docs/stackit_beta_scf_platform.md‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
## stackit beta scf platform
2+
3+
Provides functionality for STACKIT Cloud Foundry platforms
4+
5+
### Synopsis
6+
7+
Provides functionality for STACKIT Cloud Foundry platforms.
8+
9+
```
10+
stackit beta scf platform [flags]
11+
```
12+
13+
### Options
14+
15+
```
16+
-h, --help Help for "stackit beta scf platform"
17+
```
18+
19+
### Options inherited from parent commands
20+
21+
```
22+
-y, --assume-yes If set, skips all confirmation prompts
23+
--async If set, runs the command asynchronously
24+
-o, --output-format string Output format, (one of: [json, pretty, none, yaml])
25+
-p, --project-id string Project ID
26+
--region string Target region for region-specific requests
27+
--verbosity string Verbosity of the CLI, (one of: [debug, info, warning, error]) (default "info")
28+
```
29+
30+
### SEE ALSO
31+
32+
* [stackit beta scf](./stackit_beta_scf.md) - Provides functionality for STACKIT Cloud Foundry
33+
* [stackit beta scf platform describe](./stackit_beta_scf_platform_describe.md) - Shows details of a STACKIT Cloud Foundry platform
34+
* [stackit beta scf platform list](./stackit_beta_scf_platform_list.md) - Lists all STACKIT Cloud Foundry platforms
35+
* [stackit beta scf platform quota](./stackit_beta_scf_platform_quota.md) - Shows quotas of STACKIT Cloud Foundry platforms
36+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
## stackit beta scf platform describe
2+
3+
Shows details of a STACKIT Cloud Foundry platform
4+
5+
### Synopsis
6+
7+
Shows details of a STACKIT Cloud Foundry platform.
8+
9+
```
10+
stackit beta scf platform describe PLATFORM_ID [flags]
11+
```
12+
13+
### Examples
14+
15+
```
16+
Get details of a STACKIT Cloud Foundry platform with ID "xxx"
17+
$ stackit beta scf platform describe xxx
18+
19+
Get details of a STACKIT Cloud Foundry platform with ID "xxx" in JSON format
20+
$ stackit beta scf platform describe xxx --output-format json
21+
```
22+
23+
### Options
24+
25+
```
26+
-h, --help Help for "stackit beta scf platform describe"
27+
```
28+
29+
### Options inherited from parent commands
30+
31+
```
32+
-y, --assume-yes If set, skips all confirmation prompts
33+
--async If set, runs the command asynchronously
34+
-o, --output-format string Output format, (one of: [json, pretty, none, yaml])
35+
-p, --project-id string Project ID
36+
--region string Target region for region-specific requests
37+
--verbosity string Verbosity of the CLI, (one of: [debug, info, warning, error]) (default "info")
38+
```
39+
40+
### SEE ALSO
41+
42+
* [stackit beta scf platform](./stackit_beta_scf_platform.md) - Provides functionality for STACKIT Cloud Foundry platforms
43+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
## stackit beta scf platform list
2+
3+
Lists all STACKIT Cloud Foundry platforms
4+
5+
### Synopsis
6+
7+
Lists all STACKIT Cloud Foundry platforms. The number of fetched platforms is limited to 5000.
8+
9+
```
10+
stackit beta scf platform list [flags]
11+
```
12+
13+
### Examples
14+
15+
```
16+
List all STACKIT Cloud Foundry platforms
17+
$ stackit beta scf platform list
18+
19+
List up to 10 STACKIT Cloud Foundry platforms
20+
$ stackit beta scf platform list --limit 10
21+
```
22+
23+
### Options
24+
25+
```
26+
-h, --help Help for "stackit beta scf platform list"
27+
--limit int Maximum number of entries to list
28+
```
29+
30+
### Options inherited from parent commands
31+
32+
```
33+
-y, --assume-yes If set, skips all confirmation prompts
34+
--async If set, runs the command asynchronously
35+
-o, --output-format string Output format, (one of: [json, pretty, none, yaml])
36+
-p, --project-id string Project ID
37+
--region string Target region for region-specific requests
38+
--verbosity string Verbosity of the CLI, (one of: [debug, info, warning, error]) (default "info")
39+
```
40+
41+
### SEE ALSO
42+
43+
* [stackit beta scf platform](./stackit_beta_scf_platform.md) - Provides functionality for STACKIT Cloud Foundry platforms
44+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
## stackit beta scf platform quota
2+
3+
Shows quotas of STACKIT Cloud Foundry platforms
4+
5+
### Synopsis
6+
7+
Shows quotas of STACKIT Cloud Foundry platforms.
8+
9+
```
10+
stackit beta scf platform quota [flags]
11+
```
12+
13+
### Options
14+
15+
```
16+
-h, --help Help for "stackit beta scf platform quota"
17+
```
18+
19+
### Options inherited from parent commands
20+
21+
```
22+
-y, --assume-yes If set, skips all confirmation prompts
23+
--async If set, runs the command asynchronously
24+
-o, --output-format string Output format, (one of: [json, pretty, none, yaml])
25+
-p, --project-id string Project ID
26+
--region string Target region for region-specific requests
27+
--verbosity string Verbosity of the CLI, (one of: [debug, info, warning, error]) (default "info")
28+
```
29+
30+
### SEE ALSO
31+
32+
* [stackit beta scf platform](./stackit_beta_scf_platform.md) - Provides functionality for STACKIT Cloud Foundry platforms
33+
* [stackit beta scf platform quota describe](./stackit_beta_scf_platform_quota_describe.md) - Shows details of a STACKIT Cloud Foundry platform quota
34+
* [stackit beta scf platform quota list](./stackit_beta_scf_platform_quota_list.md) - Lists the quotas of a STACKIT Cloud Foundry platform
35+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
## stackit beta scf platform quota describe
2+
3+
Shows details of a STACKIT Cloud Foundry platform quota
4+
5+
### Synopsis
6+
7+
Shows details of a STACKIT Cloud Foundry platform quota. A value of "unlimited" means no limit is set.
8+
9+
```
10+
stackit beta scf platform quota describe PLATFORM_ID [flags]
11+
```
12+
13+
### Examples
14+
15+
```
16+
Get details of the quota with ID "yyy" of a STACKIT Cloud Foundry platform with ID "xxx"
17+
$ stackit beta scf platform quota describe xxx --quota-id yyy
18+
19+
Get details of the quota with ID "yyy" of a STACKIT Cloud Foundry platform with ID "xxx" in JSON format
20+
$ stackit beta scf platform quota describe xxx --quota-id yyy --output-format json
21+
```
22+
23+
### Options
24+
25+
```
26+
-h, --help Help for "stackit beta scf platform quota describe"
27+
--quota-id string The UUID of the quota
28+
```
29+
30+
### Options inherited from parent commands
31+
32+
```
33+
-y, --assume-yes If set, skips all confirmation prompts
34+
--async If set, runs the command asynchronously
35+
-o, --output-format string Output format, (one of: [json, pretty, none, yaml])
36+
-p, --project-id string Project ID
37+
--region string Target region for region-specific requests
38+
--verbosity string Verbosity of the CLI, (one of: [debug, info, warning, error]) (default "info")
39+
```
40+
41+
### SEE ALSO
42+
43+
* [stackit beta scf platform quota](./stackit_beta_scf_platform_quota.md) - Shows quotas of STACKIT Cloud Foundry platforms
44+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
## stackit beta scf platform quota list
2+
3+
Lists the quotas of a STACKIT Cloud Foundry platform
4+
5+
### Synopsis
6+
7+
Lists the quotas of a STACKIT Cloud Foundry platform.
8+
9+
```
10+
stackit beta scf platform quota list PLATFORM_ID [flags]
11+
```
12+
13+
### Examples
14+
15+
```
16+
List the quotas of a STACKIT Cloud Foundry platform with ID "xxx"
17+
$ stackit beta scf platform quota list xxx
18+
19+
List the quotas of a STACKIT Cloud Foundry platform with ID "xxx" in JSON format
20+
$ stackit beta scf platform quota list xxx --output-format json
21+
```
22+
23+
### Options
24+
25+
```
26+
-h, --help Help for "stackit beta scf platform quota list"
27+
```
28+
29+
### Options inherited from parent commands
30+
31+
```
32+
-y, --assume-yes If set, skips all confirmation prompts
33+
--async If set, runs the command asynchronously
34+
-o, --output-format string Output format, (one of: [json, pretty, none, yaml])
35+
-p, --project-id string Project ID
36+
--region string Target region for region-specific requests
37+
--verbosity string Verbosity of the CLI, (one of: [debug, info, warning, error]) (default "info")
38+
```
39+
40+
### SEE ALSO
41+
42+
* [stackit beta scf platform quota](./stackit_beta_scf_platform_quota.md) - Shows quotas of STACKIT Cloud Foundry platforms
43+
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
package describe
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/spf13/cobra"
8+
scf "github.com/stackitcloud/stackit-sdk-go/services/scf/v1api"
9+
10+
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
11+
cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors"
12+
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
13+
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
14+
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
15+
"github.com/stackitcloud/stackit-cli/internal/pkg/services/scf/client"
16+
"github.com/stackitcloud/stackit-cli/internal/pkg/tables"
17+
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
18+
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
19+
)
20+
21+
const (
22+
platformIdArg = "PLATFORM_ID"
23+
)
24+
25+
type inputModel struct {
26+
*globalflags.GlobalFlagModel
27+
PlatformId string
28+
}
29+
30+
func NewCmd(p *types.CmdParams) *cobra.Command {
31+
cmd := &cobra.Command{
32+
Use: fmt.Sprintf("describe %s", platformIdArg),
33+
Short: "Shows details of a STACKIT Cloud Foundry platform",
34+
Long: "Shows details of a STACKIT Cloud Foundry platform.",
35+
Args: args.SingleArg(platformIdArg, utils.ValidateUUID),
36+
Example: examples.Build(
37+
examples.NewExample(
38+
`Get details of a STACKIT Cloud Foundry platform with ID "xxx"`,
39+
`$ stackit beta scf platform describe xxx`),
40+
examples.NewExample(
41+
`Get details of a STACKIT Cloud Foundry platform with ID "xxx" in JSON format`,
42+
`$ stackit beta scf platform describe xxx --output-format json`),
43+
),
44+
RunE: func(cmd *cobra.Command, args []string) error {
45+
ctx := context.Background()
46+
model, err := parseInput(p.Printer, cmd, args)
47+
if err != nil {
48+
return err
49+
}
50+
51+
// Configure API client
52+
apiClient, err := client.ConfigureClient(p.Printer, p.CliVersion)
53+
if err != nil {
54+
return err
55+
}
56+
57+
// Call API
58+
req := buildRequest(ctx, model, apiClient.DefaultAPI)
59+
resp, err := req.Execute()
60+
if err != nil {
61+
return fmt.Errorf("get STACKIT Cloud Foundry platform: %w", err)
62+
}
63+
64+
return outputResult(p.Printer, model.OutputFormat, resp)
65+
},
66+
}
67+
return cmd
68+
}
69+
70+
func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inputModel, error) {
71+
platformId := inputArgs[0]
72+
73+
globalFlags := globalflags.Parse(p, cmd)
74+
if globalFlags.ProjectId == "" {
75+
return nil, &cliErr.ProjectIdError{}
76+
}
77+
78+
model := inputModel{
79+
GlobalFlagModel: globalFlags,
80+
PlatformId: platformId,
81+
}
82+
83+
p.DebugInputModel(model)
84+
return &model, nil
85+
}
86+
87+
func buildRequest(ctx context.Context, model *inputModel, apiClient scf.DefaultAPI) scf.ApiGetPlatformRequest {
88+
return apiClient.GetPlatform(ctx, model.ProjectId, model.Region, model.PlatformId)
89+
}
90+
91+
func outputResult(p *print.Printer, outputFormat string, platform *scf.Platforms) error {
92+
return p.OutputResult(outputFormat, platform, func() error {
93+
if platform == nil {
94+
return fmt.Errorf("received nil response, could not display details")
95+
}
96+
97+
table := tables.NewTable()
98+
table.SetHeader("Attribute", "Value")
99+
100+
table.AddRow("ID", platform.GetGuid())
101+
table.AddRow("Name", platform.GetDisplayName())
102+
table.AddRow("System ID", platform.GetSystemId())
103+
table.AddRow("Region", platform.GetRegion())
104+
table.AddRow("API URL", platform.GetApiUrl())
105+
table.AddRow("Console URL", utils.PtrString(platform.ConsoleUrl))
106+
107+
err := table.Display(p)
108+
if err != nil {
109+
return fmt.Errorf("render table: %w", err)
110+
}
111+
112+
return nil
113+
})
114+
}

0 commit comments

Comments
 (0)