onfido-python 2.10.0__py3-none-any.whl → 3.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (326) hide show
  1. onfido/__init__.py +311 -2
  2. onfido/api/__init__.py +5 -0
  3. onfido/api/default_api.py +17207 -0
  4. onfido/api_client.py +770 -0
  5. onfido/api_response.py +21 -0
  6. onfido/configuration.py +460 -0
  7. onfido/exceptions.py +184 -77
  8. onfido/models/__init__.py +291 -0
  9. onfido/models/address.py +169 -0
  10. onfido/models/address_builder.py +169 -0
  11. onfido/models/address_shared.py +169 -0
  12. onfido/models/addresses_list.py +108 -0
  13. onfido/models/applicant.py +162 -0
  14. onfido/models/applicant_builder.py +152 -0
  15. onfido/models/applicant_create.py +117 -0
  16. onfido/models/applicant_request.py +116 -0
  17. onfido/models/applicant_response.py +146 -0
  18. onfido/models/applicant_shared.py +115 -0
  19. onfido/models/applicant_update.py +123 -0
  20. onfido/models/applicant_updater.py +158 -0
  21. onfido/models/applicants_list.py +108 -0
  22. onfido/models/check.py +147 -0
  23. onfido/models/check_builder.py +127 -0
  24. onfido/models/check_request.py +119 -0
  25. onfido/models/check_response.py +137 -0
  26. onfido/models/check_shared.py +108 -0
  27. onfido/models/checks_list.py +108 -0
  28. onfido/models/complete_task_builder.py +104 -0
  29. onfido/models/complete_task_data_builder.py +143 -0
  30. onfido/models/consent_item.py +109 -0
  31. onfido/models/consents_builder.py +98 -0
  32. onfido/models/country_codes.py +285 -0
  33. onfido/models/device_intelligence_breakdown.py +110 -0
  34. onfido/models/device_intelligence_breakdown_breakdown.py +104 -0
  35. onfido/models/device_intelligence_breakdown_breakdown_device.py +104 -0
  36. onfido/models/device_intelligence_breakdown_breakdown_device_breakdown.py +114 -0
  37. onfido/models/device_intelligence_breakdown_properties.py +116 -0
  38. onfido/models/device_intelligence_breakdown_properties_device.py +189 -0
  39. onfido/models/device_intelligence_breakdown_properties_geolocation.py +105 -0
  40. onfido/models/device_intelligence_breakdown_properties_ip.py +106 -0
  41. onfido/models/device_intelligence_report.py +135 -0
  42. onfido/models/document.py +142 -0
  43. onfido/models/document_breakdown.py +152 -0
  44. onfido/models/document_breakdown_age_validation.py +106 -0
  45. onfido/models/document_breakdown_age_validation_breakdown.py +104 -0
  46. onfido/models/document_breakdown_compromised_document.py +106 -0
  47. onfido/models/document_breakdown_compromised_document_breakdown.py +109 -0
  48. onfido/models/document_breakdown_data_comparison.py +106 -0
  49. onfido/models/document_breakdown_data_comparison_breakdown.py +139 -0
  50. onfido/models/document_breakdown_data_comparison_breakdown_issuing_country.py +102 -0
  51. onfido/models/document_breakdown_data_consistency.py +106 -0
  52. onfido/models/document_breakdown_data_consistency_breakdown.py +149 -0
  53. onfido/models/document_breakdown_data_validation.py +106 -0
  54. onfido/models/document_breakdown_data_validation_breakdown.py +136 -0
  55. onfido/models/document_breakdown_data_validation_breakdown_document_expiration.py +102 -0
  56. onfido/models/document_breakdown_data_validation_breakdown_expiry_date.py +102 -0
  57. onfido/models/document_breakdown_image_integrity.py +106 -0
  58. onfido/models/document_breakdown_image_integrity_breakdown.py +122 -0
  59. onfido/models/document_breakdown_image_integrity_breakdown_colour_picture.py +102 -0
  60. onfido/models/document_breakdown_image_integrity_breakdown_conclusive_document_quality.py +106 -0
  61. onfido/models/document_breakdown_image_integrity_breakdown_image_quality.py +106 -0
  62. onfido/models/document_breakdown_image_integrity_breakdown_supported_document.py +102 -0
  63. onfido/models/document_breakdown_issuing_authority.py +106 -0
  64. onfido/models/document_breakdown_issuing_authority_breakdown.py +110 -0
  65. onfido/models/document_breakdown_issuing_authority_breakdown_nfc_active_authentication.py +102 -0
  66. onfido/models/document_breakdown_issuing_authority_breakdown_nfc_passive_authentication.py +102 -0
  67. onfido/models/document_breakdown_police_record.py +100 -0
  68. onfido/models/document_breakdown_visual_authenticity.py +106 -0
  69. onfido/models/document_breakdown_visual_authenticity_breakdown.py +146 -0
  70. onfido/models/document_breakdown_visual_authenticity_breakdown_digital_tampering.py +102 -0
  71. onfido/models/document_breakdown_visual_authenticity_breakdown_face_detection.py +102 -0
  72. onfido/models/document_breakdown_visual_authenticity_breakdown_fonts.py +102 -0
  73. onfido/models/document_breakdown_visual_authenticity_breakdown_original_document_present.py +106 -0
  74. onfido/models/document_breakdown_visual_authenticity_breakdown_other.py +102 -0
  75. onfido/models/document_breakdown_visual_authenticity_breakdown_picture_face_integrity.py +102 -0
  76. onfido/models/document_breakdown_visual_authenticity_breakdown_security_features.py +102 -0
  77. onfido/models/document_breakdown_visual_authenticity_breakdown_template.py +102 -0
  78. onfido/models/document_cdq_reasons.py +114 -0
  79. onfido/models/document_iq_reasons.py +118 -0
  80. onfido/models/document_odp_reasons.py +106 -0
  81. onfido/models/document_properties.py +191 -0
  82. onfido/models/document_properties_address_lines.py +110 -0
  83. onfido/models/document_properties_barcode_inner.py +135 -0
  84. onfido/models/document_properties_document_classification.py +104 -0
  85. onfido/models/document_properties_document_numbers_inner.py +102 -0
  86. onfido/models/document_properties_driving_licence_information.py +107 -0
  87. onfido/models/document_properties_extracted_data.py +141 -0
  88. onfido/models/document_properties_nfc.py +125 -0
  89. onfido/models/document_report.py +141 -0
  90. onfido/models/document_response.py +111 -0
  91. onfido/models/document_shared.py +129 -0
  92. onfido/models/document_types.py +60 -0
  93. onfido/models/document_video_report.py +141 -0
  94. onfido/models/document_video_with_address_information_report.py +141 -0
  95. onfido/models/document_with_address_information_report.py +141 -0
  96. onfido/models/document_with_driver_verification_report.py +141 -0
  97. onfido/models/document_with_driver_verification_report_all_of_properties.py +215 -0
  98. onfido/models/document_with_driver_verification_report_all_of_properties_all_of_passenger_vehicle.py +105 -0
  99. onfido/models/document_with_driver_verification_report_all_of_properties_all_of_vehicle_class_details_inner.py +107 -0
  100. onfido/models/document_with_driving_licence_information_report.py +141 -0
  101. onfido/models/documents_list.py +108 -0
  102. onfido/models/error.py +104 -0
  103. onfido/models/error1.py +106 -0
  104. onfido/models/error_properties.py +104 -0
  105. onfido/models/error_properties1.py +102 -0
  106. onfido/models/extract_request.py +100 -0
  107. onfido/models/extraction.py +112 -0
  108. onfido/models/extraction_document_classification.py +120 -0
  109. onfido/models/extraction_extracted_data.py +176 -0
  110. onfido/models/facial_similarity_motion_breakdown.py +116 -0
  111. onfido/models/facial_similarity_motion_breakdown_face_comparison.py +106 -0
  112. onfido/models/facial_similarity_motion_breakdown_image_integrity.py +106 -0
  113. onfido/models/facial_similarity_motion_breakdown_image_integrity_breakdown.py +110 -0
  114. onfido/models/facial_similarity_motion_breakdown_image_integrity_breakdown_face_detected.py +102 -0
  115. onfido/models/facial_similarity_motion_breakdown_image_integrity_breakdown_source_integrity.py +106 -0
  116. onfido/models/facial_similarity_motion_breakdown_visual_authenticity.py +106 -0
  117. onfido/models/facial_similarity_motion_breakdown_visual_authenticity_breakdown.py +110 -0
  118. onfido/models/facial_similarity_motion_breakdown_visual_authenticity_breakdown_spoofing_detection.py +106 -0
  119. onfido/models/facial_similarity_motion_properties.py +100 -0
  120. onfido/models/facial_similarity_motion_report.py +141 -0
  121. onfido/models/facial_similarity_photo_breakdown.py +116 -0
  122. onfido/models/facial_similarity_photo_breakdown_face_comparison.py +106 -0
  123. onfido/models/facial_similarity_photo_breakdown_face_comparison_breakdown.py +104 -0
  124. onfido/models/facial_similarity_photo_breakdown_face_comparison_breakdown_face_match.py +106 -0
  125. onfido/models/facial_similarity_photo_breakdown_face_comparison_breakdown_face_match_properties.py +102 -0
  126. onfido/models/facial_similarity_photo_breakdown_image_integrity.py +106 -0
  127. onfido/models/facial_similarity_photo_breakdown_image_integrity_breakdown.py +110 -0
  128. onfido/models/facial_similarity_photo_breakdown_image_integrity_breakdown_face_detected.py +102 -0
  129. onfido/models/facial_similarity_photo_breakdown_image_integrity_breakdown_source_integrity.py +106 -0
  130. onfido/models/facial_similarity_photo_breakdown_visual_authenticity.py +106 -0
  131. onfido/models/facial_similarity_photo_breakdown_visual_authenticity_breakdown.py +104 -0
  132. onfido/models/facial_similarity_photo_breakdown_visual_authenticity_breakdown_spoofing_detection.py +106 -0
  133. onfido/models/facial_similarity_photo_breakdown_visual_authenticity_breakdown_spoofing_detection_properties.py +100 -0
  134. onfido/models/facial_similarity_photo_fully_auto_breakdown.py +116 -0
  135. onfido/models/facial_similarity_photo_fully_auto_breakdown_image_integrity.py +106 -0
  136. onfido/models/facial_similarity_photo_fully_auto_breakdown_image_integrity_breakdown.py +110 -0
  137. onfido/models/facial_similarity_photo_fully_auto_breakdown_image_integrity_breakdown_source_integrity.py +106 -0
  138. onfido/models/facial_similarity_photo_fully_auto_properties.py +100 -0
  139. onfido/models/facial_similarity_photo_fully_auto_report.py +141 -0
  140. onfido/models/facial_similarity_photo_properties.py +100 -0
  141. onfido/models/facial_similarity_photo_report.py +141 -0
  142. onfido/models/facial_similarity_video_breakdown.py +116 -0
  143. onfido/models/facial_similarity_video_breakdown_face_comparison.py +106 -0
  144. onfido/models/facial_similarity_video_breakdown_image_integrity.py +106 -0
  145. onfido/models/facial_similarity_video_breakdown_image_integrity_breakdown.py +110 -0
  146. onfido/models/facial_similarity_video_breakdown_image_integrity_breakdown_face_detected.py +102 -0
  147. onfido/models/facial_similarity_video_breakdown_image_integrity_breakdown_source_integrity.py +106 -0
  148. onfido/models/facial_similarity_video_breakdown_visual_authenticity.py +106 -0
  149. onfido/models/facial_similarity_video_breakdown_visual_authenticity_breakdown.py +110 -0
  150. onfido/models/facial_similarity_video_breakdown_visual_authenticity_breakdown_liveness_detected.py +102 -0
  151. onfido/models/facial_similarity_video_breakdown_visual_authenticity_breakdown_spoofing_detection.py +106 -0
  152. onfido/models/facial_similarity_video_properties.py +100 -0
  153. onfido/models/facial_similarity_video_report.py +141 -0
  154. onfido/models/id_number.py +114 -0
  155. onfido/models/id_photo.py +113 -0
  156. onfido/models/id_photo_response.py +113 -0
  157. onfido/models/id_photos_list.py +108 -0
  158. onfido/models/identity_enhanced_breakdown.py +122 -0
  159. onfido/models/identity_enhanced_breakdown_address.py +106 -0
  160. onfido/models/identity_enhanced_breakdown_address_breakdown.py +116 -0
  161. onfido/models/identity_enhanced_breakdown_address_breakdown_credit_agencies.py +106 -0
  162. onfido/models/identity_enhanced_breakdown_address_breakdown_credit_agencies_properties.py +100 -0
  163. onfido/models/identity_enhanced_breakdown_address_breakdown_telephone_database.py +102 -0
  164. onfido/models/identity_enhanced_breakdown_address_breakdown_voting_register.py +102 -0
  165. onfido/models/identity_enhanced_breakdown_date_of_birth.py +106 -0
  166. onfido/models/identity_enhanced_breakdown_date_of_birth_breakdown.py +110 -0
  167. onfido/models/identity_enhanced_breakdown_date_of_birth_breakdown_credit_agencies.py +102 -0
  168. onfido/models/identity_enhanced_breakdown_date_of_birth_breakdown_voting_register.py +102 -0
  169. onfido/models/identity_enhanced_breakdown_mortality.py +100 -0
  170. onfido/models/identity_enhanced_breakdown_sources.py +106 -0
  171. onfido/models/identity_enhanced_breakdown_sources_breakdown.py +104 -0
  172. onfido/models/identity_enhanced_breakdown_sources_breakdown_total_sources.py +106 -0
  173. onfido/models/identity_enhanced_breakdown_sources_breakdown_total_sources_properties.py +100 -0
  174. onfido/models/identity_enhanced_properties.py +110 -0
  175. onfido/models/identity_enhanced_properties_matched_addresses_inner.py +102 -0
  176. onfido/models/identity_enhanced_report.py +141 -0
  177. onfido/models/india_pan_report.py +141 -0
  178. onfido/models/india_pan_report_all_of_breakdown.py +104 -0
  179. onfido/models/india_pan_report_all_of_breakdown_device.py +104 -0
  180. onfido/models/india_pan_report_all_of_breakdown_device_breakdown.py +109 -0
  181. onfido/models/india_pan_report_all_of_breakdown_device_breakdown_pan_valid.py +100 -0
  182. onfido/models/india_pan_report_all_of_properties.py +104 -0
  183. onfido/models/india_pan_report_all_of_properties_device.py +102 -0
  184. onfido/models/known_faces_breakdown.py +110 -0
  185. onfido/models/known_faces_breakdown_image_integrity.py +100 -0
  186. onfido/models/known_faces_breakdown_previously_seen_faces.py +100 -0
  187. onfido/models/known_faces_properties.py +108 -0
  188. onfido/models/known_faces_properties_matches_inner.py +108 -0
  189. onfido/models/known_faces_report.py +141 -0
  190. onfido/models/live_photo.py +113 -0
  191. onfido/models/live_photo_response.py +113 -0
  192. onfido/models/live_photos_list.py +108 -0
  193. onfido/models/live_video.py +115 -0
  194. onfido/models/live_videos_list.py +108 -0
  195. onfido/models/location.py +103 -0
  196. onfido/models/location_builder.py +103 -0
  197. onfido/models/location_shared.py +103 -0
  198. onfido/models/motion_capture.py +113 -0
  199. onfido/models/motion_captures_list.py +108 -0
  200. onfido/models/photo_auto_reasons.py +108 -0
  201. onfido/models/photo_reasons.py +108 -0
  202. onfido/models/proof_of_address_breakdown.py +116 -0
  203. onfido/models/proof_of_address_breakdown_data_comparison.py +106 -0
  204. onfido/models/proof_of_address_breakdown_data_comparison_breakdown.py +114 -0
  205. onfido/models/proof_of_address_breakdown_document_classification.py +106 -0
  206. onfido/models/proof_of_address_breakdown_document_classification_breakdown.py +104 -0
  207. onfido/models/proof_of_address_breakdown_image_integrity.py +106 -0
  208. onfido/models/proof_of_address_breakdown_image_integrity_breakdown.py +104 -0
  209. onfido/models/proof_of_address_properties.py +125 -0
  210. onfido/models/proof_of_address_report.py +141 -0
  211. onfido/models/repeat_attempts_list.py +117 -0
  212. onfido/models/repeat_attempts_list_repeat_attempts_inner.py +143 -0
  213. onfido/models/report.py +621 -0
  214. onfido/models/report_document.py +100 -0
  215. onfido/models/report_name.py +56 -0
  216. onfido/models/report_result.py +38 -0
  217. onfido/models/report_shared.py +129 -0
  218. onfido/models/report_status.py +40 -0
  219. onfido/models/report_sub_result.py +39 -0
  220. onfido/models/reports_list.py +108 -0
  221. onfido/models/results_feedback.py +116 -0
  222. onfido/models/sdk_token.py +100 -0
  223. onfido/models/sdk_token_builder.py +106 -0
  224. onfido/models/sdk_token_request.py +106 -0
  225. onfido/models/sdk_token_response.py +100 -0
  226. onfido/models/task.py +146 -0
  227. onfido/models/task_item.py +128 -0
  228. onfido/models/timeline_file_reference.py +102 -0
  229. onfido/models/us_driving_licence_breakdown.py +116 -0
  230. onfido/models/us_driving_licence_breakdown_address.py +106 -0
  231. onfido/models/us_driving_licence_breakdown_address_breakdown.py +129 -0
  232. onfido/models/us_driving_licence_breakdown_document.py +106 -0
  233. onfido/models/us_driving_licence_breakdown_document_breakdown.py +119 -0
  234. onfido/models/us_driving_licence_breakdown_personal.py +106 -0
  235. onfido/models/us_driving_licence_breakdown_personal_breakdown.py +164 -0
  236. onfido/models/us_driving_licence_builder.py +185 -0
  237. onfido/models/us_driving_licence_report.py +141 -0
  238. onfido/models/us_driving_licence_shared.py +185 -0
  239. onfido/models/video_reasons.py +106 -0
  240. onfido/models/watchlist_aml_breakdown.py +122 -0
  241. onfido/models/watchlist_aml_breakdown_adverse_media.py +100 -0
  242. onfido/models/watchlist_aml_breakdown_legal_and_regulatory_warnings.py +100 -0
  243. onfido/models/watchlist_aml_breakdown_politically_exposed_person.py +100 -0
  244. onfido/models/watchlist_aml_breakdown_sanction.py +100 -0
  245. onfido/models/watchlist_aml_properties.py +100 -0
  246. onfido/models/watchlist_aml_report.py +141 -0
  247. onfido/models/watchlist_enhanced_breakdown.py +122 -0
  248. onfido/models/watchlist_enhanced_properties.py +100 -0
  249. onfido/models/watchlist_enhanced_report.py +141 -0
  250. onfido/models/watchlist_monitor.py +120 -0
  251. onfido/models/watchlist_monitor_builder.py +111 -0
  252. onfido/models/watchlist_monitor_match.py +102 -0
  253. onfido/models/watchlist_monitor_matches_list.py +108 -0
  254. onfido/models/watchlist_monitor_matches_updater.py +102 -0
  255. onfido/models/watchlist_monitor_response.py +107 -0
  256. onfido/models/watchlist_monitor_shared.py +111 -0
  257. onfido/models/watchlist_monitors_list.py +108 -0
  258. onfido/models/watchlist_peps_only_report.py +141 -0
  259. onfido/models/watchlist_sanctions_only_report.py +141 -0
  260. onfido/models/watchlist_standard_breakdown.py +116 -0
  261. onfido/models/watchlist_standard_properties.py +100 -0
  262. onfido/models/watchlist_standard_report.py +141 -0
  263. onfido/models/webhook.py +115 -0
  264. onfido/models/webhook_builder.py +109 -0
  265. onfido/models/webhook_create.py +100 -0
  266. onfido/models/webhook_event.py +104 -0
  267. onfido/models/webhook_event_payload.py +111 -0
  268. onfido/models/webhook_event_payload_object.py +107 -0
  269. onfido/models/webhook_event_type.py +52 -0
  270. onfido/models/webhook_resend.py +108 -0
  271. onfido/models/webhook_response.py +106 -0
  272. onfido/models/webhook_shared.py +107 -0
  273. onfido/models/webhook_update.py +100 -0
  274. onfido/models/webhook_updater.py +109 -0
  275. onfido/models/webhooks_list.py +108 -0
  276. onfido/models/webhooks_resend_item.py +103 -0
  277. onfido/models/workflow_run.py +149 -0
  278. onfido/models/workflow_run_builder.py +123 -0
  279. onfido/models/workflow_run_request.py +100 -0
  280. onfido/models/workflow_run_response.py +126 -0
  281. onfido/models/workflow_run_response_error.py +102 -0
  282. onfido/models/workflow_run_shared.py +121 -0
  283. onfido/models/workflow_run_shared_link.py +119 -0
  284. onfido/py.typed +0 -0
  285. onfido/rest.py +258 -0
  286. onfido/webhook_event_verifier.py +7 -3
  287. {onfido_python-2.10.0.dist-info → onfido_python-3.1.0.dist-info}/LICENSE +1 -1
  288. onfido_python-3.1.0.dist-info/METADATA +18 -0
  289. onfido_python-3.1.0.dist-info/RECORD +291 -0
  290. {onfido_python-2.10.0.dist-info → onfido_python-3.1.0.dist-info}/WHEEL +2 -1
  291. onfido_python-3.1.0.dist-info/top_level.txt +1 -0
  292. onfido/aio_resource.py +0 -132
  293. onfido/mimetype.py +0 -5
  294. onfido/onfido.py +0 -71
  295. onfido/onfido_download.py +0 -11
  296. onfido/regions.py +0 -11
  297. onfido/resource.py +0 -88
  298. onfido/resources/address_picker.py +0 -6
  299. onfido/resources/applicants.py +0 -23
  300. onfido/resources/checks.py +0 -19
  301. onfido/resources/documents.py +0 -16
  302. onfido/resources/extraction.py +0 -6
  303. onfido/resources/live_photos.py +0 -17
  304. onfido/resources/live_videos.py +0 -16
  305. onfido/resources/motion_captures.py +0 -16
  306. onfido/resources/reports.py +0 -16
  307. onfido/resources/sdk_tokens.py +0 -5
  308. onfido/resources/watchlist_monitors.py +0 -16
  309. onfido/resources/webhooks.py +0 -18
  310. onfido/resources/workflow_runs.py +0 -17
  311. onfido/resources_aio/address_picker.py +0 -6
  312. onfido/resources_aio/applicants.py +0 -23
  313. onfido/resources_aio/checks.py +0 -19
  314. onfido/resources_aio/documents.py +0 -16
  315. onfido/resources_aio/extraction.py +0 -6
  316. onfido/resources_aio/live_photos.py +0 -17
  317. onfido/resources_aio/live_videos.py +0 -16
  318. onfido/resources_aio/motion_captures.py +0 -16
  319. onfido/resources_aio/reports.py +0 -16
  320. onfido/resources_aio/sdk_tokens.py +0 -6
  321. onfido/resources_aio/watchlist_monitors.py +0 -16
  322. onfido/resources_aio/webhooks.py +0 -18
  323. onfido/resources_aio/workflow_runs.py +0 -17
  324. onfido/utils.py +0 -22
  325. onfido_python-2.10.0.dist-info/METADATA +0 -181
  326. onfido_python-2.10.0.dist-info/RECORD +0 -40
