2022-05-16 11:44:03 +01:00
|
|
|
from flask import Flask, redirect, url_for
|
|
|
|
from flask.typing import ResponseReturnValue
|
2022-10-05 15:25:51 +01:00
|
|
|
from werkzeug.middleware.dispatcher import DispatcherMiddleware
|
|
|
|
from prometheus_client import make_wsgi_app, REGISTRY
|
2022-03-10 14:26:22 +00:00
|
|
|
import yaml
|
2022-10-08 19:20:15 +01:00
|
|
|
import sys
|
2022-03-10 14:26:22 +00:00
|
|
|
|
|
|
|
from app.extensions import db
|
|
|
|
from app.extensions import migrate
|
|
|
|
from app.extensions import bootstrap
|
|
|
|
from app.portal import portal
|
2022-08-29 19:16:35 +01:00
|
|
|
from app.tfstate import tfstate
|
2022-03-10 14:26:22 +00:00
|
|
|
|
2022-10-05 15:25:51 +01:00
|
|
|
|
2022-03-10 14:26:22 +00:00
|
|
|
app = Flask(__name__)
|
|
|
|
app.config.from_file("../config.yaml", load=yaml.safe_load)
|
2022-10-05 15:25:51 +01:00
|
|
|
|
2022-10-08 19:26:50 +01:00
|
|
|
app.wsgi_app = DispatcherMiddleware(app.wsgi_app, { # type: ignore[assignment]
|
|
|
|
'/metrics': make_wsgi_app() # type: ignore[no-untyped-call]
|
2022-10-05 15:25:51 +01:00
|
|
|
})
|
|
|
|
|
2022-03-10 14:26:22 +00:00
|
|
|
db.init_app(app)
|
|
|
|
migrate.init_app(app, db, render_as_batch=True)
|
|
|
|
bootstrap.init_app(app)
|
|
|
|
|
|
|
|
app.register_blueprint(portal, url_prefix="/portal")
|
2022-08-29 19:16:35 +01:00
|
|
|
app.register_blueprint(tfstate, url_prefix="/tfstate")
|
2022-03-10 14:26:22 +00:00
|
|
|
|
2022-10-05 15:25:51 +01:00
|
|
|
|
2022-11-02 13:17:20 +00:00
|
|
|
if 'nose' not in sys.modules.keys() and sys.argv[1] != "db":
|
2022-10-08 19:20:15 +01:00
|
|
|
from app.metrics import DefinedProxiesCollector, BlockedProxiesCollector, AutomationCollector
|
|
|
|
|
2022-11-02 13:24:02 +00:00
|
|
|
REGISTRY.register(DefinedProxiesCollector(app)) # type: ignore[no-untyped-call]
|
|
|
|
REGISTRY.register(BlockedProxiesCollector(app)) # type: ignore[no-untyped-call]
|
|
|
|
REGISTRY.register(AutomationCollector(app)) # type: ignore[no-untyped-call]
|
2022-10-05 15:25:51 +01:00
|
|
|
|
|
|
|
|
2022-03-10 14:26:22 +00:00
|
|
|
@app.route('/')
|
2022-05-16 11:44:03 +01:00
|
|
|
def index() -> ResponseReturnValue:
|
2022-03-10 14:26:22 +00:00
|
|
|
return redirect(url_for("portal.portal_home"))
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
app.run()
|