Skip to content
Closed
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
14 changes: 13 additions & 1 deletion apps/common/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@

import fsspec
from dagster import AssetKey, DagsterEventType, DagsterInstance, EventRecordsFilter
from django.conf import settings
from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin
from django.http import Http404, HttpResponseRedirect
from django.views import View
from revproxy.views import ProxyView

EXPLORER_CLOUDFRONT_URL = settings.EXPLORER_CLOUDFRONT_URL


class DagsterProxyView(LoginRequiredMixin, PermissionRequiredMixin, ProxyView):
login_url = "/admin/login/"
upstream = f"{os.environ.get('DAGSTER_WEBSERVER_URL')}/{os.environ.get('DAGSTER_WEBSERVER_PREFIX')}/"
# ignore type warning because parent class uses a property for "upstream"
upstream = f"{os.environ.get('DAGSTER_WEBSERVER_URL')}/{os.environ.get('DAGSTER_WEBSERVER_PREFIX')}/" # type: ignore
permission_required = "common.access_dagster_ui"
raise_exception = False

Expand Down Expand Up @@ -55,3 +59,11 @@ def get(self, request, asset_name, partition_name=None):

except Exception as e:
raise Http404(f"Failed to locate or sign asset '{asset_name}': {str(e)}")


class BaselineExplorerProxyView(ProxyView):
"""
A revproxy view to serve the data explorer assets via a cloudfront distribution.
"""

upstream = EXPLORER_CLOUDFRONT_URL # type: ignore
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ services:
- -c
- random_page_cost=0.11


# MinIO is an Amazon S3 compatible object storage server.
minio:
restart: unless-stopped
Expand Down Expand Up @@ -108,6 +107,7 @@ services:
MINIO_ROOT_USER: ${MINIO_ROOT_USER}
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD}
MINIO_ENDPOINT_URL: http://minio:9000
EXPLORER_CLOUDFRONT_URL: ${EXPLORER_CLOUDFRONT_URL:-http://localhost:3000}
SUPPORT_EMAIL_ADDRESS: ${SUPPORT_EMAIL_ADDRESS}
DJANGO_MIGRATE: 1
GOOGLE_APPLICATION_CREDENTIALS: ${GOOGLE_APPLICATION_CREDENTIALS}
Expand Down Expand Up @@ -178,4 +178,4 @@ volumes:
db_data:
external: false
minio_data:
external: false
external: false
1 change: 1 addition & 0 deletions env.example
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ MINIO_ROOT_USER=minioadmin
MINIO_ROOT_PASSWORD=minioadminpassword
MINIO_ENDPOINT_URL=http://minio:9000 # change to http://localhost:9000 if using a local environment
[email protected]
EXPLORER_CLOUDFRONT_URL=http://localhost:3000
PIP_INDEX_URL=https://pypi.python.org/simple/

# Google API related settings
Expand Down
5 changes: 5 additions & 0 deletions hea/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,11 @@
PRIVACY_URL = "https://help.fews.net/fdp/privacy-policy"
DISCLAIMER_URL = "https://help.fews.net/fdp/data-and-information-use-and-attribution-policy"


########## DATA EXPLORER CONFIGURATION
EXPLORER_CLOUDFRONT_URL = env.str("EXPLORER_CLOUDFRONT_URL")
########## End DATA EXPLORER CONFIGURATION

# Allow GDAL/GEOS library path overrides to be set in the environment, for MacOS.
GDAL_LIBRARY_PATH = env("GDAL_LIBRARY_PATH", default=None) # For example, /opt/homebrew/lib/libgdal.dylib
GEOS_LIBRARY_PATH = env("GEOS_LIBRARY_PATH", default=None) # For example, /opt/homebrew/lib/libgeos_c.dylib
7 changes: 6 additions & 1 deletion hea/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
WealthGroupViewSet,
WildFoodGatheringViewSet,
)
from common.views import AssetDownloadView, DagsterProxyView
from common.views import AssetDownloadView, BaselineExplorerProxyView, DagsterProxyView
from common.viewsets import (
ClassifiedProductViewSet,
CountryViewSet,
Expand Down Expand Up @@ -147,6 +147,11 @@
AssetDownloadView.as_view(),
name="asset_download_partitioned",
),
# Baseline Explorer React GUI using Django rev proxy to serve a cloudfront distro
path("baseline-explorer/<path:path>", BaselineExplorerProxyView.as_view(), name="baseline_explorer"),
# The URL pattern below does not capture any path parameter from the URL. But django-revproxy views
# require a path argument. We manually pass a default: {"path": ""}.
path("baseline-explorer/", BaselineExplorerProxyView.as_view(), {"path": ""}, name="baseline_explorer"),
]


Expand Down
Loading