def __query_job_status(self, user_id, job_id, option_params, sec_key, timestamp): job_status = Utilities.execute_post( self.url + "/job_status", self.__configure_job_query(user_id, job_id, option_params, sec_key, timestamp), ) if job_status.status_code != 200: raise ServerError( "Failed to post entity to {}, response={}:{} - {}", self.url + "/job_status", job_status.status_code, job_status.reason, job_status.json(), ) else: job_status_json_resp = job_status.json() timestamp = job_status_json_resp["timestamp"] server_signature = job_status_json_resp["signature"] signature = Signature(self.partner_id, self.api_key) valid = signature.confirm_sec_key(timestamp, server_signature) if not valid: raise ServerError( "Unable to confirm validity of the job_status response") return job_status
def submit_job(self, partner_params, id_params, use_validation_api=True): Utilities.validate_partner_params(partner_params) if not id_params: raise ValueError( "Please ensure that you send through ID Information") Utilities.validate_id_params(self.url, id_params, partner_params, use_validation_api) if partner_params.get("job_type") != 5: raise ValueError( "Please ensure that you are setting your job_type to 5 to query ID Api" ) sec_key_object = self.__get_sec_key() payload = self.__configure_json( partner_params, id_params, sec_key_object["sec_key"], sec_key_object["timestamp"], ) response = self.__execute_http(payload) if response.status_code != 200: raise ServerError( "Failed to post entity to {}, status={}, response={}".format( self.url + "/id_verification", response.status_code, response.json())) return response
def get_smile_id_services(sid_server): if sid_server in [0, 1]: sid_server_map = { 0: "https://3eydmgh10d.execute-api.us-west-2.amazonaws.com/test", 1: "https://la7am6gdm8.execute-api.us-west-2.amazonaws.com/prod", } url = sid_server_map[sid_server] else: url = sid_server response = Utilities.execute_get(url + "/services") if response.status_code != 200: raise ServerError( "Failed to get to {}, status={}, response={}".format( url + "/services", response.status_code, response.json())) return response
def validate_id_params(sid_server, id_info_params, partner_params, use_validation_api=True): if not id_info_params["entered"]: return for field in ["country", "id_type", "id_number"]: if field in id_info_params: if id_info_params[field]: continue else: raise ValueError("key " + field + " cannot be empty") else: raise ValueError("key " + field + " cannot be empty") if not use_validation_api: return response = Utilities.get_smile_id_services(sid_server) if response.status_code != 200: raise ServerError( "Failed to get to {}, status={}, response={}".format( url + "/services", response.status_code, response.json())) response_json = response.json() if response_json["id_types"]: if not id_info_params["country"] in response_json["id_types"]: raise ValueError("country " + id_info_params["country"] + " is invalid") selected_country = response_json["id_types"][ id_info_params["country"]] if not id_info_params["id_type"] in selected_country: raise ValueError("id_type " + id_info_params["id_type"] + " is invalid") id_params = selected_country[id_info_params["id_type"]] for key in id_params: if key not in id_info_params and key not in partner_params: raise ValueError("key " + key + " is required") if key in id_info_params and not id_info_params[key]: raise ValueError("key " + key + " cannot be empty") if key in partner_params and not partner_params[key]: raise ValueError("key " + key + " cannot be empty")
def submit_job( self, partner_params, images_params, id_info_params, options_params, use_validation_api=True, ): Utilities.validate_partner_params(partner_params) job_type = partner_params["job_type"] if not id_info_params: if job_type == 5: Utilities.validate_id_params(self.url, id_info_params, partner_params, use_validation_api) id_info_params = { "first_name": None, "middle_name": None, "last_name": None, "country": None, "id_type": None, "id_number": None, "dob": None, "phone_number": None, "entered": False, } if job_type == 5: return self.__call_id_api(partner_params, id_info_params, use_validation_api) if not options_params: options_params = { "return_job_status": True, "return_history": False, "return_images": False, } self.__validate_options(options_params) validate_images(images_params) Utilities.validate_id_params(self.url, id_info_params, partner_params, use_validation_api) self.__validate_return_data(options_params) sec_key_object = self.__get_sec_key() sec_key = sec_key_object["sec_key"] timestamp = sec_key_object["timestamp"] prep_upload = WebApi.execute_http( self.url + "/upload", self.__prepare_prep_upload_payload(partner_params, sec_key, timestamp), ) if prep_upload.status_code != 200: raise ServerError( "Failed to post entity to {}, status={}, response={}".format( self.url + "/upload", prep_upload.status_code, prep_upload.json())) else: prep_upload_json_resp = prep_upload.json() upload_url = prep_upload_json_resp["upload_url"] smile_job_id = prep_upload_json_resp["smile_job_id"] zip_stream = generate_zip_file( partner_id=self.partner_id, sec_key=sec_key, timestamp=timestamp, callback_url=self.call_back_url, image_params=images_params, partner_params=partner_params, id_info_params=id_info_params, upload_url=upload_url, ) upload_response = WebApi.upload(upload_url, zip_stream) if upload_response.status_code != 200: raise ServerError( "Failed to post entity to {}, status={}, response={}". format(upload_url, prep_upload.status_code, prep_upload.json())) if options_params["return_job_status"]: self.utilities = Utilities(self.partner_id, self.api_key, self.sid_server) job_status = self.poll_job_status( 0, partner_params, options_params, sec_key_object["sec_key"], sec_key_object["timestamp"], ) job_status_response = job_status.json() job_status_response["success"] = True job_status_response["smile_job_id"] = smile_job_id return job_status else: return {"success": True, "smile_job_id": smile_job_id}