Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/stackit_beta_kms_key.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ stackit beta kms key [flags]
* [stackit beta kms](./stackit_beta_kms.md) - Provides functionality for KMS
* [stackit beta kms key create](./stackit_beta_kms_key_create.md) - Creates a KMS key
* [stackit beta kms key delete](./stackit_beta_kms_key_delete.md) - Deletes a KMS key
* [stackit beta kms key describe](./stackit_beta_kms_key_describe.md) - Describe a KMS key
* [stackit beta kms key import](./stackit_beta_kms_key_import.md) - Import a KMS key
* [stackit beta kms key list](./stackit_beta_kms_key_list.md) - List all KMS keys
* [stackit beta kms key restore](./stackit_beta_kms_key_restore.md) - Restore a key
Expand Down
41 changes: 41 additions & 0 deletions docs/stackit_beta_kms_key_describe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
## stackit beta kms key describe

Describe a KMS key

### Synopsis

Describe a KMS key

```
stackit beta kms key describe KEY_ID [flags]
```

### Examples

```
Describe a KMS key with ID xxx of keyring yyy
$ stackit beta kms key describe xxx --keyring-id yyy
```

### Options

```
-h, --help Help for "stackit beta kms key describe"
--keyring-id string Key Ring ID
```

### Options inherited from parent commands

```
-y, --assume-yes If set, skips all confirmation prompts
--async If set, runs the command asynchronously
-o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"]
-p, --project-id string Project ID
--region string Target region for region-specific requests
--verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info")
```

### SEE ALSO

* [stackit beta kms key](./stackit_beta_kms_key.md) - Manage KMS keys

1 change: 1 addition & 0 deletions docs/stackit_beta_kms_keyring.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ stackit beta kms keyring [flags]
* [stackit beta kms](./stackit_beta_kms.md) - Provides functionality for KMS
* [stackit beta kms keyring create](./stackit_beta_kms_keyring_create.md) - Creates a KMS key ring
* [stackit beta kms keyring delete](./stackit_beta_kms_keyring_delete.md) - Deletes a KMS key ring
* [stackit beta kms keyring describe](./stackit_beta_kms_keyring_describe.md) - Describe a KMS key ring
* [stackit beta kms keyring list](./stackit_beta_kms_keyring_list.md) - Lists all KMS key rings

40 changes: 40 additions & 0 deletions docs/stackit_beta_kms_keyring_describe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## stackit beta kms keyring describe

Describe a KMS key ring

### Synopsis

Describe a KMS key ring

```
stackit beta kms keyring describe KEYRING_ID [flags]
```

### Examples

```
Describe a KMS key ring with ID xxx
$ stackit beta kms keyring describe xxx
```

### Options

```
-h, --help Help for "stackit beta kms keyring describe"
```

### Options inherited from parent commands

```
-y, --assume-yes If set, skips all confirmation prompts
--async If set, runs the command asynchronously
-o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"]
-p, --project-id string Project ID
--region string Target region for region-specific requests
--verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info")
```

### SEE ALSO

* [stackit beta kms keyring](./stackit_beta_kms_keyring.md) - Manage KMS key rings

1 change: 1 addition & 0 deletions docs/stackit_beta_kms_wrapping-key.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ stackit beta kms wrapping-key [flags]
* [stackit beta kms](./stackit_beta_kms.md) - Provides functionality for KMS
* [stackit beta kms wrapping-key create](./stackit_beta_kms_wrapping-key_create.md) - Creates a KMS wrapping key
* [stackit beta kms wrapping-key delete](./stackit_beta_kms_wrapping-key_delete.md) - Deletes a KMS wrapping key
* [stackit beta kms wrapping-key describe](./stackit_beta_kms_wrapping-key_describe.md) - Describe a KMS wrapping key
* [stackit beta kms wrapping-key list](./stackit_beta_kms_wrapping-key_list.md) - Lists all KMS wrapping keys

41 changes: 41 additions & 0 deletions docs/stackit_beta_kms_wrapping-key_describe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
## stackit beta kms wrapping-key describe

Describe a KMS wrapping key

### Synopsis

Describe a KMS wrapping key

```
stackit beta kms wrapping-key describe WRAPPING_KEY_ID [flags]
```

### Examples

```
Describe a KMS wrapping key with ID xxx of keyring yyy
$ stackit beta kms wrappingkey describe xxx --keyring-id yyy
```

### Options

```
-h, --help Help for "stackit beta kms wrapping-key describe"
--keyring-id string Key Ring ID
```

### Options inherited from parent commands

```
-y, --assume-yes If set, skips all confirmation prompts
--async If set, runs the command asynchronously
-o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"]
-p, --project-id string Project ID
--region string Target region for region-specific requests
--verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info")
```

