@@ -6,11 +6,12 @@ import copy
6
6
import logging
7
7
import multiprocessing
8
8
import sys
9
- import urllib3
10
9
import http.client as httplib
11
10
11
+ from typing import Dict
12
12
13
- class Configuration(object):
13
+
14
+ class Configuration:
14
15
"""NOTE: This class is auto generated by the swagger code generator program.
15
16
16
17
Ref: https://github.com/swagger-api/swagger-codegen
@@ -19,7 +20,7 @@ class Configuration(object):
19
20
20
21
_default = None
21
22
22
- def __init__(self, api_key, region= "us"):
23
+ def __init__(self, api_key: str , region: str = "us"):
23
24
"""Constructor"""
24
25
if self._default:
25
26
for key in self._default.__dict__.keys():
@@ -33,24 +34,14 @@ class Configuration(object):
33
34
34
35
# Authentication Settings
35
36
# dict to store API key(s)
36
- self.api_key = { }
37
- self.api_key['Auth-API-Key'] = api_key
38
- # dict to store API prefix (e.g. Bearer)
39
- self.api_key_prefix = { }
40
- # function to refresh API key if expired
41
- self.refresh_api_key_hook = None
42
- # Username for HTTP basic authentication
43
- self.username = ""
44
- # Password for HTTP basic authentication
45
- self.password = ""
37
+ self.api_key = api_key
46
38
{ {#authMethods} }{ {#isOAuth} }
47
39
# access token for OAuth
48
40
self.access_token = ""
49
41
{ {/isOAuth} }{ {/authMethods} }
50
42
# Logging Settings
51
- self.logger = { }
52
- self.logger["package_logger"] = logging.getLogger("{ {packageName} }")
53
- self.logger["urllib3_logger"] = logging.getLogger("urllib3")
43
+ self.logger = { " package_logger" : logging.getLogger(" {{packageName}}" ),
44
+ " urllib3_logger" : logging.getLogger(" urllib3" )}
54
45
# Log format
55
46
self.logger_format = '%(asctime)s %(levelname)s %(message)s'
56
47
# Log stream handler
@@ -95,26 +86,24 @@ class Configuration(object):
95
86
cls._default = default
96
87
97
88
@property
98
- def logger_file(self):
89
+ def logger_file(self) -> str :
99
90
"""The logger file.
100
91
101
92
If the logger_file is None, then add stream handler and remove file
102
93
handler. Otherwise, add file handler and remove stream handler.
103
94
104
- :param value: The logger_file path.
105
- :type: str
95
+ :return: The logger_file path.
106
96
"""
107
97
return self.__logger_file
108
98
109
99
@logger_file.setter
110
- def logger_file(self, value):
100
+ def logger_file(self, value: str ):
111
101
"""The logger file.
112
102
113
103
If the logger_file is None, then add stream handler and remove file
114
104
handler. Otherwise, add file handler and remove stream handler.
115
105
116
106
:param value: The logger_file path.
117
- :type: str
118
107
"""
119
108
self.__logger_file = value
120
109
if self.__logger_file:
@@ -137,20 +126,18 @@ class Configuration(object):
137
126
logger.removeHandler(self.logger_file_handler)
138
127
139
128
@property
140
- def debug(self):
129
+ def debug(self) -> bool :
141
130
"""Debug status
142
131
143
132
:param value: The debug status, True or False.
144
- :type: bool
145
133
"""
146
134
return self.__debug
147
135
148
136
@debug.setter
149
- def debug(self, value):
137
+ def debug(self, value: bool ):
150
138
"""Debug status
151
139
152
140
:param value: The debug status, True or False.
153
- :type: bool
154
141
"""
155
142
self.__debug = value
156
143
if self.__debug:
@@ -168,91 +155,47 @@ class Configuration(object):
168
155
httplib.HTTPConnection.debuglevel = 0
169
156
170
157
@property
171
- def logger_format(self):
158
+ def logger_format(self) -> str :
172
159
"""The logger format.
173
160
174
161
The logger_formatter will be updated when sets logger_format.
175
162
176
- :param value: The format string.
177
- :type: str
163
+ :return: The format string.
178
164
"""
179
165
return self.__logger_format
180
166
181
167
@logger_format.setter
182
- def logger_format(self, value):
168
+ def logger_format(self, value: str ):
183
169
"""The logger format.
184
170
185
171
The logger_formatter will be updated when sets logger_format.
186
172
187
173
:param value: The format string.
188
- :type: str
189
174
"""
190
175
self.__logger_format = value
191
176
self.logger_formatter = logging.Formatter(self.__logger_format)
192
177
193
- def get_api_key_with_prefix(self, identifier):
194
- """Gets API key (with prefix if set).
195
-
196
- :param identifier: The identifier of apiKey.
197
- :return: The token for api key authentication.
198
- """
199
-
200
- if self.refresh_api_key_hook:
201
- self.refresh_api_key_hook(self)
202
-
203
- key = self.api_key.get(identifier)
204
- if key:
205
- prefix = self.api_key_prefix.get(identifier)
206
- if prefix:
207
- return "%s %s" % (prefix, key)
208
- else:
209
- return key
210
-
211
- def get_basic_auth_token(self):
212
- """Gets HTTP basic authentication header (string).
213
-
214
- :return: The token for basic HTTP authentication.
215
- """
216
- return urllib3.util.make_headers(
217
- basic_auth=self.username + ':' + self.password
218
- ).get('authorization')
219
-
220
- def auth_settings(self):
178
+ def auth_settings(self) -> Dict[str, Dict[str, str]]:
221
179
"""Gets Auth Settings dict for api client.
222
180
223
181
:return: The Auth Settings information dict.
224
182
"""
225
183
return {
226
184
{{#authMethods} }
227
185
{ {#isApiKey} }
186
+ { {#isKeyInHeader} }
228
187
'{ {name} }':
229
188
{
230
189
' type' : ' api_key' ,
231
- ' in' : {{#isKeyInHeader} }'header'{ {/isKeyInHeader} }{ {#isKeyInQuery} }'query'{ {/isKeyInQuery} },
232
- 'key': '{ {keyParamName} }',
233
- 'value': self.get_api_key_with_prefix('{ {keyParamName} }')
234
- },
235
- { {/isApiKey} }
236
- { {#isBasic} }
237
- '{ {name} }':
238
- {
239
- ' type' : ' basic' ,
240
- ' in' : ' header' ,
241
- ' key' : ' Authorization' ,
242
- ' value' : self.get_basic_auth_token()
243
- } ,
244
- { {/isBasic} }{ {#isOAuth} }
245
- '{ {name} }':
246
- {
247
- ' type' : ' oauth2' ,
248
190
' in' : ' header' ,
249
- ' key' : ' Authorization ' ,
250
- ' value' : ' Bearer ' + self.access_token
191
+ ' key' : ' {{keyParamName}} ' ,
192
+ ' value' : self.api_key
251
193
} ,
252
- { {/isOAuth} }{ {/authMethods} }
194
+ { {/isKeyInHeader} }
195
+ { {/isApiKey} }{ {/authMethods} }
253
196
}
254
197
255
- def get_host(self, region) :
198
+ def get_host(self, region: str) -> str :
256
199
return {
257
200
" us" : " https://api.fpjs.io" ,
258
201
" eu" : " https://eu.api.fpjs.io" ,
0 commit comments