Skip to content

Commit 0e2238e

Browse files
committed
Add health checks to the application
1 parent 2a76f66 commit 0e2238e

File tree

4 files changed

+102
-2
lines changed

4 files changed

+102
-2
lines changed

app/Health/__init__.py

Whitespace-only changes.

app/Health/controllers.py

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# ------------------------------------------------------------------------------
2+
# Copyright (c) 2019 Parallax Inc. -
3+
# -
4+
# Permission is hereby granted, free of charge, to any person obtaining -
5+
# a copy of this software and associated documentation files (the -
6+
# “Software”), to deal in the Software without restriction, including -
7+
# without limitation the rights to use, copy, modify, merge, publish, -
8+
# distribute, sublicense, and/or sell copies of the Software, and to -
9+
# permit persons to whom the Software is furnished to do so, subject -
10+
# to the following conditions: -
11+
# -
12+
# The above copyright notice and this permission notice shall be -
13+
# included in all copies or substantial portions of the Software. -
14+
# -
15+
# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, -
16+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -
17+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. -
18+
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -
19+
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -
20+
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -
21+
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -
22+
# -
23+
# -
24+
# ------------------------------------------------------------------------------
25+
26+
import logging
27+
from flask_restful import Api, Resource
28+
from flask import request, Blueprint
29+
from app import __version__
30+
31+
32+
# Set the base URL for this module and register it
33+
health_app = Blueprint('health', __name__, url_prefix='/health')
34+
api = Api(health_app)
35+
36+
37+
class Ping(Resource):
38+
# noinspection PyUnresolvedReferences
39+
"""
40+
Provide a simple response to verify that the Rest API is functioning.
41+
42+
Args:
43+
None
44+
45+
Returns:
46+
A JSON document with the key 'success' set to True, 'message' set to
47+
the constant 'pong', and a 200 response code.
48+
49+
Raises:
50+
None
51+
"""
52+
def get(self):
53+
# Ping the REST server for signs of life
54+
server = request.headers.get('server')
55+
logging.info("Requesting ping from server %s", server)
56+
57+
return {
58+
'Success': True,
59+
'message': 'pong',
60+
'code': 200
61+
}
62+
63+
64+
class Version(Resource):
65+
# noinspection PyUnresolvedReferences
66+
"""
67+
Provide the application version string.
68+
69+
Args:
70+
None
71+
72+
Returns:
73+
A JSON document with the key 'success' set to True, 'message' contains a
74+
version element holding a string representation of the application version
75+
number, and a 200 response code.
76+
77+
Raises:
78+
None
79+
"""
80+
def get(self):
81+
# Ping the REST server for signs of life
82+
server = request.headers.get('server')
83+
logging.info("Requesting version info from server %s", server)
84+
85+
return {
86+
'Success': True,
87+
'message': {
88+
'version': __version__.__version__,
89+
},
90+
'code': 200
91+
}
92+
93+
94+
api.add_resource(Ping, '/ping')
95+
api.add_resource(Version, '/version')

app/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,14 +225,15 @@
225225
if db is not None:
226226
from app.Authenticate.controllers import authenticate_app
227227
from app.AuthToken.controllers import auth_token_app
228+
from app.Health.controllers import health_app
228229
from app.User.controllers import user_app
229230
from app.LocalUser.controllers import local_user_app
230231
from app.RateLimiting.controllers import rate_limiting_app
231232
from app.OAuth.controllers import oauth_app
232233

233-
234234
app.register_blueprint(auth_token_app)
235235
app.register_blueprint(authenticate_app)
236+
app.register_blueprint(health_app)
236237
app.register_blueprint(user_app)
237238
app.register_blueprint(local_user_app)
238239
app.register_blueprint(rate_limiting_app)

app/__version__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
"""
2828
Change Log
2929
30+
1.3.2 Update supervisor package to accommodate the removal of the cgi
31+
library in python 3.8.
32+
Add API keys for version and ping.
33+
3034
1.3.1 Add error handling to password authentication to trap the possibility
3135
of an unencoded password submission.
3236
Update password hash methods to accommodate a change in default string
@@ -51,4 +55,4 @@
5155
5256
"""
5357

54-
__version__ = "1.3.1"
58+
__version__ = "1.3.2"

0 commit comments

Comments
 (0)