Repository navigation
Conversation
Regulated workloads protect Spanner databases at rest with a Cloud KMS CryptoKey passed via EncryptionConfig.kms_key_name. Add spanner_create_database_with_encryption_key.
|
Here is the summary of changes. You are about to add 1 region tag.
This comment is generated by snippet-bot.
|
There was a problem hiding this comment.
Code Review
This pull request introduces a new script and associated tests for creating a Spanner database encrypted with a Cloud KMS Customer-Managed Encryption Key (CMEK). The review feedback suggests adding defensive checks when accessing the database's encryption configuration to prevent potential AttributeError exceptions if the returned database object or its encryption configuration is not fully populated.
| configured_key_id = database.encryption_config.kms_key_name.split("/")[-1] | ||
| print(f"Resource ID: {database_id}") | ||
| print(f"Encryption Key ID: {configured_key_id}") |
There was a problem hiding this comment.
To prevent potential AttributeError exceptions (e.g., if the database object or its encryption_config is not fully populated or is None), use defensive checks before accessing database.encryption_config.kms_key_name.
| configured_key_id = database.encryption_config.kms_key_name.split("/")[-1] | |
| print(f"Resource ID: {database_id}") | |
| print(f"Encryption Key ID: {configured_key_id}") | |
| if database and database.encryption_config and database.encryption_config.kms_key_name: | |
| configured_key_id = database.encryption_config.kms_key_name.split("/")[-1] | |
| print(f"Resource ID: {database_id}") | |
| print(f"Encryption Key ID: {configured_key_id}") | |
| else: | |
| print(f"Resource ID: {database_id}") |
There was a problem hiding this comment.
Thanks! Keeping this as is: the field is populated in the responses this sample handles, and the extra branching would distract from what the sample shows.
…_encryption_key Problem: multi-line SQL and DDL statements were written as adjacent string fragments. That style is easy to get wrong (a missing trailing space joins two SQL tokens) and is harder to read than the statement itself, and the samples in this set mixed it with triple-quoted SQL. Solution: write each multi-line statement as a single triple-quoted string, matching the layout already used by the other samples. Only whitespace between SQL tokens changes; the statements are otherwise identical. Files updated: - spanner/database_admin/src/spanner_database_admin/create_database_with_encryption_key.py
…tion_key Problem: review of this sample identified correctness and robustness improvements in the sample and its tests. Solution: apply the accepted review suggestions and extend the tests to cover the updated behavior. Details are in the review thread replies. Files updated: - spanner/database_admin/tests/create_database_with_encryption_key_test.py
Description
Adds
spanner_create_database_with_encryption_keycreating a CMEK-protected Spanner database usingEncryptionConfig(kms_key_name=...).Checklist
Testing
Compliance & Style
spanner/, which the default repository owners cover.Post-Approval Actions