### SEE ALSO

* [stackit beta kms wrapping-key](./stackit_beta_kms_wrapping-key.md) - Manage KMS wrapping keys

131 changes: 131 additions & 0 deletions internal/cmd/beta/kms/key/describe/describe.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
package describe

import (
"context"
"fmt"

"github.com/spf13/cobra"
"github.com/stackitcloud/stackit-cli/internal/cmd/params"
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
"github.com/stackitcloud/stackit-cli/internal/pkg/errors"
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
"github.com/stackitcloud/stackit-cli/internal/pkg/flags"
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
"github.com/stackitcloud/stackit-cli/internal/pkg/services/kms/client"
"github.com/stackitcloud/stackit-cli/internal/pkg/tables"
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
"github.com/stackitcloud/stackit-sdk-go/services/kms"
)

const (
argKeyID = "KEY_ID"
flagKeyRingID = "keyring-id"
)

type inputModel struct {
*globalflags.GlobalFlagModel
KeyID string
KeyRingID string
}

func NewCmd(params *params.CmdParams) *cobra.Command {
cmd := &cobra.Command{
Use: fmt.Sprintf("describe %s", argKeyID),
Short: "Describe a KMS key",
Long: "Describe a KMS key",
Args: args.SingleArg(argKeyID, utils.ValidateUUID),
Example: examples.Build(
examples.NewExample(
`Describe a KMS key with ID xxx of keyring yyy`,
`$ stackit beta kms key describe xxx --keyring-id yyy`,
),
),
RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.Background()

model, err := parseInput(params.Printer, cmd, args)
if err != nil {
return err
}

apiClient, err := client.ConfigureClient(params.Printer, params.CliVersion)
if err != nil {
return err
}

req := buildRequest(ctx, model, apiClient)

resp, err := req.Execute()
if err != nil {
return fmt.Errorf("get key: %w", err)
}

return outputResult(params.Printer, model.OutputFormat, resp)
},
}
configureFlags(cmd)
return cmd
}

func configureFlags(cmd *cobra.Command) {
cmd.Flags().Var(flags.UUIDFlag(), flagKeyRingID, "Key Ring ID")
err := flags.MarkFlagsRequired(cmd, flagKeyRingID)
cobra.CheckErr(err)
}

func parseInput(p *print.Printer, cmd *cobra.Command, args []string) (*inputModel, error) {
globalFlags := globalflags.Parse(p, cmd)
if globalFlags.ProjectId == "" {
return nil, &errors.ProjectIdError{}
}
model := &inputModel{
GlobalFlagModel: globalFlags,
KeyID: args[0],
KeyRingID: flags.FlagToStringValue(p, cmd, flagKeyRingID),
}
p.DebugInputModel(model)
return model, nil
}

func buildRequest(ctx context.Context, model *inputModel, apiClient *kms.APIClient) kms.ApiGetKeyRequest {
return apiClient.GetKey(ctx, model.ProjectId, model.Region, model.KeyRingID, model.KeyID)
}

func outputResult(p *print.Printer, outputFormat string, key *kms.Key) error {
if key == nil {
return fmt.Errorf("key response is empty")
}
return p.OutputResult(outputFormat, key, func() error {
table := tables.NewTable()
table.AddRow("ID", utils.PtrString(key.Id))
table.AddSeparator()
table.AddRow("DISPLAY NAME", utils.PtrString(key.DisplayName))
table.AddSeparator()
table.AddRow("CREATED AT", utils.PtrString(key.CreatedAt))
table.AddSeparator()
table.AddRow("STATE", utils.PtrString(key.State))
table.AddSeparator()
table.AddRow("DESCRIPTION", utils.PtrString(key.Description))
table.AddSeparator()
table.AddRow("ACCESS SCOPE", utils.PtrString(key.AccessScope))
table.AddSeparator()
table.AddRow("ALGORITHM", utils.PtrString(key.Algorithm))
table.AddSeparator()
table.AddRow("DELETION DATE", utils.PtrString(key.DeletionDate))
table.AddSeparator()
table.AddRow("IMPORT ONLY", utils.PtrString(key.ImportOnly))
table.AddSeparator()
table.AddRow("KEYRING ID", utils.PtrString(key.KeyRingId))
table.AddSeparator()
table.AddRow("PROTECTION", utils.PtrString(key.Protection))
table.AddSeparator()
table.AddRow("PURPOSE", utils.PtrString(key.Purpose))

err := table.Display(p)
if err != nil {
return fmt.Errorf("display table: %w", err)
}
return nil
})
}
Loading
Loading