Skip to content

Commit 5a4e11d

Browse files
s-interrubenhoenle
authored andcommitted
feat(secrets-manager): add KMS key details to instance output
1 parent 1079356 commit 5a4e11d

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

internal/cmd/secrets-manager/instance/describe/describe.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,17 @@ func outputResult(p *print.Printer, outputFormat string, instance *secretsmanage
128128
table.AddSeparator()
129129
table.AddRow("CREATION DATE", utils.PtrString(instance.CreationStartDate))
130130
table.AddSeparator()
131+
kmsKey := instance.KmsKey
132+
showKms := kmsKey != nil && (kmsKey.KeyId != nil || kmsKey.KeyRingId != nil || kmsKey.KeyVersion != nil || kmsKey.ServiceAccountEmail != nil)
133+
if showKms {
134+
table.AddRow("KMS KEY ID", utils.PtrString(kmsKey.KeyId))
135+
table.AddSeparator()
136+
table.AddRow("KMS KEYRING ID", utils.PtrString(kmsKey.KeyRingId))
137+
table.AddSeparator()
138+
table.AddRow("KMS KEY VERSION", utils.PtrString(kmsKey.KeyVersion))
139+
table.AddSeparator()
140+
table.AddRow("KMS SERVICE ACCOUNT EMAIL", utils.PtrString(kmsKey.ServiceAccountEmail))
141+
}
131142
// Only show ACL if it's present and not empty
132143
if aclList.Acls != nil && len(*aclList.Acls) > 0 {
133144
var cidrs []string
@@ -136,6 +147,9 @@ func outputResult(p *print.Printer, outputFormat string, instance *secretsmanage
136147
cidrs = append(cidrs, *acl.Cidr)
137148
}
138149

150+
if showKms {
151+
table.AddSeparator()
152+
}
139153
table.AddRow("ACL", strings.Join(cidrs, ","))
140154
}
141155
err := table.Display(p)

internal/cmd/secrets-manager/instance/describe/describe_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
1010
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
1111
"github.com/stackitcloud/stackit-cli/internal/pkg/testutils"
12+
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
1213

1314
"github.com/google/go-cmp/cmp"
1415
"github.com/google/go-cmp/cmp/cmpopts"
@@ -247,6 +248,21 @@ func TestOutputResult(t *testing.T) {
247248
},
248249
wantErr: false,
249250
},
251+
{
252+
name: "instance with kms key",
253+
args: args{
254+
instance: &secretsmanager.Instance{
255+
KmsKey: &secretsmanager.KmsKeyPayload{
256+
KeyId: utils.Ptr("key-id"),
257+
KeyRingId: utils.Ptr("keyring-id"),
258+
KeyVersion: utils.Ptr(int64(1)),
259+
ServiceAccountEmail: utils.Ptr("my-service-account-1234567@sa.stackit.cloud"),
260+
},
261+
},
262+
aclList: &secretsmanager.ListACLsResponse{},
263+
},
264+
wantErr: false,
265+
},
250266
}
251267
p := print.NewPrinter()
252268
p.Cmd = NewCmd(&types.CmdParams{Printer: p})

0 commit comments

Comments
 (0)