+
+# Send status
+# /sendstatus?policyid=<policyid>
+@app.route('/sendstatus', methods=['POST'])
+def sendstatus():
+ policyid = request.args.get('policyid')
+ if policyid is None:
+ return Response('Parameter <policyid> missing in request', status=400, mimetype=TEXT_PLAIN)
+ if policyid not in policy_status.keys():
+ return Response('Policyid: '+policyid+' not found.', status=404, mimetype=TEXT_PLAIN)
+
+ ps = policy_status[ policyid ]
+ cb_url = callbacks[ policyid ]
+
+ try:
+ resp = requests.post(cb_url, json = json.dumps(ps), headers = { "Content-Type": APPL_JSON, "Accept": "*/*" })
+ resp.raise_for_status()
+ if (resp.status_code >= 200 and resp.status_code <= 300):
+ return Response("OK", resp.status_code, mimetype = TEXT_PLAIN)
+ return Response('Post status failed', status = resp.status_code, mimetype = TEXT_PLAIN)
+
+ except requests.ConnectionError as error:
+ return Response('Post status failed with Connection Error, could not send to ' + str(cb_url), status = 502, mimetype = TEXT_PLAIN)
+ except requests.Timeout as error:
+ return Response('Post status failed with Timeout, could not send to ' + str(cb_url), status = 504, mimetype = TEXT_PLAIN)
+ except requests.HTTPError as error:
+ return Response('Post status failed with HTTP Error, could not send to ' + str(cb_url), status = 502, mimetype = TEXT_PLAIN)
+ except requests.RequestException as error:
+ return Response('Post status failed with RequestException, could not send to ' + str(cb_url), status = 500, mimetype = TEXT_PLAIN)
+
+# Receive status (only for testing callbacks)
+# /statustest
+@app.route('/statustest', methods=['POST', 'PUT'])
+def statustest():
+ try:
+ data = request.data
+ data = json.loads(data)
+ except Exception:
+ return Response("The status data is corrupt or missing.", 400, mimetype=TEXT_PLAIN)
+
+ return Response("OK", 201, mimetype=TEXT_PLAIN)
+
+app.add_api('openapi.yaml', resolver=RelativeResolver('controllers.a1_mediator_controller'))