def api_key_check(): """Api key verificcation interceptor """ req_path = request.path method_type = request.method app.logger.info(">>> path = {}, method = {}".format(req_path, method_type)) if not app_props.api_key_check: app.logger.debug('>>> api key check closed') return None if req_path in app_props.api_key_white_list: app.logger.info('>>> {} in white list, pass'.format(req_path)) return None headers = request.headers api_key_from_req = headers.get('x-api-key') if not api_key_from_req: app.logger.debug('>>> enter api-key error') return resp_json(BaseResp.err('no x-api-key header')) key_obj = Key.query.filter_by(api_key=api_key_from_req).first() if key_obj: app.logger.debug('>>> consumer_id = {}, secret_key = {}'.format(key_obj.consumer_id, key_obj.secret_key)) g.consumer_id = key_obj.consumer_id g.secret_key = key_obj.secret_key return None else: return resp_json(BaseResp.err('Err api key'))
def sign_check(): # order decided by code order """ sign check sign gen format: md5(secret_key + k1v1k2v2.. + secret_key) """ if not app_props.sign_check: app.logger.debug('>>> sign check closed') return None # dict data = request_parse(request) # is a list -> [(k,v),...] data_sorted = sort_dict(data) data_to_be_enc = [] for entry in data_sorted: data_to_be_enc.append(entry[0] + entry[1]) secret_key = g.get("secret_key") data_to_be_enc = secret_key + ''.join(data_to_be_enc) + secret_key data_enc = str_utils.md5(data_to_be_enc) sign_from_req = request.headers.get('x-sign') if not sign_from_req: return resp_json(BaseResp.err('no x-sign header')) if sign_from_req != data_enc: return resp_json(BaseResp.err('Sign error'))
def save_pic(): """ 仅仅允许独照, 合照无法确认每个人的名字 req: { "image": "base64_str", "name": "Tom", "suffix": "jpg" } """ re = execute() return obj_utils.resp_json(re)
def face_recognize(): """ 识别 req: { "image": "base64" } resp: { "code": 0, "msg": "", data: { "name": "xxx" } } """ re = execute() return obj_utils.resp_json(re)
def find_consumer(): consumers = Consumer.query.all() data = [ConsumerFindResp(id=c.id, name=c.name, pwd=c.pwd).dict() for c in consumers] current_app.logger.debug(data) return resp_json(BaseResp.ok_with_data(data))
def register(): re = execute() return resp_json(re)
def handling_unknown_err(e): """Global unknown exception Handler""" app.logger.exception(e) return resp_json(BaseResp.err(e.name))
def supported_dataset(): re = execute() return resp_json(re)