Skip to content

Commit 9dcab03

Browse files
committed
onboard sfs project lock command
1 parent 80963e0 commit 9dcab03

13 files changed

Lines changed: 968 additions & 0 deletions

docs/stackit_beta_sfs.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ stackit beta sfs [flags]
3232
* [stackit beta](./stackit_beta.md) - Contains beta STACKIT CLI commands
3333
* [stackit beta sfs export-policy](./stackit_beta_sfs_export-policy.md) - Provides functionality for SFS export policies
3434
* [stackit beta sfs performance-class](./stackit_beta_sfs_performance-class.md) - Provides functionality for SFS performance classes
35+
* [stackit beta sfs project-lock](./stackit_beta_sfs_project-lock.md) - Provides functionality for SFS project locks
3536
* [stackit beta sfs resource-pool](./stackit_beta_sfs_resource-pool.md) - Provides functionality for SFS resource pools
3637
* [stackit beta sfs share](./stackit_beta_sfs_share.md) - Provides functionality for SFS shares
3738
* [stackit beta sfs snapshot](./stackit_beta_sfs_snapshot.md) - Provides functionality for SFS snapshots
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
## stackit beta sfs project-lock
2+
3+
Provides functionality for SFS project locks
4+
5+
### Synopsis
6+
7+
Provides functionality for SFS project locks.
8+
9+
```
10+
stackit beta sfs project-lock [flags]
11+
```
12+
13+
### Options
14+
15+
```
16+
-h, --help Help for "stackit beta sfs project-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 beta sfs](./stackit_beta_sfs.md) - Provides functionality for SFS (stackit file storage)
33+
* [stackit beta sfs project-lock describe](./stackit_beta_sfs_project-lock_describe.md) - Get lock status for a project
34+
* [stackit beta sfs project-lock lock](./stackit_beta_sfs_project-lock_lock.md) - Enables lock for a project
35+
* [stackit beta sfs project-lock unlock](./stackit_beta_sfs_project-lock_unlock.md) - Clean up lock for a project
36+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
## stackit beta sfs project-lock describe
2+
3+
Get lock status for a project
4+
5+
### Synopsis
6+
7+
Get lock status for a project.
8+
9+
```
10+
stackit beta sfs project-lock describe [flags]
11+
```
12+
13+
### Examples
14+
15+
```
16+
Get lock status for project
17+
$ stackit beta sfs project-lock describe
18+
```
19+
20+
### Options
21+
22+
```
23+
-h, --help Help for "stackit beta sfs project-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 beta sfs project-lock](./stackit_beta_sfs_project-lock.md) - Provides functionality for SFS project locks
40+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
## stackit beta sfs project-lock lock
2+
3+
Enables lock for a project
4+
5+
### Synopsis
6+
7+
Enables lock for a project. Necessary for immutable snapshots and to prevent accidental deletion of resources.
8+
9+
```
10+
stackit beta sfs project-lock lock [flags]
11+
```
12+
13+
### Examples
14+
15+
```
16+
Enable lock for project
17+
$ stackit beta sfs project-lock lock
18+
```
19+
20+
### Options
21+
22+
```
23+
-h, --help Help for "stackit beta sfs project-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 beta sfs project-lock](./stackit_beta_sfs_project-lock.md) - Provides functionality for SFS project locks
40+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
## stackit beta sfs project-lock unlock
2+
3+
Clean up lock for a project
4+
5+
### Synopsis
6+
7+
Clean up lock for a project.
8+
9+
```
10+
stackit beta sfs project-lock unlock [flags]
11+
```
12+
13+
### Examples
14+
15+
```
16+
Disable lock for project
17+
$ stackit beta sfs project-lock unlock
18+
```
19+
20+
### Options
21+
22+
```
23+
-h, --help Help for "stackit beta sfs project-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 beta sfs project-lock](./stackit_beta_sfs_project-lock.md) - Provides functionality for SFS project locks
40+
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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/sfs/client"
13+
"github.com/stackitcloud/stackit-cli/internal/pkg/tables"
14+
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
15+
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
16+
17+
"github.com/spf13/cobra"
18+
sfs "github.com/stackitcloud/stackit-sdk-go/services/sfs/v1api"
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: "Get lock status for a project",
29+
Long: "Get lock status for a project.",
30+
Args: args.NoArgs,
31+
Example: examples.Build(
32+
examples.NewExample(
33+
`Get lock status for project`,
34+
"$ stackit beta sfs project-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+
// Call API
50+
req := buildRequest(ctx, model, apiClient)
51+
resp, err := req.Execute()
52+
if err != nil {
53+
return fmt.Errorf("get lock status for project: %w", err)
54+
}
55+
56+
return outputResult(params.Printer, model.OutputFormat, resp)
57+
},
58+
}
59+
return cmd
60+
}
61+
62+
func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, error) {
63+
globalFlags := globalflags.Parse(p, cmd)
64+
if globalFlags.ProjectId == "" {
65+
return nil, &errors.ProjectIdError{}
66+
}
67+
68+
model := inputModel{
69+
GlobalFlagModel: globalFlags,
70+
}
71+
72+
p.DebugInputModel(model)
73+
return &model, nil
74+
}
75+
76+
func buildRequest(ctx context.Context, model *inputModel, apiClient *sfs.APIClient) sfs.ApiGetLockRequest {
77+
req := apiClient.DefaultAPI.GetLock(ctx, model.Region, model.ProjectId)
78+
return req
79+
}
80+
81+
func outputResult(p *print.Printer, outputFormat string, resp *sfs.GetLockResponse) error {
82+
return p.OutputResult(outputFormat, resp, func() error {
83+
if resp == nil {
84+
return fmt.Errorf("response is empty")
85+
}
86+
87+
table := tables.NewTable()
88+
table.AddRow("LOCK ID", utils.PtrString(resp.LockId))
89+
table.AddSeparator()
90+
91+
err := table.Display(p)
92+
if err != nil {
93+
return fmt.Errorf("render table: %w", err)
94+
}
95+
96+
return nil
97+
})
98+
}

0 commit comments

Comments
 (0)