Skip to content

Commit dc4ed44

Browse files
authored
bug(project): Update settings.py to have defaults for github variables. (#13488)
Because - I made a change recently to add specific github environment variables to the project scope for the Klaatu tasks. I did not add defaults to them in the settings.py and this is causing django to choke. This commit - Adds the defaults - Uses the settings file within the task to access the variables Fixes #13487
1 parent 3f75dae commit dc4ed44

File tree

3 files changed

+12
-17
lines changed

3 files changed

+12
-17
lines changed

experimenter/experimenter/klaatu/tasks.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import os
21
import time
32

43
import jwt
54
import markus
65
import requests
76
from celery.utils.log import get_task_logger
7+
from django.conf import settings
88
from packaging import version
99

1010
from experimenter.celery import app
@@ -23,9 +23,9 @@
2323

2424

2525
def _create_auth_token() -> str:
26-
app_id = os.environ["GH_APP_ID"]
27-
installation_id = os.environ["GH_INSTALLATION_ID"]
28-
private_key = os.environ["GH_APP_PRIVATE_KEY"].replace("\\n", "\n")
26+
app_id = settings.GH_APP_ID
27+
installation_id = settings.GH_INSTALLATION_ID
28+
private_key = settings.GH_APP_PRIVATE_KEY.replace("\\n", "\n")
2929

3030
now = int(time.time())
3131
payload = {"iat": now, "exp": now + 540, "iss": app_id}

experimenter/experimenter/klaatu/tests/test_tasks.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import os
21
from unittest import mock
32

4-
from django.test import TestCase
3+
from django.test import TestCase, override_settings
54
from parameterized import parameterized
65

76
from experimenter.experiments.constants import NimbusConstants
@@ -179,14 +178,10 @@ def test_klaatu_task_fetches_job_complete_status_and_updates_experiment(
179178
self.assertEqual(self.experiment.klaatu_status, value)
180179

181180
def test_klaatu_task_auth_token_generation(self):
182-
with mock.patch.dict(
183-
os.environ,
184-
{
185-
"GH_APP_ID": "1",
186-
"GH_INSTALLATION_ID": "2",
187-
"GH_APP_PRIVATE_KEY": "-----BEGIN KEY-----\\nabc\\n-----END KEY-----",
188-
},
189-
clear=False,
181+
with override_settings(
182+
GH_APP_ID=1,
183+
GH_INSTALLATION_ID=2,
184+
GH_APP_PRIVATE_KEY="-----BEGIN KEY-----\\nabc\\n-----END KEY-----",
190185
):
191186
jwt_patcher = mock.patch(
192187
"experimenter.klaatu.tasks.jwt.encode", return_value="jwt123"

experimenter/experimenter/settings.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@
4444
# SECURITY WARNING: keep the secret key used in production secret!
4545
SECRET_KEY = config("SECRET_KEY")
4646

47-
GH_APP_ID = config("GH_APP_ID")
48-
GH_INSTALLATION_ID = config("GH_INSTALLATION_ID")
49-
GH_APP_PRIVATE_KEY = config("GH_APP_PRIVATE_KEY")
47+
GH_APP_ID = config("GH_APP_ID", default=None)
48+
GH_INSTALLATION_ID = config("GH_INSTALLATION_ID", default=None)
49+
GH_APP_PRIVATE_KEY = config("GH_APP_PRIVATE_KEY", default=None)
5050

5151
DEV_USER_EMAIL = "[email protected]"
5252

0 commit comments

Comments
 (0)