Skip to content

Commit

Permalink
refactor: Added assertions on conn_id, tenant_id, client_id and clien…
Browse files Browse the repository at this point in the history
…t_secret
  • Loading branch information
davidblain-infrabel committed Mar 14, 2024
1 parent 4cef94e commit 88aa7dc
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions airflow/providers/microsoft/azure/hooks/msgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from __future__ import annotations

import json
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Any
from urllib.parse import urljoin

import httpx
Expand Down Expand Up @@ -106,12 +106,19 @@ def to_httpx_proxies(proxies: dict) -> dict:
proxies["https://"] = proxies.pop("https")
return proxies

def get_conn(self) -> RequestAdapter:
if not self.conn_id:
@staticmethod
def assert_not_none(value: Any, message: str) -> None:
if not value:
raise AirflowException(
"Failed to create the KiotaRequestAdapterHook. No conn_id provided!"
)

def get_conn(self) -> RequestAdapter:
self.assert_not_none(
self.conn_id,
"Failed to create the KiotaRequestAdapterHook. No conn_id provided!",
)

api_version, request_adapter = self.cached_request_adapters.get(
self.conn_id, (None, None)
)
Expand Down Expand Up @@ -146,6 +153,20 @@ def get_conn(self) -> RequestAdapter:
self.log.info("Timeout: %s", self.timeout)
self.log.info("Trust env: %s", trust_env)
self.log.info("Proxies: %s", json.dumps(proxies))

self.assert_not_none(
tenant_id,
"Failed to create the KiotaRequestAdapterHook. No tenant_id provided!",
)
self.assert_not_none(
connection.login,
"Failed to create the KiotaRequestAdapterHook. No client_id provided!",
)
self.assert_not_none(
connection.password,
"Failed to create the KiotaRequestAdapterHook. No client_secret provided!",
)

credentials = identity.ClientSecretCredential(
tenant_id=tenant_id,
client_id=connection.login,
Expand Down

0 comments on commit 88aa7dc

Please sign in to comment.