|
2 | 2 | The application setup and initialization code lives here |
3 | 3 | """ |
4 | 4 |
|
5 | | -import json |
6 | 5 | import logging |
7 | 6 | import os |
8 | 7 |
|
9 | | -import csh_ldap |
10 | 8 | import onesignal |
11 | 9 | from flask import Flask |
12 | 10 | from flask_gzip import Gzip |
|
26 | 24 |
|
27 | 25 | # Load default configuration and any environment variable overrides |
28 | 26 | _root_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) |
29 | | -app.config.from_pyfile(os.path.join(_root_dir, 'config.env.py')) |
| 27 | +app.config.from_pyfile(os.path.join(_root_dir, "config.env.py")) |
30 | 28 |
|
31 | 29 | # Load file based configuration overrides if present |
32 | | -_pyfile_config = os.path.join(_root_dir, 'config.py') |
| 30 | +_pyfile_config = os.path.join(_root_dir, "config.py") |
33 | 31 | if os.path.exists(_pyfile_config): |
34 | 32 | app.config.from_pyfile(_pyfile_config) |
35 | 33 |
|
36 | 34 | # Fetch the version number |
37 | | -app.config['VERSION'] = get_version() |
| 35 | +app.config["VERSION"] = get_version() |
38 | 36 |
|
39 | 37 | # Logger configuration |
40 | | -logging.getLogger().setLevel(app.config['LOG_LEVEL']) |
41 | | -app.logger.info('Launching packet ' + app.config['VERSION']) |
42 | | -app.logger.info('Using the {} realm'.format(app.config['REALM'])) |
| 38 | +logging.getLogger().setLevel(app.config["LOG_LEVEL"]) |
| 39 | +app.logger.info("Launching packet " + app.config["VERSION"]) |
| 40 | +app.logger.info("Using the {} realm".format(app.config["REALM"])) |
43 | 41 |
|
44 | 42 | # Initialize the extensions |
45 | 43 | db = SQLAlchemy(app) |
46 | 44 | migrate = Migrate(app, db) |
47 | | -app.logger.info('SQLAlchemy pointed at ' + repr(db.engine.url)) |
| 45 | +app.logger.info("SQLAlchemy pointed at " + repr(db.engine.url)) |
48 | 46 |
|
49 | | -APP_CONFIG = ProviderConfiguration(issuer=app.config['OIDC_ISSUER'], |
50 | | - client_metadata=ClientMetadata(app.config['OIDC_CLIENT_ID'], |
51 | | - app.config['OIDC_CLIENT_SECRET'])) |
| 47 | +APP_CONFIG = ProviderConfiguration( |
| 48 | + issuer=app.config["OIDC_ISSUER"], |
| 49 | + client_metadata=ClientMetadata( |
| 50 | + app.config["OIDC_CLIENT_ID"], app.config["OIDC_CLIENT_SECRET"] |
| 51 | + ), |
| 52 | +) |
52 | 53 |
|
53 | 54 | # Initialize Onesignal Notification apps |
54 | 55 | csh_onesignal_client = None |
55 | | -if app.config['ONESIGNAL_USER_AUTH_KEY'] and \ |
56 | | - app.config['ONESIGNAL_CSH_APP_AUTH_KEY'] and \ |
57 | | - app.config['ONESIGNAL_CSH_APP_ID']: |
| 56 | +if ( |
| 57 | + app.config["ONESIGNAL_USER_AUTH_KEY"] |
| 58 | + and app.config["ONESIGNAL_CSH_APP_AUTH_KEY"] |
| 59 | + and app.config["ONESIGNAL_CSH_APP_ID"] |
| 60 | +): |
58 | 61 | csh_onesignal_client = onesignal.Client( |
59 | | - user_auth_key=app.config['ONESIGNAL_USER_AUTH_KEY'], |
60 | | - app_auth_key=app.config['ONESIGNAL_CSH_APP_AUTH_KEY'], |
61 | | - app_id=app.config['ONESIGNAL_CSH_APP_ID'] |
| 62 | + user_auth_key=app.config["ONESIGNAL_USER_AUTH_KEY"], |
| 63 | + app_auth_key=app.config["ONESIGNAL_CSH_APP_AUTH_KEY"], |
| 64 | + app_id=app.config["ONESIGNAL_CSH_APP_ID"], |
62 | 65 | ) |
63 | | - app.logger.info('CSH Onesignal configured and notifications enabled') |
| 66 | + app.logger.info("CSH Onesignal configured and notifications enabled") |
64 | 67 |
|
65 | 68 | intro_onesignal_client = None |
66 | | -if app.config['ONESIGNAL_USER_AUTH_KEY'] and \ |
67 | | - app.config['ONESIGNAL_INTRO_APP_AUTH_KEY'] and \ |
68 | | - app.config['ONESIGNAL_INTRO_APP_ID']: |
| 69 | +if ( |
| 70 | + app.config["ONESIGNAL_USER_AUTH_KEY"] |
| 71 | + and app.config["ONESIGNAL_INTRO_APP_AUTH_KEY"] |
| 72 | + and app.config["ONESIGNAL_INTRO_APP_ID"] |
| 73 | +): |
69 | 74 | intro_onesignal_client = onesignal.Client( |
70 | | - user_auth_key=app.config['ONESIGNAL_USER_AUTH_KEY'], |
71 | | - app_auth_key=app.config['ONESIGNAL_INTRO_APP_AUTH_KEY'], |
72 | | - app_id=app.config['ONESIGNAL_INTRO_APP_ID'] |
| 75 | + user_auth_key=app.config["ONESIGNAL_USER_AUTH_KEY"], |
| 76 | + app_auth_key=app.config["ONESIGNAL_INTRO_APP_AUTH_KEY"], |
| 77 | + app_id=app.config["ONESIGNAL_INTRO_APP_ID"], |
73 | 78 | ) |
74 | | - app.logger.info('Intro Onesignal configured and notifications enabled') |
| 79 | + app.logger.info("Intro Onesignal configured and notifications enabled") |
75 | 80 |
|
76 | 81 | # OIDC Auth |
77 | | -auth = OIDCAuthentication({'app': APP_CONFIG}, app) |
78 | | -app.logger.info('OIDCAuth configured') |
| 82 | +auth = OIDCAuthentication({"app": APP_CONFIG}, app) |
| 83 | +app.logger.info("OIDCAuth configured") |
79 | 84 |
|
80 | 85 | # Sentry |
81 | 86 | # pylint: disable=abstract-class-instantiated |
82 | 87 | sentry_sdk.init( |
83 | | - dsn=app.config['SENTRY_DSN'], |
84 | | - integrations=[FlaskIntegration(), SqlalchemyIntegration()] |
| 88 | + dsn=app.config["SENTRY_DSN"], |
| 89 | + integrations=[FlaskIntegration(), SqlalchemyIntegration()], |
85 | 90 | ) |
86 | 91 |
|
87 | | - |
88 | | -# pylint: disable=wrong-import-position |
89 | | -from .ldap import ldap |
90 | | -from . import models |
91 | | -from . import context_processors |
92 | | -from . import commands |
93 | | -from .routes import api, shared |
94 | | - |
95 | | -if app.config['REALM'] == 'csh': |
96 | | - from .routes import upperclassmen |
97 | | - from .routes import admin |
| 92 | +__all__: list = [ |
| 93 | + "ldap", |
| 94 | + "models", |
| 95 | + "context_processors", |
| 96 | + "commands", |
| 97 | + "api", |
| 98 | + "shared", |
| 99 | +] |
| 100 | + |
| 101 | +if app.config["REALM"] == "csh": |
| 102 | + from .routes import upperclassmen as upperclassmen |
| 103 | + from .routes import admin as admin |
98 | 104 | else: |
99 | | - from .routes import freshmen |
| 105 | + from .routes import freshmen as freshmen |
100 | 106 |
|
101 | | -app.logger.info('Routes registered') |
| 107 | +app.logger.info("Routes registered") |
0 commit comments