1313
1414
1515import copy
16+ import http .client as httplib
1617import logging
1718from logging import FileHandler
1819import multiprocessing
1920import sys
20- from typing import Optional
21- import urllib3
21+ from typing import Any , ClassVar , Dict , List , Literal , Optional , TypedDict
22+ from typing_extensions import NotRequired , Self
2223
23- import http . client as httplib
24+ import urllib3
2425
2526from enum import Enum
2627
@@ -37,6 +38,107 @@ class Region(Enum):
3738 'minLength' , 'pattern' , 'maxItems' , 'minItems'
3839}
3940
41+ ServerVariablesT = Dict [str , str ]
42+
43+ GenericAuthSetting = TypedDict (
44+ "GenericAuthSetting" ,
45+ {
46+ "type" : str ,
47+ "in" : str ,
48+ "key" : str ,
49+ "value" : str ,
50+ },
51+ )
52+
53+
54+ OAuth2AuthSetting = TypedDict (
55+ "OAuth2AuthSetting" ,
56+ {
57+ "type" : Literal ["oauth2" ],
58+ "in" : Literal ["header" ],
59+ "key" : Literal ["Authorization" ],
60+ "value" : str ,
61+ },
62+ )
63+
64+
65+ APIKeyAuthSetting = TypedDict (
66+ "APIKeyAuthSetting" ,
67+ {
68+ "type" : Literal ["api_key" ],
69+ "in" : str ,
70+ "key" : str ,
71+ "value" : Optional [str ],
72+ },
73+ )
74+
75+
76+ BasicAuthSetting = TypedDict (
77+ "BasicAuthSetting" ,
78+ {
79+ "type" : Literal ["basic" ],
80+ "in" : Literal ["header" ],
81+ "key" : Literal ["Authorization" ],
82+ "value" : Optional [str ],
83+ },
84+ )
85+
86+
87+ BearerFormatAuthSetting = TypedDict (
88+ "BearerFormatAuthSetting" ,
89+ {
90+ "type" : Literal ["bearer" ],
91+ "in" : Literal ["header" ],
92+ "format" : Literal ["JWT" ],
93+ "key" : Literal ["Authorization" ],
94+ "value" : str ,
95+ },
96+ )
97+
98+
99+ BearerAuthSetting = TypedDict (
100+ "BearerAuthSetting" ,
101+ {
102+ "type" : Literal ["bearer" ],
103+ "in" : Literal ["header" ],
104+ "key" : Literal ["Authorization" ],
105+ "value" : str ,
106+ },
107+ )
108+
109+
110+ HTTPSignatureAuthSetting = TypedDict (
111+ "HTTPSignatureAuthSetting" ,
112+ {
113+ "type" : Literal ["http-signature" ],
114+ "in" : Literal ["header" ],
115+ "key" : Literal ["Authorization" ],
116+ "value" : None ,
117+ },
118+ )
119+
120+
121+ AuthSettings = TypedDict (
122+ "AuthSettings" ,
123+ {
124+ "Token" : APIKeyAuthSetting ,
125+ },
126+ total = False ,
127+ )
128+
129+
130+ class HostSettingVariable (TypedDict ):
131+ description : str
132+ default_value : str
133+ enum_values : List [str ]
134+
135+
136+ class HostSetting (TypedDict ):
137+ url : str
138+ description : str
139+ variables : NotRequired [Dict [str , HostSettingVariable ]]
140+
141+
40142class Configuration :
41143 """This class contains various settings of the API client.
42144
@@ -76,20 +178,23 @@ class Configuration:
76178 Cookie: JSESSIONID abc123
77179 """
78180
79- _default = None
80-
81- def __init__ (self , host = None ,
82- api_token = None ,
83- region = Region .EU ,
84- timeout = None ,
85- server_index = None ,
86- server_operation_index = None , server_operation_variables = None ,
87- ignore_operation_servers = False ,
88- ssl_ca_cert = None ,
89- retries = None ,
90- * ,
91- debug : Optional [bool ] = None
92- ) -> None :
181+ _default : ClassVar [Optional [Self ]] = None
182+
183+ def __init__ (
184+ self ,
185+ host : Optional [str ]= None ,
186+ api_token : Optional [str ]= None ,
187+ region : Optional [Region ]= Region .EU ,
188+ timeout : Optional [urllib3 .util .Timeout ]= None ,
189+ server_index : Optional [int ]= None ,
190+ server_operation_index : Optional [Dict [int , int ]]= None ,
191+ server_operation_variables : Optional [Dict [int , ServerVariablesT ]]= None ,
192+ ignore_operation_servers : bool = False ,
193+ ssl_ca_cert : Optional [str ]= None ,
194+ retries : Optional [int ] = None ,
195+ * ,
196+ debug : Optional [bool ] = None ,
197+ ) -> None :
93198 """Constructor
94199 """
95200 self ._base_path = "https://api.eu.onfido.com/v3.6" if host is None else host
@@ -199,7 +304,7 @@ def __init__(self, host=None,
199304 """date format
200305 """
201306
202- def __deepcopy__ (self , memo ) :
307+ def __deepcopy__ (self , memo : Dict [ int , Any ]) -> Self :
203308 cls = self .__class__
204309 result = cls .__new__ (cls )
205310 memo [id (self )] = result
@@ -213,11 +318,11 @@ def __deepcopy__(self, memo):
213318 result .debug = self .debug
214319 return result
215320
216- def __setattr__ (self , name , value ) :
321+ def __setattr__ (self , name : str , value : Any ) -> None :
217322 object .__setattr__ (self , name , value )
218323
219324 @classmethod
220- def set_default (cls , default ) :
325+ def set_default (cls , default : Optional [ Self ]) -> None :
221326 """Set default instance of configuration.
222327
223328 It stores default configuration, which can be
@@ -228,7 +333,7 @@ def set_default(cls, default):
228333 cls ._default = default
229334
230335 @classmethod
231- def get_default_copy (cls ):
336+ def get_default_copy (cls ) -> Self :
232337 """Deprecated. Please use `get_default` instead.
233338
234339 Deprecated. Please use `get_default` instead.
@@ -238,7 +343,7 @@ def get_default_copy(cls):
238343 return cls .get_default ()
239344
240345 @classmethod
241- def get_default (cls ):
346+ def get_default (cls ) -> Self :
242347 """Return the default configuration.
243348
244349 This method returns newly created, based on default constructor,
@@ -248,11 +353,11 @@ def get_default(cls):
248353 :return: The configuration object.
249354 """
250355 if cls ._default is None :
251- cls ._default = Configuration ()
356+ cls ._default = cls ()
252357 return cls ._default
253358
254359 @property
255- def logger_file (self ):
360+ def logger_file (self ) -> Optional [ str ] :
256361 """The logger file.
257362
258363 If the logger_file is None, then add stream handler and remove file
@@ -264,7 +369,7 @@ def logger_file(self):
264369 return self .__logger_file
265370
266371 @logger_file .setter
267- def logger_file (self , value ) :
372+ def logger_file (self , value : Optional [ str ]) -> None :
268373 """The logger file.
269374
270375 If the logger_file is None, then add stream handler and remove file
@@ -283,7 +388,7 @@ def logger_file(self, value):
283388 logger .addHandler (self .logger_file_handler )
284389
285390 @property
286- def debug (self ):
391+ def debug (self ) -> bool :
287392 """Debug status
288393
289394 :param value: The debug status, True or False.
@@ -292,7 +397,7 @@ def debug(self):
292397 return self .__debug
293398
294399 @debug .setter
295- def debug (self , value ) :
400+ def debug (self , value : bool ) -> None :
296401 """Debug status
297402
298403 :param value: The debug status, True or False.
@@ -314,7 +419,7 @@ def debug(self, value):
314419 httplib .HTTPConnection .debuglevel = 0
315420
316421 @property
317- def logger_format (self ):
422+ def logger_format (self ) -> str :
318423 """The logger format.
319424
320425 The logger_formatter will be updated when sets logger_format.
@@ -325,7 +430,7 @@ def logger_format(self):
325430 return self .__logger_format
326431
327432 @logger_format .setter
328- def logger_format (self , value ) :
433+ def logger_format (self , value : str ) -> None :
329434 """The logger format.
330435
331436 The logger_formatter will be updated when sets logger_format.
@@ -336,7 +441,7 @@ def logger_format(self, value):
336441 self .__logger_format = value
337442 self .logger_formatter = logging .Formatter (self .__logger_format )
338443
339- def get_api_key_with_prefix (self , identifier , alias = None ):
444+ def get_api_key_with_prefix (self , identifier : str , alias : Optional [ str ] = None ) -> Optional [ str ] :
340445 """Gets API key (with prefix if set).
341446
342447 :param identifier: The identifier of apiKey.
@@ -353,7 +458,9 @@ def get_api_key_with_prefix(self, identifier, alias=None):
353458 else :
354459 return key
355460
356- def get_basic_auth_token (self ):
461+ return None
462+
463+ def get_basic_auth_token (self ) -> Optional [str ]:
357464 """Gets HTTP basic authentication header (string).
358465
359466 :return: The token for basic HTTP authentication.
@@ -368,12 +475,12 @@ def get_basic_auth_token(self):
368475 basic_auth = username + ':' + password
369476 ).get ('authorization' )
370477
371- def auth_settings (self ):
478+ def auth_settings (self )-> AuthSettings :
372479 """Gets Auth Settings dict for api client.
373480
374481 :return: The Auth Settings information dict.
375482 """
376- auth = {}
483+ auth : AuthSettings = {}
377484 if 'Token' in self .api_key :
378485 auth ['Token' ] = {
379486 'type' : 'api_key' ,
@@ -385,7 +492,7 @@ def auth_settings(self):
385492 }
386493 return auth
387494
388- def to_debug_report (self ):
495+ def to_debug_report (self ) -> str :
389496 """Gets the essential information for debugging.
390497
391498 :return: The report for debugging.
@@ -397,7 +504,7 @@ def to_debug_report(self):
397504 "SDK Package Version: 5.0.0" .\
398505 format (env = sys .platform , pyversion = sys .version )
399506
400- def get_host_settings (self ):
507+ def get_host_settings (self ) -> List [ HostSetting ] :
401508 """Gets an array of host settings
402509
403510 :return: An array of host settings
@@ -420,7 +527,12 @@ def get_host_settings(self):
420527 }
421528 ]
422529
423- def get_host_from_settings (self , index , variables = None , servers = None ):
530+ def get_host_from_settings (
531+ self ,
532+ index : Optional [int ],
533+ variables : Optional [ServerVariablesT ]= None ,
534+ servers : Optional [List [HostSetting ]]= None ,
535+ ) -> str :
424536 """Gets host URL based on the index and variables
425537 :param index: array index of the host settings
426538 :param variables: hash of variable and the corresponding value
@@ -460,12 +572,12 @@ def get_host_from_settings(self, index, variables=None, servers=None):
460572 return url
461573
462574 @property
463- def host (self ):
575+ def host (self ) -> str :
464576 """Return generated host."""
465577 return self .get_host_from_settings (self .server_index , variables = self .server_variables )
466578
467579 @host .setter
468- def host (self , value ) :
580+ def host (self , value : str ) -> None :
469581 """Fix base path."""
470582 self ._base_path = value
471583 self .server_index = None
0 commit comments