Skip to content

Commit

Permalink
made django_secret and discourse_api_key configurable via env
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMrSheldon committed Sep 19, 2024
1 parent 45f99f3 commit 5c458fc
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 37 deletions.
5 changes: 1 addition & 4 deletions .devcontainer/Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,12 @@ ENV PIP_BREAK_SYSTEM_PACKAGES 1
USER root
RUN apt-get update && apt-get install -y python3 python3-pip python3-dev pkg-config default-libmysqlclient-dev \
libpcre3-dev
# Create a dummy secret
COPY <<EOF /etc/discourse/client-api-key
I am so secret
EOF

# Environment Variables for TIRA Configuration:
ENV TIRA_ROOT=/workspaces/tira/model/src
ENV TIRA_CONFIG=/workspaces/tira/application/config/tira-application-config.yml
ENV TIRA_DEBUG=true
ENV DISCOURSE_API_KEY="I am so secret"

########################################################################################################################
# Client #
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ jobs:
- name: Install dependencies
working-directory: ${{github.workspace}}/application
run: |
# Create a dummy DISRAPTOR_API_KEY
sudo bash -c 'mkdir -p "/etc/discourse/" && echo "I am so secret" > "/etc/discourse/client-api-key"'
pip3 install .[dev,test]
make setup
env:
TIRA_ROOT: ${{github.workspace}}/model/src
TIRA_CONFIG: ${{github.workspace}}/application/config/tira-application-config.yml
DISCOURSE_API_KEY: "I am so secret"
- name: Run backend tests
working-directory: ${{github.workspace}}/application/test
run: pytest
Expand Down
4 changes: 2 additions & 2 deletions application/config/tira-application-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
debug: !ENV ${TIRA_DEBUG:false}
allowed_hosts:
- "*"
django_secret: "not-so-secret"
django_secret: !ENV ${DJANGO_SECRET:change-me!}
# ---
tira_root: !ENV ${TIRA_ROOT:/tira}
disraptor_secret_file: /etc/discourse/client-api-key
# The directory where logs are written to. Defaults to TIRA_ROOT/log/tira-application
# logging_dir: /mnt/ceph/tira/log/tira-application
# grpc_host can be local or remote. If local, it will call localhost (i.e. for testing). If remote, it will call the vm-host
Expand All @@ -22,3 +21,4 @@ database:
port: !ENV ${TIRA_DB_PORT:3306} # ignored when using sqlite3
github_token: !ENV ${TIRA_GITHUB_TOKEN}
discourse_api_url: !ENV ${DISCOURSE_API_URL:https://www.tira.io}
discourse_api_key: !ENV ${DISCOURSE_API_KEY:""}
10 changes: 1 addition & 9 deletions application/src/django_admin/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
https://docs.djangoproject.com/en/3.1/ref/settings/
"""

import errno
import importlib.resources as resources
import logging
import os
Expand Down Expand Up @@ -52,7 +51,6 @@

(TIRA_ROOT / "state").mkdir(parents=True, exist_ok=True)

DISRAPTOR_SECRET_FILE = Path(custom_settings["disraptor_secret_file"])
HOST_GRPC_PORT = custom_settings.get("host_grpc_port", "50051")
APPLICATION_GRPC_PORT = custom_settings.get("application_grpc_port", "50052")
GRPC_HOST = custom_settings.get("grpc_host", "local") # can be local or remote
Expand Down Expand Up @@ -378,6 +376,7 @@ def logger_config(log_dir: Path):
USE_TZ = True

DISCOURSE_API_URL = custom_settings["discourse_api_url"]
DISRAPTOR_API_KEY = custom_settings["discourse_api_key"]
PUBLIC_TRAINING_DATA = set(["jena-topics-20231026-test", "leipzig-topics-20231025-test"])

CODE_SUBMISSION_REFERENCE_REPOSITORIES = {
Expand All @@ -400,10 +399,3 @@ def logger_config(log_dir: Path):
}

CODE_SUBMISSION_REPOSITORY_NAMESPACE = "tira-io"
if DISRAPTOR_SECRET_FILE.exists():
DISRAPTOR_API_KEY = DISRAPTOR_SECRET_FILE.read_text().strip()
elif DEBUG:
logging.warning(f"The Disraptor Secret File, {DISRAPTOR_SECRET_FILE}, could not be found.")
DISRAPTOR_API_KEY = ""
else:
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), str(DISRAPTOR_SECRET_FILE))
10 changes: 1 addition & 9 deletions application/test/settings_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
https://docs.djangoproject.com/en/3.1/ref/settings/
"""

import errno
import importlib.resources as resources
import logging
import os
Expand Down Expand Up @@ -52,7 +51,6 @@

(TIRA_ROOT / "state").mkdir(parents=True, exist_ok=True)

DISRAPTOR_SECRET_FILE = Path(custom_settings["disraptor_secret_file"])
HOST_GRPC_PORT = custom_settings.get("host_grpc_port", "50051")
APPLICATION_GRPC_PORT = custom_settings.get("application_grpc_port", "50052")
GRPC_HOST = custom_settings.get("grpc_host", "local") # can be local or remote
Expand Down Expand Up @@ -318,6 +316,7 @@ def logger_config(log_dir: Path):
USE_TZ = True

DISCOURSE_API_URL = custom_settings["discourse_api_url"]
DISRAPTOR_API_KEY = custom_settings["discourse_api_key"]
PUBLIC_TRAINING_DATA = set(["jena-topics-20231026-test", "leipzig-topics-20231025-test"])

CODE_SUBMISSION_REFERENCE_REPOSITORIES = {
Expand All @@ -328,10 +327,3 @@ def logger_config(log_dir: Path):
REFERENCE_DATASETS: dict[str, str] = {}

CODE_SUBMISSION_REPOSITORY_NAMESPACE = "tira-io"
if DISRAPTOR_SECRET_FILE.exists():
DISRAPTOR_API_KEY = DISRAPTOR_SECRET_FILE.read_text().strip()
elif DEBUG:
logging.warning(f"The Disraptor Secret File, {DISRAPTOR_SECRET_FILE}, could not be found.")
DISRAPTOR_API_KEY = ""
else:
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), str(DISRAPTOR_SECRET_FILE))
19 changes: 8 additions & 11 deletions pipelines/src/config/tira-application-config.dev.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
# ---task/celebrity-profiling/user/hodge20a
debug: true
allowed_hosts:
- "0.0.0.0"
django_secret: 'not-so-secret'
- "*"
django_secret: "not-so-secret"
# ---
# tira_root: /mnt/ceph/tira
# deployment = {disraptor}
deployment: disraptor
# disraptor_secret_file: /etc/discourse/client-api-key
# The directory where logs are written to. Defaults to TIRA_ROOT/log/tira-application
# logging_dir: /mnt/ceph/tira/log/tira-application
# grpc_host can be local or remote. If local, it will call localhost (i.e. for testing). If remote, it will call the vm-host
Expand All @@ -16,9 +13,9 @@ grpc_host: local
host_grpc_port: 50051
application_grpc_port: 50052
database:
engine: django.db.backends.sqlite3 # django.db.backends.mysql or django.db.backends.sqlite3
name: tira # when backend is sqlite, this will be the name of the database below TIRA_ROOT/state
user: tira # ignored when using sqlite3
password: TODO-ENTER-PASSWORD # ignored when using sqlite3
host: tira-mariadb # ignored when using sqlite3
port: 3306 # ignored when using sqlite3
engine: django.db.backends.sqlite3 # django.db.backends.mysql or django.db.backends.sqlite3
name: tira # when backend is sqlite, this will be the name of the database below TIRA_ROOT/state
user: tira # ignored when using sqlite3
password: TODO-ENTER-PASSWORD # ignored when using sqlite3
host: tira-mariadb # ignored when using sqlite3
port: 3306 # ignored when using sqlite3

0 comments on commit 5c458fc

Please sign in to comment.