def patch(self): cli = Client(remote, pull_token()) try: r = cli.tokens_edit(request.data) except AuthError: return jsonify_unauth() except Exception as e: logger.error(e) return jsonify_unknown() if not r: return jsonify_unauth() return jsonify_success(r)
def patch(self): cli = Client(remote, pull_token()) try: r = cli.tokens_edit(request.data) except AuthError: return jsonify_unauth() except Exception as e: logger.error(e) return jsonify_unknown() if not r: return jsonify_unauth() return jsonify_success(r)
def tokens(): cli = Client(remote, pull_token()) if request.method == 'DELETE': try: r = cli.tokens_delete(request.data) except Exception as e: logger.error(e) response = jsonify({"message": "failed", "data": []}) response.status_code = 503 else: response = jsonify({'message': 'success', 'data': r}) response.status_code = 200 elif request.method == 'POST': if request.data: try: r = cli.tokens_create(request.data) except AuthError: response = jsonify({ 'message': 'admin privs required', 'data': [] }) response.status_code = 401 except Exception as e: logger.error(e) response = jsonify({'message': 'create failed', 'data': []}) response.status_code = 503 else: if r: response = jsonify({'message': 'success', 'data': r}) response.status_code = 200 else: response = jsonify({ 'message': 'admin privs required', 'data': [] }) response.status_code = 401 else: response = jsonify({'message': 'create failed', 'data': []}) response.status_code = 400 elif request.method == 'PATCH': try: r = cli.tokens_edit(request.data) except AuthError: response = jsonify({'message': 'admin privs required', 'data': []}) response.status_code = 401 except Exception as e: logger.error(e) import traceback traceback.print_exc() response = jsonify({'message': 'create failed', 'data': []}) response.status_code = 503 else: if r: response = jsonify({'message': 'success', 'data': r}) response.status_code = 200 else: response = jsonify({ 'message': 'admin privs required', 'data': [] }) response.status_code = 401 else: filters = {} for f in TOKEN_FILTERS: filters[f] = request.args.get(f) try: r = cli.tokens_search(filters) except AuthError: response = jsonify({"message": "failed", "data": []}) response.status_code = 401 except Exception as e: logger.error(e) response = jsonify({"message": "failed", "data": []}) response.status_code = 503 else: response = jsonify({'message': 'success', 'data': r}) response.status_code = 200 return response
def tokens(): cli = Client(remote, pull_token()) if request.method == 'DELETE': try: r = cli.tokens_delete(request.data) except Exception as e: logger.error(e) response = jsonify({ "message": "failed", "data": [] }) response.status_code = 503 else: response = jsonify({ 'message': 'success', 'data': r }) response.status_code = 200 elif request.method == 'POST': if request.data: try: r = cli.tokens_create(request.data) except AuthError: response = jsonify({ 'message': 'admin privs required', 'data': [] }) response.status_code = 401 except Exception as e: logger.error(e) response = jsonify({ 'message': 'create failed', 'data': [] }) response.status_code = 503 else: if r: response = jsonify({ 'message': 'success', 'data': r }) response.status_code = 200 else: response = jsonify({ 'message': 'admin privs required', 'data': [] }) response.status_code = 401 else: response = jsonify({ 'message': 'create failed', 'data': [] }) response.status_code = 400 elif request.method == 'PATCH': try: r = cli.tokens_edit(request.data) except AuthError: response = jsonify({ 'message': 'admin privs required', 'data': [] }) response.status_code = 401 except Exception as e: logger.error(e) import traceback traceback.print_exc() response = jsonify({ 'message': 'create failed', 'data': [] }) response.status_code = 503 else: if r: response = jsonify({ 'message': 'success', 'data': r }) response.status_code = 200 else: response = jsonify({ 'message': 'admin privs required', 'data': [] }) response.status_code = 401 else: filters = {} for f in TOKEN_FILTERS: filters[f] = request.args.get(f) try: r = cli.tokens_search(filters) except AuthError: response = jsonify({ "message": "failed", "data": [] }) response.status_code = 401 except Exception as e: logger.error(e) response = jsonify({ "message": "failed", "data": [] }) response.status_code = 503 else: response = jsonify({ 'message': 'success', 'data': r }) response.status_code = 200 return response