3131
3232# Sentry setup
3333sentry_sdk .init (
34- dsn = app .config [" SENTRY_DSN" ],
34+ dsn = app .config [' SENTRY_DSN' ],
3535 integrations = [FlaskIntegration (), SqlalchemyIntegration ()],
36- environment = app .config [" SENTRY_ENV" ],
36+ environment = app .config [' SENTRY_ENV' ],
3737)
3838
39- ldap = CSHLDAP (
40- app . config [ "LDAP_BIND_DN" ], app .config [" LDAP_BIND_PW" ], ro = app . config [ "LDAP_RO" ]
41- )
39+ ldap = CSHLDAP (app . config [ 'LDAP_BIND_DN' ],
40+ app .config [' LDAP_BIND_PW' ],
41+ ro = app . config [ 'LDAP_RO' ] )
4242
4343client_metadata = ClientMetadata (app .config ["OIDC_CLIENT_CONFIG" ])
44- provider_config = ProviderConfiguration (
45- issuer = app .config ["OIDC_ISSUER" ], client_registration_info = client_metadata
46- )
47- frosh_provider_config = ProviderConfiguration (
48- issuer = app .config ["FROSH_OIDC_ISSUER" ], client_registration_info = client_metadata
49- )
44+ provider_config = ProviderConfiguration (issuer = app .config ["OIDC_ISSUER" ], client_registration_info = client_metadata )
5045
51- auth = OIDCAuthentication (
52- {"default" : provider_config , "frosh" : frosh_provider_config }, app
53- )
46+ auth = OIDCAuthentication ({'default' : provider_config }, app )
5447
5548app .secret_key = app .config ["SECRET_KEY" ]
5649
@@ -67,48 +60,42 @@ def start_of_year():
6760
6861
6962# Configure Logging
70- def request_processor (
71- logger , log_method , event_dict
72- ): # pylint: disable=unused-argument, redefined-outer-name
73- if "request" in event_dict :
74- flask_request = event_dict ["request" ]
75- event_dict ["ip" ] = flask_request .remote_addr
76- event_dict ["method" ] = flask_request .method
77- event_dict ["blueprint" ] = flask_request .blueprint
78- event_dict ["path" ] = flask_request .full_path
79- if "auth_dict" in event_dict :
80- auth_dict = event_dict ["auth_dict" ]
81- event_dict ["user" ] = auth_dict ["username" ]
63+ def request_processor (logger , log_method , event_dict ): # pylint: disable=unused-argument, redefined-outer-name
64+ if 'request' in event_dict :
65+ flask_request = event_dict ['request' ]
66+ event_dict ['ip' ] = flask_request .remote_addr
67+ event_dict ['method' ] = flask_request .method
68+ event_dict ['blueprint' ] = flask_request .blueprint
69+ event_dict ['path' ] = flask_request .full_path
70+ if 'auth_dict' in event_dict :
71+ auth_dict = event_dict ['auth_dict' ]
72+ event_dict ['user' ] = auth_dict ['username' ]
8273 return event_dict
8374
8475
85- def database_processor (
86- logger , log_method , event_dict
87- ): # pylint: disable=unused-argument, redefined-outer-name
88- if "request" in event_dict :
89- if event_dict ["method" ] != "GET" :
76+ def database_processor (logger , log_method , event_dict ): # pylint: disable=unused-argument, redefined-outer-name
77+ if 'request' in event_dict :
78+ if event_dict ['method' ] != 'GET' :
9079 log = UserLog (
91- ipaddr = event_dict ["ip" ],
92- user = event_dict [" user" ],
93- method = event_dict [" method" ],
94- blueprint = event_dict [" blueprint" ],
95- path = event_dict [" path" ],
96- description = event_dict [" event" ],
80+ ipaddr = event_dict ['ip' ],
81+ user = event_dict [' user' ],
82+ method = event_dict [' method' ],
83+ blueprint = event_dict [' blueprint' ],
84+ path = event_dict [' path' ],
85+ description = event_dict [' event' ]
9786 )
9887 db .session .add (log )
9988 db .session .flush ()
10089 db .session .commit ()
101- del event_dict [" request" ]
90+ del event_dict [' request' ]
10291 return event_dict
10392
10493
105- structlog .configure (
106- processors = [
107- request_processor ,
108- database_processor ,
109- structlog .processors .KeyValueRenderer (),
110- ]
111- )
94+ structlog .configure (processors = [
95+ request_processor ,
96+ database_processor ,
97+ structlog .processors .KeyValueRenderer ()
98+ ])
11299
113100logger = structlog .get_logger ()
114101
@@ -146,16 +133,16 @@ def database_processor(
146133from .util .ldap import ldap_get_member
147134
148135
149- @app .route (" /<path:path>" )
136+ @app .route (' /<path:path>' )
150137def static_proxy (path ):
151138 # send_static_file will guess the correct MIME type
152139 return app .send_static_file (path )
153140
154141
155- @app .route ("/" )
142+ @app .route ('/' )
156143@auth .oidc_auth ("default" )
157144def default_route ():
158- return redirect (" /dashboard" )
145+ return redirect (' /dashboard' )
159146
160147
161148@app .route ("/logout" )
@@ -169,7 +156,7 @@ def health():
169156 """
170157 Shows an ok status if the application is up and running
171158 """
172- return {" status" : "ok" }
159+ return {' status' : 'ok' }
173160
174161
175162@app .errorhandler (404 )
@@ -180,17 +167,17 @@ def route_errors(error, user_dict=None):
180167 data = {}
181168
182169 # Handle the case where the header isn't present
183- if user_dict [" username" ] is not None :
184- data [" username" ] = user_dict [" account" ].uid
185- data [" name" ] = user_dict [" account" ].cn
170+ if user_dict [' username' ] is not None :
171+ data [' username' ] = user_dict [' account' ].uid
172+ data [' name' ] = user_dict [' account' ].cn
186173 else :
187- data [" username" ] = "unknown"
188- data [" name" ] = "Unknown"
174+ data [' username' ] = "unknown"
175+ data [' name' ] = "Unknown"
189176
190177 # Figure out what kind of error was passed
191178 if isinstance (error , int ):
192179 code = error
193- elif hasattr (error , " code" ):
180+ elif hasattr (error , ' code' ):
194181 code = error .code
195182 else :
196183 # Unhandled exception
@@ -202,13 +189,11 @@ def route_errors(error, user_dict=None):
202189 else :
203190 error_desc = type (error ).__name__
204191
205- return render_template (
206- "errors.html" ,
207- error = error_desc ,
208- error_code = code ,
209- event_id = sentry_sdk .last_event_id (),
210- ** data
211- ), int (code )
192+ return render_template ('errors.html' ,
193+ error = error_desc ,
194+ error_code = code ,
195+ event_id = sentry_sdk .last_event_id (),
196+ ** data ), int (code )
212197
213198
214- logger .info (" conditional started" )
199+ logger .info (' conditional started' )
0 commit comments