Skip to content

Commit

Permalink
chore: rename getenv utility to getenvp (#477)
Browse files Browse the repository at this point in the history
  • Loading branch information
vncsna authored Nov 1, 2023
1 parent 9ff570a commit f4027e2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 33 deletions.
16 changes: 8 additions & 8 deletions bd_api/settings/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,26 @@
# https://docs.djangoproject.com/en/4.0/ref/settings/#email-backend
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST = getenv("EMAIL_HOST", "smtp.gmail.com")
EMAIL_HOST_USER = getenv("EMAIL_HOST_USER", "NOT SET")
EMAIL_HOST_PASSWORD = getenv("EMAIL_HOST_PASSWORD", "NOT SET")
EMAIL_HOST_USER = getenv("EMAIL_HOST_USER")
EMAIL_HOST_PASSWORD = getenv("EMAIL_HOST_PASSWORD")
EMAIL_PORT = int(getenv("EMAIL_PORT", "587"))
EMAIL_USE_TLS = bool(getenv("EMAIL_PORT", "True"))
SERVER_EMAIL = getenv("EMAIL_HOST_USER", "NOT SET")
DEFAULT_FROM_EMAIL = getenv("EMAIL_HOST_USER", "NOT SET")
SERVER_EMAIL = getenv("EMAIL_HOST_USER")
DEFAULT_FROM_EMAIL = getenv("EMAIL_HOST_USER")

# Logging
setup_logger(level="DEBUG", serialize=False)

# Google Application Credentials
GOOGLE_APPLICATION_CREDENTIALS = getenv("GOOGLE_APPLICATION_CREDENTIALS", "")
GOOGLE_APPLICATION_CREDENTIALS = getenv("GOOGLE_APPLICATION_CREDENTIALS")

# Google Cloud Storage
...

# Stripe
STRIPE_LIVE_MODE = bool(getenv("STRIPE_LIVE_MODE", "False"))
STRIPE_LIVE_SECRET_KEY = getenv("STRIPE_LIVE_SECRET_KEY", "")
STRIPE_TEST_SECRET_KEY = getenv("STRIPE_TEST_SECRET_KEY", "")
DJSTRIPE_WEBHOOK_SECRET = getenv("DJSTRIPE_WEBHOOK_SECRET", "")
STRIPE_LIVE_SECRET_KEY = getenv("STRIPE_LIVE_SECRET_KEY")
STRIPE_TEST_SECRET_KEY = getenv("STRIPE_TEST_SECRET_KEY")
DJSTRIPE_WEBHOOK_SECRET = getenv("DJSTRIPE_WEBHOOK_SECRET")
DJSTRIPE_USE_NATIVE_JSONFIELD = True
DJSTRIPE_FOREIGN_KEY_TO_FIELD = "id"
40 changes: 20 additions & 20 deletions bd_api/settings/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

from bd_api.custom.logger import setup_logger
from bd_api.settings.base import * # noqa
from bd_api.utils import getadmins, getenv
from bd_api.utils import getadmins, getenvp

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = getenv("DJANGO_SECRET_KEY")
SECRET_KEY = getenvp("DJANGO_SECRET_KEY")

# CSRF
# https://docs.djangoproject.com/en/4.2/ref/csrf/
Expand All @@ -32,35 +32,35 @@
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql_psycopg2",
"NAME": getenv("DB_NAME"),
"USER": getenv("DB_USER"),
"PASSWORD": getenv("DB_PASSWORD"),
"HOST": getenv("DB_HOST"),
"PORT": getenv("DB_PORT"),
"NAME": getenvp("DB_NAME"),
"USER": getenvp("DB_USER"),
"PASSWORD": getenvp("DB_PASSWORD"),
"HOST": getenvp("DB_HOST"),
"PORT": getenvp("DB_PORT"),
}
}

