Skip to content

Instantly share code, notes, and snippets.

@meetme2meat
Created December 7, 2022 09:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meetme2meat/9c80e30a82f37d1eef77ee2e64c3393f to your computer and use it in GitHub Desktop.
Save meetme2meat/9c80e30a82f37d1eef77ee2e64c3393f to your computer and use it in GitHub Desktop.
import requests
from flask import Flask
from flask import request, jsonify
import pdb
# Flask constructor takes the name of
# current module (__name__) as argument.
app = Flask(__name__)
EDOS_ENDPOINT = "https://localhost:8091"
# The route() function of the Flask class is a decorator,
# which tells the application which URL should call
# the associated function.
@app.route('/edos/v1/client/details', methods=['GET'])
def hello_world():
try:
url = EDOS_ENDPOINT + request.path
r = requests.get(url, timeout=5, headers=request.headers)
if r.status_code == 423:
return jsonify({"locked": True, "status": "LOCKED"}), r.status_code
if r.status_code <= 200:
return jsonify({"locked": False, "status": "OPEN"}), r.status_code
print("we are not examining ",r.status_code)
return jsonify({"locked": True, "status": "UNKNOWN"}), r.status_code
except Exception as e:
print("got exception", e)
return jsonify({"locked": False, "status": "UNRESPONSIVE"}), 500
@app.route('/edos/v1/kms/keys/<string:kid>', methods=['GET'])
def hello_world2(kid):
print(kid)
try:
url = EDOS_ENDPOINT + request.path
r = requests.get(url, timeout=5, headers=request.headers)
if r.status_code == 404:
return jsonify({"found": False, "status": "NOT_FOUND"}), r.status_code
if r.status_code == 200:
return jsonify({"found": True, "status": "FOUND"}), r.status_code
print("we are not examining ",r.status_code)
return jsonify({"found": False, "status": "UNKNOWN"}), r.status_code
except Exception as e:
print("got exception", e)
return jsonify({"found": False, "status":"NOT_FOUND"}), 500
# main driver function
if __name__ == '__main__':
app.run(port=9190)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment