-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
feat[Spanner]: Add Multi Region Encryption samples #2832
feat[Spanner]: Add Multi Region Encryption samples #2832
Conversation
Here is the summary of changes. You are about to add 4 region tags.
This comment is generated by snippet-bot.
|
@panerorenn9541 FYI |
d7d1609
to
9ba9295
Compare
9ba9295
to
ab94b89
Compare
public async Task TestCopyBackupWithMultiRegionEncryptionAsync() | ||
{ | ||
CopyBackupWithMultiRegionEncryptionAsyncSample copyBackupSample = new CopyBackupWithMultiRegionEncryptionAsyncSample(); | ||
string source_Project_id = _fixture.ProjectId; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason these are using underscores instead of sourceProjectId
etc?
You could potentially introduce a record type to make this simpler:
var source = new BackupName(_fixture.ProjectId, _fixture.InstanceId, _fixture.BackupId);
var target = new BackupName(_fixture.ProjectId, _fixture.InstanceId, SpannerFixture.GenerateId("test_", 16));
...
var backup = await copyBackupSample.CopyBackupWithMultiRegionEncryptionAsync(
source.InstanceId, source.ProjectId, source.BackupId,
target.InstanceId, target.ProjectId, target.BackupId,
expireTime, kmsKeyNames);
...
}
// As a nested type
public record BackupName(string ProjectId, string InstanceId, string BackupId)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is assuming there isn't a good BackupName class already, of course - I'd really have hoped there would be...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like we do have BackupName, because it's used later. Just use that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I simpliefied this. I used named parameters when calling the method and pass the fixture values directly.
Note that we don't pass the BackupName to the sample as parameter because we want to show how to use BackupName.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've also fixed the code from where this was copied.
[SkippableFact] | ||
public async Task TestCreateBackupWithMultiRegionEncryptionAsync() | ||
{ | ||
Skip.If(!_fixture.RunCmekBackupSampleTests, SpannerFixture.SkipCmekBackupSamplesMessage); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps change RunCmekBackupSampleTests to SkipCmekBackupSampleTests for consistency between the two properties, and to avoid the negation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! And changed everywhere.
|
||
Console.WriteLine($"Backup copied successfully."); | ||
Console.WriteLine($"Backup with Id {sourceBackupId} has been copied from {sourceProjectId}/{sourceInstanceId} to {targetProjectId}/{targetInstanceId} Backup {targetBackupId}"); | ||
Console.WriteLine($"Backup {backup.Name} of size {backup.SizeBytes} bytes was created with encryption keys {string.Join(", ", (object[]) kmsKeyNames)} at {backup.CreateTime} from {backup.Database} and is in state {backup.State} and has version time {backup.VersionTime.ToDateTime()}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the cast to object[]
? I wouldn't expect that to be necessary. (I assume I'm missing something, but I'd like to know what...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to call ToDateTime() either - I believe we'll end up with an ISO-8601-formatted timestamp if you just use {backup.VersionTime}
. (You're doing that later with CreateTime, so I'd assume it would work the same?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the cast to object[]? I wouldn't expect that to be necessary.
This is an array of CryptoKeyNames
so the call to string.Join
is ambiguos between object[]
and IEnumerable<T>
. I'm changing this to be an IEnumerable<CryptoKeyNames>
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to call ToDateTime() either
Yes, removed the call to ToDateTime, here and in the cody from where this was copied.
} | ||
|
||
var backup = completedResponse.Result; | ||
Console.WriteLine($"Backup {backup.Name} of size {backup.SizeBytes} bytes was created with encryption keys {string.Join(", ", (object[]) kmsKeyNames)} at {backup.CreateTime}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto on the cast here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(It's in later samples too.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turned the parameter to IEnumerable<CryptoKeyName>
everywhere. And removed the cast.
DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.Create(); | ||
// Define create table statement for table #1. | ||
var createSingersTable = | ||
@"CREATE TABLE Singers ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: indent this line? (Ditto for createAlbumsTable)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done here and in all the create database samples.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving so that you can merge after addressing the comments, which are all nits really.
ab94b89
to
e10cf06
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jskeet all comments addressed and fixed elsewhere. Changes in the second commit. PTAL.
public async Task TestCopyBackupWithMultiRegionEncryptionAsync() | ||
{ | ||
CopyBackupWithMultiRegionEncryptionAsyncSample copyBackupSample = new CopyBackupWithMultiRegionEncryptionAsyncSample(); | ||
string source_Project_id = _fixture.ProjectId; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I simpliefied this. I used named parameters when calling the method and pass the fixture values directly.
Note that we don't pass the BackupName to the sample as parameter because we want to show how to use BackupName.
[SkippableFact] | ||
public async Task TestCreateBackupWithMultiRegionEncryptionAsync() | ||
{ | ||
Skip.If(!_fixture.RunCmekBackupSampleTests, SpannerFixture.SkipCmekBackupSamplesMessage); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! And changed everywhere.
public async Task TestCopyBackupWithMultiRegionEncryptionAsync() | ||
{ | ||
CopyBackupWithMultiRegionEncryptionAsyncSample copyBackupSample = new CopyBackupWithMultiRegionEncryptionAsyncSample(); | ||
string source_Project_id = _fixture.ProjectId; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've also fixed the code from where this was copied.
|
||
Console.WriteLine($"Backup copied successfully."); | ||
Console.WriteLine($"Backup with Id {sourceBackupId} has been copied from {sourceProjectId}/{sourceInstanceId} to {targetProjectId}/{targetInstanceId} Backup {targetBackupId}"); | ||
Console.WriteLine($"Backup {backup.Name} of size {backup.SizeBytes} bytes was created with encryption keys {string.Join(", ", (object[]) kmsKeyNames)} at {backup.CreateTime} from {backup.Database} and is in state {backup.State} and has version time {backup.VersionTime.ToDateTime()}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the cast to object[]? I wouldn't expect that to be necessary.
This is an array of CryptoKeyNames
so the call to string.Join
is ambiguos between object[]
and IEnumerable<T>
. I'm changing this to be an IEnumerable<CryptoKeyNames>
instead.
|
||
Console.WriteLine($"Backup copied successfully."); | ||
Console.WriteLine($"Backup with Id {sourceBackupId} has been copied from {sourceProjectId}/{sourceInstanceId} to {targetProjectId}/{targetInstanceId} Backup {targetBackupId}"); | ||
Console.WriteLine($"Backup {backup.Name} of size {backup.SizeBytes} bytes was created with encryption keys {string.Join(", ", (object[]) kmsKeyNames)} at {backup.CreateTime} from {backup.Database} and is in state {backup.State} and has version time {backup.VersionTime.ToDateTime()}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to call ToDateTime() either
Yes, removed the call to ToDateTime, here and in the cody from where this was copied.
} | ||
|
||
var backup = completedResponse.Result; | ||
Console.WriteLine($"Backup {backup.Name} of size {backup.SizeBytes} bytes was created with encryption keys {string.Join(", ", (object[]) kmsKeyNames)} at {backup.CreateTime}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turned the parameter to IEnumerable<CryptoKeyName>
everywhere. And removed the cast.
DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.Create(); | ||
// Define create table statement for table #1. | ||
var createSingersTable = | ||
@"CREATE TABLE Singers ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done here and in all the create database samples.
e10cf06
to
95a5008
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One simple nit - rest looks good.
@@ -38,9 +38,11 @@ public void CopyBackup() | |||
string target_backupId = SpannerFixture.GenerateId("test_", 16); | |||
DateTimeOffset expireTime = DateTimeOffset.UtcNow.AddHours(12); | |||
|
|||
Backup backup = copyBackupSample.CopyBackup(source_Instance_id, source_Project_id, source_backupId, | |||
target_Instance_id, target_Project_id, target_backupId, expireTime); | |||
Backup backup = copyBackupSample.CopyBackup( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variables are still declared above, just not used any more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, thanks!
95a5008
to
adb188b
Compare
No description provided.