# Email
# https://docs.djangoproject.com/en/4.0/ref/settings/#email-backend
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST = "smtp.gmail.com"
EMAIL_HOST_USER = getenv("EMAIL_HOST_USER")
EMAIL_HOST_PASSWORD = getenv("EMAIL_HOST_PASSWORD")
EMAIL_PORT = int(getenv("EMAIL_PORT", "587"))
EMAIL_USE_TLS = bool(getenv("EMAIL_PORT", "True"))
SERVER_EMAIL = getenv("EMAIL_HOST_USER")
DEFAULT_FROM_EMAIL = getenv("EMAIL_HOST_USER")
EMAIL_HOST_USER = getenvp("EMAIL_HOST_USER")
EMAIL_HOST_PASSWORD = getenvp("EMAIL_HOST_PASSWORD")
EMAIL_PORT = int(getenvp("EMAIL_PORT", "587"))
EMAIL_USE_TLS = bool(getenvp("EMAIL_PORT", "True"))
SERVER_EMAIL = getenvp("EMAIL_HOST_USER")
DEFAULT_FROM_EMAIL = getenvp("EMAIL_HOST_USER")

# Logging
setup_logger(level="INFO", serialize=True)

# Google Application Credentials
GOOGLE_APPLICATION_CREDENTIALS = getenv("GOOGLE_APPLICATION_CREDENTIALS", "")
GOOGLE_APPLICATION_CREDENTIALS = getenvp("GOOGLE_APPLICATION_CREDENTIALS", "")

# Google Cloud Storage
GS_SERVICE_ACCOUNT = getenv("GCP_SA")
GS_SERVICE_ACCOUNT = getenvp("GCP_SA")
GS_CREDENTIALS = service_account.Credentials.from_service_account_info(loads(GS_SERVICE_ACCOUNT))
GS_BUCKET_NAME = getenv("GCP_BUCKET_NAME")
GS_BUCKET_NAME = getenvp("GCP_BUCKET_NAME")
GS_EXPIRATION = timedelta(seconds=604800)
STORAGES = {
"default": {
Expand All @@ -72,9 +72,9 @@
}

# Stripe
STRIPE_LIVE_MODE = bool(getenv("STRIPE_LIVE_MODE"))
STRIPE_LIVE_SECRET_KEY = getenv("STRIPE_LIVE_SECRET_KEY")
STRIPE_TEST_SECRET_KEY = getenv("STRIPE_TEST_SECRET_KEY")
DJSTRIPE_WEBHOOK_SECRET = getenv("DJSTRIPE_WEBHOOK_SECRET")
STRIPE_LIVE_MODE = bool(getenvp("STRIPE_LIVE_MODE"))
STRIPE_LIVE_SECRET_KEY = getenvp("STRIPE_LIVE_SECRET_KEY")
STRIPE_TEST_SECRET_KEY = getenvp("STRIPE_TEST_SECRET_KEY")
DJSTRIPE_WEBHOOK_SECRET = getenvp("DJSTRIPE_WEBHOOK_SECRET")
DJSTRIPE_USE_NATIVE_JSONFIELD = True
DJSTRIPE_FOREIGN_KEY_TO_FIELD = "id"
10 changes: 5 additions & 5 deletions bd_api/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
from os import getenv as _getenv
from os import getenv

API_URL = _getenv("BASE_URL_API", "https://localhost:8080")
SETTINGS = _getenv("DJANGO_SETTINGS_MODULE", "bd_api.settings")
API_URL = getenv("BASE_URL_API", "https://localhost:8080")
SETTINGS = getenv("DJANGO_SETTINGS_MODULE", "bd_api.settings")


def getadmins():
Expand All @@ -13,9 +13,9 @@ def getadmins():
return [admin.split(",") for admin in admins.split(";")]


def getenv(var, default=None):
def getenvp(var, default=None):
"""Get environment variable or raise exception if not set"""
value = _getenv(var, default)
value = getenv(var, default)
if value is None:
raise ValueError(f"Environment variable {var} not set")
return value
Expand Down

0 comments on commit f4027e2

Please sign in to comment.