Skip to content

Commit 0cb9522

Browse files
committed
feat(git): Add update command for ACLs
Extend describe command to show ACLs. STACKITCLI-555 Signed-off-by: Alexander Dahmen <alexander.dahmen@inovex.de>
1 parent bc4b561 commit 0cb9522

12 files changed

Lines changed: 539 additions & 16 deletions

‎docs/stackit_git_instance.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ stackit git instance [flags]
3232
* [stackit git](./stackit_git.md) - Provides functionality for STACKIT Git
3333
* [stackit git instance create](./stackit_git_instance_create.md) - Creates STACKIT Git instance
3434
* [stackit git instance delete](./stackit_git_instance_delete.md) - Deletes STACKIT Git instance
35-
* [stackit git instance describe](./stackit_git_instance_describe.md) - Describes STACKIT Git instance
35+
* [stackit git instance describe](./stackit_git_instance_describe.md) - Shows details of a STACKIT Git instance
3636
* [stackit git instance list](./stackit_git_instance_list.md) - Lists all instances of STACKIT Git
37+
* [stackit git instance update](./stackit_git_instance_update.md) - Updates STACKIT Git instance
3738

‎docs/stackit_git_instance_create.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ stackit git instance create [flags]
2626
### Options
2727

2828
```
29-
--acl strings Acl for the instance.
29+
--acl strings List of IP networks in CIDR notation which are allowed to access this instance (default [])
3030
--flavor string Flavor of the instance.
3131
-h, --help Help for "stackit git instance create"
3232
--name string The name of the instance.

‎docs/stackit_git_instance_describe.md‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
## stackit git instance describe
22

3-
Describes STACKIT Git instance
3+
Shows details of a STACKIT Git instance
44

55
### Synopsis
66

7-
Describes a STACKIT Git instance by its internal ID.
7+
Shows details of a STACKIT Git instance.
88

99
```
1010
stackit git instance describe INSTANCE_ID [flags]
@@ -13,8 +13,11 @@ stackit git instance describe INSTANCE_ID [flags]
1313
### Examples
1414

1515
```
16-
Describe instance "xxx"
17-
$ stackit git describe xxx
16+
Get details of a STACKIT Git instance with ID "xxx"
17+
$ stackit git instance describe xxx
18+
19+
Get details of a STACKIT Git instance with ID "xxx" in JSON format
20+
$ stackit git instance describe xxx --output-format json
1821
```
1922

