Skip to content

Commit accbc99

Browse files
committed
onboard folder (alpha)
1 parent bc4b561 commit accbc99

10 files changed

Lines changed: 1250 additions & 0 deletions

File tree

‎docs/stackit_alpha.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,6 @@ stackit alpha [flags]
4141
### SEE ALSO
4242

4343
* [stackit](./stackit.md) - Manage STACKIT resources using the command line
44+
* [stackit alpha folder](./stackit_alpha_folder.md) - Manages the lifecycle of folders.
4445
* [stackit alpha vpc](./stackit_alpha_vpc.md) - Manages vpcs
4546

‎docs/stackit_alpha_folder.md‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
## stackit alpha folder
2+
3+
Manages the lifecycle of folders.
4+
5+
### Synopsis
6+
7+
Manages the lifecycle of folders.
8+
A folder provides a structure for organizing projects within an organization.
9+
10+
```
11+
stackit alpha folder [flags]
12+
```
13+
14+
### Options
15+
16+
```
17+
-h, --help Help for "stackit alpha folder"
18+
```
19+
20+
### Options inherited from parent commands
21+
22+
```
23+
-y, --assume-yes If set, skips all confirmation prompts
24+
--async If set, runs the command asynchronously
25+
-o, --output-format string Output format, (one of: [json, pretty, none, yaml])
26+
-p, --project-id string Project ID
27+
--region string Target region for region-specific requests
28+
--verbosity string Verbosity of the CLI, (one of: [debug, info, warning, error]) (default "info")
29+
```
30+
31+
### SEE ALSO
32+
33+
* [stackit alpha](./stackit_alpha.md) - Contains alpha STACKIT CLI commands
34+
* [stackit alpha folder describe](./stackit_alpha_folder_describe.md) - Shows details of a STACKIT folder
35+
* [stackit alpha folder list](./stackit_alpha_folder_list.md) - Lists STACKIT folders
36+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
## stackit alpha folder describe
2+
3+
Shows details of a STACKIT folder
4+
5+
### Synopsis
6+
7+
Shows details of a STACKIT folder.
8+
9+
```
10+
stackit alpha folder describe [flags]
11+
```
12+
13+
### Examples
14+
15+
```
16+
Get the details of the configured STACKIT folder
17+
$ stackit folder describe
18+
19+
Get the details of a STACKIT folder by explicitly providing the container ID
20+
$ stackit folder describe xxx
21+
22+
Get the details of the configured STACKIT folder, including details of the parent resources
23+
$ stackit folder describe --include-parents
24+
```
25+
26+
### Options
27+
28+
```
29+
-h, --help Help for "stackit alpha folder describe"
30+
--include-parents When true, the details of the parent resources will be included in the output
31+
```
32+
33+
### Options inherited from parent commands
34+
35+
```
36+
-y, --assume-yes If set, skips all confirmation prompts
37+
--async If set, runs the command asynchronously
38+
-o, --output-format string Output format, (one of: [json, pretty, none, yaml])
39+
-p, --project-id string Project ID
40+
--region string Target region for region-specific requests
41+
--verbosity string Verbosity of the CLI, (one of: [debug, info, warning, error]) (default "info")
42+
```
43+
44+
### SEE ALSO
45+
46+
* [stackit alpha folder](./stackit_alpha_folder.md) - Manages the lifecycle of folders.
47+

‎docs/stackit_alpha_folder_list.md‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
## stackit alpha folder list
2+
3+
Lists STACKIT folders
4+
5+
### Synopsis
6+
7+
Lists all STACKIT folders that match certain criteria.
8+
9+
```
10+
stackit alpha folder list [flags]
11+
```
12+
13+
### Examples
14+
15+
```
16+
List all STACKIT folders that are children of the configured project
17+
$ stackit folder list
18+
19+
List all STACKIT folders that are children of a specific parent
20+
$ stackit folder list --parent-id xxx
21+
22+
List all STACKIT folders that match the given project IDs, located under the same parent resource
23+
$ stackit folder list --project-id-like xxx,yyy,zzz
24+
25+
List all STACKIT folders that a certain user is a member of
26+
$ stackit folder list --member [email protected]
27+
```
28+
29+
### Options
30+
31+
```
32+
--creation-time-after string Filter by creation timestamp, in a date-time with the RFC3339 layout format, e.g. 2023-01-01T00:00:00Z. The list of folders that were created after the given timestamp will be shown
33+
-h, --help Help for "stackit alpha folder list"
34+
--limit int Maximum number of entries to list
35+
--member string Filter by member. The list of folders of which the member is part of will be shown
36+
--page-size int Number of items fetched in each API call. Does not affect the number of items in the command output (default 50)
37+
--parent-id string Filter by parent identifier
38+
--project-id-like strings Filter by project identifier. Multiple project IDs can be provided, but they need to belong to the same parent resource (default [])
39+
```
40+
41+
### Options inherited from parent commands
42+
43+
```
44+
-y, --assume-yes If set, skips all confirmation prompts
45+
--async If set, runs the command asynchronously
46+
-o, --output-format string Output format, (one of: [json, pretty, none, yaml])
47+
-p, --project-id string Project ID
48+
--region string Target region for region-specific requests
49+
--verbosity string Verbosity of the CLI, (one of: [debug, info, warning, error]) (default "info")
50+
```
51+
52+
### SEE ALSO
53+
54+
* [stackit alpha folder](./stackit_alpha_folder.md) - Manages the lifecycle of folders.
55+

‎internal/cmd/alpha/alpha.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/spf13/cobra"
77

