Skip to content

Commit

Permalink
introduce required_env function
Browse files Browse the repository at this point in the history
  • Loading branch information
tyliec committed Apr 7, 2024
1 parent 5bbcfd9 commit 3bcbd67
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
10 changes: 10 additions & 0 deletions uipa_org/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,19 @@

rec = lambda x: re.compile(x, re.I | re.U)

# Helper functions for reading environment variables

# env() returns the value of an environment variable, or None if it is not set
def env(key, default=None):
return os.environ.get(key, default)

# required_env() returns the value of an environment variable, or raises an exception if it is not set
def required_env(key):
value = env(key)
if value is None or value == "":
raise ValueError(f"Required environment variable {key} is not set")
return value

THEME_ROOT = Path(__file__).resolve().parent.parent

# Note: The settings in this file are either Django settings or Froide settings.
Expand Down
22 changes: 11 additions & 11 deletions uipa_org/settings/development.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import

from .base import UipaOrgThemeBase, env
from .base import UipaOrgThemeBase, env, required_env

class Dev(UipaOrgThemeBase):
DEBUG = True
Expand All @@ -25,34 +25,34 @@ def TEMPLATES(self):
ENABLE_EMAIL = env("ENABLE_EMAIL", False)

if ENABLE_EMAIL:
SERVER_EMAIL = env("SERVER_EMAIL") # This is the inbound address for the SMTP server (i.e. [email protected])
SERVER_EMAIL = required_env("SERVER_EMAIL") # This is the inbound address for the SMTP server (i.e. [email protected])
DEFAULT_FROM_EMAIL = env(
"DEFAULT_FROM_EMAIL", "TEST UIPA.org <[email protected]>"
)
EMAIL_SUBJECT_PREFIX = env("EMAIL_SUBJECT_PREFIX", "[TEST UIPA.org] ")
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' # This will be different for production

# These settings are for sending regular email notifications (not FOI requests to public bodies)
EMAIL_HOST = env("EMAIL_HOST") # This is the SMTP server for sending mail (i.e. smtp.postmarkapp.com)
EMAIL_HOST = required_env("EMAIL_HOST") # This is the SMTP server for sending mail (i.e. smtp.postmarkapp.com)
EMAIL_PORT = env("EMAIL_PORT", 2525)
EMAIL_HOST_USER = env("EMAIL_HOST_USER") # This is the username for the SMTP server (i.e. 12345678-1234-1234-1234-123456789012) - this is the same as the password
EMAIL_HOST_PASSWORD = env("EMAIL_HOST_PASSWORD") # This is the password for the SMTP server (i.e. 12345678-1234-1234-1234-123456789012)
EMAIL_HOST_USER = required_env("EMAIL_HOST_USER") # This is the username for the SMTP server (i.e. 12345678-1234-1234-1234-123456789012) - this is the same as the password
EMAIL_HOST_PASSWORD = required_env("EMAIL_HOST_PASSWORD") # This is the password for the SMTP server (i.e. 12345678-1234-1234-1234-123456789012)
EMAIL_USE_TLS = env("EMAIL_USE_TLS", True)

# These settings are for sending FOI requests to public bodies
FOI_EMAIL_FIXED_FROM_ADDRESS = env("FOI_EMAIL_FIXED_FROM_ADDRESS", True)
FOI_EMAIL_HOST_USER = env("FOI_EMAIL_HOST_USER") # This is the username for the SMTP server (i.e. 12345678-1234-1234-1234-123456789012) - this is the same as the password
FOI_EMAIL_HOST_PASSWORD = env("FOI_EMAIL_HOST_PASSWORD") # This is the password for the SMTP server (i.e. 12345678-1234-1234-1234-123456789012)
FOI_EMAIL_HOST = env("FOI_EMAIL_HOST") # This is the SMTP server for sending mail (i.e. smtp.postmarkapp.com)
FOI_EMAIL_HOST_USER = required_env("FOI_EMAIL_HOST_USER") # This is the username for the SMTP server (i.e. 12345678-1234-1234-1234-123456789012) - this is the same as the password
FOI_EMAIL_HOST_PASSWORD = required_env("FOI_EMAIL_HOST_PASSWORD") # This is the password for the SMTP server (i.e. 12345678-1234-1234-1234-123456789012)
FOI_EMAIL_HOST = required_env("FOI_EMAIL_HOST") # This is the SMTP server for sending mail (i.e. smtp.postmarkapp.com)
FOI_EMAIL_PORT = env("FOI_EMAIL_PORT", 2525)
FOI_EMAIL_USE_TLS = env("FOI_EMAIL_USE_TLS", True)

# These settings are for receiving FOI responses from public bodies
FOI_EMAIL_HOST_FROM = env("FOI_EMAIL_HOST_FROM") # This is the inbound address for the SMTP server (i.e. [email protected])
FOI_EMAIL_HOST_FROM = required_env("FOI_EMAIL_HOST_FROM") # This is the inbound address for the SMTP server (i.e. [email protected])
# When defining the "FOI_EMAIL_DOMAIN" setting for testing, Postmark enforces that all recipient addresses must share the same domain as the inbound address.
# Basically, if your email address ends in @example.com, then the "FOI_EMAIL_DOMAIN" setting must be set to "example.com".
FOI_EMAIL_DOMAIN = env("FOI_EMAIL_DOMAIN") # This defines the "From" address for the inbound email (i.e. beta-foi.uipa.org)
FOI_MAIL_SERVER_HOST = env("FOI_MAIL_SERVER_HOST") # This defines the "Message-Id" header for the inbound email (i.e. beta-foi.uipa.org)
FOI_EMAIL_DOMAIN = required_env("FOI_EMAIL_DOMAIN") # This defines the "From" address for the inbound email (i.e. beta-foi.uipa.org)
FOI_MAIL_SERVER_HOST = required_env("FOI_MAIL_SERVER_HOST") # This defines the "Message-Id" header for the inbound email (i.e. beta-foi.uipa.org)

# End of email settings

0 comments on commit 3bcbd67

Please sign in to comment.