Skip to content

Commit

Permalink
[Fixes #12828] New remote datasets are not registered inside proxy al…
Browse files Browse the repository at this point in the history
…lowed hosts when GeoNode runs asynchoronously
  • Loading branch information
mattiagiupponi committed Jan 20, 2025
1 parent 7e7234f commit 298cff0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
31 changes: 17 additions & 14 deletions geonode/proxy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

from django.conf import settings
from django.db.models import signals
from django.core.cache import caches

site_url = urlsplit(settings.SITEURL)

PROXIED_LINK_TYPES = ["OGC:WMS", "OGC:WFS", "data"]

proxy_allowed_hosts_cache = caches["proxy_allowed_hosts"]
if not settings.MEMCACHED_ENABLED:
from django.core.cache import caches

proxy_cache = caches["proxy_allowed_hosts"]
else:
from django.core.cache import cache as proxy_cache

Check warning on line 15 in geonode/proxy/utils.py

View check run for this annotation

Codecov / codecov/patch

geonode/proxy/utils.py#L15

Added line #L15 was not covered by tests


class ProxyUrlsRegistry:
Expand All @@ -19,13 +23,11 @@ def initialize(self):
from geonode.geoserver.helpers import ogc_server_settings

# since we are initializing the cache, we will clear the previous values
cache_val = proxy_allowed_hosts_cache.get("proxy_list")
if cache_val:
proxy_allowed_hosts_cache.set("proxy_list", {})

if not proxy_cache.get("proxy_list") or proxy_cache.get("proxy_list"):
proxy_cache.set("proxy_list", {})
# adding the value of the proxy in
proxy_allowed_hosts_cache.set(
"proxy_list", set([site_url.hostname] + list(getattr(settings, "PROXY_ALLOWED_HOSTS", ())))
)
proxy_cache.set("proxy_list", set([site_url.hostname] + list(getattr(settings, "PROXY_ALLOWED_HOSTS", ()))))

if ogc_server_settings:
self.register_host(ogc_server_settings.hostname)
Expand All @@ -40,26 +42,27 @@ def initialize(self):
self._first_init = False

def set(self, hosts):
proxy_allowed_hosts_cache.set("proxy_list", set(hosts))
proxy_cache.set("proxy_list", set(hosts))
return self

def clear(self):
proxy_allowed_hosts_cache.get("proxy_list").clear()
if proxy_cache.get("proxy_list"):
proxy_cache.set("proxy_list", {})
return self

def register_host(self, host):
prev = proxy_allowed_hosts_cache.get("proxy_list")
prev = proxy_cache.get("proxy_list")
if prev:
old_hosts = prev.copy()
old_hosts.add(host)
host = old_hosts
proxy_allowed_hosts_cache.set("proxy_list", host)
proxy_cache.set("proxy_list", host)

def unregister_host(self, host):
proxy_allowed_hosts_cache.get("proxy_list").remove(host)
proxy_cache.get("proxy_list").remove(host)

Check warning on line 62 in geonode/proxy/utils.py

View check run for this annotation

Codecov / codecov/patch

geonode/proxy/utils.py#L62

Added line #L62 was not covered by tests

def get_proxy_allowed_hosts(self):
return proxy_allowed_hosts_cache.get("proxy_list")
return proxy_cache.get("proxy_list")


proxy_urls_registry = ProxyUrlsRegistry()
Expand Down
9 changes: 5 additions & 4 deletions geonode/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,6 @@
"TIMEOUT": 600,
"OPTIONS": {"MAX_ENTRIES": 10000},
},
"proxy_allowed_hosts": {
"BACKEND": "django.core.cache.backends.filebased.FileBasedCache",
"LOCATION": os.getenv("FILE_SYSTEM_CACHE_LOCATION", "/tmp/django_cache"),
},
}

# Whitenoise Settings - ref.: http://whitenoise.evans.io/en/stable/django.html
Expand All @@ -390,6 +386,11 @@
"BACKEND": MEMCACHED_BACKEND,
"LOCATION": MEMCACHED_LOCATION,
}
else:
CACHES["proxy_allowed_hosts"] = {
"BACKEND": "django.core.cache.backends.filebased.FileBasedCache",
"LOCATION": os.getenv("FILE_SYSTEM_CACHE_LOCATION", "/tmp/django_cache"),
}

# Define the STATICFILES_STORAGE accordingly
if not DEBUG and CACHE_BUSTING_STATIC_ENABLED:
Expand Down

0 comments on commit 298cff0

Please sign in to comment.