mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-05 10:53:28 -05:00
Merge pull request #127 from alphagov/status_page_update
Status page update
This commit is contained in:
10
app.py
10
app.py
@@ -1,7 +1,7 @@
|
||||
import os
|
||||
from flask.ext.script import Manager, Server
|
||||
from flask_migrate import Migrate, MigrateCommand
|
||||
from app import create_app
|
||||
from app import (create_app, get_app_version)
|
||||
|
||||
|
||||
application = create_app(os.getenv('NOTIFICATIONS_ADMIN_ENVIRONMENT') or 'development')
|
||||
@@ -17,5 +17,13 @@ def list_routes():
|
||||
print("{:10} {}".format(", ".join(rule.methods - set(['OPTIONS', 'HEAD'])), rule.rule))
|
||||
|
||||
|
||||
@manager.command
|
||||
def app_version():
|
||||
"""
|
||||
Retrieve the version of the api.
|
||||
"""
|
||||
return get_app_version()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
manager.run()
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import os
|
||||
import re
|
||||
import ast
|
||||
|
||||
import dateutil
|
||||
from flask import Flask, session, Markup, escape, render_template
|
||||
@@ -12,6 +13,7 @@ from app.notify_client.api_client import NotificationsAdminAPIClient
|
||||
from app.notify_client.api_key_api_client import ApiKeyApiClient
|
||||
from app.notify_client.user_api_client import UserApiClient
|
||||
from app.notify_client.job_api_client import JobApiClient
|
||||
from app.notify_client.status_api_client import StatusApiClient
|
||||
from app.its_dangerous_session import ItsdangerousSessionInterface
|
||||
import app.proxy_fix
|
||||
from config import configs
|
||||
@@ -24,6 +26,7 @@ notifications_api_client = NotificationsAdminAPIClient()
|
||||
user_api_client = UserApiClient()
|
||||
api_key_api_client = ApiKeyApiClient()
|
||||
job_api_client = JobApiClient()
|
||||
status_api_client = StatusApiClient()
|
||||
|
||||
|
||||
def create_app(config_name, config_overrides=None):
|
||||
@@ -39,6 +42,7 @@ def create_app(config_name, config_overrides=None):
|
||||
user_api_client.init_app(application)
|
||||
api_key_api_client.init_app(application)
|
||||
job_api_client.init_app(application)
|
||||
status_api_client.init_app(application)
|
||||
|
||||
login_manager.init_app(application)
|
||||
login_manager.login_view = 'main.sign_in'
|
||||
@@ -160,3 +164,13 @@ def register_errorhandlers(application):
|
||||
return render_template("error/{0}.html".format(error_code)), error_code
|
||||
for errcode in [401, 404, 500]:
|
||||
application.errorhandler(errcode)(render_error)
|
||||
|
||||
|
||||
def get_app_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
|
||||
|
||||
16
app/notify_client/status_api_client.py
Normal file
16
app/notify_client/status_api_client.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from client.base import BaseAPIClient
|
||||
|
||||
|
||||
class StatusApiClient(BaseAPIClient):
|
||||
def __init__(self, base_url=None, client_id=None, secret=None):
|
||||
super(self.__class__, self).__init__(base_url=base_url or 'base_url',
|
||||
client_id=client_id or 'client_id',
|
||||
secret=secret or 'secret')
|
||||
|
||||
def init_app(self, app):
|
||||
self.base_url = app.config['API_HOST_NAME']
|
||||
self.client_id = app.config['ADMIN_CLIENT_USER_NAME']
|
||||
self.secret = app.config['ADMIN_CLIENT_SECRET']
|
||||
|
||||
def get_status(self, *params):
|
||||
return self.get(url='/status/_status', *params)
|
||||
@@ -5,6 +5,12 @@ from app.status import status
|
||||
|
||||
@status.route('/_status')
|
||||
def status():
|
||||
return jsonify(
|
||||
status="ok",
|
||||
), 200
|
||||
from app import (get_app_version, status_api_client)
|
||||
api_status = 'n/a'
|
||||
try:
|
||||
api_status = status_api_client.get_status()
|
||||
except:
|
||||
api_status = 'n/a'
|
||||
return jsonify(status="ok",
|
||||
app_version=get_app_version(),
|
||||
api_status=api_status), 200
|
||||
|
||||
1
app/version.py
Normal file
1
app/version.py
Normal file
@@ -0,0 +1 @@
|
||||
__version__ = '0.1.1'
|
||||
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