Skip to content

Commit 98aa39a

Browse files
author
Edvard Majakari
authored
prefer more generic Mapping over dict type (#10)
* prefer more generic Mapping over dict type typically it's better to specify more generic types for input parameters, and specific types our return values. In this case changing headers param from dict to Mapping should resolve typing issues when eg. starlette.requests.headers.Headers instance is passed to get_principal_from_headers() * collections.abc.Mapping instead of deprecated typing.Mapping
1 parent e364265 commit 98aa39a

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

audit_log/headers.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import re
2+
from collections.abc import Mapping
23
from dataclasses import dataclass
34
from urllib.parse import urlparse
45

@@ -65,14 +66,14 @@ def parse_spiffe(xfcc_header: str) -> ParsedSPIFFE:
6566

6667

6768
def get_principal_from_headers(
68-
headers: dict[str, str],
69+
headers: Mapping[str, str],
6970
) -> Principal:
7071
"""Get principal from headers, supports mTLS, headers set in Istio, and JWTs.
7172
7273
Note: Do not use this to handle your auth, it expects auth to already be handled elsewhere and this is just to help get principals.
7374
7475
Args:
75-
headers (dict[str, str]): Headers with all keys lowercase
76+
headers (Mapping[str, str]): Headers with all keys lowercase
7677
7778
Raises:
7879
AuditPrincipalError: Cannot get a principal from the headers

0 commit comments

Comments
 (0)