Skip to content

Commit bb03603

Browse files
committed
feature: fix regressions
1 parent 66c5c91 commit bb03603

File tree

5 files changed

+34
-10
lines changed

5 files changed

+34
-10
lines changed

internal/cmd/beta/security-group/delete/delete.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ import (
1010
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
1111
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
1212
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
13+
"github.com/stackitcloud/stackit-cli/internal/pkg/projectname"
1314
"github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/client"
1415
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
1516
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
1617
)
1718

1819
type inputModel struct {
1920
*globalflags.GlobalFlagModel
20-
Id string
21+
SecurityGroupId string
2122
}
2223

2324
const groupIdArg = "GROUP_ID"
@@ -44,8 +45,18 @@ func NewCmd(p *print.Printer) *cobra.Command {
4445
return err
4546
}
4647

48+
projectLabel, err := projectname.GetProjectName(ctx, p, cmd)
49+
if err != nil {
50+
return fmt.Errorf("get project name: %w", err)
51+
}
52+
53+
securityGroupResp, err := apiClient.GetSecurityGroup(ctx, model.ProjectId, model.SecurityGroupId).Execute()
54+
if err != nil {
55+
return fmt.Errorf("get security group %q: %w", model.SecurityGroupId, err)
56+
}
57+
4758
if !model.AssumeYes {
48-
prompt := fmt.Sprintf("Are you sure you want to delete the security group %q?", model.Id)
59+
prompt := fmt.Sprintf("Are you sure you want to delete the security group %q for %q?", *securityGroupResp.Name, projectLabel)
4960
err = p.PromptForConfirmation(prompt)
5061
if err != nil {
5162
return err
@@ -58,7 +69,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
5869
if err := request.Execute(); err != nil {
5970
return fmt.Errorf("delete security group: %w", err)
6071
}
61-
p.Info("Deleted security group %q for %q\n", model.Id, model.ProjectId)
72+
p.Info("Deleted security group %q for %q\n", *securityGroupResp.Name, projectLabel)
6273

6374
return nil
6475
},
@@ -75,7 +86,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, cliArgs []string) (*inputM
7586

7687
model := inputModel{
7788
GlobalFlagModel: globalFlags,
78-
Id: cliArgs[0],
89+
SecurityGroupId: cliArgs[0],
7990
}
8091

8192
if p.IsVerbosityDebug() {
@@ -91,6 +102,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command, cliArgs []string) (*inputM
91102
}
92103

93104
func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APIClient) iaas.ApiDeleteSecurityGroupRequest {
94-
request := apiClient.DeleteSecurityGroup(ctx, model.ProjectId, model.Id)
105+
request := apiClient.DeleteSecurityGroup(ctx, model.ProjectId, model.SecurityGroupId)
95106
return request
96107
}

internal/cmd/beta/security-group/delete/delete_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st
3737
func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
3838
model := &inputModel{
3939
GlobalFlagModel: &globalflags.GlobalFlagModel{ProjectId: testProjectId, Verbosity: globalflags.VerbosityDefault},
40-
Id: testGroupId,
40+
SecurityGroupId: testGroupId,
4141
}
4242
for _, mod := range mods {
4343
mod(model)

internal/cmd/beta/security-group/list/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
3737
Args: args.NoArgs,
3838
Example: examples.Build(
3939
examples.NewExample(`List all groups`, `$ stackit beta security-group list`),
40-
examples.NewExample(`List groups with labels`, `$ stackit beta security-group list --labels label1=value1,label2=value2`),
40+
examples.NewExample(`List groups with labels`, `$ stackit beta security-group list --label-selector label1=value1,label2=value2`),
4141
),
4242
RunE: func(cmd *cobra.Command, _ []string) error {
4343
ctx := context.Background()

internal/cmd/beta/security-group/update/update.go

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

77
"github.com/spf13/cobra"
8+
cmd_utils "github.com/stackitcloud/stackit-cli/internal/cmd/beta/security-group/utils"
89
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
910
"github.com/stackitcloud/stackit-cli/internal/pkg/errors"
1011
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
@@ -62,14 +63,22 @@ func NewCmd(p *print.Printer) *cobra.Command {
6263
projectLabel = model.ProjectId
6364
}
6465

66+
if !model.AssumeYes {
67+
prompt := fmt.Sprintf("Are you sure you want to update the security group %q?", model.SecurityGroupId)
68+
err = p.PromptForConfirmation(prompt)
69+
if err != nil {
70+
return err
71+
}
72+
}
73+
6574
// Call API
6675
req := buildRequest(ctx, model, apiClient)
6776

68-
_, err = req.Execute()
77+
resp, err := req.Execute()
6978
if err != nil {
7079
return fmt.Errorf("update security group: %w", err)
7180
}
72-
p.Info("Updated security group \"%v\" for %q\n", model.Name, projectLabel)
81+
p.Info("Updated security group \"%v\" for %q\n", cmd_utils.PtrString(resp.Name), projectLabel)
7382

7483
return nil
7584
},
@@ -99,6 +108,10 @@ func parseInput(p *print.Printer, cmd *cobra.Command, cliArgs []string) (*inputM
99108
SecurityGroupId: cliArgs[0],
100109
}
101110

111+
if model.Labels==nil && model.Description==nil && model.Name==nil {
112+
return nil,fmt.Errorf("no flags have been passed")
113+
}
114+
102115
if p.IsVerbosityDebug() {
103116
modelStr, err := print.BuildDebugStrFromInputModel(model)
104117
if err != nil {

internal/cmd/beta/security-group/update/update_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func TestParseInput(t *testing.T) {
104104
projectIdFlag: testProjectId,
105105
},
106106
args: testGroupId,
107-
isValid: true,
107+
isValid: false,
108108
expectedModel: fixtureInputModel(func(model *inputModel) {
109109
model.Labels = nil
110110
model.Name = nil

0 commit comments

Comments
 (0)