Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: align ee settings to include huey #1448

Merged
merged 2 commits into from
Jan 29, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion enterprise/backend/enterprise_core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def set_ciso_assistant_url(_, __, event_dict):

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.environ.get("DJANGO_DEBUG", "False") == "True"
MAIL_DEBUG = os.environ.get("MAIL_DEBUG", "False") == "True"

logger.info("DEBUG mode: %s", DEBUG)
logger.info("CISO_ASSISTANT_URL: %s", CISO_ASSISTANT_URL)
Expand Down Expand Up @@ -157,6 +158,7 @@ def set_ciso_assistant_url(_, __, event_dict):
"allauth.socialaccount",
"allauth.socialaccount.providers.saml",
"allauth.mfa",
"huey.contrib.djhuey",
]

MIDDLEWARE = [
Expand Down Expand Up @@ -308,9 +310,16 @@ def set_ciso_assistant_url(_, __, event_dict):
("es", "Spanish"),
("de", "German"),
("it", "Italian"),
("nd", "Dutch"),
("nl", "Dutch"),
("pl", "Polish"),
("pt", "Portuguese"),
("ar", "Arabic"),
("ro", "Romanian"),
("hi", "Hindi"),
("ur", "Urdu"),
("cs", "Czech"),
("sv", "Swedish"),
("id", "Indonesian"),
]

PROJECT_PATH = os.path.dirname(os.path.abspath(__file__))
Expand Down Expand Up @@ -339,6 +348,7 @@ def set_ciso_assistant_url(_, __, event_dict):
"PASSWORD": os.environ["POSTGRES_PASSWORD"],
"HOST": os.environ["DB_HOST"],
"PORT": os.environ.get("DB_PORT", "5432"),
"CONN_MAX_AGE": os.environ.get("CONN_MAX_AGE", 300),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Convert CONN_MAX_AGE to integer and document load balancer considerations.

The CONN_MAX_AGE should be converted to an integer, and we should document potential issues with load balancers.

-            "CONN_MAX_AGE": os.environ.get("CONN_MAX_AGE", 300),
+            "CONN_MAX_AGE": int(os.environ.get("CONN_MAX_AGE", "300")),

Consider documenting that if you're using a load balancer, CONN_MAX_AGE should be less than the load balancer's connection timeout to prevent connection reset issues.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"CONN_MAX_AGE": os.environ.get("CONN_MAX_AGE", 300),
"CONN_MAX_AGE": int(os.environ.get("CONN_MAX_AGE", "300")),

}
}
else:
Expand Down Expand Up @@ -427,3 +437,19 @@ def set_ciso_assistant_url(_, __, event_dict):
logger.info("License information", seats=LICENSE_SEATS, expiration=LICENSE_EXPIRATION)

INSTALLED_APPS.append("enterprise_core")

if MAIL_DEBUG:
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
DEFAULT_FROM_EMAIL = "[email protected]"


## Huey settings
HUEY_FILE_PATH = os.environ.get("HUEY_FILE_PATH", BASE_DIR / "db" / "huey.db")

HUEY = {
"huey_class": "huey.SqliteHuey",
"name": "ciso_assistant",
"filename": HUEY_FILE_PATH,
"results": True, # would be interesting for debug
"immediate": False, # set to False to run in "live" mode regardless of DEBUG, otherwise it will follow
}
Comment on lines +446 to +455
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enhance Huey configuration robustness.

Several improvements needed for the Huey configuration:

  1. The comment on line 447 is incomplete
  2. Missing directory existence check for HUEY_FILE_PATH
  3. Consider documenting SQLite limitations for high task volumes
 ## Huey settings
 HUEY_FILE_PATH = os.environ.get("HUEY_FILE_PATH", BASE_DIR / "db" / "huey.db")
+# Ensure directory exists
+os.makedirs(os.path.dirname(HUEY_FILE_PATH), exist_ok=True)
 
 HUEY = {
     "huey_class": "huey.SqliteHuey",
     "name": "ciso_assistant",
     "filename": HUEY_FILE_PATH,
     "results": True,  # would be interesting for debug
-    "immediate": False,  # set to False to run in "live" mode regardless of DEBUG, otherwise it will follow
+    "immediate": False,  # Set to False to run in "live" mode regardless of DEBUG setting
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
## Huey settings
HUEY_FILE_PATH = os.environ.get("HUEY_FILE_PATH", BASE_DIR / "db" / "huey.db")
HUEY = {
"huey_class": "huey.SqliteHuey",
"name": "ciso_assistant",
"filename": HUEY_FILE_PATH,
"results": True, # would be interesting for debug
"immediate": False, # set to False to run in "live" mode regardless of DEBUG, otherwise it will follow
}
## Huey settings
HUEY_FILE_PATH = os.environ.get("HUEY_FILE_PATH", BASE_DIR / "db" / "huey.db")
# Ensure directory exists
os.makedirs(os.path.dirname(HUEY_FILE_PATH), exist_ok=True)
HUEY = {
"huey_class": "huey.SqliteHuey",
"name": "ciso_assistant",
"filename": HUEY_FILE_PATH,
"results": True, # would be interesting for debug
"immediate": False, # Set to False to run in "live" mode regardless of DEBUG setting
}

Loading