Last active
October 6, 2023 14:15
-
-
Save matburt/db023a9c8e5361f897ddfbc7e48f82b8 to your computer and use it in GitHub Desktop.
Demonstrating a basic flask POST request handler that examines request headers.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from flask import Flask, request, abort, jsonify | |
app = Flask(__name__) | |
@app.route('/push', methods=['POST']) | |
def handle_push(): | |
if not request.json: | |
abort(400) | |
if 'AnsibleTower' in request.headers and request.headers['AnsibleTower'] == 'xSecretx': | |
# Trigger some other external action | |
print("Request dictionary: {}".format(request.json)) | |
return jsonify({'status': 'triggered'}), 201 | |
return jsonify({'status': 'ok'}), 200 | |
if __name__ == '__main__': | |
print("Listening...") | |
app.run(debug=True, host='0.0.0.0', port=8085) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment