private async Task InitializeEncryptedBackupAsync() { // Sample backup for encrypted restore test. try { CreateDatabaseWithEncryptionKeyAsyncSample createDatabaseAsyncSample = new CreateDatabaseWithEncryptionKeyAsyncSample(); InsertDataAsyncSample insertDataAsyncSample = new InsertDataAsyncSample(); await createDatabaseAsyncSample.CreateDatabaseWithEncryptionKeyAsync(ProjectId, InstanceId, FixedEncryptedDatabaseId, KmsKeyName); await insertDataAsyncSample.InsertDataAsync(ProjectId, InstanceId, FixedEncryptedDatabaseId); } catch (Exception e) when(e.ToString().Contains("Database already exists")) { // We intentionally keep an existing database around to reduce // the likelihood of test timeouts when creating a backup so // it's ok to get an AlreadyExists error. Console.WriteLine($"Database {FixedEncryptedDatabaseId} already exists."); } try { CreateBackupWithEncryptionKeyAsyncSample createBackupSample = new CreateBackupWithEncryptionKeyAsyncSample(); await createBackupSample.CreateBackupWithEncryptionKeyAsync(ProjectId, InstanceId, FixedEncryptedDatabaseId, FixedEncryptedBackupId, KmsKeyName); } catch (RpcException e) when(e.StatusCode == StatusCode.AlreadyExists) { // We intentionally keep an existing backup around to reduce // the likelihood of test timeouts when creating a backup so // it's ok to get an AlreadyExists error. Console.WriteLine($"Backup {FixedEncryptedBackupId} already exists."); } }
public async Task TestCreateDatabaseWithEncryptionKeyAsync() { // Create a database with a custom encryption key. var sample = new CreateDatabaseWithEncryptionKeyAsyncSample(); var database = await sample.CreateDatabaseWithEncryptionKeyAsync(_fixture.ProjectId, _fixture.InstanceId, _fixture.EncryptedDatabaseId, _fixture.KmsKeyName); Assert.Equal(_fixture.KmsKeyName, CryptoKeyName.Parse(database.EncryptionConfig.KmsKeyName)); }