feat: initial api implementation

This commit is contained in:
Iain Learmonth 2024-11-10 13:38:51 +00:00
parent a482d5bba8
commit ae905c6d80
4 changed files with 239 additions and 9 deletions

View file

@ -1,19 +1,20 @@
import os
import sys
from typing import Iterator
import yaml
from flask import Flask, redirect, url_for, send_from_directory
from flask.typing import ResponseReturnValue
from prometheus_client import make_wsgi_app, REGISTRY, Metric
from prometheus_client.metrics_core import GaugeMetricFamily, CounterMetricFamily
from prometheus_client.registry import Collector
from sqlalchemy import text
from werkzeug.middleware.dispatcher import DispatcherMiddleware
from prometheus_client import make_wsgi_app, REGISTRY, Metric
import yaml
import sys
from app.api import api
from app.extensions import bootstrap
from app.extensions import db
from app.extensions import migrate
from app.extensions import bootstrap
from app.models.automation import Automation, AutomationState
from app.portal import portal
from app.portal.report import report
@ -26,10 +27,11 @@ app.wsgi_app = DispatcherMiddleware(app.wsgi_app, { # type: ignore[method-assig
'/metrics': make_wsgi_app()
})
db.init_app(app) # type: ignore[no-untyped-call]
db.init_app(app)
migrate.init_app(app, db, render_as_batch=True)
bootstrap.init_app(app)
app.register_blueprint(api, url_prefix="/api")
app.register_blueprint(portal, url_prefix="/portal")
app.register_blueprint(tfstate, url_prefix="/tfstate")
app.register_blueprint(report, url_prefix="/report")
@ -110,17 +112,19 @@ if not_migrating() and 'DISABLE_METRICS' not in os.environ:
@app.route('/ui')
def redirect_ui():
def redirect_ui() -> ResponseReturnValue:
return redirect("/ui/")
@app.route('/ui/', defaults={'path': ''})
@app.route('/ui/<path:path>')
def serve_ui(path):
def serve_ui(path: str) -> ResponseReturnValue:
if path != "" and os.path.exists("app/static/ui/" + path):
return send_from_directory('static/ui', path)
else:
return send_from_directory('static/ui', 'index.html')
@app.route('/')
def index() -> ResponseReturnValue:
# TODO: update to point at new UI when ready