def wrapper(*args, **kwargs): api_key = args[0].values.get('public_api_key', False) if not api_key: api_key = args[0].values.get('private_api_key', False) if not api_key: res = {'api':{'success': False, 'msg': 'Invalid public API key', 'function': func.__name__}} return render_json_response(res) customer = ApiKey.query(ApiKey.public_api_key == api_key).get() if not customer: customer = ApiKey.query(ApiKey.private_api_key == api_key).get() if not customer: res = {'api':{'success': False, 'msg': 'Oops, you do not have read permission', 'function': func.__name__}} return render_json_response(res) return func(*args, **kwargs)
def checking_right(*args, **kwargs): api_key = args[0].values.get('private_api_key', False) if not api_key: return render_json_response({ 'api_success': False, 'api_msg': 'Invalid private API key', 'api_function': func.__name__ }) customer = ApiKey.query(ApiKey.private_api_key == api_key).get() if not customer or not customer.is_writer: return render_json_response({ 'api_success': False, 'api_msg': 'Oops, you do not have write permission', 'api_function': func.__name__ }) return func(*args, **kwargs)
def wrapper(*args, **kwargs): try: api_key = args[0].values.get('public_api_key', False) if not api_key: res = {'api_success': False, 'api_msg': 'Invalid public API key', 'api_function': func.__name__} return render_json_response(res) customer = ApiKey.query(ApiKey.public_api_key == api_key).get() if not customer: res = {'api_success': False, 'api_msg': 'Oops, you do not have read permission', 'api_function': func.__name__} return render_json_response(res) return func(*args, **kwargs) except Exception, e: res = {'api_success': False, 'api_msg': str(e), 'api_function': func.__name__} logging.error(res) return render_json_response(res)
def get_api_keys(request): api_keys = ApiKey.query() return render_json_response([key.to_json() for key in api_keys])