Skip to content

Commit c3e6602

Browse files
committed
feat(objectstorage): onboard compliance lock cmd
relates to STACKITCLI-341
1 parent aa3f6fe commit c3e6602

13 files changed

+1009
-0
lines changed

docs/stackit_object-storage.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ stackit object-storage [flags]
3131

3232
* [stackit](./stackit.md) - Manage STACKIT resources using the command line
3333
* [stackit object-storage bucket](./stackit_object-storage_bucket.md) - Provides functionality for Object Storage buckets
34+
* [stackit object-storage compliance-lock](./stackit_object-storage_compliance-lock.md) - Provides functionality to manage Object Storage compliance lock
3435
* [stackit object-storage credentials](./stackit_object-storage_credentials.md) - Provides functionality for Object Storage credentials
3536
* [stackit object-storage credentials-group](./stackit_object-storage_credentials-group.md) - Provides functionality for Object Storage credentials group
3637
* [stackit object-storage disable](./stackit_object-storage_disable.md) - Disables Object Storage for a project
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
## stackit object-storage compliance-lock
2+
3+
Provides functionality to manage Object Storage compliance lock
4+
5+
### Synopsis
6+
7+
Provides functionality to manage Object Storage compliance lock.
8+
9+
```
10+
stackit object-storage compliance-lock [flags]
11+
```
12+
13+
### Options
14+
15+
```
16+
-h, --help Help for "stackit object-storage compliance-lock"
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 object-storage](./stackit_object-storage.md) - Provides functionality for Object Storage
33+
* [stackit object-storage compliance-lock describe](./stackit_object-storage_compliance-lock_describe.md) - Describe object storage compliance lock
34+
* [stackit object-storage compliance-lock lock](./stackit_object-storage_compliance-lock_lock.md) - Create object storage compliance lock
35+
* [stackit object-storage compliance-lock unlock](./stackit_object-storage_compliance-lock_unlock.md) - Delete object storage compliance lock
36+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
## stackit object-storage compliance-lock describe
2+
3+
Describe object storage compliance lock
4+
5+
### Synopsis
6+
7+
Describe object storage compliance lock.
8+
9+
```
10+
stackit object-storage compliance-lock describe [flags]
11+
```
12+
13+
### Examples
14+
15+
```
16+
Describe object storage compliance lock
17+
$ stackit object-storage compliance-lock describe
18+
```
19+
20+
### Options
21+
22+
```
23+
-h, --help Help for "stackit object-storage compliance-lock describe"
24+
```
25+
26+
### Options inherited from parent commands
27+
28+
```
29+
-y, --assume-yes If set, skips all confirmation prompts
30+
--async If set, runs the command asynchronously
31+
-o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"]
32+
-p, --project-id string Project ID
33+
--region string Target region for region-specific requests
34+
--verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info")
35+
```
36+
37+
### SEE ALSO
38+
39+
* [stackit object-storage compliance-lock](./stackit_object-storage_compliance-lock.md) - Provides functionality to manage Object Storage compliance lock
40+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
## stackit object-storage compliance-lock lock
2+
3+
Create object storage compliance lock
4+
5+
### Synopsis
6+
7+
Create object storage compliance lock.
8+
9+
```
10+
stackit object-storage compliance-lock lock [flags]
11+
```
12+
13+
### Examples
14+
15+
```
16+
Create object storage compliance lock
17+
$ stackit object-storage compliance-lock lock
18+
```
19+
20+
### Options
21+
22+
```
23+
-h, --help Help for "stackit object-storage compliance-lock lock"
24+
```
25+
26+
### Options inherited from parent commands
27+
28+
```
29+
-y, --assume-yes If set, skips all confirmation prompts
30+
--async If set, runs the command asynchronously
31+
-o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"]
32+
-p, --project-id string Project ID
33+
--region string Target region for region-specific requests
34+
--verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info")
35+
```
36+
37+
### SEE ALSO
38+
39+
* [stackit object-storage compliance-lock](./stackit_object-storage_compliance-lock.md) - Provides functionality to manage Object Storage compliance lock
40+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
## stackit object-storage compliance-lock unlock
2+
3+
Delete object storage compliance lock
4+
5+
### Synopsis
6+
7+
Delete object storage compliance lock.
8+
9+
```
10+
stackit object-storage compliance-lock unlock [flags]
11+
```
12+
13+
### Examples
14+
15+
```
16+
Delete object storage compliance lock
17+
$ stackit object-storage compliance-lock unlock
18+
```
19+
20+
### Options
21+
22+
```
23+
-h, --help Help for "stackit object-storage compliance-lock unlock"
24+
```
25+
26+
### Options inherited from parent commands
27+
28+
```
29+
-y, --assume-yes If set, skips all confirmation prompts
30+
--async If set, runs the command asynchronously
31+
-o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"]
32+
-p, --project-id string Project ID
33+
--region string Target region for region-specific requests
34+
--verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info")
35+
```
36+
37+
### SEE ALSO
38+
39+
* [stackit object-storage compliance-lock](./stackit_object-storage_compliance-lock.md) - Provides functionality to manage Object Storage compliance lock
40+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package compliancelock
2+
3+
import (
4+
"github.com/stackitcloud/stackit-cli/internal/cmd/object-storage/compliance-lock/describe"
5+
"github.com/stackitcloud/stackit-cli/internal/cmd/object-storage/compliance-lock/lock"
6+
"github.com/stackitcloud/stackit-cli/internal/cmd/object-storage/compliance-lock/unlock"
7+
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
8+
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
9+
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
10+
11+
"github.com/spf13/cobra"
12+
)
13+
14+
func NewCmd(params *types.CmdParams) *cobra.Command {
15+
cmd := &cobra.Command{
16+
Use: "compliance-lock",
17+
Short: "Provides functionality to manage Object Storage compliance lock",
18+
Long: "Provides functionality to manage Object Storage compliance lock.",
19+
Args: args.NoArgs,
20+
Run: utils.CmdHelp,
21+
}
22+
addSubcommands(cmd, params)
23+
return cmd
24+
}
25+
26+
func addSubcommands(cmd *cobra.Command, params *types.CmdParams) {
27+
cmd.AddCommand(lock.NewCmd(params))
28+
cmd.AddCommand(unlock.NewCmd(params))
29+
cmd.AddCommand(describe.NewCmd(params))
30+
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
package describe
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
8+
"github.com/stackitcloud/stackit-cli/internal/pkg/errors"
9+
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
10+
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
11+
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
12+
"github.com/stackitcloud/stackit-cli/internal/pkg/services/object-storage/client"
13+
objectStorageUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/object-storage/utils"
14+
"github.com/stackitcloud/stackit-cli/internal/pkg/tables"
15+
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
16+
17+
"github.com/spf13/cobra"
18+
objectstorage "github.com/stackitcloud/stackit-sdk-go/services/objectstorage/v2api"
19+
)
20+
21+
type inputModel struct {
22+
*globalflags.GlobalFlagModel
23+
}
24+
25+
func NewCmd(params *types.CmdParams) *cobra.Command {
26+
cmd := &cobra.Command{
27+
Use: "describe",
28+
Short: "Describe object storage compliance lock",
29+
Long: "Describe object storage compliance lock.",
30+
Args: args.NoArgs,
31+
Example: examples.Build(
32+
examples.NewExample(
33+
`Describe object storage compliance lock`,
34+
"$ stackit object-storage compliance-lock describe"),
35+
),
36+
RunE: func(cmd *cobra.Command, args []string) error {
37+
ctx := context.Background()
38+
model, err := parseInput(params.Printer, cmd, args)
39+
if err != nil {
40+
return err
41+
}
42+
43+
// Configure API client
44+
apiClient, err := client.ConfigureClient(params.Printer, params.CliVersion)
45+
if err != nil {
46+
return err
47+
}
48+
49+
// Check if the project is enabled before trying to describe
50+
enabled, err := objectStorageUtils.ProjectEnabled(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region)
51+
if err != nil {
52+
return fmt.Errorf("check if Object Storage is enabled: %w", err)
53+
}
54+
if !enabled {
55+
return &errors.ServiceDisabledError{
56+
Service: "object-storage",
57+
}
58+
}
59+
60+
// Call API
61+
req := buildRequest(ctx, model, apiClient)
62+
resp, err := req.Execute()
63+
if err != nil {
64+
return fmt.Errorf("get object storage compliance lock: %w", err)
65+
}
66+
67+
return outputResult(params.Printer, model.OutputFormat, resp)
68+
},
69+
}
70+
return cmd
71+
}
72+
73+
func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, error) {
74+
globalFlags := globalflags.Parse(p, cmd)
75+
if globalFlags.ProjectId == "" {
76+
return nil, &errors.ProjectIdError{}
77+
}
78+
79+
model := inputModel{
80+
GlobalFlagModel: globalFlags,
81+
}
82+
83+
p.DebugInputModel(model)
84+
return &model, nil
85+
}
86+
87+
func buildRequest(ctx context.Context, model *inputModel, apiClient *objectstorage.APIClient) objectstorage.ApiGetComplianceLockRequest {
88+
req := apiClient.DefaultAPI.GetComplianceLock(ctx, model.ProjectId, model.Region)
89+
return req
90+
}
91+
92+
func outputResult(p *print.Printer, outputFormat string, resp *objectstorage.ComplianceLockResponse) error {
93+
return p.OutputResult(outputFormat, resp, func() error {
94+
if resp == nil {
95+
return fmt.Errorf("response is empty")
96+
}
97+
98+
table := tables.NewTable()
99+
table.AddRow("PROJECT ID", resp.Project)
100+
table.AddSeparator()
101+
table.AddRow("MAX RETENTION DAYS", resp.MaxRetentionDays)
102+
table.AddSeparator()
103+
104+
err := table.Display(p)
105+
if err != nil {
106+
return fmt.Errorf("render table: %w", err)
107+
}
108+
109+
return nil
110+
})
111+
}

0 commit comments

Comments
 (0)