Skip to content
Merged
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
13 changes: 12 additions & 1 deletion geonode/proxy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django.conf import settings
from django.db.models import signals

from django.utils.timezone import now

site_url = urlsplit(settings.SITEURL)

Expand All @@ -11,6 +11,8 @@

class ProxyUrlsRegistry:
_first_init = True
_last_registry_load = None
_registry_reload_threshold = getattr(settings, "PROXY_RELOAD_REGISTRY_THRESHOLD_DAYS", 1)

def initialize(self):
from geonode.base.models import Link
Expand All @@ -30,12 +32,16 @@
signals.post_delete.connect(link_post_delete, sender=Link)
self._first_init = False

self._last_registry_load = now()

def set(self, hosts):
self.proxy_allowed_hosts = set(hosts)
self._last_registry_load = now()
return self

def clear(self):
self.proxy_allowed_hosts = set()
self._last_registry_load = now()
return self

def register_host(self, host):
Expand All @@ -45,6 +51,11 @@
self.proxy_allowed_hosts.remove(host)

def get_proxy_allowed_hosts(self):
if (
self._last_registry_load is None
or (now() - self._last_registry_load).days >= self._registry_reload_threshold
):
self.initialize()

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

View check run for this annotation

Codecov / codecov/patch

geonode/proxy/utils.py#L58

Added line #L58 was not covered by tests
return self.proxy_allowed_hosts


Expand Down
Loading