You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
975 B
Python

7 years ago
import os
import logging
from flask import Blueprint, jsonify, request
LOGGER = logging.getLogger('gunicorn.error')
#SECRET_CODE = os.environ.get('SECRET_CODE')
# Here we are accessing the secret_code set by the external config in our docker-compose file
SECRET_CODE = open('/run/secrets/secret_code').read().strip()
7 years ago
main_blueprint = Blueprint('main', __name__)
@main_blueprint.route('/ping', methods=['GET'])
def ping_pong():
LOGGER.info('Hitting the "/ping" route')
return jsonify({
'status': 'success',
'message': 'pong!',
'container_id': os.uname()[1]
})
@main_blueprint.route('/secret', methods=['POST'])
def secret():
LOGGER.info('Hitting the "/secret" route')
response_object = {
'status': 'success',
'message': 'nay!',
'container_id': os.uname()[1]
}
if request.get_json().get('secret') == SECRET_CODE:
response_object['message'] = 'yay!'
return jsonify(response_object)