-
Notifications
You must be signed in to change notification settings - Fork 42
feat: Add kms key options to secrets manager instance commands #1347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
s-inter
merged 12 commits into
main
from
feat/STACKITCLI-338-Add-kms-key-options-to-secrets-manager-instance-commands
Mar 27, 2026
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a8dcff8
feat(secrets-manager): add KMS flags to create and update instance co…
s-inter 317e9cb
feat(secrets-manager): implement request building with KMS key
s-inter c2b2f81
feat(secrets-manager): enforce mutual exclusivity between ACL and KMS…
s-inter 2935546
refactor(secrets-manager): refactor flag requirements to use cobra bu…
s-inter 8281b6f
feat(secrets-manager): add KMS key options examples for create and up…
s-inter 3dfd38b
refactor(secrets-manager): change test data
s-inter 1079356
feat(secrets-manager): add KMS key options to create and update insta…
s-inter 5a4e11d
feat(secrets-manager): add KMS key details to instance output
s-inter 3939539
feat(secrets-manager): add docs
s-inter 9bfec73
fix(secrets-manager): include instance name in payload, as it is requ…
s-inter c010c40
feat(secrets-manager): Support multiple API calls for instance update…
s-inter b9520c8
feat(secrets-manager): test new instance update features
s-inter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,14 +18,21 @@ stackit secrets-manager instance create [flags] | |
|
|
||
| Create a Secrets Manager instance with name "my-instance" and specify IP range which is allowed to access it | ||
| $ stackit secrets-manager instance create --name my-instance --acl 1.2.3.0/24 | ||
|
|
||
| Create a Secrets Manager instance with name "my-instance" and configure KMS key options | ||
| $ stackit secrets-manager instance create --name my-instance --kms-key-id key-id --kms-keyring-id keyring-id --kms-key-version 1 --kms-service-account-email [email protected] | ||
| ``` | ||
|
|
||
| ### Options | ||
|
|
||
| ``` | ||
| --acl strings List of IP networks in CIDR notation which are allowed to access this instance (default []) | ||
| -h, --help Help for "stackit secrets-manager instance create" | ||
| -n, --name string Instance name | ||
| --acl strings List of IP networks in CIDR notation which are allowed to access this instance (default []) | ||
| -h, --help Help for "stackit secrets-manager instance create" | ||
| --kms-key-id string ID of the KMS key to use for encryption | ||
| --kms-key-version int Version of the KMS key | ||
| --kms-keyring-id string ID of the KMS key ring | ||
| --kms-service-account-email string Service account email for KMS access | ||
| -n, --name string Instance name | ||
| ``` | ||
|
|
||
| ### Options inherited from parent commands | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,15 +13,29 @@ stackit secrets-manager instance update INSTANCE_ID [flags] | |
| ### Examples | ||
|
|
||
| ``` | ||
| Update the name of a Secrets Manager instance with ID "xxx" | ||
| $ stackit secrets-manager instance update xxx --name my-new-name | ||
|
|
||
| Update the range of IPs allowed to access a Secrets Manager instance with ID "xxx" | ||
| $ stackit secrets-manager instance update xxx --acl 1.2.3.0/24 | ||
|
|
||
| Update the name and ACLs of a Secrets Manager instance with ID "xxx" | ||
| $ stackit secrets-manager instance update xxx --name my-new-name --acl 1.2.3.0/24 | ||
|
|
||
| Update the KMS key settings of a Secrets Manager instance with ID "xxx" | ||
| $ stackit secrets-manager instance update xxx --name my-instance --kms-key-id key-id --kms-keyring-id keyring-id --kms-key-version 1 --kms-service-account-email [email protected] | ||
| ``` | ||
|
|
||
| ### Options | ||
|
|
||
| ``` | ||
| --acl strings List of IP networks in CIDR notation which are allowed to access this instance (default []) | ||
| -h, --help Help for "stackit secrets-manager instance update" | ||
| --acl strings List of IP networks in CIDR notation which are allowed to access this instance (default []) | ||
| -h, --help Help for "stackit secrets-manager instance update" | ||
| --kms-key-id string ID of the KMS key to use for encryption | ||
| --kms-key-version int Version of the KMS key | ||
| --kms-keyring-id string ID of the KMS key ring | ||
| --kms-service-account-email string Service account email for KMS access | ||
| -n, --name string Instance name | ||
| ``` | ||
|
|
||
| ### Options inherited from parent commands | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,13 +23,23 @@ import ( | |
| const ( | ||
| instanceNameFlag = "name" | ||
| aclFlag = "acl" | ||
|
|
||
| kmsKeyIdFlag = "kms-key-id" | ||
| kmsKeyringIdFlag = "kms-keyring-id" | ||
| kmsKeyVersionFlag = "kms-key-version" | ||
| kmsServiceAccountEmailFlag = "kms-service-account-email" | ||
| ) | ||
|
|
||
| type inputModel struct { | ||
| *globalflags.GlobalFlagModel | ||
|
|
||
| InstanceName *string | ||
| Acls *[]string | ||
|
|
||
| KmsKeyId *string | ||
| KmsKeyringId *string | ||
| KmsKeyVersion *int64 | ||
| KmsServiceAccountEmail *string | ||
| } | ||
|
|
||
| func NewCmd(params *types.CmdParams) *cobra.Command { | ||
|
|
@@ -45,6 +55,9 @@ func NewCmd(params *types.CmdParams) *cobra.Command { | |
| examples.NewExample( | ||
| `Create a Secrets Manager instance with name "my-instance" and specify IP range which is allowed to access it`, | ||
| `$ stackit secrets-manager instance create --name my-instance --acl 1.2.3.0/24`), | ||
| examples.NewExample( | ||
| `Create a Secrets Manager instance with name "my-instance" and configure KMS key options`, | ||
| `$ stackit secrets-manager instance create --name my-instance --kms-key-id key-id --kms-keyring-id keyring-id --kms-key-version 1 --kms-service-account-email [email protected]`), | ||
| ), | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| ctx := context.Background() | ||
|
|
@@ -103,8 +116,15 @@ func configureFlags(cmd *cobra.Command) { | |
| cmd.Flags().StringP(instanceNameFlag, "n", "", "Instance name") | ||
| cmd.Flags().Var(flags.CIDRSliceFlag(), aclFlag, "List of IP networks in CIDR notation which are allowed to access this instance") | ||
|
|
||
| cmd.Flags().String(kmsKeyIdFlag, "", "ID of the KMS key to use for encryption") | ||
| cmd.Flags().String(kmsKeyringIdFlag, "", "ID of the KMS key ring") | ||
| cmd.Flags().Int64(kmsKeyVersionFlag, 0, "Version of the KMS key") | ||
| cmd.Flags().String(kmsServiceAccountEmailFlag, "", "Service account email for KMS access") | ||
|
|
||
| err := flags.MarkFlagsRequired(cmd, instanceNameFlag) | ||
| cobra.CheckErr(err) | ||
|
|
||
| cmd.MarkFlagsRequiredTogether(kmsKeyIdFlag, kmsKeyringIdFlag, kmsKeyVersionFlag, kmsServiceAccountEmailFlag) | ||
| } | ||
|
|
||
| func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, error) { | ||
|
|
@@ -114,9 +134,13 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, | |
| } | ||
|
|
||
| model := inputModel{ | ||
| GlobalFlagModel: globalFlags, | ||
| InstanceName: flags.FlagToStringPointer(p, cmd, instanceNameFlag), | ||
| Acls: flags.FlagToStringSlicePointer(p, cmd, aclFlag), | ||
| GlobalFlagModel: globalFlags, | ||
| InstanceName: flags.FlagToStringPointer(p, cmd, instanceNameFlag), | ||
| Acls: flags.FlagToStringSlicePointer(p, cmd, aclFlag), | ||
| KmsKeyId: flags.FlagToStringPointer(p, cmd, kmsKeyIdFlag), | ||
| KmsKeyringId: flags.FlagToStringPointer(p, cmd, kmsKeyringIdFlag), | ||
| KmsKeyVersion: flags.FlagToInt64Pointer(p, cmd, kmsKeyVersionFlag), | ||
| KmsServiceAccountEmail: flags.FlagToStringPointer(p, cmd, kmsServiceAccountEmailFlag), | ||
| } | ||
|
|
||
| p.DebugInputModel(model) | ||
|
|
@@ -126,9 +150,20 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, | |
| func buildCreateInstanceRequest(ctx context.Context, model *inputModel, apiClient *secretsmanager.APIClient) secretsmanager.ApiCreateInstanceRequest { | ||
| req := apiClient.CreateInstance(ctx, model.ProjectId) | ||
|
|
||
| req = req.CreateInstancePayload(secretsmanager.CreateInstancePayload{ | ||
| payload := secretsmanager.CreateInstancePayload{ | ||
| Name: model.InstanceName, | ||
| }) | ||
| } | ||
|
|
||
| if model.KmsKeyId != nil { | ||
| payload.KmsKey = &secretsmanager.KmsKeyPayload{ | ||
| KeyId: model.KmsKeyId, | ||
| KeyRingId: model.KmsKeyringId, | ||
| KeyVersion: model.KmsKeyVersion, | ||
| ServiceAccountEmail: model.KmsServiceAccountEmail, | ||
| } | ||
| } | ||
|
|
||
| req = req.CreateInstancePayload(payload) | ||
|
|
||
| return req | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,13 @@ var testClient = &secretsmanager.APIClient{} | |
| var testProjectId = uuid.NewString() | ||
| var testInstanceId = uuid.NewString() | ||
|
|
||
| const ( | ||
| testKmsKeyId = "key-id" | ||
| testKmsKeyringId = "keyring-id" | ||
| testKmsKeyVersion = int64(1) | ||
| testKmsServiceAccountEmail = "[email protected]" | ||
| ) | ||
|
|
||
| func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string { | ||
| flagValues := map[string]string{ | ||
| projectIdFlag: testProjectId, | ||
|
|
@@ -162,6 +169,24 @@ func TestParseInput(t *testing.T) { | |
| *model.Acls = append(*model.Acls, "1.2.3.4/32") | ||
| }), | ||
| }, | ||
| { | ||
| description: "kms flags", | ||
| flagValues: fixtureFlagValues(func(flagValues map[string]string) { | ||
| delete(flagValues, aclFlag) | ||
| flagValues[kmsKeyIdFlag] = testKmsKeyId | ||
| flagValues[kmsKeyringIdFlag] = testKmsKeyringId | ||
| flagValues[kmsKeyVersionFlag] = "1" | ||
| flagValues[kmsServiceAccountEmailFlag] = testKmsServiceAccountEmail | ||
| }), | ||
| isValid: true, | ||
| expectedModel: fixtureInputModel(func(model *inputModel) { | ||
| model.Acls = nil | ||
| model.KmsKeyId = utils.Ptr(testKmsKeyId) | ||
| model.KmsKeyringId = utils.Ptr(testKmsKeyringId) | ||
| model.KmsKeyVersion = utils.Ptr(testKmsKeyVersion) | ||
| model.KmsServiceAccountEmail = utils.Ptr(testKmsServiceAccountEmail) | ||
| }), | ||
| }, | ||
| { | ||
| description: "project id missing", | ||
| flagValues: fixtureFlagValues(func(flagValues map[string]string) { | ||
|
|
@@ -205,6 +230,28 @@ func TestBuildCreateInstanceRequest(t *testing.T) { | |
| model: fixtureInputModel(), | ||
| expectedRequest: fixtureRequest(), | ||
| }, | ||
| { | ||
| description: "with kms", | ||
| model: fixtureInputModel(func(model *inputModel) { | ||
| model.Acls = nil | ||
| model.KmsKeyId = utils.Ptr(testKmsKeyId) | ||
| model.KmsKeyringId = utils.Ptr(testKmsKeyringId) | ||
| model.KmsKeyVersion = utils.Ptr(testKmsKeyVersion) | ||
| model.KmsServiceAccountEmail = utils.Ptr(testKmsServiceAccountEmail) | ||
| }), | ||
| expectedRequest: fixtureRequest(func(request *secretsmanager.ApiCreateInstanceRequest) { | ||
| payload := secretsmanager.CreateInstancePayload{ | ||
| Name: utils.Ptr("example"), | ||
| KmsKey: &secretsmanager.KmsKeyPayload{ | ||
| KeyId: utils.Ptr(testKmsKeyId), | ||
| KeyRingId: utils.Ptr(testKmsKeyringId), | ||
| KeyVersion: utils.Ptr(testKmsKeyVersion), | ||
| ServiceAccountEmail: utils.Ptr(testKmsServiceAccountEmail), | ||
| }, | ||
| } | ||
| *request = (*request).CreateInstancePayload(payload) | ||
| }), | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ import ( | |
| "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" | ||
| "github.com/stackitcloud/stackit-cli/internal/pkg/print" | ||
| "github.com/stackitcloud/stackit-cli/internal/pkg/testutils" | ||
| "github.com/stackitcloud/stackit-cli/internal/pkg/utils" | ||
|
|
||
| "github.com/google/go-cmp/cmp" | ||
| "github.com/google/go-cmp/cmp/cmpopts" | ||
|
|
@@ -247,6 +248,21 @@ func TestOutputResult(t *testing.T) { | |
| }, | ||
| wantErr: false, | ||
| }, | ||
| { | ||
| name: "instance with kms key", | ||
| args: args{ | ||
| instance: &secretsmanager.Instance{ | ||
| KmsKey: &secretsmanager.KmsKeyPayload{ | ||
| KeyId: utils.Ptr("key-id"), | ||
| KeyRingId: utils.Ptr("keyring-id"), | ||
| KeyVersion: utils.Ptr(int64(1)), | ||
| ServiceAccountEmail: utils.Ptr("[email protected]"), | ||
| }, | ||
| }, | ||
| aclList: &secretsmanager.ListACLsResponse{}, | ||
| }, | ||
| wantErr: false, | ||
| }, | ||
| } | ||
| p := print.NewPrinter() | ||
| p.Cmd = NewCmd(&types.CmdParams{Printer: p}) | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.