onfido/api_response.py ADDED
@@ -0,0 +1,21 @@
1
+ """API response object."""
2
+
3
+ from __future__ import annotations
4
+ from typing import Optional, Generic, Mapping, TypeVar
5
+ from pydantic import Field, StrictInt, StrictBytes, BaseModel
6
+
7
+ T = TypeVar("T")
8
+
9
+ class ApiResponse(BaseModel, Generic[T]):
10
+ """
11
+ API response object
12
+ """
13
+
14
+ status_code: StrictInt = Field(description="HTTP status code")
15
+ headers: Optional[Mapping[str, str]] = Field(None, description="HTTP headers")
16
+ data: T = Field(description="Deserialized data given the data type")
17
+ raw_data: StrictBytes = Field(description="Raw data (HTTP response body)")
18
+
19
+ model_config = {
20
+ "arbitrary_types_allowed": True
21
+ }
@@ -0,0 +1,460 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ Onfido API v3.6
5
+
6
+ The Onfido API (v3.6)
7
+
8
+ The version of the OpenAPI document: v3.6
9
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
10
+
11
+ Do not edit the class manually.
12
+ """ # noqa: E501
13
+
14
+
15
+ import copy
16
+ import logging
17
+ from logging import FileHandler
18
+ import multiprocessing
19
+ import sys
20
+ from typing import Optional
21
+ import urllib3
22
+
23
+ import http.client as httplib
24
+
25
+ from enum import Enum
26
+
27
+ class Region(Enum):
28
+ EU = 'eu'
29
+ US = 'us'
30
+ CA = 'ca'
31
+
32
+
33
+
34
+ JSON_SCHEMA_VALIDATION_KEYWORDS = {
35
+ 'multipleOf', 'maximum', 'exclusiveMaximum',
36
+ 'minimum', 'exclusiveMinimum', 'maxLength',
37
+ 'minLength', 'pattern', 'maxItems', 'minItems'
38
+ }
39
+
40
+ class Configuration:
41
+ """This class contains various settings of the API client.
42
+
43
+ :param api_token: API token to use.
44
+ :param region: region to target.
45
+ :param host: Base url.
46
+ :param server_index: Index to servers configuration.
47
+ :param server_operation_index: Mapping from operation ID to an index to server
48
+ configuration.
49
+ :param server_operation_variables: Mapping from operation ID to a mapping with
50
+ string values to replace variables in templated server configuration.
51
+ The validation of enums is performed for variables with defined enum
52
+ values before.
53
+ :param ssl_ca_cert: str - the path to a file of concatenated CA certificates
54
+ in PEM format.
55
+
56
+ :Example:
57
+
58
+ API Key Authentication Example.
59
+ Given the following security scheme in the OpenAPI specification:
60
+ components:
61
+ securitySchemes:
62
+ cookieAuth: # name for the security scheme
63
+ type: apiKey
64
+ in: cookie
65
+ name: JSESSIONID # cookie name
66
+
67
+ You can programmatically set the cookie:
68
+
69
+ conf = onfido.Configuration(
70
+ api_key={'cookieAuth': 'abc123'}
71
+ api_key_prefix={'cookieAuth': 'JSESSIONID'}
72
+ )
73
+
74
+ The following cookie will be added to the HTTP request:
75
+ Cookie: JSESSIONID abc123
76
+ """
77
+
78
+ _default = None
79
+
80
+ def __init__(self, host=None,
81
+ api_token=None,
82
+ region=Region.EU,
83
+ timeout=None,
84
+ server_index=None,
85
+ server_operation_index=None, server_operation_variables=None,
86
+ ssl_ca_cert=None,
87
+ ) -> None:
88
+ """Constructor
89
+ """
90
+ self._base_path = "https://api.eu.onfido.com/v3.6" if host is None else host
91
+ """Default Base url
92
+ """
93
+ self.server_index = 0 if server_index is None and host is None else server_index
94
+ self.server_operation_index = server_operation_index or {}
95
+ """Default server index
96
+ """
97
+ self.timeout = timeout or urllib3.util.Timeout(connect=30.0, read=30.0)
98
+ self.server_variables = {'region': region.value}
99
+ self.server_operation_variables = server_operation_variables or {}
100
+ """Default server variables
101
+ """
102
+ self.temp_folder_path = None
103
+ """Temp file folder for downloading files
104
+ """
105
+ # Authentication Settings
106
+ self.api_key = {"Token": f"Token token={api_token}"}
107
+ self.api_key_prefix = {}
108
+ self.refresh_api_key_hook = None
109
+ self.username = None
110
+ self.password = None
111
+ self.access_token = None
112
+
113
+ self.logger = {}
114
+ """Logging Settings
115
+ """
116
+ self.logger["package_logger"] = logging.getLogger("onfido")
117
+ self.logger["urllib3_logger"] = logging.getLogger("urllib3")
118
+ self.logger_format = '%(asctime)s %(levelname)s %(message)s'
119
+ """Log format
120
+ """
121
+ self.logger_stream_handler = None
122
+ """Log stream handler
123
+ """
124
+ self.logger_file_handler: Optional[FileHandler] = None
125
+ """Log file handler
126
+ """
127
+ self.logger_file = None
128
+ """Debug file location
129
+ """
130
+ self.debug = False
131
+ """Debug switch
132
+ """
133
+
134
+ self.verify_ssl = True
135
+ """SSL/TLS verification
136
+ Set this to false to skip verifying SSL certificate when calling API
137
+ from https server.
138
+ """
139
+ self.ssl_ca_cert = ssl_ca_cert
140
+ """Set this to customize the certificate file to verify the peer.
141
+ """
142
+ self.cert_file = None
143
+ """client certificate file
144
+ """
145
+ self.key_file = None
146
+ """client key file
147
+ """
148
+ self.assert_hostname = None
149
+ """Set this to True/False to enable/disable SSL hostname verification.
150
+ """
151
+ self.tls_server_name = None
152
+ """SSL/TLS Server Name Indication (SNI)
153
+ Set this to the SNI value expected by the server.
154
+ """
155
+
156
+ self.connection_pool_maxsize = multiprocessing.cpu_count() * 5
157
+ """urllib3 connection pool's maximum number of connections saved
158
+ per pool. urllib3 uses 1 connection as default value, but this is
159
+ not the best value when you are making a lot of possibly parallel
160
+ requests to the same host, which is often the case here.
161
+ cpu_count * 5 is used as default value to increase performance.
162
+ """
163
+
164
+ self.proxy: Optional[str] = None
165
+ """Proxy URL
166
+ """
167
+ self.proxy_headers = None
168
+ """Proxy headers
169
+ """
170
+ self.safe_chars_for_path_param = ''
171
+ """Safe chars for path_param
172
+ """
173
+ self.retries = None
174
+ """Adding retries to override urllib3 default value 3
175
+ """
176
+ # Enable client side validation
177
+ self.client_side_validation = True
178
+
179
+ self.socket_options = None
180
+ """Options to pass down to the underlying urllib3 socket
181
+ """
182
+
183
+ self.datetime_format = "%Y-%m-%dT%H:%M:%S.%f%z"
184
+ """datetime format
185
+ """
186
+
187
+ self.date_format = "%Y-%m-%d"
188
+ """date format
189
+ """
190
+
191
+ def __deepcopy__(self, memo):
192
+ cls = self.__class__
193
+ result = cls.__new__(cls)
194
+ memo[id(self)] = result
195
+ for k, v in self.__dict__.items():
196
+ if k not in ('logger', 'logger_file_handler'):
197
+ setattr(result, k, copy.deepcopy(v, memo))
198
+ # shallow copy of loggers
199
+ result.logger = copy.copy(self.logger)
200
+ # use setters to configure loggers
201
+ result.logger_file = self.logger_file
202
+ result.debug = self.debug
203
+ return result
204
+
205
+ def __setattr__(self, name, value):
206
+ object.__setattr__(self, name, value)
207
+
208
+ @classmethod
209
+ def set_default(cls, default):
210
+ """Set default instance of configuration.
211
+
212
+ It stores default configuration, which can be
213
+ returned by get_default_copy method.
214
+
215
+ :param default: object of Configuration
216
+ """
217
+ cls._default = default
218
+
219
+ @classmethod
220
+ def get_default_copy(cls):
221
+ """Deprecated. Please use `get_default` instead.
222
+
223
+ Deprecated. Please use `get_default` instead.
224
+
225
+ :return: The configuration object.
226
+ """
227
+ return cls.get_default()
228
+
229
+ @classmethod
230
+ def get_default(cls):
231
+ """Return the default configuration.
232
+
233
+ This method returns newly created, based on default constructor,
234
+ object of Configuration class or returns a copy of default
235
+ configuration.
236
+
237
+ :return: The configuration object.
238
+ """
239
+ if cls._default is None:
240
+ cls._default = Configuration()
241
+ return cls._default
242
+
243
+ @property
244
+ def logger_file(self):
245
+ """The logger file.
246
+
247
+ If the logger_file is None, then add stream handler and remove file
248
+ handler. Otherwise, add file handler and remove stream handler.
249
+
250
+ :param value: The logger_file path.
251
+ :type: str
252
+ """
253
+ return self.__logger_file
254
+
255
+ @logger_file.setter
256
+ def logger_file(self, value):
257
+ """The logger file.
258
+
259
+ If the logger_file is None, then add stream handler and remove file
260
+ handler. Otherwise, add file handler and remove stream handler.
261
+
262
+ :param value: The logger_file path.
263
+ :type: str
264
+ """
265
+ self.__logger_file = value
266
+ if self.__logger_file:
267
+ # If set logging file,
268
+ # then add file handler and remove stream handler.
269
+ self.logger_file_handler = logging.FileHandler(self.__logger_file)
270
+ self.logger_file_handler.setFormatter(self.logger_formatter)
271
+ for _, logger in self.logger.items():
272
+ logger.addHandler(self.logger_file_handler)
273
+
274
+ @property
275
+ def debug(self):
276
+ """Debug status
277
+
278
+ :param value: The debug status, True or False.
279
+ :type: bool
280
+ """
281
+ return self.__debug
282
+
283
+ @debug.setter
284
+ def debug(self, value):
285
+ """Debug status
286
+
287
+ :param value: The debug status, True or False.
288
+ :type: bool
289
+ """
290
+ self.__debug = value
291
+ if self.__debug:
292
+ # if debug status is True, turn on debug logging
293
+ for _, logger in self.logger.items():
294
+ logger.setLevel(logging.DEBUG)
295
+ # turn on httplib debug
296
+ httplib.HTTPConnection.debuglevel = 1
297
+ else:
298
+ # if debug status is False, turn off debug logging,
299
+ # setting log level to default `logging.WARNING`
300
+ for _, logger in self.logger.items():
301
+ logger.setLevel(logging.WARNING)
302
+ # turn off httplib debug
303
+ httplib.HTTPConnection.debuglevel = 0
304
+
305
+ @property
306
+ def logger_format(self):
307
+ """The logger format.
308
+
309
+ The logger_formatter will be updated when sets logger_format.
310
+
311
+ :param value: The format string.
312
+ :type: str
313
+ """
314
+ return self.__logger_format
315
+
316
+ @logger_format.setter
317
+ def logger_format(self, value):
318
+ """The logger format.
319
+
320
+ The logger_formatter will be updated when sets logger_format.
321
+
322
+ :param value: The format string.
323
+ :type: str
324
+ """
325
+ self.__logger_format = value
326
+ self.logger_formatter = logging.Formatter(self.__logger_format)
327
+
328
+ def get_api_key_with_prefix(self, identifier, alias=None):
329
+ """Gets API key (with prefix if set).
330
+
331
+ :param identifier: The identifier of apiKey.
332
+ :param alias: The alternative identifier of apiKey.
333
+ :return: The token for api key authentication.
334
+ """
335
+ if self.refresh_api_key_hook is not None:
336
+ self.refresh_api_key_hook(self)
337
+ key = self.api_key.get(identifier, self.api_key.get(alias) if alias is not None else None)
338
+ if key:
339
+ prefix = self.api_key_prefix.get(identifier)
340
+ if prefix:
341
+ return "%s %s" % (prefix, key)
342
+ else:
343
+ return key
344
+
345
+ def get_basic_auth_token(self):
346
+ """Gets HTTP basic authentication header (string).
347
+
348
+ :return: The token for basic HTTP authentication.
349
+ """
350
+ username = ""
351
+ if self.username is not None:
352
+ username = self.username
353
+ password = ""
354
+ if self.password is not None:
355
+ password = self.password
356
+ return urllib3.util.make_headers(
357
+ basic_auth=username + ':' + password
358
+ ).get('authorization')
359
+
360
+ def auth_settings(self):
361
+ """Gets Auth Settings dict for api client.
362
+
363
+ :return: The Auth Settings information dict.
364
+ """
365
+ auth = {}
366
+ if 'Token' in self.api_key:
367
+ auth['Token'] = {
368
+ 'type': 'api_key',
369
+ 'in': 'header',
370
+ 'key': 'Authorization',
371
+ 'value': self.get_api_key_with_prefix(
372
+ 'Token',
373
+ ),
374
+ }
375
+ return auth
376
+
377
+ def to_debug_report(self):
378
+ """Gets the essential information for debugging.
379
+
380
+ :return: The report for debugging.
381
+ """
382
+ return "Python SDK Debug Report:\n"\
383
+ "OS: {env}\n"\
384
+ "Python Version: {pyversion}\n"\
385
+ "Version of the API: v3.6\n"\
386
+ "SDK Package Version: 3.1.0".\
387
+ format(env=sys.platform, pyversion=sys.version)
388
+
389
+ def get_host_settings(self):
390
+ """Gets an array of host settings
391
+
392
+ :return: An array of host settings
393
+ """
394
+ return [
395
+ {
396
+ 'url': "https://api.{region}.onfido.com/v3.6",
397
+ 'description': "No description provided",
398
+ 'variables': {
399
+ 'region': {
400
+ 'description': "No description provided",
401
+ 'default_value': "eu",
402
+ 'enum_values': [
403
+ "eu",
404
+ "us",
405
+ "ca"
406
+ ]
407
+ }
408
+ }
409
+ }
410
+ ]
411
+
412
+ def get_host_from_settings(self, index, variables=None, servers=None):
413
+ """Gets host URL based on the index and variables
414
+ :param index: array index of the host settings
415
+ :param variables: hash of variable and the corresponding value
416
+ :param servers: an array of host settings or None
417
+ :return: URL based on host settings
418
+ """
419
+ if index is None:
420
+ return self._base_path
421
+
422
+ variables = {} if variables is None else variables
423
+ servers = self.get_host_settings() if servers is None else servers
424
+
425
+ try:
426
+ server = servers[index]
427
+ except IndexError:
428
+ raise ValueError(
429
+ "Invalid index {0} when selecting the host settings. "
430
+ "Must be less than {1}".format(index, len(servers)))
431
+
432
+ url = server['url']
433
+
434
+ # go through variables and replace placeholders
435
+ for variable_name, variable in server.get('variables', {}).items():
436
+ used_value = variables.get(
437
+ variable_name, variable['default_value'])
438
+
439
+ if 'enum_values' in variable \
440
+ and used_value not in variable['enum_values']:
441
+ raise ValueError(
442
+ "The variable `{0}` in the host URL has invalid value "
443
+ "{1}. Must be {2}.".format(
444
+ variable_name, variables[variable_name],
445
+ variable['enum_values']))
446
+
447
+ url = url.replace("{" + variable_name + "}", used_value)
448
+
449
+ return url
450
+
451
+ @property
452
+ def host(self):
453
+ """Return generated host."""
454
+ return self.get_host_from_settings(self.server_index, variables=self.server_variables)
455
+
456
+ @host.setter
457
+ def host(self, value):
458
+ """Fix base path."""
459
+ self._base_path = value
460
+ self.server_index = None