def test(): if 'api_key' in request.args: api_key = request.args.get('api_key') token = Token.find_one(by={'api_key_hash': api_key}) if token is not None: return jsonify(ok=True) else: return jsonify(error='Wrong API key'), 401 else: return jsonify(error='No API key'), 401
def queue(): if 'api_key' in request.args: api_key = request.args.get('api_key') token = Token.find_one(by={'api_key_hash': api_key}) if token is not None: job = Job.pop() if job is None: return jsonify(error='Not Found'), 404 job.set_status(Job.RUNNING) return jsonify(job.to_dict()) else: return jsonify(error='Wrong API key'), 401 else: return jsonify(error='No API key'), 401
def update(idx): if 'api_key' in request.args: api_key = request.args.get('api_key') token = Token.find_one(by={'api_key_hash': api_key}) if token is not None: job = Job.find_one(idx) if job is None: return jsonify(error='Not Found'), 404 data = request.get_json() if 'status' in data: job.set_status(data.get('status')) if 'result' in data: job.set_result(data.get('result')) return jsonify(job.to_dict()) else: return jsonify(error='Wrong API key'), 401 else: return jsonify(error='No API key'), 401
def delete(idx): token = Token.find_one(idx) token.delete() flash('Token deleted successfully') return jsonify(deleted=True)
def get(idx): token = Token.find_one(idx) return jsonify(api_key=token.api_key_hash)