Skip to content

Commit eae8ec2

Browse files
author
Jan Sternagel
committed
added import from file
1 parent ae0efe3 commit eae8ec2

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

docs/stackit_beta_kms_key_import.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Import a KMS key
44

55
### Synopsis
66

7-
Import a new version to the given KMS key.
7+
After encrypting the secret with the wrapping key’s public key and Base64-encoding it, import it as a new version of the specified KMS key.
88

99
```
1010
stackit beta kms key import KEY_ID [flags]
@@ -13,16 +13,19 @@ stackit beta kms key import KEY_ID [flags]
1313
### Examples
1414

1515
```
16-
Import a new version for the given KMS key "MY_KEY_ID"
17-
$ stackit beta kms key import "MY_KEY_ID" --keyring-id "MY_KEYRING_ID" --wrapped-key "base64-encoded-wrapped-key-material" --wrapping-key-id "MY_WRAPPING_KEY_ID"
16+
Import a new version for the given KMS key "MY_KEY_ID" from literal value
17+
$ stackit beta kms key import "MY_KEY_ID" --keyring-id "MY_KEYRING_ID" --wrapped-key "BASE64_VALUE" --wrapping-key-id "MY_WRAPPING_KEY_ID"
18+
19+
Import from a file
20+
$ stackit beta kms key import "MY_KEY_ID" --keyring-id "MY_KEYRING_ID" --wrapped-key "path/to/wrapped.key.b64" --wrapping-key-id "MY_WRAPPING_KEY_ID"
1821
```
1922

2023
### Options
2124

2225
```
2326
-h, --help Help for "stackit beta kms key import"
2427
--keyring-id string ID of the KMS key ring
25-
--wrapped-key string The wrapped key material that has to be imported. Encoded in base64
28+
--wrapped-key string The wrapped key material to be imported. Base64-encoded. Pass the value directly or a file path (e.g. path/to/wrapped.key.b64)
2629
--wrapping-key-id string The unique id of the wrapping key the key material has been wrapped with
2730
```
2831

internal/cmd/beta/kms/key/importKey/importKey.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,18 @@ func NewCmd(params *params.CmdParams) *cobra.Command {
4242
cmd := &cobra.Command{
4343
Use: fmt.Sprintf("import %s", keyIdArg),
4444
Short: "Import a KMS key",
45-
Long: "Import a new version to the given KMS key.",
45+
Long: "After encrypting the secret with the wrapping key’s public key and Base64-encoding it, import it as a new version of the specified KMS key.",
4646
Args: args.SingleArg(keyIdArg, utils.ValidateUUID),
4747
Example: examples.Build(
4848
examples.NewExample(
49-
`Import a new version for the given KMS key "MY_KEY_ID"`,
50-
`$ stackit beta kms key import "MY_KEY_ID" --keyring-id "MY_KEYRING_ID" --wrapped-key "base64-encoded-wrapped-key-material" --wrapping-key-id "MY_WRAPPING_KEY_ID"`),
49+
`Import a new version for the given KMS key "MY_KEY_ID" from literal value`,
50+
`$ stackit beta kms key import "MY_KEY_ID" --keyring-id "MY_KEYRING_ID" --wrapped-key "BASE64_VALUE" --wrapping-key-id "MY_WRAPPING_KEY_ID"`),
51+
examples.NewExample(
52+
`Import from a file`,
53+
`$ stackit beta kms key import "MY_KEY_ID" --keyring-id "MY_KEYRING_ID" --wrapped-key "path/to/wrapped.key.b64" --wrapping-key-id "MY_WRAPPING_KEY_ID"`,
54+
),
5155
),
56+
5257
RunE: func(cmd *cobra.Command, args []string) error {
5358
ctx := context.Background()
5459
model, err := parseInput(params.Printer, cmd, args)
@@ -109,7 +114,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
109114
if err != nil || *wrappedKey == "" {
110115
return nil, &cliErr.FlagValidationError{
111116
Flag: wrappedKeyFlag,
112-
Details: "The 'wrappedKey' argument is required and needs to be base64 encoded.",
117+
Details: "The 'wrappedKey' argument is required and needs to be base64 encoded (whether provided inline or via file).",
113118
}
114119
}
115120

@@ -168,7 +173,7 @@ func outputResult(p *print.Printer, outputFormat, keyRingName, keyName string, r
168173

169174
func configureFlags(cmd *cobra.Command) {
170175
cmd.Flags().Var(flags.UUIDFlag(), keyRingIdFlag, "ID of the KMS key ring")
171-
cmd.Flags().String(wrappedKeyFlag, "", "The wrapped key material that has to be imported. Encoded in base64")
176+
cmd.Flags().Var(flags.ReadFromFileFlag(), wrappedKeyFlag, "The wrapped key material to be imported. Base64-encoded. Pass the value directly or a file path (e.g. path/to/wrapped.key.b64)")
172177
cmd.Flags().Var(flags.UUIDFlag(), wrappingKeyIdFlag, "The unique id of the wrapping key the key material has been wrapped with")
173178

174179
err := flags.MarkFlagsRequired(cmd, keyRingIdFlag, wrappedKeyFlag, wrappingKeyIdFlag)

0 commit comments

Comments
 (0)