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' )
0 commit comments