1- import os
21from pathlib import Path
32
43SSO_ENV_SCHEMA = {
@@ -108,7 +107,7 @@ def _saml2_attrib_map_format(din):
108107
109108def apply_sso_settings (env , globs ):
110109 """Apply all SSO-related settings. Called from settings.dist.py inside a try/except ImportError block."""
111- from netaddr import IPNetwork , IPSet
110+ from netaddr import IPNetwork , IPSet # noqa: PLC0415
112111
113112 SITE_URL = globs ["SITE_URL" ]
114113 URL_PREFIX = globs .get ("URL_PREFIX" , "" )
@@ -283,7 +282,7 @@ def apply_sso_settings(env, globs):
283282 # --------------------------------------------------------------------------
284283 # INSTALLED_APPS
285284 # --------------------------------------------------------------------------
286- globs ["INSTALLED_APPS" ] = globs [ "INSTALLED_APPS" ] + ("social_django" ,)
285+ globs ["INSTALLED_APPS" ] += ("social_django" ,)
287286
288287 # --------------------------------------------------------------------------
289288 # MIDDLEWARE
@@ -292,7 +291,7 @@ def apply_sso_settings(env, globs):
292291 if isinstance (MIDDLEWARE , list ):
293292 MIDDLEWARE .append ("dojo.sso.middleware.CustomSocialAuthExceptionMiddleware" )
294293 else :
295- globs ["MIDDLEWARE" ] = list ( MIDDLEWARE ) + [ "dojo.sso.middleware.CustomSocialAuthExceptionMiddleware" ]
294+ globs ["MIDDLEWARE" ] = [ * MIDDLEWARE , "dojo.sso.middleware.CustomSocialAuthExceptionMiddleware" ]
296295 MIDDLEWARE = globs ["MIDDLEWARE" ]
297296
298297 # --------------------------------------------------------------------------
@@ -302,7 +301,7 @@ def apply_sso_settings(env, globs):
302301 context_processors .append ("social_django.context_processors.backends" )
303302 context_processors .append ("social_django.context_processors.login_redirect" )
304303 context_processors .append ("dojo.sso.context_processors.sso_context" )
305- sso_template_dir = os . path . join ( os . path . dirname (__file__ ), "templates" )
304+ sso_template_dir = str ( Path (__file__ ). parent / "templates" )
306305 globs ["TEMPLATES" ][0 ]["DIRS" ].append (sso_template_dir )
307306
308307 # --------------------------------------------------------------------------
@@ -312,18 +311,18 @@ def apply_sso_settings(env, globs):
312311 globs ["SAML2_LOGIN_BUTTON_TEXT" ] = env ("DD_SAML2_LOGIN_BUTTON_TEXT" )
313312 globs ["SAML2_LOGOUT_URL" ] = env ("DD_SAML2_LOGOUT_URL" )
314313 if globs ["SAML2_ENABLED" ]:
315- import saml2
316- import saml2 .saml
314+ import saml2 # noqa: PLC0415
315+ import saml2 .saml # noqa: PLC0415
317316
318317 SAML_METADATA = {}
319318 if len (env ("DD_SAML2_METADATA_AUTO_CONF_URL" )) > 0 :
320319 SAML_METADATA ["remote" ] = [{"url" : env ("DD_SAML2_METADATA_AUTO_CONF_URL" )}]
321320 if len (env ("DD_SAML2_METADATA_LOCAL_FILE_PATH" )) > 0 :
322321 SAML_METADATA ["local" ] = [env ("DD_SAML2_METADATA_LOCAL_FILE_PATH" )]
323- globs ["INSTALLED_APPS" ] = globs [ "INSTALLED_APPS" ] + ("djangosaml2" ,)
322+ globs ["INSTALLED_APPS" ] += ("djangosaml2" ,)
324323 MIDDLEWARE .append ("djangosaml2.middleware.SamlSessionMiddleware" )
325- globs ["AUTHENTICATION_BACKENDS" ] = globs [ "AUTHENTICATION_BACKENDS" ] + (env ("DD_SAML2_AUTHENTICATION_BACKENDS" ),)
326- globs ["LOGIN_EXEMPT_URLS" ] = globs [ "LOGIN_EXEMPT_URLS" ] + (rf"^{ URL_PREFIX } saml2/" ,)
324+ globs ["AUTHENTICATION_BACKENDS" ] += (env ("DD_SAML2_AUTHENTICATION_BACKENDS" ),)
325+ globs ["LOGIN_EXEMPT_URLS" ] += (rf"^{ URL_PREFIX } saml2/" ,)
327326 globs ["SAML_LOGOUT_REQUEST_PREFERRED_BINDING" ] = saml2 .BINDING_HTTP_POST
328327 globs ["SAML_IGNORE_LOGOUT_ERRORS" ] = True
329328 globs ["SAML_DJANGO_USER_MAIN_ATTRIBUTE" ] = "username"
0 commit comments