mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-23 00:41:35 -05:00
Merge pull request #43 from alphagov/update_status_page
Status page updated with api version and db version.
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import os
|
||||
import re
|
||||
import ast
|
||||
|
||||
from flask import request, url_for
|
||||
from flask._compat import string_types
|
||||
@@ -116,3 +118,22 @@ def convert_to_number(value):
|
||||
return float(value) if "." in value else int(value)
|
||||
except (TypeError, ValueError):
|
||||
return value
|
||||
|
||||
|
||||
def get_api_version():
|
||||
_version_re = re.compile(r'__version__\s+=\s+(.*)')
|
||||
version = 'n/a'
|
||||
dir_path = os.path.dirname(os.path.abspath(__file__))
|
||||
with open(os.path.join(dir_path, 'version.py'), 'rb') as f:
|
||||
version = str(ast.literal_eval(_version_re.search(
|
||||
f.read().decode('utf-8')).group(1)))
|
||||
return version
|
||||
|
||||
|
||||
def get_db_version():
|
||||
try:
|
||||
query = 'SELECT version_num FROM alembic_version'
|
||||
full_name = db.session.execute(query).fetchone()[0]
|
||||
return full_name.split('_')[0]
|
||||
except:
|
||||
return 'n/a'
|
||||
|
||||
@@ -6,6 +6,7 @@ status = Blueprint('status', __name__)
|
||||
|
||||
@status.route('/_status', methods=['GET', 'POST'])
|
||||
def show_status():
|
||||
return jsonify(
|
||||
status="ok",
|
||||
), 200
|
||||
from app import (get_api_version, get_db_version)
|
||||
return jsonify(status="ok",
|
||||
api_version=get_api_version(),
|
||||
db_version=get_db_version()), 200
|
||||
|
||||
1
app/version.py
Normal file
1
app/version.py
Normal file
@@ -0,0 +1 @@
|
||||
__version__ = '0.1.1'
|
||||
Reference in New Issue
Block a user