Skip to content

Commit 04df93e

Browse files
Merge pull request #211 from RedisLabs/feat/customer-managed-encryption-keys
Customer managed encryption keys
2 parents 1a79923 + 2df372f commit 04df93e

File tree

4 files changed

+120
-11
lines changed

4 files changed

+120
-11
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,18 @@
22
All notable changes to this project will be documented in this file.
33
See updating [Changelog example here](https://keepachangelog.com/en/1.0.0/).
44

5+
## 0.31.0
6+
7+
### Added
8+
9+
* Adding an API call and endpoint for updating customer-managed encryption keys (CMKs) to an existing subscription.
10+
* Adding a new status to support the `encryption_key_pending` status of a subscription.
11+
512
## 0.30.0
613

714
### Added
815

9-
* Adding in support for `persistentStorageEncryptionType`, to support CMEK, across pro and active active subscription creation
16+
* Adding in support for `persistentStorageEncryptionType`, to support customer-managed encryption keys (CMKs) across pro and active-active subscription creation
1017

1118
## 0.29.0
1219

service/subscriptions/model.go

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,38 @@ func (o UpdateSubscription) String() string {
109109
return internal.ToString(o)
110110
}
111111

112+
type UpdateSubscriptionCMKs struct {
113+
DeletionGracePeriod *string `json:"deletionGracePeriod,omitempty"`
114+
CustomerManagedKeys *[]CustomerManagedKey `json:"customerManagedKeys,omitempty"`
115+
}
116+
117+
type CustomerManagedKey struct {
118+
ResourceName *string `json:"resourceName,omitempty"`
119+
Region *string `json:"region,omitempty"`
120+
}
121+
122+
func (o UpdateSubscriptionCMKs) String() string {
123+
return internal.ToString(o)
124+
}
125+
112126
type Subscription struct {
113-
ID *int `json:"id,omitempty"`
114-
Name *string `json:"name,omitempty"`
115-
Status *string `json:"status,omitempty"`
116-
DeploymentType *string `json:"deploymentType,omitempty"`
117-
PaymentMethod *string `json:"paymentMethodType,omitempty"`
118-
PaymentMethodID *int `json:"paymentMethodId,omitempty"`
119-
MemoryStorage *string `json:"memoryStorage,omitempty"`
120-
StorageEncryption *bool `json:"storageEncryption,omitempty"`
121-
NumberOfDatabases *int `json:"numberOfDatabases,omitempty"`
122-
CloudDetails []*CloudDetail `json:"cloudDetails,omitempty"`
127+
ID *int `json:"id,omitempty"`
128+
Name *string `json:"name,omitempty"`
129+
Status *string `json:"status,omitempty"`
130+
DeploymentType *string `json:"deploymentType,omitempty"`
131+
PaymentMethod *string `json:"paymentMethodType,omitempty"`
132+
PaymentMethodID *int `json:"paymentMethodId,omitempty"`
133+
MemoryStorage *string `json:"memoryStorage,omitempty"`
134+
StorageEncryption *bool `json:"storageEncryption,omitempty"`
135+
NumberOfDatabases *int `json:"numberOfDatabases,omitempty"`
136+
CloudDetails []*CloudDetail `json:"cloudDetails,omitempty"`
137+
CustomerManagedKeyAccessDetails *CustomerManagedKeyAccessDetails `json:"customerManagedKeyAccessDetails,omitempty"`
138+
}
139+
140+
type CustomerManagedKeyAccessDetails struct {
141+
RedisServiceAccount *string `json:"redisServiceAccount,omitempty"`
142+
GooglePredefinedRoles []*string `json:"googlePredefinedRoles,omitempty"`
143+
GoogleCustomPermissions []*string `json:"googleCustomPermissions,omitempty"`
123144
}
124145

125146
func (o Subscription) String() string {
@@ -312,6 +333,8 @@ const (
312333
SubscriptionStatusActive = "active"
313334
// SubscriptionStatusPending is the pending value of the `Status` field in `Subscription`
314335
SubscriptionStatusPending = "pending"
336+
// SubscriptionStatusEncryptionKeyPending is the encryption key pending value of the `Status` field in `Subscription`
337+
SubscriptionStatusEncryptionKeyPending = "encryption_key_pending"
315338
// SubscriptionStatusError is the error value of the `Status` field in `Subscription`
316339
SubscriptionStatusError = "error"
317340
// SubscriptionStatusDeleting is the deleting value of the `Status` field in `Subscription`

service/subscriptions/service.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,24 @@ func (a *API) Update(ctx context.Context, id int, subscription UpdateSubscriptio
9393
return nil
9494
}
9595

96+
// Update will make changes to an existing subscription's CMKs.
97+
func (a *API) UpdateCMKs(ctx context.Context, id int, subscriptionCMKs UpdateSubscriptionCMKs) error {
98+
var task internal.TaskResponse
99+
err := a.client.Put(ctx, fmt.Sprintf("update subscription %d", id), fmt.Sprintf("/subscriptions/%d", id), subscriptionCMKs, &task)
100+
if err != nil {
101+
return wrap404Error(id, err)
102+
}
103+
104+
a.logger.Printf("Waiting for task %s to finish updating subscription %d", task, id)
105+
106+
err = a.taskWaiter.Wait(ctx, *task.ID)
107+
if err != nil {
108+
return fmt.Errorf("failed when updating subscription %d: %w", id, err)
109+
}
110+
111+
return nil
112+
}
113+
96114
// Delete will destroy an existing subscription. All existing databases within the subscription should already be
97115
// deleted, otherwise this function will fail.
98116
func (a *API) Delete(ctx context.Context, id int) error {

subscription_test.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,67 @@ func TestSubscription_Update(t *testing.T) {
592592
require.NoError(t, err)
593593
}
594594

595+
func TestSubscription_Update_CMKs(t *testing.T) {
596+
597+
const request = `
598+
{
599+
"deletionGracePeriod": "test",
600+
"customerManagedKeys": [
601+
{
602+
"resourceName": "test_cmk",
603+
"region": "us-east-1"
604+
}
605+
]
606+
}
607+
`
608+
609+
const body = `{
610+
"taskId": "task",
611+
"commandType": "subscriptionUpdateRequest",
612+
"status": "received",
613+
"description": "Task request received and is being queued for processing.",
614+
"timestamp": "2020-11-02T09:05:34.3Z",
615+
"_links": {
616+
"task": {
617+
"href": "https://example.org",
618+
"title": "getTaskStatusUpdates",
619+
"type": "GET"
620+
}
621+
}
622+
}`
623+
624+
s := httptest.NewServer(testServer("key", "secret", putRequest(t, "/subscriptions/1234", request, body), getRequest(t, "/tasks/task", `{
625+
"taskId": "e02b40d6-1395-4861-a3b9-ecf829d835fd",
626+
"commandType": "subscriptionUpdateRequest",
627+
"status": "processing-completed",
628+
"timestamp": "2020-10-28T09:58:16.798Z",
629+
"response": {
630+
},
631+
"_links": {
632+
"self": {
633+
"href": "https://example.com",
634+
"type": "GET"
635+
}
636+
}
637+
}`)))
638+
defer s.Close()
639+
640+
subject, err := clientFromTestServer(s, "key", "secret")
641+
require.NoError(t, err)
642+
643+
err = subject.Subscription.UpdateCMKs(context.TODO(), 1234, subscriptions.UpdateSubscriptionCMKs{
644+
DeletionGracePeriod: redis.String("test"),
645+
CustomerManagedKeys: &[]subscriptions.CustomerManagedKey{
646+
{
647+
ResourceName: redis.String("test_cmk"),
648+
Region: redis.String("us-east-1"),
649+
},
650+
},
651+
})
652+
653+
require.NoError(t, err)
654+
}
655+
595656
func TestSubscription_Delete(t *testing.T) {
596657
s := httptest.NewServer(testServer("apiKey", "secret", deleteRequest(t, "/subscriptions/12356", `{
597658
"taskId": "task",

0 commit comments

Comments
 (0)