2023
### Options
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
## stackit git instance update
2+
3+
Updates STACKIT Git instance
4+
5+
### Synopsis
6+
7+
Updates a STACKIT Git instance.
8+
9+
```
10+
stackit git instance update INSTANCE_ID [flags]
11+
```
12+
13+
### Examples
14+
15+
```
16+
Update the ACL of the instance with ID "xxx"
17+
$ stackit git instance update xxx --acl 1.2.3.0/24
18+
19+
Update the ACL of the instance with ID "xxx" with multiple ranges
20+
$ stackit git instance update xxx --acl 1.2.3.0/24,4.5.6.0/24
21+
```
22+
23+
### Options
24+
25+
```
26+
--acl strings List of IP networks in CIDR notation which are allowed to access this instance. Replaces the existing ACL. (default [])
27+
-h, --help Help for "stackit git instance update"
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 git instance](./stackit_git_instance.md) - Provides functionality for STACKIT Git instances
44+

‎internal/cmd/git/instance/create/create.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
7878

7979
result, err := request.Execute()
8080
if err != nil {
81-
return fmt.Errorf("create stackit git instance: %w", err)
81+
return fmt.Errorf("create STACKIT Git instance: %w", err)
8282
}
8383

8484
// Wait for async operation, if async mode not enabled
@@ -88,7 +88,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
8888
return err
8989
})
9090
if err != nil {
91-
return fmt.Errorf("wait for stackit git Instance creation: %w", err)
91+
return fmt.Errorf("wait for STACKIT Git instance creation: %w", err)
9292
}
9393
}
9494

@@ -103,7 +103,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
103103
func configureFlags(cmd *cobra.Command) {
104104
cmd.Flags().String(nameFlag, "", "The name of the instance.")
105105
cmd.Flags().String(flavorFlag, "", "Flavor of the instance.")
106-
cmd.Flags().StringSlice(aclFlag, []string{}, "Acl for the instance.")
106+
cmd.Flags().Var(flags.CIDRSliceFlag(), aclFlag, "List of IP networks in CIDR notation which are allowed to access this instance")
107107
if err := flags.MarkFlagsRequired(cmd, nameFlag); err != nil {
108108
cobra.CheckErr(err)
109109
}

‎internal/cmd/git/instance/create/create_test.go‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,23 @@ func TestParseInput(t *testing.T) {
125125
}),
126126
isValid: false,
127127
},
128+
{
129+
description: "multiple acl entries",
130+
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
131+
flagValues[aclFlag] = "1.2.3.0/24,4.5.6.0/24"
132+
}),
133+
isValid: true,
134+
expectedModel: fixtureInputModel(func(model *inputModel) {
135+
model.Acl = []string{"1.2.3.0/24", "4.5.6.0/24"}
136+
}),
137+
},
138+
{
139+
description: "invalid acl",
140+
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
141+
flagValues[aclFlag] = "invalid-cidr"
142+
}),
143+
isValid: false,
144+
},
128145
}
129146

130147
for _, tt := range tests {

‎internal/cmd/git/instance/delete/delete.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
6060

6161
instanceName, err := gitUtils.GetInstanceName(ctx, apiClient.DefaultAPI, model.ProjectId, model.InstanceId)
6262
if err != nil {
63-
params.Printer.Debug(print.ErrorLevel, "get stackit git instance name: %v", err)
63+
params.Printer.Debug(print.ErrorLevel, "get STACKIT Git instance name: %v", err)
6464
instanceName = model.InstanceId
6565
} else if instanceName == "" {
6666
instanceName = model.InstanceId
6767
}
6868

69-
prompt := fmt.Sprintf("Are you sure you want to delete the stackit git instance %q for %q?", instanceName, projectName)
69+
prompt := fmt.Sprintf("Are you sure you want to delete the STACKIT Git instance %q for %q?", instanceName, projectName)
7070
err = params.Printer.PromptForConfirmation(prompt)
7171
if err != nil {
7272
return err
@@ -87,15 +87,15 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
8787
return err
8888
})
8989
if err != nil {
90-
return fmt.Errorf("wait for stackit git instance deletion: %w", err)
90+
return fmt.Errorf("wait for STACKIT Git instance deletion: %w", err)
9191
}
9292
}
9393

9494
operationState := "Deleted"
9595
if model.Async {
9696
operationState = "Triggered deletion of"
9797
}
98-
params.Printer.Info("%s stackit git instance %s \n", operationState, model.InstanceId)
98+
params.Printer.Info("%s STACKIT Git instance %s \n", operationState, model.InstanceId)
9999

100100
return nil
101101
},

‎internal/cmd/git/instance/describe/describe.go‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package describe
33
import (
44
"context"
55
"fmt"
6+
"strings"
67

78
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
89

@@ -29,11 +30,16 @@ const instanceIdArg = "INSTANCE_ID"
2930
func NewCmd(params *types.CmdParams) *cobra.Command {
3031
cmd := &cobra.Command{
3132
Use: fmt.Sprintf("describe %s", instanceIdArg),
32-
Short: "Describes STACKIT Git instance",
33-
Long: "Describes a STACKIT Git instance by its internal ID.",
33+
Short: "Shows details of a STACKIT Git instance",
34+
Long: "Shows details of a STACKIT Git instance.",
3435
Args: args.SingleArg(instanceIdArg, utils.ValidateUUID),
3536
Example: examples.Build(
36-
examples.NewExample(`Describe instance "xxx"`, `$ stackit git describe xxx`),
37+
examples.NewExample(
38+
`Get details of a STACKIT Git instance with ID "xxx"`,
39+
`$ stackit git instance describe xxx`),
40+
examples.NewExample(
41+
`Get details of a STACKIT Git instance with ID "xxx" in JSON format`,
42+
`$ stackit git instance describe xxx --output-format json`),
3743
),
3844
RunE: func(cmd *cobra.Command, args []string) error {
3945
ctx := context.Background()
@@ -102,10 +108,16 @@ func outputResult(p *print.Printer, outputFormat string, resp *git.Instance) err
102108
table.AddSeparator()
103109
table.AddRow("VERSION", resp.Version)
104110
table.AddSeparator()
111+
table.AddRow("FLAVOR", resp.Flavor)
112+
table.AddSeparator()
105113
table.AddRow("STATE", resp.State)
106114
table.AddSeparator()
107115
table.AddRow("CREATED", resp.Created)
108116
table.AddSeparator()
117+
if len(resp.Acl) > 0 {
118+
table.AddRow("ACL", strings.Join(resp.Acl, ","))
119+
table.AddSeparator()
120+
}
109121

110122
if err := table.Display(p); err != nil {
111123
return fmt.Errorf("render table: %w", err)

‎internal/cmd/git/instance/describe/describe_test.go‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,15 @@ func TestOutputResult(t *testing.T) {
210210
},
211211
wantErr: false,
212212
},
213+
{
214+
name: "with acl",
215+
args: args{
216+
resp: &git.Instance{
217+
Acl: []string{"1.2.3.0/24", "4.5.6.0/24"},
218+
},
219+
},
220+
wantErr: false,
221+
},
213222
{
214223
name: "nil",
215224
args: args{},

‎internal/cmd/git/instance/instance.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"github.com/stackitcloud/stackit-cli/internal/cmd/git/instance/delete"
66
"github.com/stackitcloud/stackit-cli/internal/cmd/git/instance/describe"
77
"github.com/stackitcloud/stackit-cli/internal/cmd/git/instance/list"
8+
"github.com/stackitcloud/stackit-cli/internal/cmd/git/instance/update"
89
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
910
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
1011
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
@@ -30,5 +31,6 @@ func addSubcommands(cmd *cobra.Command, params *types.CmdParams) {
3031
describe.NewCmd(params),
3132
create.NewCmd(params),
3233
delete.NewCmd(params),
34+
update.NewCmd(params),
3335
)
3436
}

0 commit comments

Comments
 (0)