From 4b86e216855094600a90af5a52499fcd957c2bb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Wed, 10 Feb 2016 09:08:32 +0100 Subject: [PATCH] worker: use actual tenants to determine if hobo_notify is relevant --- .../common/management/commands/get_tenants_dir.py | 22 ++++++++++++++ hobo/agent/worker/services.py | 34 ++++++++++++++++++---- 2 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 hobo/agent/common/management/commands/get_tenants_dir.py diff --git a/hobo/agent/common/management/commands/get_tenants_dir.py b/hobo/agent/common/management/commands/get_tenants_dir.py new file mode 100644 index 0000000..e4a780a --- /dev/null +++ b/hobo/agent/common/management/commands/get_tenants_dir.py @@ -0,0 +1,22 @@ +# hobo - portal to configure and deploy applications +# Copyright (C) 2016 Entr'ouvert +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +from django.conf import settings +from django.core.management.base import BaseCommand, CommandError + +class Command(BaseCommand): + def handle(self, *args, **kwargs): + print settings.TENANT_BASE diff --git a/hobo/agent/worker/services.py b/hobo/agent/worker/services.py index 0774449..f5ee4dc 100644 --- a/hobo/agent/worker/services.py +++ b/hobo/agent/worker/services.py @@ -34,6 +34,22 @@ class BaseService(object): self.title = title self.secret_key = secret_key + _tenants_dir = Ellipsis + @classmethod + def get_actual_tenants(cls): + if cls._tenants_dir is Ellipsis: + try: + stdout = subprocess.check_output( + cls.service_manage_cmd + ' get_tenants_dir', + shell=True) + except subprocess.CalledProcessError: + cls.tenants_dir = None + return None + cls._tenants_dir = stdout.splitlines()[-1].strip() + if cls._tenants_dir is None: + return None + return os.listdir(cls._tenants_dir) + @classmethod def is_for_us(cls, url): # This function checks if the requested service is to be hosted @@ -75,13 +91,17 @@ class BaseService(object): @classmethod def notify(cls, data): - for audience in data.get('audience', []): - if cls.is_for_us(audience): - break - else: - return if not os.path.exists(cls.service_manage_try_cmd): return + tenants = cls.get_actual_tenants() + if tenants is not None: + for audience in data.get('audience', []): + parsed_url = urllib2.urlparse.urlsplit(audience) + netloc = parsed_url.netloc.split(':')[0] + if netloc in tenants: + break + else: + return cmd = cls.service_manage_cmd + ' hobo_notify -' try: cmd_process = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, @@ -104,6 +124,10 @@ class Wcs(BaseService): service_manage_cmd = settings.WCS_MANAGE_COMMAND service_manage_try_cmd = settings.WCS_MANAGE_TRY_COMMAND + @classmethod + def get_actual_tenants(cls): + return None + class Authentic(BaseService): service_id = 'authentic' -- 2.7.0