-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.py
38 lines (27 loc) · 995 Bytes
/
api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from flask import Flask, jsonify, request
from database import DB
from logger import log, error
from config import get_setting
TOKEN = get_setting('token')
DEFAULT_REFRESH_INTERVAL = get_setting("default-refresh-interval") or 60
if not TOKEN:
error('Token is not configured. Exiting...')
raise ValueError("Token is not configured.")
def create_app():
"""Service Status Indicator API"""
app = Flask(__name__)
@app.route('/services')
def services():
"""Return the list of services along with there status"""
# Check if is an authenticated request
token = request.headers.get('Authorization')
if token != f'Token {TOKEN}':
return jsonify({'error': 'Unauthorized access'}), 401
services = DB.get_enabled_services()
for service in services:
del service['running']
return jsonify(services)
log('API is listening...')
return app
if __name__ == '__main__':
create_app().run()