4
4
from abc import abstractmethod
5
5
import logging
6
6
import os
7
+ from typing import Mapping
7
8
8
9
from cachetools import TTLCache
9
10
from requests .auth import HTTPBasicAuth , AuthBase
@@ -26,7 +27,7 @@ def __init__(self, log: logging.Logger, cache_size: int = 100, cache_ttl: int =
26
27
def _build_user_instance (self , auth : AuthBase ) -> CumulocityApi :
27
28
"""This must be defined by the implementing classes."""
28
29
29
- def get_user_instance (self , headers : dict = None , cookies : dict = None ) -> CumulocityApi :
30
+ def get_user_instance (self , headers : Mapping [ str , str ] = None , cookies : Mapping [ str , str ] = None ) -> CumulocityApi :
30
31
"""Return a user-specific CumulocityApi instance.
31
32
32
33
The instance will have user access, based on the Authorization header
@@ -35,9 +36,9 @@ def get_user_instance(self, headers: dict = None, cookies: dict = None) -> Cumul
35
36
are cached.
36
37
37
38
Args:
38
- headers (dict ): A dictionary of HTTP header entries. The user
39
+ headers (Mapping ): A dictionary of HTTP header entries. The user
39
40
access is based on the Authorization header within.
40
- cookies (dict ): A dictionary of HTTP Cookie entries. The user
41
+ cookies (Mapping ): A dictionary of HTTP Cookie entries. The user
41
42
access is based on an authorization cookie as provided by
42
43
Cumulocity.
43
44
Returns:
@@ -71,7 +72,7 @@ def clear_user_cache(self, username: str = None):
71
72
self .log .info (f"User '{ username } ' cleared from cache." )
72
73
73
74
@staticmethod
74
- def _get_auth_header (headers : dict = None , cookies : dict = None ) -> str :
75
+ def _get_auth_header (headers : Mapping [ str , str ] = None , cookies : Mapping [ str , str ] = None ) -> str :
75
76
"""Extract the authorization information from headers and cookies."""
76
77
headers = headers or {}
77
78
cookies = cookies or {}
@@ -302,15 +303,16 @@ def _build_user_instance(self, auth) -> CumulocityApi:
302
303
return CumulocityApi (base_url = self .bootstrap_instance .base_url , tenant_id = tenant_id , auth = auth ,
303
304
application_key = self .application_key , processing_mode = self .processing_mode )
304
305
305
- def get_tenant_instance (self , tenant_id : str = None , headers : dict = None , cookies : dict = None ) -> CumulocityApi :
306
+ def get_tenant_instance (self , tenant_id : str = None ,
307
+ headers : Mapping [str , str ] = None , cookies : Mapping [str , str ] = None ) -> CumulocityApi :
306
308
"""Provide access to a tenant-specific instance in a multi-tenant
307
309
application setup.
308
310
309
311
Args:
310
312
tenant_id (str): ID of the tenant to get access to
311
- headers (dict ): Inbound request headers, the tenant ID
313
+ headers (Mapping ): Inbound request headers, the tenant ID
312
314
is resolved from the Authorization header
313
- cookies (dict ): A dictionary of HTTP Cookie entries. The user
315
+ cookies (Mapping ): A dictionary of HTTP Cookie entries. The user
314
316
access is based on an authorization cookie as provided by
315
317
Cumulocity.
316
318
0 commit comments