8000 Replace hardcoded sensitive data with environment variables by skdishansachin · Pull Request #31 · github/codespaces-django · GitHub
[go: up one dir, main page]

Skip to content

Replace hardcoded sensitive data with environment variables #31

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

Merged
merged 10 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"waitFor": "onCreateCommand",
"updateContentCommand": "pip install -r requirements.txt && python manage.py migrate",
"postCreateCommand": "",
"postCreateCommand": "cp .env.example .env",
"postAttachCommand": {
"server": "python manage.py runserver"
},
Expand Down
11 changes: 11 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
SECRET_KEY=my_secret_key
DEBUG=True

# ALLOWED_HOSTS=yourdomain.com,anotherdomain.com (Each host is separated by a comma)
ALLOWED_HOSTS=*

DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=""
DB_USERNAME=""
DB_PASSWORD=""
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
db.sqlite3
__pycache__/
staticfiles/
.env/
.env
venv/
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ To collect static files:
```python
python manage.py collectstatic
```

To run this application:

```python
Expand Down
9 changes: 6 additions & 3 deletions hello_world/settings.py
7689
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
"""
import os
from pathlib import Path
from dotenv import load_dotenv

load_dotenv()

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
Expand All @@ -20,12 +23,12 @@
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "django-insecure-rc@04_mry_3-$@2sq$b9%-9jp6q2eyxf4bsw9&&esj++aw&r)p"
SECRET_KEY = os.getenv("SECRET_KEY")

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
DEBUG = os.getenv("DEBUG")

ALLOWED_HOSTS = []
ALLOWED_HOSTS = os.getenv('ALLOWED_HOSTS', '').split(',')

if 'CODESPACE_NAME' in os.environ:
codespace_name = os.getenv("CODESPACE_NAME")
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Django==4.1.13
django-browser-reload==1.6.0
python-dotenv==1.0.0
0