Skip to content

Commit 78871c2

Browse files
author
Jan Sternagel
committed
removed risky delete output
1 parent 0852ada commit 78871c2

File tree

2 files changed

+3
-76
lines changed

2 files changed

+3
-76
lines changed

internal/cmd/beta/kms/keyring/delete/delete.go

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ package delete
22

33
import (
44
"context"
5-
"encoding/json"
65
"fmt"
76

8-
"github.com/goccy/go-yaml"
97
"github.com/spf13/cobra"
108
"github.com/stackitcloud/stackit-cli/internal/cmd/params"
119
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
@@ -76,12 +74,9 @@ func NewCmd(params *params.CmdParams) *cobra.Command {
7674

7775
// Wait for async operation not relevant. Key ring deletion is synchronous.
7876

79-
// Get the key ring so it can be outputted in the state it is after the deletion.
80-
resp, err := apiClient.GetKeyRingExecute(ctx, model.ProjectId, model.Region, model.KeyRingId)
81-
if err != nil {
82-
params.Printer.Debug(print.ErrorLevel, "get KMS Key Ring: %w", err)
83-
}
84-
return outputResult(params.Printer, model.OutputFormat, resp)
77+
// Don't output anything. It's a deletion.
78+
params.Printer.Info("Deleted the key ring %q\n", keyRingLabel)
79+
return nil
8580
},
8681
}
8782
return cmd
@@ -116,28 +111,3 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *kms.APIClie
116111
req := apiClient.DeleteKeyRing(ctx, model.ProjectId, model.Region, model.KeyRingId)
117112
return req
118113
}
119-
120-
func outputResult(p *print.Printer, outputFormat string, resp *kms.KeyRing) error {
121-
if resp == nil {
122-
return fmt.Errorf("response from 'GetKeyExecute()' is nil")
123-
}
124-
125-
switch outputFormat {
126-
case print.JSONOutputFormat:
127-
details, err := json.MarshalIndent(resp, "", " ")
128-
if err != nil {
129-
return fmt.Errorf("marshal output to JSON: %w", err)
130-
}
131-
p.Outputln(string(details))
132-
case print.YAMLOutputFormat:
133-
details, err := yaml.MarshalWithOptions(resp, yaml.IndentSequence(true), yaml.UseJSONMarshaler())
134-
if err != nil {
135-
return fmt.Errorf("marshal output to YAML: %w", err)
136-
}
137-
p.Outputln(string(details))
138-
139-
default:
140-
p.Outputf("Deleted key ring: %s\n", utils.PtrString(resp.DisplayName))
141-
}
142-
return nil
143-
}

internal/cmd/beta/kms/keyring/delete/delete_test.go

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -210,46 +210,3 @@ func TestBuildRequest(t *testing.T) {
210210
})
211211
}
212212
}
213-
214-
func TestOutputResult(t *testing.T) {
215-
tests := []struct {
216-
description string
217-
wantErr bool
218-
outputFormat string
219-
resp *kms.KeyRing
220-
}{
221-
{
222-
description: "nil response",
223-
resp: nil,
224-
wantErr: true,
225-
},
226-
{
227-
description: "default output",
228-
resp: &kms.KeyRing{},
229-
wantErr: false,
230-
},
231-
{
232-
description: "json output",
233-
outputFormat: print.JSONOutputFormat,
234-
resp: &kms.KeyRing{},
235-
wantErr: false,
236-
},
237-
{
238-
description: "yaml output",
239-
outputFormat: print.YAMLOutputFormat,
240-
resp: &kms.KeyRing{},
241-
wantErr: false,
242-
},
243-
}
244-
245-
p := print.NewPrinter()
246-
p.Cmd = NewCmd(&params.CmdParams{Printer: p})
247-
for _, tt := range tests {
248-
t.Run(tt.description, func(t *testing.T) {
249-
err := outputResult(p, tt.outputFormat, tt.resp)
250-
if (err != nil) != tt.wantErr {
251-
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
252-
}
253-
})
254-
}
255-
}

0 commit comments

Comments
 (0)