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

Test secrets debugging #402

Closed
wants to merge 15 commits into from
46 changes: 30 additions & 16 deletions .github/workflows/django.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,50 @@ jobs:
max-parallel: 4
matrix:
python-version: [3.9]
environment: Testing # Specify the environment here

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Debugging Step

- name: Create secrets file
run: |
echo "SECRET_KEY=${{ secrets.SECRET_KEY }}" >> server/.env
echo "DJANGO_GOOGLE_OAUTH2_CLIENT_ID=${{ secrets.DJANGO_GOOGLE_OAUTH2_CLIENT_ID }}" >> server/.env
echo "DJANGO_GOOGLE_OAUTH2_CLIENT_SECRET=${{ secrets.DJANGO_GOOGLE_OAUTH2_CLIENT_SECRET }}" >> server/.env
echo "DJANGO_ORCID_OAUTH2_CLIENT_URL=${{ secrets.DJANGO_ORCID_OAUTH2_CLIENT_URL }}" >> server/.env
echo "DJANGO_ORCID_OAUTH2_CLIENT_ID=${{ secrets.DJANGO_ORCID_OAUTH2_CLIENT_ID }}" >> server/.env
echo "DJANGO_ORCID_OAUTH2_CLIENT_SECRET=${{ secrets.DJANGO_ORCID_OAUTH2_CLIENT_SECRET }}" >> server/.env
echo "DJANGO_ORCID_OAUTH2_URL=${{ secrets.DJANGO_ORCID_OAUTH2_URL }}" >> server/.env
echo "SERVER_VERSION=${{ secrets.SERVER_VERSION }}" >> server/.env
echo "SERVER_URL=${{ secrets.SERVER_URL }}" >> server/.env
echo "DATABASE=${{ secrets.DATABASE }}" >> server/.env
echo "EMAIL_BACKEND=${{ secrets.EMAIL_BACKEND }}" >> server/.env

- name: Debug Secrets
run: |
cat server/.env

- name: Export Environment Variables
run: |
ls -R server # List all files and directories recursively
cat server/requirements.txt # Print the contents of the requirements file
export $(cat server/.env | xargs)
shell: bash

- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r server/requirements.txt

- name: Run Tests
env:
SECRET_KEY: ${{ secrets.SECRET_KEY }}
DJANGO_GOOGLE_OAUTH2_CLIENT_ID: ${{ secrets.DJANGO_GOOGLE_OAUTH2_CLIENT_ID }}
DJANGO_GOOGLE_OAUTH2_CLIENT_SECRET: ${{ secrets.DJANGO_GOOGLE_OAUTH2_CLIENT_SECRET }}
DJANGO_ORCID_OAUTH2_CLIENT_URL: ${{ secrets.DJANGO_ORCID_OAUTH2_CLIENT_URL }}
DJANGO_ORCID_OAUTH2_CLIENT_ID: ${{ secrets.DJANGO_ORCID_OAUTH2_CLIENT_ID }}
DJANGO_ORCID_OAUTH2_CLIENT_SECRET: ${{ secrets.DJANGO_ORCID_OAUTH2_CLIENT_SECRET }}
DJANGO_ORCID_OAUTH2_URL: ${{ secrets.DJANGO_ORCID_OAUTH2_URL }}
SERVER_VERSION: ${{ secrets.SERVER_VERSION }}
SERVER_URL: ${{ secrets.SERVER_URL }}
DATABASE: ${{ secrets.DATABASE }}

run: |
cd server # Change to the subdirectory
python3.9 manage.py test

- name: Clean up
run: |
rm server/.env
2 changes: 1 addition & 1 deletion client/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ REACT_APP_ORCID_URL=
REACT_APP_ORCID_CLIENT_ID=
REACT_APP_ORCID_CLIENT_SECRET=
REACT_APP_SERVER_URL=
REACT_APP_BCOAPI_TOKEN=
REACT_APP_BCOAPI_TOKEN=
16 changes: 15 additions & 1 deletion server/portaluserdb/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import configparser
from django.core.management.utils import get_random_secret_key



# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

Expand Down Expand Up @@ -38,6 +40,8 @@
"SERVER_VERSION": os.environ.get("SERVER_VERSION"),
"SERVER_URL": os.environ.get("SERVER_URL"),
"DATABASE": os.environ.get("DATABASE"),
"EMAIL_BACKEND": os.environ.get("EMAIL_BACKEND", "django.core.mail.backends.console.EmailBackend"),

},
}
if secrets["DJANGO_KEYS"]["SECRET_KEY"] == None:
Expand Down Expand Up @@ -67,8 +71,18 @@
GOOGLE_CLIENT = secrets["GOOGLE_KEYS"]["DJANGO_GOOGLE_OAUTH2_CLIENT_ID"]
if secrets["GOOGLE_KEYS"]["DJANGO_GOOGLE_OAUTH2_CLIENT_SECRET"]:
GOOGLE_SECRET = secrets["GOOGLE_KEYS"]["DJANGO_GOOGLE_OAUTH2_CLIENT_SECRET"]
if secrets["SERVER"]["EMAIL_BACKEND"]:
EMAIL_BACKEND = secrets["SERVER"]["EMAIL_BACKEND"]
try:
EMAIL_BACKEND = secrets["SERVER"]["EMAIL_BACKEND"]
except KeyError:
raise KeyError("EMAIL_BACKEND not found in secrets")



EMAIL_BACKEND = secrets["SERVER"]["EMAIL_BACKEND"]
# Use print statements for debugging
print(f"Secrets: {secrets}")
print(f"EMAIL_BACKEND: {EMAIL_BACKEND}")

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
Expand Down
Loading