mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-16 18:22:17 -05:00
Status page updated with api version and db version.
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
|
import re
|
||||||
|
import ast
|
||||||
|
|
||||||
from flask import request, url_for
|
from flask import request, url_for
|
||||||
from flask._compat import string_types
|
from flask._compat import string_types
|
||||||
@@ -116,3 +118,22 @@ def convert_to_number(value):
|
|||||||
return float(value) if "." in value else int(value)
|
return float(value) if "." in value else int(value)
|
||||||
except (TypeError, ValueError):
|
except (TypeError, ValueError):
|
||||||
return value
|
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'])
|
@status.route('/_status', methods=['GET', 'POST'])
|
||||||
def show_status():
|
def show_status():
|
||||||
return jsonify(
|
from app import (get_api_version, get_db_version)
|
||||||
status="ok",
|
return jsonify(status="ok",
|
||||||
), 200
|
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'
|
||||||
@@ -4,7 +4,7 @@ from __future__ import print_function
|
|||||||
import os
|
import os
|
||||||
from flask.ext.script import Manager, Server
|
from flask.ext.script import Manager, Server
|
||||||
from flask.ext.migrate import Migrate, MigrateCommand
|
from flask.ext.migrate import Migrate, MigrateCommand
|
||||||
from app import create_app, db
|
from app import (create_app, db, get_api_version, get_db_version)
|
||||||
|
|
||||||
application = create_app(os.getenv('NOTIFY_API_ENVIRONMENT') or 'development')
|
application = create_app(os.getenv('NOTIFY_API_ENVIRONMENT') or 'development')
|
||||||
manager = Manager(application)
|
manager = Manager(application)
|
||||||
@@ -22,5 +22,21 @@ def list_routes():
|
|||||||
print("{:10} {}".format(", ".join(rule.methods - set(['OPTIONS', 'HEAD'])), rule.rule))
|
print("{:10} {}".format(", ".join(rule.methods - set(['OPTIONS', 'HEAD'])), rule.rule))
|
||||||
|
|
||||||
|
|
||||||
|
@manager.command
|
||||||
|
def api_version():
|
||||||
|
"""
|
||||||
|
Retrieve the version of the api.
|
||||||
|
"""
|
||||||
|
return get_api_version()
|
||||||
|
|
||||||
|
|
||||||
|
@manager.command
|
||||||
|
def db_version():
|
||||||
|
"""
|
||||||
|
Retrieve the db version.
|
||||||
|
"""
|
||||||
|
return get_db_version()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
manager.run()
|
manager.run()
|
||||||
|
|||||||
55
scripts/push-tag.sh
Normal file
55
scripts/push-tag.sh
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
function pretty() {
|
||||||
|
local blue="\033[34m"
|
||||||
|
local reset="\033[0m"
|
||||||
|
while read line; do
|
||||||
|
echo -e "${blue}[publishing]${reset} ${line}"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
function warn() {
|
||||||
|
local orange="\033[33m"
|
||||||
|
local reset="\033[0m"
|
||||||
|
while read line; do
|
||||||
|
echo -e "${orange}[warning]${reset} ${line}"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_sha(){
|
||||||
|
REF=$(git log -n 1 -- VERSION --name-only)
|
||||||
|
SHA=$(echo $REF | awk '{ print $2 }')
|
||||||
|
|
||||||
|
echo "checking out ${SHA}" | pretty
|
||||||
|
|
||||||
|
git checkout $SHA
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_version(){
|
||||||
|
VERSION=$(python setup.py --version)
|
||||||
|
echo "latest version is ${VERSION}" | pretty
|
||||||
|
}
|
||||||
|
|
||||||
|
function push_tag_or_die(){
|
||||||
|
TAG_EXISTS=$(git tag | grep -G "^${VERSION}$")
|
||||||
|
if [ "$TAG_EXISTS" ]; then
|
||||||
|
echo "Tag already exists, exiting" | warn
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
push_tag $VERSION
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function push_tag(){
|
||||||
|
git tag -a $VERSION -m "Version tag for ${VERSION}"
|
||||||
|
echo "Pushing tags to github ${VERSION} to Github" | pretty
|
||||||
|
git push origin --tags
|
||||||
|
}
|
||||||
|
|
||||||
|
function main(){
|
||||||
|
get_sha
|
||||||
|
get_version
|
||||||
|
push_tag_or_die
|
||||||
|
}
|
||||||
|
|
||||||
|
main
|
||||||
Reference in New Issue
Block a user