8+
"github.com/stackitcloud/stackit-cli/internal/cmd/alpha/folder"
89
"github.com/stackitcloud/stackit-cli/internal/cmd/alpha/vpc"
910
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
1011
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
@@ -35,5 +36,6 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
3536
}
3637

3738
func addSubcommands(cmd *cobra.Command, params *types.CmdParams) {
39+
cmd.AddCommand(folder.NewCmd(params))
3840
cmd.AddCommand(vpc.NewCmd(params))
3941
}
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
package describe
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
8+
9+
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
10+
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
11+
"github.com/stackitcloud/stackit-cli/internal/pkg/flags"
12+
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
13+
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
14+
"github.com/stackitcloud/stackit-cli/internal/pkg/services/resourcemanager/client"
15+
"github.com/stackitcloud/stackit-cli/internal/pkg/tables"
16+
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
17+
18+
"github.com/spf13/cobra"
19+
resourcemanager "github.com/stackitcloud/stackit-sdk-go/services/resourcemanager/v0api"
20+
)
21+
22+
const (
23+
includeParentsFlag = "include-parents"
24+
25+
containerIdArg = "CONTAINER_ID"
26+
)
27+
28+
type inputModel struct {
29+
*globalflags.GlobalFlagModel
30+
ArgContainerId string
31+
IncludeParents bool
32+
}
33+
34+
func NewCmd(params *types.CmdParams) *cobra.Command {
35+
cmd := &cobra.Command{
36+
Use: "describe",
37+
Short: "Shows details of a STACKIT folder",
38+
Long: "Shows details of a STACKIT folder.",
39+
Args: args.SingleOptionalArg(containerIdArg, utils.ValidateUUID),
40+
Example: examples.Build(
41+
examples.NewExample(
42+
`Get the details of the configured STACKIT folder`,
43+
"$ stackit folder describe"),
44+
examples.NewExample(
45+
`Get the details of a STACKIT folder by explicitly providing the container ID`,
46+
"$ stackit folder describe xxx"),
47+
examples.NewExample(
48+
`Get the details of the configured STACKIT folder, including details of the parent resources`,
49+
"$ stackit folder describe --include-parents"),
50+
),
51+
RunE: func(cmd *cobra.Command, args []string) error {
52+
ctx := context.Background()
53+
model, err := parseInput(params.Printer, cmd, args)
54+
if err != nil {
55+
return err
56+
}
57+
58+
// Configure API client
59+
apiClient, err := client.ConfigureClient(params.Printer, params.CliVersion)
60+
if err != nil {
61+
return err
62+
}
63+
64+
// Call API
65+
req := buildRequest(ctx, model, apiClient)
66+
resp, err := req.Execute()
67+
if err != nil {
68+
return fmt.Errorf("read folder details: %w", err)
69+
}
70+
71+
return outputResult(params.Printer, model.OutputFormat, resp)
72+
},
73+
}
74+
configureFlags(cmd)
75+
return cmd
76+
}
77+
78+
func configureFlags(cmd *cobra.Command) {
79+
cmd.Flags().Bool(includeParentsFlag, false, "When true, the details of the parent resources will be included in the output")
80+
}
81+
82+
func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inputModel, error) {
83+
var containerId string
84+
if len(inputArgs) > 0 {
85+
containerId = inputArgs[0]
86+
}
87+
88+
globalFlags := globalflags.Parse(p, cmd)
89+
if globalFlags.ProjectId == "" && containerId == "" {
90+
return nil, fmt.Errorf("container ID needs to be provided either as an argument or as a flag")
91+
}
92+
93+
if containerId == "" {
94+
containerId = globalFlags.ProjectId
95+
}
96+
97+
model := inputModel{
98+
GlobalFlagModel: globalFlags,
99+
ArgContainerId: containerId,
100+
IncludeParents: flags.FlagToBoolValue(p, cmd, includeParentsFlag),
101+
}
102+
103+
p.DebugInputModel(model)
104+
return &model, nil
105+
}
106+
107+
func buildRequest(ctx context.Context, model *inputModel, apiClient *resourcemanager.APIClient) resourcemanager.ApiGetFolderDetailsRequest {
108+
req := apiClient.DefaultAPI.GetFolderDetails(ctx, model.ArgContainerId)
109+
req.IncludeParents(model.IncludeParents)
110+
return req
111+
}
112+
113+
func outputResult(p *print.Printer, outputFormat string, folder *resourcemanager.GetFolderDetailsResponse) error {
114+
if folder == nil {
115+
return fmt.Errorf("response not set")
116+
}
117+
118+
return p.OutputResult(outputFormat, folder, func() error {
119+
table := tables.NewTable()
120+
table.AddRow("ID", folder.FolderId)
121+
table.AddSeparator()
122+
table.AddRow("NAME", folder.Name)
123+
table.AddSeparator()
124+
table.AddRow("CREATION", folder.CreationTime)
125+
table.AddSeparator()
126+
table.AddRow("CONTAINER ID", folder.ContainerId)
127+
table.AddSeparator()
128+
table.AddRow("PARENT ID", folder.Parent.Id)
129+
130+
var labels string
131+
if folder.Labels != nil {
132+
labels = utils.JoinStringMap(*folder.Labels, "=", ", ")
133+
}
134+
table.AddSeparator()
135+
table.AddRow("LABELS", labels)
136+
137+
err := table.Display(p)
138+
if err != nil {
139+
return fmt.Errorf("render table: %w", err)
140+
}
141+
142+
return nil
143+
})
144+
}

0 commit comments

Comments
 (0)