68
68
69
69
def resolve_auth_headers (
70
70
headers : Optional [Mapping [str , str ]],
71
+ http_auth : Union [DefaultType , None , Tuple [str , str ], str ] = DEFAULT ,
71
72
api_key : Union [DefaultType , None , Tuple [str , str ], str ] = DEFAULT ,
72
73
basic_auth : Union [DefaultType , None , Tuple [str , str ], str ] = DEFAULT ,
73
74
bearer_auth : Union [DefaultType , None , str ] = DEFAULT ,
@@ -77,7 +78,32 @@ def resolve_auth_headers(
77
78
elif not isinstance (headers , HttpHeaders ):
78
79
headers = HttpHeaders (headers )
79
80
81
+ resolved_http_auth = http_auth if http_auth is not DEFAULT else None
80
82
resolved_basic_auth = basic_auth if basic_auth is not DEFAULT else None
83
+ if resolved_http_auth is not None :
84
+ if resolved_basic_auth is not None :
85
+ raise ValueError (
86
+ "Can't specify both 'http_auth' and 'basic_auth', "
87
+ "instead only specify 'basic_auth'"
88
+ )
89
+ if isinstance (http_auth , str ) or (
90
+ isinstance (resolved_http_auth , (list , tuple ))
91
+ and all (isinstance (x , str ) for x in resolved_http_auth )
92
+ ):
93
+ resolved_basic_auth = resolved_http_auth
94
+ else :
95
+ raise TypeError (
96
+ "The deprecated 'http_auth' parameter must be either 'Tuple[str, str]' or 'str'. "
97
+ "Use either the 'basic_auth' parameter instead"
98
+ )
99
+
100
+ warnings .warn (
101
+ "The 'http_auth' parameter is deprecated. "
102
+ "Use 'basic_auth' or 'bearer_auth' parameters instead" ,
103
+ category = DeprecationWarning ,
104
+ stacklevel = warn_stacklevel (),
105
+ )
106
+
81
107
resolved_api_key = api_key if api_key is not DEFAULT else None
82
108
resolved_bearer_auth = bearer_auth if bearer_auth is not DEFAULT else None
83
109
if resolved_api_key or resolved_basic_auth or resolved_bearer_auth :
0 commit comments