Skip to content

Instantly share code, notes, and snippets.

@matburt
Last active October 6, 2023 14:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matburt/db023a9c8e5361f897ddfbc7e48f82b8 to your computer and use it in GitHub Desktop.
Save matburt/db023a9c8e5361f897ddfbc7e48f82b8 to your computer and use it in GitHub Desktop.
Demonstrating a basic flask POST request handler that examines request headers.
#!/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