Commit 677d74d8 authored by Yannick's avatar Yannick
Browse files

keep secret value to avoid multiple sync call to the keyvault

parent f4172ec7
Pipeline #44941 passed with stage
in 48 seconds
......@@ -10,7 +10,8 @@ from osdu_az.identity.az_identity import AzureIdentity
_LOGGER = logging.getLogger(__name__)
class PartitionInfo():
class PartitionInfo:
def __init__(self, partition_properties: dict = None):
self._partition_properties = partition_properties
self._secret_client = None
......@@ -23,8 +24,9 @@ class PartitionInfo():
if not partition_property.get('sensitive'):
return partition_property['value']
secret = self._get_secret(partition_property['value'])
return secret.value
if 'secret' not in partition_property:
partition_property['secret'] = self._get_secret(partition_property['value']).value
return partition_property['secret']
def _get_secret(self, key: str):
ts = datetime.utcnow()
......
......@@ -42,6 +42,7 @@ partition_service_response = \
}
"""
def test_get_value():
storage_account_name = 'mocked_storage_account_name_in_key_vault'
......@@ -55,11 +56,13 @@ def test_get_value():
assert (partition_info.get_value('storage-account-name') == storage_account_name)
kv_mock.get_secret.assert_called_with('opendes-storage')
def test_get_value_invalid_property_name():
properties = json.loads(partition_service_response)
partition_info = PartitionInfo(partition_properties=properties)
assert (partition_info.get_value('invalid-partition-service-property') is None)
def test_get_value_non_sensitive():
kv_mock = MagicMock()
......@@ -69,3 +72,19 @@ def test_get_value_non_sensitive():
assert (partition_info.get_value('compliance-ruleset') == 'shared')
kv_mock.get_secret.assert_not_called()
def test_not_trigger_key_vault_fetch_twice():
storage_account_name = 'mocked_storage_account_name_in_key_vault'
kv_mock = MagicMock()
kv_mock.get_secret.return_value = KeyVaultSecret('opendes-storage', storage_account_name)
properties = json.loads(partition_service_response)
partition_info = PartitionInfo(partition_properties=properties)
partition_info._secret_client = kv_mock
partition_info.get_value('storage-account-name')
partition_info.get_value('storage-account-name')
kv_mock.get_secret.assert_called_once()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment