mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 02:11:11 -05:00
@@ -53,7 +53,7 @@ def create_app():
|
|||||||
application.register_blueprint(service_blueprint, url_prefix='/service')
|
application.register_blueprint(service_blueprint, url_prefix='/service')
|
||||||
application.register_blueprint(user_blueprint, url_prefix='/user')
|
application.register_blueprint(user_blueprint, url_prefix='/user')
|
||||||
application.register_blueprint(template_blueprint)
|
application.register_blueprint(template_blueprint)
|
||||||
application.register_blueprint(status_blueprint, url_prefix='/status')
|
application.register_blueprint(status_blueprint)
|
||||||
application.register_blueprint(notifications_blueprint)
|
application.register_blueprint(notifications_blueprint)
|
||||||
application.register_blueprint(job_blueprint)
|
application.register_blueprint(job_blueprint)
|
||||||
application.register_blueprint(invite_blueprint)
|
application.register_blueprint(invite_blueprint)
|
||||||
@@ -80,31 +80,11 @@ def init_app(app):
|
|||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
def get_api_version():
|
|
||||||
build = 'n/a'
|
|
||||||
build_time = "n/a"
|
|
||||||
try:
|
|
||||||
from app import version
|
|
||||||
build = version.__build__
|
|
||||||
build_time = version.__time__
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
return build, build_time
|
|
||||||
|
|
||||||
|
|
||||||
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'
|
|
||||||
|
|
||||||
|
|
||||||
def email_safe(string):
|
def email_safe(string):
|
||||||
return "".join([
|
return "".join([
|
||||||
character.lower() if character.isalnum() or character == "." else ""
|
character.lower()
|
||||||
for character in re.sub("\s+", ".", string.strip())
|
if character.isalnum() or character == "."
|
||||||
|
else "" for character in re.sub("\s+", ".", string.strip())
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,40 @@
|
|||||||
from flask import jsonify
|
from flask import jsonify
|
||||||
|
|
||||||
from flask import Blueprint
|
from flask import Blueprint, request
|
||||||
|
|
||||||
|
from app import db, version
|
||||||
|
|
||||||
status = Blueprint('status', __name__)
|
status = Blueprint('status', __name__)
|
||||||
|
|
||||||
|
|
||||||
@status.route('/_status', methods=['GET', 'POST'])
|
@status.route('/_status', methods=['GET', 'POST'])
|
||||||
def show_status():
|
def show_status():
|
||||||
from app import (get_api_version, get_db_version)
|
travis_commit, travis_build_number, build_time = get_api_version()
|
||||||
build, build_time = get_api_version()
|
if request.args.get('elb', None):
|
||||||
return jsonify(status="ok",
|
return jsonify(status="ok"), 200
|
||||||
api_build=build,
|
else:
|
||||||
api_built_time=build_time,
|
return jsonify(
|
||||||
|
status="ok",
|
||||||
|
travis_commit=travis_commit,
|
||||||
|
travis_build_number=travis_build_number,
|
||||||
|
build_time=build_time,
|
||||||
db_version=get_db_version()), 200
|
db_version=get_db_version()), 200
|
||||||
|
|
||||||
|
|
||||||
|
def get_api_version():
|
||||||
|
try:
|
||||||
|
travis_commit = version.__travis_commit__
|
||||||
|
travis_job_number = version.__travis_job_number__
|
||||||
|
build_time = version.__time__
|
||||||
|
return travis_commit, travis_job_number, build_time
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def get_db_version():
|
||||||
|
try:
|
||||||
|
query = 'SELECT version_num FROM alembic_version'
|
||||||
|
full_name = db.session.execute(query).fetchone()[0]
|
||||||
|
return full_name
|
||||||
|
except:
|
||||||
|
return 'n/a'
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
__build__ = ""
|
__travis_commit__ = "dev"
|
||||||
__time__ = ""
|
__time__ = "dev"
|
||||||
|
__travis_job_number__ = "dev"
|
||||||
|
|||||||
@@ -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, get_api_version, get_db_version)
|
from app import (create_app, db)
|
||||||
|
|
||||||
application = create_app()
|
application = create_app()
|
||||||
manager = Manager(application)
|
manager = Manager(application)
|
||||||
@@ -22,21 +22,5 @@ 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()
|
||||||
|
|||||||
@@ -2,5 +2,6 @@
|
|||||||
#
|
#
|
||||||
# Update the version file of the project from the Travis build details
|
# Update the version file of the project from the Travis build details
|
||||||
#
|
#
|
||||||
sed -i -e "s/__build__ =.*/__build__ = \"$TRAVIS_COMMIT\"/g" ./app/version.py
|
sed -i -e "s/__travis_commit__ =.*/__build__ = \"$TRAVIS_COMMIT\"/g" ./app/version.py
|
||||||
sed -i -e "s/__time__ =.*/__time__ = \"$('date +%Y-%m-%d:%H:%M:%S')\"/g" ./app/version.py
|
sed -i -e "s/__travis_job_number__ =.*/__build__ = \"$TRAVIS_BUILD_NUMBER\"/g" ./app/version.py
|
||||||
|
sed -i -e "s/__time__ =.*/__time__ = \"$(date +%Y-%m-%d:%H:%M:%S)\"/g" ./app/version.py
|
||||||
Reference in New Issue
Block a user