forked from scylladb/argus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
argus_backend.py
43 lines (34 loc) · 1.5 KB
/
argus_backend.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
39
40
41
42
43
import logging
from flask import Flask
from argus.backend.template_filters import export_filters
from argus.backend.controller import admin, api, main
from argus.backend.cli import cli_bp
from argus.backend.util.logsetup import setup_application_logging
from argus.backend.util.encoders import ArgusJSONEncoder, ArgusJSONProvider
from argus.backend.db import ScyllaCluster
from argus.backend.controller import auth
from argus.backend.util.config import Config
LOGGER = logging.getLogger(__name__)
def start_server(config=None) -> Flask:
app = Flask(__name__, static_url_path="/s/", static_folder="public")
app.json_provider_class = ArgusJSONProvider
app.json = ArgusJSONProvider(app)
app.jinja_env.policies["json.dumps_kwargs"]["default"] = app.json.default
app.config.from_mapping(Config.load_yaml_config())
if config:
app.config.from_mapping(config)
setup_application_logging(log_level=app.config["APP_LOG_LEVEL"])
app.logger.info("Starting Scylla Cluster connection...")
ScyllaCluster.get(app.config).attach_to_app(app)
app.logger.info("Loading filters...")
for filter_func in export_filters():
app.add_template_filter(filter_func, name=filter_func.filter_name)
app.logger.info("Registering blueprints...")
app.register_blueprint(auth.bp)
app.register_blueprint(main.bp)
app.register_blueprint(api.bp)
app.register_blueprint(admin.bp)
app.register_blueprint(cli_bp)
app.logger.info("Ready.")
return app
argus_app = start_server()