Skip to content

Commit a8411ea

Browse files
committed
Updated typing to be more generic.
1 parent 069ea0d commit a8411ea

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

c8y_api/app/__init__.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from abc import abstractmethod
55
import logging
66
import os
7+
from typing import Mapping
78

89
from cachetools import TTLCache
910
from requests.auth import HTTPBasicAuth, AuthBase
@@ -26,7 +27,7 @@ def __init__(self, log: logging.Logger, cache_size: int = 100, cache_ttl: int =
2627
def _build_user_instance(self, auth: AuthBase) -> CumulocityApi:
2728
"""This must be defined by the implementing classes."""
2829

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:
3031
"""Return a user-specific CumulocityApi instance.
3132
3233
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
3536
are cached.
3637
3738
Args:
38-
headers (dict): A dictionary of HTTP header entries. The user
39+
headers (Mapping): A dictionary of HTTP header entries. The user
3940
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
4142
access is based on an authorization cookie as provided by
4243
Cumulocity.
4344
Returns:
@@ -71,7 +72,7 @@ def clear_user_cache(self, username: str = None):
7172
self.log.info(f"User '{username}' cleared from cache.")
7273

7374
@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:
7576
"""Extract the authorization information from headers and cookies."""
7677
headers = headers or {}
7778
cookies = cookies or {}
@@ -302,15 +303,16 @@ def _build_user_instance(self, auth) -> CumulocityApi:
302303
return CumulocityApi(base_url=self.bootstrap_instance.base_url, tenant_id=tenant_id, auth=auth,
303304
application_key=self.application_key, processing_mode=self.processing_mode)
304305

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:
306308
"""Provide access to a tenant-specific instance in a multi-tenant
307309
application setup.
308310
309311
Args:
310312
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
312314
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
314316
access is based on an authorization cookie as provided by
315317
Cumulocity.
316318

0 commit comments

Comments
 (0)