@@ -96,6 +96,8 @@ class KiotaRequestAdapterHook(BaseHook):
9696 :param timeout: The HTTP timeout being used by the KiotaRequestAdapter (default is None).
9797 When no timeout is specified or set to None then no HTTP timeout is applied on each request.
9898 :param proxies: A Dict defining the HTTP proxies to be used (default is None).
99+ :param host: The host to be used (default is "https://graph.microsoft.com").
100+ :param scopes: The scopes to be used (default is ["https://graph.microsoft.com/.default"]).
99101 :param api_version: The API version of the Microsoft Graph API to be used (default is v1).
100102 You can pass an enum named APIVersion which has 2 possible members v1 and beta,
101103 or you can pass a string as "v1.0" or "beta".
@@ -123,27 +125,22 @@ def __init__(
123125 self ._api_version = self .resolve_api_version_from_value (api_version )
124126
125127 @property
126- def api_version (self ) -> APIVersion :
128+ def api_version (self ) -> str | None :
127129 self .get_conn () # Make sure config has been loaded through get_conn to have correct api version!
128130 return self ._api_version
129131
130132 @staticmethod
131133 def resolve_api_version_from_value (
132- api_version : APIVersion | str , default : APIVersion | None = None
133- ) -> APIVersion :
134+ api_version : APIVersion | str , default : str | None = None
135+ ) -> str | None :
134136 if isinstance (api_version , APIVersion ):
135- return api_version
136- return next (
137- filter (lambda version : version .value == api_version , APIVersion ),
138- default ,
139- )
137+ return api_version .value
138+ return api_version or default
140139
141- def get_api_version (self , config : dict ) -> APIVersion :
142- if self ._api_version is None :
143- return self .resolve_api_version_from_value (
144- api_version = config .get ("api_version" ), default = APIVersion .v1
145- )
146- return self ._api_version
140+ def get_api_version (self , config : dict ) -> str :
141+ return self ._api_version or self .resolve_api_version_from_value (
142+ config .get ("api_version" ), APIVersion .v1 .value
143+ ) # type: ignore
147144
148145 def get_host (self , connection : Connection ) -> str :
149146 if connection .schema and connection .host :
@@ -169,15 +166,15 @@ def to_httpx_proxies(cls, proxies: dict) -> dict:
169166 return proxies
170167
171168 def to_msal_proxies (self , authority : str | None , proxies : dict ):
172- self .log .info ("authority: %s" , authority )
169+ self .log .debug ("authority: %s" , authority )
173170 if authority :
174171 no_proxies = proxies .get ("no" )
175- self .log .info ("no_proxies: %s" , no_proxies )
172+ self .log .debug ("no_proxies: %s" , no_proxies )
176173 if no_proxies :
177174 for url in no_proxies .split ("," ):
178175 self .log .info ("url: %s" , url )
179176 domain_name = urlparse (url ).path .replace ("*" , "" )
180- self .log .info ("domain_name: %s" , domain_name )
177+ self .log .debug ("domain_name: %s" , domain_name )
181178 if authority .endswith (domain_name ):
182179 return None
183180 return proxies
@@ -193,10 +190,10 @@ def get_conn(self) -> RequestAdapter:
193190 client_id = connection .login
194191 client_secret = connection .password
195192 config = connection .extra_dejson if connection .extra else {}
196- tenant_id = config .get ("tenant_id" )
193+ tenant_id = config .get ("tenant_id" ) or config . get ( "tenantId" )
197194 api_version = self .get_api_version (config )
198195 host = self .get_host (connection )
199- base_url = config .get ("base_url" , urljoin (host , api_version . value ))
196+ base_url = config .get ("base_url" , urljoin (host , api_version ))
200197 authority = config .get ("authority" )
201198 proxies = self .proxies or config .get ("proxies" , {})
202199 msal_proxies = self .to_msal_proxies (authority = authority , proxies = proxies )
@@ -209,15 +206,15 @@ def get_conn(self) -> RequestAdapter:
209206
210207 self .log .info (
211208 "Creating Microsoft Graph SDK client %s for conn_id: %s" ,
212- api_version . value ,
209+ api_version ,
213210 self .conn_id ,
214211 )
215212 self .log .info ("Host: %s" , host )
216213 self .log .info ("Base URL: %s" , base_url )
217214 self .log .info ("Tenant id: %s" , tenant_id )
218215 self .log .info ("Client id: %s" , client_id )
219216 self .log .info ("Client secret: %s" , client_secret )
220- self .log .info ("API version: %s" , api_version . value )
217+ self .log .info ("API version: %s" , api_version )
221218 self .log .info ("Scope: %s" , scopes )
222219 self .log .info ("Verify: %s" , verify )
223220 self .log .info ("Timeout: %s" , self .timeout )
@@ -238,17 +235,17 @@ def get_conn(self) -> RequestAdapter:
238235 connection_verify = verify ,
239236 )
240237 http_client = GraphClientFactory .create_with_default_middleware (
241- api_version = api_version ,
238+ api_version = api_version , # type: ignore
242239 client = httpx .AsyncClient (
243240 proxies = httpx_proxies ,
244241 timeout = Timeout (timeout = self .timeout ),
245242 verify = verify ,
246243 trust_env = trust_env ,
247244 ),
248- host = host ,
245+ host = host , # type: ignore
249246 )
250247 auth_provider = AzureIdentityAuthenticationProvider (
251- credentials = credentials ,
248+ credentials = credentials , # type: ignore
252249 scopes = scopes ,
253250 allowed_hosts = allowed_hosts ,
254251 )
@@ -295,7 +292,7 @@ async def run(
295292 error_map = self .error_mapping (),
296293 )
297294
298- self .log .info ("response: %s" , response )
295+ self .log .debug ("response: %s" , response )
299296
300297 return response
301298
0 commit comments