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 (app . config [ 'LDAP_BIND_DN' ],
40- app .config [' LDAP_BIND_PW' ],
41- ro = app . config [ 'LDAP_RO' ] )
39+ ldap = CSHLDAP (
40+ app . config [ "LDAP_BIND_DN" ], app .config [" LDAP_BIND_PW" ], ro = app . config [ "LDAP_RO" ]
41+ )
4242
4343client_metadata = ClientMetadata (app .config ["OIDC_CLIENT_CONFIG" ])
44- provider_config = ProviderConfiguration (issuer = app .config ["OIDC_ISSUER" ], client_registration_info = client_metadata )
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+ )
4550
46- auth = OIDCAuthentication ({'default' : provider_config }, app )
51+ auth = OIDCAuthentication (
52+ {"default" : provider_config , "frosh" : frosh_provider_config }, app
53+ )
4754
4855app .secret_key = app .config ["SECRET_KEY" ]
4956
@@ -60,42 +67,48 @@ def start_of_year():
6067
6168
6269# Configure Logging
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' ]
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" ]
7382 return event_dict
7483
7584
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' :
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" :
7990 log = UserLog (
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' ]
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" ],
8697 )
8798 db .session .add (log )
8899 db .session .flush ()
89100 db .session .commit ()
90- del event_dict [' request' ]
101+ del event_dict [" request" ]
91102 return event_dict
92103
93104
94- structlog .configure (processors = [
95- request_processor ,
96- database_processor ,
97- structlog .processors .KeyValueRenderer ()
98- ])
105+ structlog .configure (
106+ processors = [
107+ request_processor ,
108+ database_processor ,
109+ structlog .processors .KeyValueRenderer (),
110+ ]
111+ )
99112
100113logger = structlog .get_logger ()
101114
@@ -133,16 +146,16 @@ def database_processor(logger, log_method, event_dict): # pylint: disable=unuse
133146from .util .ldap import ldap_get_member
134147
135148
136- @app .route (' /<path:path>' )
149+ @app .route (" /<path:path>" )
137150def static_proxy (path ):
138151 # send_static_file will guess the correct MIME type
139152 return app .send_static_file (path )
140153
141154
142- @app .route ('/' )
155+ @app .route ("/" )
143156@auth .oidc_auth ("default" )
144157def default_route ():
145- return redirect (' /dashboard' )
158+ return redirect (" /dashboard" )
146159
147160
148161@app .route ("/logout" )
@@ -156,7 +169,7 @@ def health():
156169 """
157170 Shows an ok status if the application is up and running
158171 """
159- return {' status' : 'ok' }
172+ return {" status" : "ok" }
160173
161174
162175@app .errorhandler (404 )
@@ -167,17 +180,17 @@ def route_errors(error, user_dict=None):
167180 data = {}
168181
169182 # Handle the case where the header isn't present
170- if user_dict [' username' ] is not None :
171- data [' username' ] = user_dict [' account' ].uid
172- data [' name' ] = user_dict [' account' ].cn
183+ if user_dict [" username" ] is not None :
184+ data [" username" ] = user_dict [" account" ].uid
185+ data [" name" ] = user_dict [" account" ].cn
173186 else :
174- data [' username' ] = "unknown"
175- data [' name' ] = "Unknown"
187+ data [" username" ] = "unknown"
188+ data [" name" ] = "Unknown"
176189
177190 # Figure out what kind of error was passed
178191 if isinstance (error , int ):
179192 code = error
180- elif hasattr (error , ' code' ):
193+ elif hasattr (error , " code" ):
181194 code = error .code
182195 else :
183196 # Unhandled exception
@@ -189,11 +202,13 @@ def route_errors(error, user_dict=None):
189202 else :
190203 error_desc = type (error ).__name__
191204
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 )
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 )
197212
198213
199- logger .info (' conditional started' )
214+ logger .info (" conditional started" )
0 commit comments