From 3ca5f534e1bd71a0519bb5cfdda3910e62dff5f5 Mon Sep 17 00:00:00 2001 From: "T. Andrew Manning" Date: Mon, 11 Apr 2022 09:36:01 -0500 Subject: [PATCH 1/6] Support arbitrary S3 bucket URL. Allow S3 bucket config from Secret. --- helm-chart/templates/_helpers.tpl | 29 +++++++++++++++++++++++++++-- helm-chart/values.yaml | 5 ++++- mop/settings.py | 1 + 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/helm-chart/templates/_helpers.tpl b/helm-chart/templates/_helpers.tpl index f9becf05..3a4ed8d6 100644 --- a/helm-chart/templates/_helpers.tpl +++ b/helm-chart/templates/_helpers.tpl @@ -107,13 +107,38 @@ build it here and use it everywhere. - name: IRSA_USERNAME value: {{ .Values.irsaUsername | quote }} - name: IRSA_PASSWORD - value: {{ .Values.irsaPassword | quote }} + value: {{ .Values.irsaPassword | quote }} +{{- if .Values.awsExistingSecret }} +- name: AWS_S3_ENDPOINT_URL + valueFrom: + secretKeyRef: + name: {{ .Values.awsExistingSecret | quote }} + key: "awsEndpointUrl" +- name: AWS_ACCESS_KEY_ID + valueFrom: + secretKeyRef: + name: {{ .Values.awsExistingSecret | quote }} + key: "awsAccessKeyId" +- name: AWS_SECRET_ACCESS_KEY + valueFrom: + secretKeyRef: + name: {{ .Values.awsExistingSecret | quote }} + key: "awsSecretAccessKey" +- name: AWS_S3_BUCKET + valueFrom: + secretKeyRef: + name: {{ .Values.awsExistingSecret | quote }} + key: "awsS3Bucket" +{{- else }} +- name: AWS_S3_ENDPOINT_URL + value: {{ .Values.awsEndpointUrl | quote }} - name: AWS_ACCESS_KEY_ID value: {{ .Values.awsAccessKeyId | quote }} - name: AWS_SECRET_ACCESS_KEY value: {{ .Values.awsSecretAccessKey | quote }} - name: AWS_S3_BUCKET - value: {{ .Values.awsS3Bucket | quote }} + value: {{ .Values.awsS3Bucket | quote }} +{{- end }} - name: GEMINI_USERNAME value: {{ .Values.geminiUsername | quote }} - name: GEMINI_N_API_KEY diff --git a/helm-chart/values.yaml b/helm-chart/values.yaml index 55559682..85a2bf41 100644 --- a/helm-chart/values.yaml +++ b/helm-chart/values.yaml @@ -205,7 +205,10 @@ lcoProposalId: "" lcoUsername: "" # AWS Credentials -# These MUST be overriden in secret configuration file +# If `awsExistingSecret` is specified, all `aws*` params must be included in the specified secret +awsExistingSecret: "" +# These MUST be overriden in secret configuration file if `awsExistingSecret` is not specified +awsEndpointUrl: "" awsAccessKeyId: "" awsSecretAccessKey: "" awsS3Bucket: "" diff --git a/mop/settings.py b/mop/settings.py index 9239dec9..93660ad7 100644 --- a/mop/settings.py +++ b/mop/settings.py @@ -189,6 +189,7 @@ DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage' STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage' +AWS_S3_ENDPOINT_URL = os.getenv('AWS_S3_ENDPOINT_URL', '') AWS_ACCESS_KEY_ID = os.getenv('AWS_ACCESS_KEY_ID', '') AWS_SECRET_ACCESS_KEY = os.getenv('AWS_SECRET_ACCESS_KEY', '') AWS_STORAGE_BUCKET_NAME = os.getenv('AWS_S3_BUCKET', '') From 56d1741ea5c3bb36d97a5904a1e637d4c9f7901c Mon Sep 17 00:00:00 2001 From: "T. Andrew Manning" Date: Mon, 11 Apr 2022 09:48:22 -0500 Subject: [PATCH 2/6] Support non-root URL base path --- helm-chart/templates/_helpers.tpl | 2 ++ helm-chart/templates/deployment.yaml | 4 ++-- helm-chart/values.yaml | 1 + mop/settings.py | 12 ++++++++---- mop/urls.py | 13 +++++++++++-- templates/tom_common/navbar_content.html | 2 +- 6 files changed, 25 insertions(+), 9 deletions(-) diff --git a/helm-chart/templates/_helpers.tpl b/helm-chart/templates/_helpers.tpl index 3a4ed8d6..e66de913 100644 --- a/helm-chart/templates/_helpers.tpl +++ b/helm-chart/templates/_helpers.tpl @@ -76,6 +76,8 @@ build it here and use it everywhere. {{- define "mop.backendEnv" -}} - name: PYTHONUNBUFFERED value: "1" +- name: URL_BASE_PATH + value: {{ .Values.ingress.basePath | quote }} - name: DB_HOST value: {{ include "mop.dbhost" . | quote }} - name: DB_NAME diff --git a/helm-chart/templates/deployment.yaml b/helm-chart/templates/deployment.yaml index 5052eb27..bc49e440 100644 --- a/helm-chart/templates/deployment.yaml +++ b/helm-chart/templates/deployment.yaml @@ -130,11 +130,11 @@ spec: protocol: TCP livenessProbe: httpGet: - path: / + path: /{{ .Values.ingress.basePath }} port: gunicorn readinessProbe: httpGet: - path: / + path: /{{ .Values.ingress.basePath }} port: gunicorn resources: {{- toYaml .Values.resources | nindent 12 }} diff --git a/helm-chart/values.yaml b/helm-chart/values.yaml index 85a2bf41..6b479faa 100644 --- a/helm-chart/values.yaml +++ b/helm-chart/values.yaml @@ -142,6 +142,7 @@ service: ingress: enabled: false + basePath: "" annotations: {} # kubernetes.io/ingress.class: nginx # kubernetes.io/tls-acme: "true" diff --git a/mop/settings.py b/mop/settings.py index 93660ad7..4157c39b 100644 --- a/mop/settings.py +++ b/mop/settings.py @@ -22,7 +22,11 @@ # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - +# Get URL base path +base_path = os.environ.get('URL_BASE_PATH', '').strip('/') +base_path_trailing_slash = '' +if base_path: + base_path_trailing_slash = '/' # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/ @@ -149,9 +153,9 @@ }, ] -LOGIN_URL = '/accounts/login/' -LOGIN_REDIRECT_URL = '/' -LOGOUT_REDIRECT_URL = '/' +LOGIN_URL = f'/{base_path}{base_path_trailing_slash}accounts/login/' +LOGIN_REDIRECT_URL = f'/{base_path}' +LOGOUT_REDIRECT_URL = f'/{base_path}' AUTHENTICATION_BACKENDS = ( 'django.contrib.auth.backends.ModelBackend', diff --git a/mop/urls.py b/mop/urls.py index 253fe72c..7a6fdd0c 100644 --- a/mop/urls.py +++ b/mop/urls.py @@ -16,8 +16,17 @@ from django.urls import path, include from mop.views import MOPTargetDetailView +from django.views.generic import TemplateView +import os +base_path = os.environ.get('URL_BASE_PATH', '').strip('/') +trailing_slash = '' +if base_path: + trailing_slash = '/' urlpatterns = [ - path('targets//', MOPTargetDetailView.as_view(), name='detail'), - path('', include('tom_common.urls')), + path(f'''{base_path}{trailing_slash}targets//''', MOPTargetDetailView.as_view(), name='detail'), + path(f'''{base_path}{trailing_slash}''', TemplateView.as_view( + template_name='tom_common/index.html', + extra_context={"base_path": base_path}), name='home'), + path(f'''{base_path}{trailing_slash}''', include('tom_common.urls')), ] diff --git a/templates/tom_common/navbar_content.html b/templates/tom_common/navbar_content.html index 5a256b8c..edda9f74 100644 --- a/templates/tom_common/navbar_content.html +++ b/templates/tom_common/navbar_content.html @@ -5,7 +5,7 @@ {% endcomment %}
  • - Logout + +
    + {% csrf_token %} + +
  • {% else %} {% endif %}