def process(self, params): response = helper.response_msg("DUKCAPIL_GET_DATA_SUCCESS", "DUKCAPIL GET DATA SUCCESS", {}) try: pass except: print(traceback.format_exc()) # end return response
def restore(self, params): try: collection = params["collection"] db_readable_name = database.get_readable_name(collection) process_name = "RESTORE_" + db_readable_name.upper().replace( " ", "_") proc_success_status = process_name + "_SUCCESS" proc_failed_status = process_name + "_FAILED" response = helper.response_msg( status=proc_success_status, desc="Restoring {} record successful.".format( db_readable_name), data={}) ##### PAYLOAD ##### pkey = params["pkey"] ##### VALIDATION ##### record = validation.find_one(response, self.db_handle, collection, {"pkey": pkey}) if record == None: return response ##### DB OPERATION ##### timestamp, timestamp_str = utils._get_current_timestamp() bulk_action = bulk_db_action.bulk_db_action({ "db_handle": self.db_handle, "app": self.webapp }) bulk_action.deep_update(collection, {"pkey": pkey}, { "$set": { "archived_timestamp": "", "archived_timestamp_str": "" } }) bulk_action.execute({}) ##### RESPONSE ##### record["archived_timestamp"] = "" record["archived_timestamp_str"] = "" response.put("status_code", config.G_STATUS['SUCCESS']['CODE']) response.put("data", record) except: self.webapp.logger.debug(traceback.format_exc()) response.put("status_code", config.G_STATUS['UNEXPECTED_ERROR']['CODE']) response.put("status", proc_failed_status) response.put("desc", config.G_STATUS['UNEXPECTED_ERROR']['DESC']) # end try return response
def remove_two_way_reference(self, params, return_record=False): try: main_collection = params["main"]["collection"] sub_collection = params["sub"]["collection"] main_db_readable_name = database.get_readable_name(main_collection) sub_db_readable_name = database.get_readable_name(sub_collection) main_process_name = utils._to_process_name(main_db_readable_name) sub_process_name = utils._to_process_name(sub_db_readable_name) process_name = "REMOVE_REFERENCE_BETWEEN_{}_AND_{}".format( main_process_name, sub_process_name) proc_success_status = process_name + "_SUCCESS" proc_failed_status = process_name + "_FAILED" response = helper.response_msg( status=proc_success_status, desc="Removing reference between {} and {} successful.".format( main_db_readable_name, sub_db_readable_name), data={}) ##### PAYLOAD ##### main_record_pkey = params["main"]["pkey"] sub_record_pkey = params["sub"]["pkey"] ##### VALIDATION ##### main_rec = validation.find_one(response, self.db_handle, main_collection, {"pkey": main_record_pkey}) if main_rec == None: return response # ----------------------- # fk_sub_collection_key = utils._db_name_to_fk_name(sub_collection) reference_found, reference = validation.find_reference( response, main_rec, fk_sub_collection_key, sub_record_pkey) if not reference_found: return response # ----------------------- # sub_rec = validation.find_one(response, self.db_handle, sub_collection, {"pkey": sub_record_pkey}) if sub_rec == None: return response # ----------------------- # fk_main_collection_key = utils._db_name_to_fk_name(main_collection) reference_found, reference = validation.find_reference( response, sub_rec, fk_main_collection_key, main_record_pkey) if not reference_found: return response ##### DB OPERATION ##### bulk_action = bulk_db_action.bulk_db_action({ "db_handle": self.db_handle, "app": self.webapp }) bulk_action.remove_two_way_reference( { "collection": main_collection, "record": main_rec }, { "collection": sub_collection, "record": sub_rec }) bulk_action.execute({}) ##### RESPONSE ##### main_response_name = utils._db_name_to_response_name( main_collection) sub_response_name = utils._db_name_to_response_name(sub_collection) if return_record: # get updated records main_rec = validation.find_one(response, self.db_handle, main_collection, {"pkey": main_record_pkey}) sub_rec = validation.find_one(response, self.db_handle, sub_collection, {"pkey": sub_record_pkey}) else: main_rec = main_record_pkey sub_rec = sub_record_pkey response.put("status_code", config.G_STATUS['SUCCESS']['CODE']) response.put("data", { main_response_name: main_rec, sub_response_name: sub_rec, }) except: self.webapp.logger.debug(traceback.format_exc()) response.put("status_code", config.G_STATUS['UNEXPECTED_ERROR']['CODE']) response.put("status", proc_failed_status) response.put("desc", config.G_STATUS['UNEXPECTED_ERROR']['DESC']) # end try return response
def verify(self, params): response = helper.response_msg("VERIFY_TOKEN_SUCCESS", "VERIFY TOKEN SUCCESS", {}, "0000") headers = params["headers"] client_params = params["params"] # # This is where we ignore the test if we actually want to bypass # authentication # if self.ignore_flag: return response # end if # acc_label = headers["Access-Label"] request_id = headers["Request-Id"] unique_id = headers["Unique-Id"] mim_token = headers["Mim-token"] try: access_key_rec = self.mgdDB.db_access_key.find_one( {"fk_unique_id": unique_id}, { "_id": 0, "key": 1, "secret": 1, "fk_unique_id": 1, "label": 1 }) # # Make sure that this account for api access exists # if access_key_rec == None: response.put("status", "VERIFY_TOKEN_FAILED") response.put("desc", "VERIFY TOKEN FAILED") response.put("status_code", "0001") response.put("data", {}) return response # end if key = access_key_rec["key"] secret = access_key_rec["secret"] gen_secret = access_key_rec["gen_secret"] raw_gen_secret = key + secret # # here we confirm that the unique id and the key are matched # and has been signed by the correct secret so this will match # the key with the unique_id that is sent # gen_secret = hashlib.sha256( raw_gen_secret.encode('ascii')).hexdigest() if unique_id != gen_secret: response.put("status", "VERIFY_TOKEN_FAILED") response.put("desc", "VERIFY TOKEN FAILED") response.put("status_code", "0002") response.put("data", {}) return response # end if # # Start processing the token here # sequance = self.sequance(client_params) temp_token = acc_label + "%|%" +\ request_id + "%|%" +\ key + "%|%" +\ secret + "%|%" +\ unique_id + "%|%" + str(sequence) auth_token = hashlib.sha256(temp_token.encode('ascii')).hexdigest() if mim_token != auth_token: response.put("status", "VERIFY_TOKEN_FAILED") response.put("desc", "VERIFY TOKEN FAILED") response.put("status_code", "0003") response.put("data", {}) return response # end if # response.put("data", {}) except: self.webapp.logger.debug(traceback.format_exc()) response.put("status", "VERIFY_TOKEN_FAILED") response.put("desc", "GENERAL ERROR") response.put("status_code", "9999") # end try return response