Skip to content

Commit 947518e

Browse files
committed
Fix type issue in KeyValutLoader (#447)
`SecretClient` does not accept `None`s as the `credential`. This is a type issue, that `mypy` only _sometimes_ catches. There is no reason the `credentials` should be a class variable, it's only ever used inside the `_init_client` method, so it's fine to move it to a local variable.
1 parent c1d468b commit 947518e

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

cognite/extractorutils/configtools/loaders.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ class KeyVaultLoader:
6565
def __init__(self, config: dict | None):
6666
self.config = config
6767

68-
self.credentials: DefaultAzureCredential | ClientSecretCredential | None = None
6968
self.client: SecretClient | None = None
7069

7170
def _init_client(self) -> None:
@@ -89,9 +88,10 @@ def _init_client(self) -> None:
8988

9089
vault_url = f"https://{keyvault_name}.vault.azure.net"
9190

91+
credentials: TokenCredential
9292
if self.config["authentication-method"] == KeyVaultAuthenticationMethod.DEFAULT.value:
9393
_logger.info("Using Azure DefaultCredentials to access KeyVault")
94-
self.credentials = DefaultAzureCredential()
94+
credentials = DefaultAzureCredential()
9595

9696
elif self.config["authentication-method"] == KeyVaultAuthenticationMethod.CLIENTSECRET.value:
9797
auth_parameters = ("client-id", "tenant-id", "secret")
@@ -108,7 +108,7 @@ def _init_client(self) -> None:
108108
client_id = os.path.expandvars(self.config["client-id"])
109109
secret = os.path.expandvars(self.config["secret"])
110110

111-
self.credentials = ClientSecretCredential(
111+
credentials = ClientSecretCredential(
112112
tenant_id=tenant_id,
113113
client_id=client_id,
114114
client_secret=secret,
@@ -122,7 +122,7 @@ def _init_client(self) -> None:
122122
"Invalid KeyVault authentication method. Possible values : default or client-secret"
123123
)
124124

125-
self.client = SecretClient(vault_url=vault_url, credential=cast(TokenCredential, self.credentials))
125+
self.client = SecretClient(vault_url=vault_url, credential=credentials)
126126

127127
def __call__(self, _: yaml.SafeLoader, node: yaml.Node) -> str:
128128
self._init_client()

0 commit comments

Comments
 (0)