-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: add Spanner samples for MR CMEK #2772
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
Closed
Closed
Changes from 17 commits
Commits
Show all changes
68 commits
Select commit
Hold shift + click to select a range
4371db4
Add CreateDatabaseWithMRCMEKAsync.cs
panerorenn9541 eb4ee80
Update CreateDatabaseWithMRCMEKAsync.cs
panerorenn9541 9f88bf8
Add CreateBackupWithMRCMEKAsync.cs
panerorenn9541 d4dc0ef
Add RestoreDatabaseWithMRCMEKAsync.cs
panerorenn9541 d041cc5
Add CopyBackupWithMRCMEK.cs
panerorenn9541 10582b0
Add CreateDatabaseWithMRCMEKAsyncTest.cs
panerorenn9541 46dbc73
Update CreateDatabaseWithMRCMEKAsyncTest.cs
panerorenn9541 0c76ecf
Add CreateBackupWithMRCMEKAsyncTest.cs
panerorenn9541 caac817
Update CreateDatabaseWithMRCMEKAsync.cs
panerorenn9541 ef24b05
Update CopyBackupWithMRCMEK.cs
panerorenn9541 d6fc8e7
Update CreateBackupWithMRCMEKAsync.cs
panerorenn9541 79c1908
Update RestoreDatabaseWithMRCMEKAsync.cs
panerorenn9541 8ad9af3
Update CreateDatabaseWithMRCMEKAsync.cs
panerorenn9541 b0fff8b
Add CopyBackupWithMRCMEKTest.cs
panerorenn9541 2aae2df
Create RestoreDatabaseWithMRCMEKAsyncTest.cs
panerorenn9541 c6257a9
Update CreateDatabaseWithMRCMEKAsyncTest.cs
panerorenn9541 5ebb6bd
Update SpannerFixture.cs to include multiple keys
panerorenn9541 dd5a28a
Update and rename CopyBackupWithMRCMEKTest.cs to CopyBackupWithMrCmek…
panerorenn9541 197ef15
Update and rename CreateBackupWithMRCMEKAsyncTest.cs to CreateBackupW…
panerorenn9541 bffdead
Update and rename CreateDatabaseWithMRCMEKAsyncTest.cs to CreateDatab…
panerorenn9541 f426968
Update and rename RestoreDatabaseWithMRCMEKAsyncTest.cs to RestoreDat…
panerorenn9541 93ee32c
Update and rename CopyBackupWithMRCMEK.cs to CopyBackupWithMrCmek.cs
panerorenn9541 194b59c
Update and rename CreateBackupWithMRCMEKAsync.cs to CreateBackupWithM…
panerorenn9541 5a487bb
Update and rename CreateDatabaseWithMRCMEKAsync.cs to CreateDatabaseW…
panerorenn9541 6b07ecf
Update and rename RestoreDatabaseWithMRCMEKAsync.cs to RestoreDatabas…
panerorenn9541 00b3076
Update CopyBackupWithMrCmekTest.cs
panerorenn9541 b3b8330
Update CreateBackupWithMrCmekAsyncTest.cs
panerorenn9541 9967289
Update CreateDatabaseWithMrCmekAsyncTest.cs
panerorenn9541 9f33481
Update RestoreDatabaseWithMrCmekAsyncTest.cs
panerorenn9541 187157f
Update CopyBackupWithMrCmek.cs
panerorenn9541 d37be25
Update CreateBackupWithMrCmekAsync.cs
panerorenn9541 68a2f86
Update CreateDatabaseWithMrCmekAsync.cs
panerorenn9541 d405eb7
Update RestoreDatabaseWithMrCmekAsync.cs
panerorenn9541 f32a8c1
Update CopyBackupWithMrCmekTest.cs
panerorenn9541 fe995c0
Update CreateBackupWithMrCmekAsyncTest.cs
panerorenn9541 e740ee9
Update CreateDatabaseWithMrCmekAsyncTest.cs
panerorenn9541 e548d49
Update RestoreDatabaseWithMrCmekAsyncTest.cs
panerorenn9541 46eeb4b
Update CopyBackupWithMrCmek.cs
panerorenn9541 16f0b19
Update CopyBackupWithMrCmek.cs
panerorenn9541 40591ac
Update CreateBackupWithMrCmekAsync.cs
panerorenn9541 266ca60
Update CreateBackupWithMrCmekAsync.cs
panerorenn9541 a34244e
Update CreateDatabaseWithMrCmekAsync.cs
panerorenn9541 dcd1750
Update RestoreDatabaseWithMrCmekAsync.cs
panerorenn9541 ef7265d
Update CopyBackupWithMrCmekTest.cs
panerorenn9541 2c5683d
Update CreateBackupWithMrCmekAsyncTest.cs
panerorenn9541 919b655
Update CreateDatabaseWithMrCmekAsyncTest.cs
panerorenn9541 9c729d9
Update CreateDatabaseWithMrCmekAsyncTest.cs
panerorenn9541 c0be0ff
Update RestoreDatabaseWithMrCmekAsyncTest.cs
panerorenn9541 3a5bf85
Update SpannerFixture.cs
panerorenn9541 cad4c2b
Merge branch 'main' into main
panerorenn9541 b826e31
Update CreateDatabaseWithMrCmekAsync.cs
panerorenn9541 775114d
Update CreateBackupWithMrCmekAsync.cs
panerorenn9541 36b2315
Update CopyBackupWithMrCmek.cs
panerorenn9541 f2c5d36
Update RestoreDatabaseWithMrCmekAsync.cs
panerorenn9541 53e08c2
Update RestoreDatabaseWithMrCmekAsync.cs
panerorenn9541 45781a9
Update CreateBackupWithMrCmekAsync.cs
panerorenn9541 6f21975
Update CreateDatabaseWithMrCmekAsync.cs
panerorenn9541 5d8e65d
Update CopyBackupWithMrCmek.cs
panerorenn9541 3d11bb9
Update and rename CopyBackupWithMrCmek.cs to CopyBackupWithMrCmekAsyn…
panerorenn9541 33f32a5
Update SpannerFixture.cs
panerorenn9541 03b6bcc
Update CreateBackupWithMrCmekAsyncTest.cs
panerorenn9541 a63aa0e
Update CreateDatabaseWithMrCmekAsyncTest.cs
panerorenn9541 1d14bb2
Update RestoreDatabaseWithMrCmekAsyncTest.cs
panerorenn9541 8032f51
Update and rename CopyBackupWithMrCmekTest.cs to CopyBackupWithMrCmek…
panerorenn9541 30492d9
Update CreateBackupWithMrCmekAsyncTest.cs
panerorenn9541 3d9b027
Update SpannerFixture.cs
panerorenn9541 bae1591
Merge branch 'GoogleCloudPlatform:main' into main
panerorenn9541 f1499f3
Update SpannerFixture.cs
panerorenn9541 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
47 changes: 47 additions & 0 deletions
47
spanner/api/Spanner.Samples.Tests/CopyBackupWithMRCMEKTest.cs
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 |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| // Copyright 2022 Google Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| using Google.Cloud.Spanner.Admin.Database.V1; | ||
| using System; | ||
| using Xunit; | ||
|
|
||
| [Collection(nameof(SpannerFixture))] | ||
| public class CopyBackupWithMRCMEKTest | ||
| { | ||
| private readonly SpannerFixture _spannerFixture; | ||
|
|
||
| public CopyBackupWithMRCMEKTest(SpannerFixture spannerFixture) | ||
| { | ||
| _spannerFixture = spannerFixture; | ||
| } | ||
|
|
||
| [Fact] | ||
| public void CopyBackupWithMRCMEK() | ||
| { | ||
| CopyBackupWithMRCMEKSample copyBackupWithMRCMEKSample = new CopyBackupWithMRCMEKSample(); | ||
| string source_Project_id = _spannerFixture.ProjectId; | ||
| string source_Instance_id = _spannerFixture.InstanceId; | ||
| string source_backupId = _spannerFixture.BackupId; | ||
| string target_Project_id = _spannerFixture.ProjectId; | ||
| string target_Instance_id = _spannerFixture.InstanceId; | ||
| string target_backupId = SpannerFixture.GenerateId("test_", 16); | ||
| DateTimeOffset expireTime = DateTimeOffset.UtcNow.AddHours(12); | ||
| CryptoKeyName[] kmsKeyNames = _fixture.KmsKeyNames; | ||
|
|
||
| Backup backup = copyBackupWithMRCMEKSample.CopyBackupWithMRCMEK(source_Instance_id, source_Project_id, source_backupId, | ||
| target_Instance_id, target_Project_id, target_backupId, expireTime, kmsKeyNames); | ||
|
|
||
| Assert.NotNull(backup); | ||
| } | ||
| } | ||
45 changes: 45 additions & 0 deletions
45
spanner/api/Spanner.Samples.Tests/CreateBackupWithMRCMEKAsyncTest.cs
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 |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // Copyright 2021 Google Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| using System; | ||
| using System.Threading.Tasks; | ||
| using Xunit; | ||
|
|
||
| /// <summary> | ||
| /// Tests creating a backup using MR CMEK. | ||
| /// </summary> | ||
| [Collection(nameof(SpannerFixture))] | ||
| public class CreateBackupWithMRCMEKAsyncTest | ||
| { | ||
| private readonly SpannerFixture _fixture; | ||
|
|
||
| public CreateBackupWithMRCMEKAsyncTest(SpannerFixture fixture) | ||
| { | ||
| _fixture = fixture; | ||
| } | ||
|
|
||
| [SkippableFact] | ||
| public async Task TestCreatBackupWithMRCMEKAsync() | ||
| { | ||
| Skip.If(!_fixture.RunCmekBackupSampleTests, SpannerFixture.SkipCmekBackupSamplesMessage); | ||
| // Create a backup with custom encryption keys. | ||
| var sample = new CreateBackupWithMRCMEKAsyncSample(); | ||
| var backup = await sample.CreateBackupWithMRCMEKAsync(_fixture.ProjectId, _fixture.InstanceId, _fixture.FixedEncryptedDatabaseId, _fixture.EncryptedBackupId, _fixture.KmsKeyNames); | ||
panerorenn9541 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Assert.Equal(_fixture.KmsKeyNames.Length, backup.EncryptionInfo.KmsKeyVersionsAsCryptoKeyVersionNames.Length); | ||
| foreach (CryptoKeyVersionName KmsKeyVersion in backup.EncryptionInfo.KmsKeyVersionsAsCryptoKeyVersionNames) | ||
| { | ||
| Assert.True(_fixture.KmsKeyNames.contains(KmsKeyVersion.CryptoKeyId)); | ||
| } | ||
| } | ||
panerorenn9541 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
44 changes: 44 additions & 0 deletions
44
spanner/api/Spanner.Samples.Tests/CreateDatabaseWithMRCMEKAsyncTest.cs
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 |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| // Copyright 2021 Google Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| using System.Threading.Tasks; | ||
| using Xunit; | ||
| using Google.Cloud.Spanner.Admin.Database.V1; | ||
|
|
||
| /// <summary> | ||
| /// Tests creating a databases using MR CMEK. | ||
| /// </summary> | ||
| [Collection(nameof(SpannerFixture))] | ||
| public class CreateDatabaseWithMRCMEKAsyncTest | ||
| { | ||
| private readonly SpannerFixture _fixture; | ||
|
|
||
| public CreateDatabaseWithMRCMEKAsyncTest(SpannerFixture fixture) | ||
| { | ||
| _fixture = fixture; | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task TestCreateDatabaseWithMRCMEKAsync() | ||
| { | ||
| // Create a database with custom encryption keys. | ||
| var sample = new CreateDatabaseWithMRCMEKAsyncSample(); | ||
| var database = await sample.CreateDatabaseWithMRCMEKAsync(_fixture.ProjectId, _fixture.InstanceId, _fixture.EncryptedDatabaseId, _fixture.KmsKeyNames); | ||
panerorenn9541 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Assert.Equal(_fixture.KmsKeyNames.Length, database.EncryptionConfig.KmsKeyNames.Length); | ||
| foreach (string KmsKey in database.EncryptionConfig.KmsKeyNames) | ||
| { | ||
| Assert.True(_fixture.KmsKeyNames.contains(CryptoKeyName.Parse(KmsKey))); | ||
| } | ||
| } | ||
| } | ||
45 changes: 45 additions & 0 deletions
45
spanner/api/Spanner.Samples.Tests/RestoreDatabaseWithMRCMEKAsyncTest.cs
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 |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // Copyright 2021 Google Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| using Google.Cloud.Spanner.Admin.Database.V1; | ||
| using System; | ||
| using System.Threading.Tasks; | ||
| using Xunit; | ||
|
|
||
| /// <summary> | ||
| /// Tests restoring a databases using customer managed encryption. | ||
| /// </summary> | ||
| [Collection(nameof(SpannerFixture))] | ||
| public class RestoreDatabaseWithMRCMEKAsyncTest | ||
| { | ||
| private readonly SpannerFixture _fixture; | ||
|
|
||
| public RestoreDatabaseWithMRCMEKAsyncTest(SpannerFixture fixture) | ||
| { | ||
| _fixture = fixture; | ||
| } | ||
|
|
||
| [SkippableFact] | ||
| public async Task TestRestoreDatabaseWithMRCMEKAsync() | ||
| { | ||
| Skip.If(!_fixture.RunCmekBackupSampleTests, SpannerFixture.SkipCmekBackupSamplesMessage); | ||
| var sample = new RestoreDatabaseWithMRCMEKAsyncSample(); | ||
| var database = await sample.RestoreDatabaseWithMRCMEKAsync(_fixture.ProjectId, _fixture.InstanceId, _fixture.EncryptedRestoreDatabaseId, _fixture.FixedEncryptedBackupId, _fixture.KmsKeyName); | ||
| Assert.Equal(_fixture.KmsKeyNames.Length, database.EncryptionConfig.KmsKeyNames.Length); | ||
| foreach (string KmsKey in database.EncryptionConfig.KmsKeyNames) | ||
| { | ||
| Assert.True(_fixture.KmsKeyNames.contains(CryptoKeyName.Parse(KmsKey))); | ||
| } | ||
| } | ||
| } |
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.