Skip to content

Commit 6ca8fb5

Browse files
Maffoochclaude
andcommitted
Fix ruff lint errors in SSO isolation changes
- Fix import sorting in settings.dist.py - Suppress C408 for dict() kwargs merging pattern - Use Path() instead of os.path in sso/settings.py - Use augmented assignment (+=) for dict key concatenation - Use iterable unpacking instead of list concatenation - Add noqa for intentional non-top-level imports (try/except guards) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 6934876 commit 6ca8fb5

3 files changed

Lines changed: 12 additions & 12 deletions

File tree

dojo/settings/settings.dist.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import environ
1818
import pghistory
1919
from celery.schedules import crontab
20+
2021
from dojo import __version__
2122

2223
logger = logging.getLogger(__name__)
@@ -32,7 +33,7 @@
3233
pass
3334

3435
# reference: https://pypi.org/project/django-environ/
35-
env = environ.FileAwareEnv(**{**dict(
36+
env = environ.FileAwareEnv(**{**dict( # noqa: C408
3637
# Set casting and default values
3738
DD_SITE_URL=(str, "http://localhost:8080"),
3839
DD_DEBUG=(bool, False),

dojo/sso/settings.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import os
21
from pathlib import Path
32

43
SSO_ENV_SCHEMA = {
@@ -108,7 +107,7 @@ def _saml2_attrib_map_format(din):
108107

109108
def 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"

dojo/user/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def api_v2_key(request):
128128
@dojo_ratelimit(key="post:password")
129129
def login_view(request):
130130
try:
131-
from dojo.sso.views import get_sso_auto_redirect
131+
from dojo.sso.views import get_sso_auto_redirect # noqa: PLC0415
132132
redirect_response = get_sso_auto_redirect(request)
133133
if redirect_response is not None:
134134
return redirect_response

0 commit comments

Comments
 (0)