partition_info.py 1.01 KB
Newer Older
Luc Yriarte's avatar
Luc Yriarte committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from typing import Optional

from azure.keyvault.secrets import SecretClient

from osdu_az import conf
from osdu_az.identity.az_identity import AzureIdentity


class PartitionInfo():
    def __init__(self, partition_properties: dict = None):
        self._partition_properties = partition_properties
        self._secret_client = None

    def get_value(self, property_name: str) -> Optional[str]:
        partition_property = self._partition_properties.get(property_name)
        if not partition_property:
            return None

        if not partition_property.get('sensitive'):
            return partition_property['value']

        secret = self._get_secret(partition_property['value'])
        return secret.value

    def _get_secret(self, key: str):
        return self._get_secret_client().get_secret(key)

    def _get_secret_client(self):
        if not self._secret_client:
            self._secret_client = SecretClient(conf.keyvault_url, AzureIdentity.get_default_credential())
        return self._secret_client