Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions cognite/extractorutils/configtools/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

import dacite
import yaml
from azure.core.credentials import TokenCredential
from azure.core.exceptions import HttpResponseError, ResourceNotFoundError, ServiceRequestError
from azure.identity import ClientSecretCredential, DefaultAzureCredential
from azure.keyvault.secrets import SecretClient
Expand Down Expand Up @@ -65,7 +64,7 @@ class KeyVaultLoader:
def __init__(self, config: dict | None):
self.config = config

self.credentials: TokenCredential | None = None
self.credentials: DefaultAzureCredential | ClientSecretCredential | None = None
self.client: SecretClient | None = None

def _init_client(self) -> None:
Expand Down Expand Up @@ -104,9 +103,9 @@ def _init_client(self) -> None:
_logger.info(f"Local environment file not found at {Path.cwd() / '.env'}")

if all(param in self.config for param in auth_parameters):
tenant_id = os.path.expandvars(self.config.get("tenant-id", None))
client_id = os.path.expandvars(self.config.get("client-id", None))
secret = os.path.expandvars(self.config.get("secret", None))
tenant_id = os.path.expandvars(self.config["tenant-id"])
client_id = os.path.expandvars(self.config["client-id"])
secret = os.path.expandvars(self.config["secret"])

self.credentials = ClientSecretCredential(
tenant_id=tenant_id,
Expand All @@ -122,7 +121,7 @@ def _init_client(self) -> None:
"Invalid KeyVault authentication method. Possible values : default or client-secret"
)

self.client = SecretClient(vault_url=vault_url, credential=self.credentials) # type: ignore
self.client = SecretClient(vault_url=vault_url, credential=self.credentials)

def __call__(self, _: yaml.SafeLoader, node: yaml.Node) -> str:
self._init_client()
Expand Down Expand Up @@ -185,7 +184,9 @@ def ignore_unknown(self, node: yaml.Node) -> None:
config_dict = yaml.load(source, Loader=loader) # noqa: S506
except ScannerError as e:
location = e.problem_mark or e.context_mark
formatted_location = f" at line {location.line+1}, column {location.column+1}" if location is not None else ""
formatted_location = (
f" at line {location.line + 1}, column {location.column + 1}" if location is not None else ""
)
cause = e.problem or e.context
raise InvalidConfigError(f"Invalid YAML{formatted_location}: {cause or ''}") from e

Expand Down