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

Use django-environ to load Env variables #11

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
8 changes: 8 additions & 0 deletions .env_example
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
SECRET_KEY=changeme
DEBUG=true
DATABASE_URL=postgres:///connect
DJANGO_ALLOWED_HOSTS=
TWILIO_ACCOUNT_SID=
TWILIO_AUTH_TOKEN=
TWILIO_MESSAGING_SERVICE=
FCM_CREDENTIALS=
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
*~
*.swp
*.swo
*localsettings*
!*localsettings.example.py
*.env
!*.env_example
*.log*
/staticfiles/
/.idea
Expand Down
30 changes: 0 additions & 30 deletions connectid/localsettings.example.py

This file was deleted.

35 changes: 32 additions & 3 deletions connectid/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.1/ref/settings/
"""
import os
import environ

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

env = environ.Env()
env.read_env(str(BASE_DIR / ".env"))

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/
Expand Down Expand Up @@ -196,10 +197,38 @@
"DELETE_INACTIVE_DEVICES": False,
}

from .localsettings import *
Copy link
Member

Choose a reason for hiding this comment

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

We are missing two settings from prod here CSRF_TRUSTED_ORIGINS and private-key part of OAUTH2_PROVIDER

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. 14d18c0

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = env(
"SECRET_KEY",
default="django-insecure-yofpqrszrdtv0ftihjd09cuim2al9^n9j^b85%-y0v*^_lj18d",
)

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = env("DEBUG", default=False)

# Database
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases

DATABASES = {
"default": env.db(
"DATABASE_URL",
default="postgres:///connect",
),
}

ALLOWED_HOSTS = ["127.0.0.1", "localhost"] + env.list(
"DJANGO_ALLOWED_HOSTS", default=[]
)

TWILIO_ACCOUNT_SID = env("TWILIO_ACCOUNT_SID")
TWILIO_AUTH_TOKEN = env("TWILIO_AUTH_TOKEN")
TWILIO_MESSAGING_SERVICE = env("TWILIO_MESSAGING_SERVICE")

FCM_CREDENTIALS = env("FCM_CREDENTIALS", default=None)
Copy link
Member

Choose a reason for hiding this comment

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

We should probably allow only individual fields within FCM_CREDENTIALs to be configured via env? (instead of the full JSON)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. 14d18c0


# Firebase
if FCM_CREDENTIALS:
from firebase_admin import credentials, initialize_app

creds = credentials.Certificate(FCM_CREDENTIALS)
default_app = initialize_app(credential=creds)
3 changes: 2 additions & 1 deletion requirements/requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ phonenumberslite
psycopg2
twilio
zxcvbn
fcm-django
fcm-django
django-environ
22 changes: 4 additions & 18 deletions requirements/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
#
asgiref==3.6.0
# via django
build==0.10.0
Copy link
Collaborator

Choose a reason for hiding this comment

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

do you know why there are so many requirements changes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, pip-tools is not in the requirements.in file, so on pip-compile pip-tools and its dependencies were removed.

# via pip-tools
cachecontrol==0.13.1
# via firebase-admin
cachetools==5.3.1
Expand All @@ -18,8 +16,6 @@ cffi==1.15.1
# via cryptography
charset-normalizer==3.1.0
# via requests
click==8.1.3
# via pip-tools
cryptography==41.0.2
# via
# jwcrypto
Expand All @@ -34,6 +30,8 @@ django==4.1.7
# django-phonenumber-field
# djangorestframework
# fcm-django
django-environ==0.11.2
# via -r requirements.in
django-oauth-toolkit==2.3.0
# via -r requirements.in
django-otp==1.1.6
Expand Down Expand Up @@ -100,12 +98,8 @@ msgpack==1.0.7
# via cachecontrol
oauthlib==3.2.2
# via django-oauth-toolkit
packaging==23.1
# via build
phonenumberslite==8.13.11
# via -r requirements.in
pip-tools==6.13.0
# via -r requirements.in
proto-plus==1.22.3
# via google-cloud-firestore
protobuf==4.24.4
Expand All @@ -131,8 +125,6 @@ pyjwt[crypto]==2.6.0
# twilio
pyparsing==3.1.1
# via httplib2
pyproject-hooks==1.0.0
# via build
pytz==2022.7.1
# via
# djangorestframework
Expand All @@ -154,17 +146,11 @@ uritemplate==4.1.1
# via google-api-python-client
urllib3==1.26.15
# via requests
wheel==0.40.0
# via pip-tools
wrapt==1.15.0
# via deprecated
zxcvbn==4.4.28
# via -r requirements.in

# The following packages are considered to be unsafe in a requirements file:
pip==23.1.2
# via pip-tools
setuptools==67.8.0
# via
# gunicorn
# pip-tools
setuptools==69.0.3
# via gunicorn