0001-environment-store-local-hobo-info-in-Hobo-model-6057.patch
hobo/agent/hobo/management/commands/hobo_deploy.py | ||
---|---|---|
24 | 24 |
if me.get('secondary'): |
25 | 25 |
# check we are currently processing the primary hobo, we don't |
26 | 26 |
# want to create secondary services on every branches. |
27 |
if Hobo.objects.filter(secondary=False).count() == 0: |
|
27 |
if Hobo.objects.filter(secondary=False, emitter=False).count() == 0:
|
|
28 | 28 |
return |
29 | 29 |
is_primary_hobo = True |
30 | 30 |
# on the primary hobo, notify other primary services, this will |
hobo/environment/migrations/0022_emitter.py | ||
---|---|---|
1 |
# Generated by Django 2.2.24 on 2022-01-17 15:41 |
|
2 | ||
3 |
from django.db import migrations, models |
|
4 | ||
5 | ||
6 |
class Migration(migrations.Migration): |
|
7 | ||
8 |
dependencies = [ |
|
9 |
('environment', '0021_base_url_validators'), |
|
10 |
] |
|
11 | ||
12 |
operations = [ |
|
13 |
migrations.AddField( |
|
14 |
model_name='hobo', |
|
15 |
name='emitter', |
|
16 |
field=models.BooleanField(default=False), |
|
17 |
), |
|
18 |
] |
hobo/environment/models.py | ||
---|---|---|
459 | 459 |
service_label = _('Deployment Server') |
460 | 460 |
service_default_slug = 'hobo' |
461 | 461 | |
462 |
emitter = models.BooleanField(default=False) |
|
463 | ||
462 | 464 |
def get_admin_zones(self): |
463 | 465 |
return [Zone(self.title, 'hobo', self.get_base_url_path())] |
464 | 466 | |
... | ... | |
466 | 468 |
return self.get_base_url_path() + 'accounts/mellon/metadata/' |
467 | 469 | |
468 | 470 |
def get_backoffice_menu_url(self): |
469 |
return None |
|
471 |
return self.get_base_url_path() + 'menu.json' |
|
472 | ||
473 |
def as_dict(self): |
|
474 |
res = super().as_dict() |
|
475 |
del res['emitter'] |
|
476 |
if self.emitter: |
|
477 |
del res['id'] |
|
478 |
del res['secret_key'] |
|
479 |
del res['secondary'] |
|
480 |
del res['service-label'] |
|
481 |
del res['template_name'] |
|
482 |
del res['variables'] |
|
483 |
return res |
|
470 | 484 | |
471 | 485 | |
472 | 486 |
class BiJoe(ServiceBase): |
hobo/environment/utils.py | ||
---|---|---|
28 | 28 | |
29 | 29 | |
30 | 30 |
def get_installed_services(): |
31 |
from .models import AVAILABLE_SERVICES |
|
31 |
from .models import AVAILABLE_SERVICES, Hobo
|
|
32 | 32 | |
33 | 33 |
installed_services = [] |
34 | 34 |
for available_service in AVAILABLE_SERVICES: |
35 |
installed_services.extend(available_service.objects.all()) |
|
35 |
if available_service is Hobo: |
|
36 |
installed_services.extend(available_service.objects.filter(emitter=False)) |
|
37 |
else: |
|
38 |
installed_services.extend(available_service.objects.all()) |
|
36 | 39 |
return installed_services |
37 | 40 | |
38 | 41 | |
... | ... | |
46 | 49 |
return KnownServices.shared_secret(secret1, secret2)[:40] |
47 | 50 | |
48 | 51 | |
52 |
def get_or_create_local_hobo(): |
|
53 |
from .models import Hobo |
|
54 | ||
55 |
try: |
|
56 |
hobo = Hobo.objects.get(emitter=True) |
|
57 |
except Hobo.DoesNotExist: |
|
58 |
build_absolute_uri = None |
|
59 |
if hasattr(connection, 'get_tenant') and hasattr(connection.get_tenant(), 'build_absolute_uri'): |
|
60 |
build_absolute_uri = connection.get_tenant().build_absolute_uri |
|
61 |
else: |
|
62 |
request = StoreRequestMiddleware.get_request() |
|
63 |
if request: |
|
64 |
build_absolute_uri = request.build_absolute_uri |
|
65 |
if not build_absolute_uri: |
|
66 |
return None |
|
67 | ||
68 |
hobo = Hobo.objects.create( |
|
69 |
secret_key=get_local_key(build_absolute_uri('/')), |
|
70 |
title='Hobo', |
|
71 |
slug='hobo', |
|
72 |
base_url=build_absolute_uri(reverse('home')), |
|
73 |
secondary=False, |
|
74 |
emitter=True, |
|
75 |
) |
|
76 | ||
77 |
return hobo |
|
78 | ||
79 | ||
49 | 80 |
def get_local_hobo_dict(): |
50 |
build_absolute_uri = None |
|
51 |
if hasattr(connection, 'get_tenant') and hasattr(connection.get_tenant(), 'build_absolute_uri'): |
|
52 |
build_absolute_uri = connection.get_tenant().build_absolute_uri |
|
53 |
else: |
|
54 |
request = StoreRequestMiddleware.get_request() |
|
55 |
if request: |
|
56 |
build_absolute_uri = request.build_absolute_uri |
|
57 |
if not build_absolute_uri: |
|
58 |
return None |
|
59 |
# if there's a known base url hobo can advertise itself. |
|
60 |
return { |
|
61 |
'secret_key': get_local_key(build_absolute_uri('/')), |
|
62 |
'service-id': 'hobo', |
|
63 |
'title': 'Hobo', |
|
64 |
'slug': 'hobo', |
|
65 |
'base_url': build_absolute_uri(reverse('home')), |
|
66 |
'saml-sp-metadata-url': build_absolute_uri(reverse('mellon_metadata')), |
|
67 |
'backoffice-menu-url': build_absolute_uri(reverse('menu_json')), |
|
68 |
'provisionning-url': build_absolute_uri('/__provision__/'), |
|
69 |
} |
|
81 |
hobo = get_or_create_local_hobo() |
|
82 |
if hobo: |
|
83 |
return hobo.as_dict() |
|
84 |
return None |
|
70 | 85 | |
71 | 86 | |
72 | 87 |
def get_installed_services_dict(): |
73 |
- |