0001-worker-use-actual-tenants-to-determine-if-hobo_notif.patch
hobo/agent/common/management/commands/get_tenants_dir.py | ||
---|---|---|
1 |
# hobo - portal to configure and deploy applications |
|
2 |
# Copyright (C) 2016 Entr'ouvert |
|
3 |
# |
|
4 |
# This program is free software: you can redistribute it and/or modify it |
|
5 |
# under the terms of the GNU Affero General Public License as published |
|
6 |
# by the Free Software Foundation, either version 3 of the License, or |
|
7 |
# (at your option) any later version. |
|
8 |
# |
|
9 |
# This program is distributed in the hope that it will be useful, |
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
# GNU Affero General Public License for more details. |
|
13 |
# |
|
14 |
# You should have received a copy of the GNU Affero General Public License |
|
15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 | ||
17 |
from django.conf import settings |
|
18 |
from django.core.management.base import BaseCommand, CommandError |
|
19 | ||
20 |
class Command(BaseCommand): |
|
21 |
def handle(self, *args, **kwargs): |
|
22 |
print settings.TENANT_BASE |
hobo/agent/worker/services.py | ||
---|---|---|
34 | 34 |
self.title = title |
35 | 35 |
self.secret_key = secret_key |
36 | 36 | |
37 |
_tenants_dir = Ellipsis |
|
38 |
@classmethod |
|
39 |
def get_actual_tenants(cls): |
|
40 |
if cls._tenants_dir is Ellipsis: |
|
41 |
try: |
|
42 |
stdout = subprocess.check_output( |
|
43 |
cls.service_manage_cmd + ' get_tenants_dir', |
|
44 |
shell=True) |
|
45 |
except subprocess.CalledProcessError: |
|
46 |
cls.tenants_dir = None |
|
47 |
return None |
|
48 |
cls._tenants_dir = stdout.splitlines()[-1].strip() |
|
49 |
if cls._tenants_dir is None: |
|
50 |
return None |
|
51 |
return os.listdir(cls._tenants_dir) |
|
52 | ||
37 | 53 |
@classmethod |
38 | 54 |
def is_for_us(cls, url): |
39 | 55 |
# This function checks if the requested service is to be hosted |
... | ... | |
75 | 91 | |
76 | 92 |
@classmethod |
77 | 93 |
def notify(cls, data): |
78 |
for audience in data.get('audience', []): |
|
79 |
if cls.is_for_us(audience): |
|
80 |
break |
|
81 |
else: |
|
82 |
return |
|
83 | 94 |
if not os.path.exists(cls.service_manage_try_cmd): |
84 | 95 |
return |
96 |
tenants = cls.get_actual_tenants() |
|
97 |
if tenants is not None: |
|
98 |
for audience in data.get('audience', []): |
|
99 |
parsed_url = urllib2.urlparse.urlsplit(audience) |
|
100 |
netloc = parsed_url.netloc.split(':')[0] |
|
101 |
if netloc in tenants: |
|
102 |
break |
|
103 |
else: |
|
104 |
return |
|
85 | 105 |
cmd = cls.service_manage_cmd + ' hobo_notify -' |
86 | 106 |
try: |
87 | 107 |
cmd_process = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, |
... | ... | |
104 | 124 |
service_manage_cmd = settings.WCS_MANAGE_COMMAND |
105 | 125 |
service_manage_try_cmd = settings.WCS_MANAGE_TRY_COMMAND |
106 | 126 | |
127 |
@classmethod |
|
128 |
def get_actual_tenants(cls): |
|
129 |
return None |
|
130 | ||
107 | 131 | |
108 | 132 |
class Authentic(BaseService): |
109 | 133 |
service_id = 'authentic' |
110 |
- |