Merge branch 'feature/3-provide-application-health-check' into 'develop'

Implements #3, a /ping endpoint

See merge request ruben/jail2ban-pf!5
This commit is contained in:
Ruben van Staveren 2023-01-13 09:30:03 +00:00
commit 45dc173ea7
2 changed files with 19 additions and 0 deletions

View File

@ -42,6 +42,15 @@ def create_app():
check_password_hash(users.get(username), password):
return username
@app.route("/ping", methods=['GET'])
@auth.login_required
def ping():
remote_user = auth.username()
app.logger.info('Received ping for'
f' anchor f2b-jail/{remote_user}')
return jsonify({'anchor': f'f2b-jail/{remote_user}',
'operation': 'ping',
'result': 'pong'})
@app.route("/flush/<name>", methods=['GET'])
@auth.login_required
def flush(name):

10
tests/test_ping.py Normal file
View File

@ -0,0 +1,10 @@
def test_ping(client, mocker, valid_credentials):
'''
Test application health check
'''
response = client.get("/ping",
headers={"Authorization":
"Basic " + valid_credentials})
assert response.json['operation'] == 'ping'