Skip to content

Commit 2fd0352

Browse files
authored
feat: add encryption_info to Database (#284)
* feat: add encryption_info to Database * test: fix test name Co-authored-by: larkee <[email protected]>
1 parent c6cba9f commit 2fd0352

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

google/cloud/spanner_v1/database.py

+10
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ def __init__(
142142
self._restore_info = None
143143
self._version_retention_period = None
144144
self._earliest_version_time = None
145+
self._encryption_info = None
145146
self.log_commit_stats = False
146147
self._logger = logger
147148
self._encryption_config = encryption_config
@@ -269,6 +270,14 @@ def encryption_config(self):
269270
"""
270271
return self._encryption_config
271272

273+
@property
274+
def encryption_info(self):
275+
"""Encryption info for this database.
276+
:rtype: a list of :class:`~google.cloud.spanner_admin_instance_v1.types.EncryptionInfo`
277+
:returns: a list of objects representing encryption info for this database
278+
"""
279+
return self._encryption_info
280+
272281
@property
273282
def ddl_statements(self):
274283
"""DDL Statements used to define database schema.
@@ -403,6 +412,7 @@ def reload(self):
403412
self._version_retention_period = response.version_retention_period
404413
self._earliest_version_time = response.earliest_version_time
405414
self._encryption_config = response.encryption_config
415+
self._encryption_info = response.encryption_info
406416

407417
def update_ddl(self, ddl_statements, operation_id=""):
408418
"""Update DDL for this database.

tests/unit/test_database.py

+20
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,17 @@ def test_encryption_config(self):
318318
)
319319
self.assertEqual(database.encryption_config, encryption_config)
320320

321+
def test_encryption_info(self):
322+
from google.cloud.spanner_admin_database_v1 import EncryptionInfo
323+
324+
instance = _Instance(self.INSTANCE_NAME)
325+
pool = _Pool()
326+
database = self._make_one(self.DATABASE_ID, instance, pool=pool)
327+
encryption_info = database._encryption_info = [
328+
mock.create_autospec(EncryptionInfo, instance=True)
329+
]
330+
self.assertEqual(database.encryption_info, encryption_info)
331+
321332
def test_spanner_api_property_w_scopeless_creds(self):
322333

323334
client = _Client()
@@ -682,6 +693,7 @@ def test_reload_not_found(self):
682693
def test_reload_success(self):
683694
from google.cloud.spanner_admin_database_v1 import Database
684695
from google.cloud.spanner_admin_database_v1 import EncryptionConfig
696+
from google.cloud.spanner_admin_database_v1 import EncryptionInfo
685697
from google.cloud.spanner_admin_database_v1 import GetDatabaseDdlResponse
686698
from google.cloud.spanner_admin_database_v1 import RestoreInfo
687699
from google.cloud._helpers import _datetime_to_pb_timestamp
@@ -693,6 +705,12 @@ def test_reload_success(self):
693705
client = _Client()
694706
ddl_pb = GetDatabaseDdlResponse(statements=DDL_STATEMENTS)
695707
encryption_config = EncryptionConfig(kms_key_name="kms_key")
708+
encryption_info = [
709+
EncryptionInfo(
710+
encryption_type=EncryptionInfo.Type.CUSTOMER_MANAGED_ENCRYPTION,
711+
kms_key_version="kms_key_version",
712+
)
713+
]
696714
api = client.database_admin_api = self._make_database_admin_api()
697715
api.get_database_ddl.return_value = ddl_pb
698716
db_pb = Database(
@@ -702,6 +720,7 @@ def test_reload_success(self):
702720
version_retention_period="1d",
703721
earliest_version_time=_datetime_to_pb_timestamp(timestamp),
704722
encryption_config=encryption_config,
723+
encryption_info=encryption_info,
705724
)
706725
api.get_database.return_value = db_pb
707726
instance = _Instance(self.INSTANCE_NAME, client=client)
@@ -716,6 +735,7 @@ def test_reload_success(self):
716735
self.assertEqual(database._earliest_version_time, timestamp)
717736
self.assertEqual(database._ddl_statements, tuple(DDL_STATEMENTS))
718737
self.assertEqual(database._encryption_config, encryption_config)
738+
self.assertEqual(database._encryption_info, encryption_info)
719739

720740
api.get_database_ddl.assert_called_once_with(
721741
database=self.DATABASE_NAME,

0 commit comments

Comments
 (0)