Coverage for fingerprint_pro_server_api_sdk/configuration.py: 77%

79 statements  

« prev     ^ index     » next       coverage.py v7.6.9, created at 2024-12-09 17:50 +0000

1# coding: utf-8 

2 

3""" 

4 Fingerprint Pro Server API 

5 

6 Fingerprint Pro Server API allows you to get information about visitors and about individual events in a server environment. It can be used for data exports, decision-making, and data analysis scenarios. Server API is intended for server-side usage, it's not intended to be used from the client side, whether it's a browser or a mobile device. # noqa: E501 

7 

8 OpenAPI spec version: 3 

9 Contact: support@fingerprint.com 

10 Generated by: https://github.com/swagger-api/swagger-codegen.git 

11""" 

12 

13import copy 

14import logging 

15import multiprocessing 

16import sys 

17import http.client as httplib 

18 

19from typing import Dict 

20 

21 

22class Configuration: 

23 """NOTE: This class is auto generated by the swagger code generator program. 

24 

25 Ref: https://github.com/swagger-api/swagger-codegen 

26 Do not edit the class manually. 

27 """ 

28 

29 _default = None 

30 

31 def __init__(self, api_key: str, region: str = "us"): 

32 """Constructor""" 

33 if self._default: 

34 for key in self._default.__dict__.keys(): 

35 self.__dict__[key] = copy.copy(self._default.__dict__[key]) 

36 return 

37 

38 # Default Base url 

39 self.host = self.get_host(region) 

40 # Temp file folder for downloading files 

41 self.temp_folder_path = None 

42 

43 # Authentication Settings 

44 # dict to store API key(s) 

45 self.api_key = api_key 

46 # Logging Settings 

47 self.logger = {"package_logger": logging.getLogger("fingerprint_pro_server_api_sdk"), 

48 "urllib3_logger": logging.getLogger("urllib3")} 

49 # Log format 

50 self.logger_format = '%(asctime)s %(levelname)s %(message)s' 

51 # Log stream handler 

52 self.logger_stream_handler = None 

53 # Log file handler 

54 self.logger_file_handler = None 

55 # Debug file location 

56 self.logger_file = None 

57 # Debug switch 

58 self.debug = False 

59 

60 # SSL/TLS verification 

61 # Set this to false to skip verifying SSL certificate when calling API 

62 # from https server. 

63 self.verify_ssl = True 

64 # Set this to customize the certificate file to verify the peer. 

65 self.ssl_ca_cert = None 

66 # client certificate file 

67 self.cert_file = None 

68 # client key file 

69 self.key_file = None 

70 # Set this to True/False to enable/disable SSL hostname verification. 

71 self.assert_hostname = None 

72 

73 # urllib3 connection pool's maximum number of connections saved 

74 # per pool. urllib3 uses 1 connection as default value, but this is 

75 # not the best value when you are making a lot of possibly parallel 

76 # requests to the same host, which is often the case here. 

77 # cpu_count * 5 is used as default value to increase performance. 

78 self.connection_pool_maxsize = multiprocessing.cpu_count() * 5 

79 

80 # Proxy URL 

81 self.proxy = None 

82 # Safe chars for path_param 

83 self.safe_chars_for_path_param = '' 

84 

85 # Disable client side validation 

86 self.client_side_validation = True 

87 

88 @classmethod 

89 def set_default(cls, default): 

90 cls._default = default 

91 

92 @property 

93 def logger_file(self) -> str: 

94 """The logger file. 

95 

96 If the logger_file is None, then add stream handler and remove file 

97 handler. Otherwise, add file handler and remove stream handler. 

98 

99 :return: The logger_file path. 

100 """ 

101 return self.__logger_file 

102 

103 @logger_file.setter 

104 def logger_file(self, value: str): 

105 """The logger file. 

106 

107 If the logger_file is None, then add stream handler and remove file 

108 handler. Otherwise, add file handler and remove stream handler. 

109 

110 :param value: The logger_file path. 

111 """ 

112 self.__logger_file = value 

113 if self.__logger_file: 

114 # If set logging file, 

115 # then add file handler and remove stream handler. 

116 self.logger_file_handler = logging.FileHandler(self.__logger_file) 

117 self.logger_file_handler.setFormatter(self.logger_formatter) 

118 for _, logger in self.logger.items(): 

119 logger.addHandler(self.logger_file_handler) 

120 if self.logger_stream_handler: 

121 logger.removeHandler(self.logger_stream_handler) 

122 else: 

123 # If not set logging file, 

124 # then add stream handler and remove file handler. 

125 self.logger_stream_handler = logging.StreamHandler() 

126 self.logger_stream_handler.setFormatter(self.logger_formatter) 

127 for _, logger in self.logger.items(): 

128 logger.addHandler(self.logger_stream_handler) 

129 if self.logger_file_handler: 

130 logger.removeHandler(self.logger_file_handler) 

131 

132 @property 

133 def debug(self) -> bool: 

134 """Debug status 

135 

136 :param value: The debug status, True or False. 

137 """ 

138 return self.__debug 

139 

140 @debug.setter 

141 def debug(self, value: bool): 

142 """Debug status 

143 

144 :param value: The debug status, True or False. 

145 """ 

146 self.__debug = value 

147 if self.__debug: 

148 # if debug status is True, turn on debug logging 

149 for _, logger in self.logger.items(): 

150 logger.setLevel(logging.DEBUG) 

151 # turn on httplib debug 

152 httplib.HTTPConnection.debuglevel = 1 

153 else: 

154 # if debug status is False, turn off debug logging, 

155 # setting log level to default `logging.WARNING` 

156 for _, logger in self.logger.items(): 

157 logger.setLevel(logging.WARNING) 

158 # turn off httplib debug 

159 httplib.HTTPConnection.debuglevel = 0 

160 

161 @property 

162 def logger_format(self) -> str: 

163 """The logger format. 

164 

165 The logger_formatter will be updated when sets logger_format. 

166 

167 :return: The format string. 

168 """ 

169 return self.__logger_format 

170 

171 @logger_format.setter 

172 def logger_format(self, value: str): 

173 """The logger format. 

174 

175 The logger_formatter will be updated when sets logger_format. 

176 

177 :param value: The format string. 

178 """ 

179 self.__logger_format = value 

180 self.logger_formatter = logging.Formatter(self.__logger_format) 

181 

182 def auth_settings(self) -> Dict[str, Dict[str, str]]: 

183 """Gets Auth Settings dict for api client. 

184 

185 :return: The Auth Settings information dict. 

186 """ 

187 return { 

188 'ApiKeyHeader': 

189 { 

190 'type': 'api_key', 

191 'in': 'header', 

192 'key': 'Auth-API-Key', 

193 'value': self.api_key 

194 }, 

195 } 

196 

197 def get_host(self, region: str) -> str: 

198 return { 

199 "us": "https://api.fpjs.io", 

200 "eu": "https://eu.api.fpjs.io", 

201 "ap": "https://ap.api.fpjs.io", 

202 }.get(region, "https://api.fpjs.io") 

203 

204 def to_debug_report(self): 

205 """Gets the essential information for debugging. 

206 

207 :return: The report for debugging. 

208 """ 

209 return "Python SDK Debug Report:\n"\ 

210 "OS: {env}\n"\ 

211 "Python Version: {pyversion}\n"\ 

212 "Version of the API: 3\n"\ 

213 "SDK Package Version: 8.1.0".\ 

214 format(env=sys.platform, pyversion=sys.version)