environment: store local hobo info in Hobo model (#61944)
This commit is contained in:
parent
003b15204f
commit
577438f7fa
|
@ -24,7 +24,7 @@ class Command(hobo_deploy.Command):
|
|||
if me.get('secondary'):
|
||||
# check we are currently processing the primary hobo, we don't
|
||||
# want to create secondary services on every branches.
|
||||
if Hobo.objects.filter(secondary=False).count() == 0:
|
||||
if Hobo.objects.filter(secondary=False, local=False).count() == 0:
|
||||
return
|
||||
is_primary_hobo = True
|
||||
# on the primary hobo, notify other primary services, this will
|
||||
|
|
|
@ -471,8 +471,20 @@ class Hobo(ServiceBase):
|
|||
return self.get_base_url_path() + 'accounts/mellon/metadata/'
|
||||
|
||||
def get_backoffice_menu_url(self):
|
||||
if self.local:
|
||||
return self.get_base_url_path() + 'menu.json'
|
||||
return None
|
||||
|
||||
def as_dict(self):
|
||||
res = super().as_dict()
|
||||
if self.local:
|
||||
del res['id']
|
||||
del res['secondary']
|
||||
del res['service-label']
|
||||
del res['template_name']
|
||||
del res['variables']
|
||||
return res
|
||||
|
||||
|
||||
class BiJoe(ServiceBase):
|
||||
class Meta:
|
||||
|
|
|
@ -28,13 +28,16 @@ from hobo.profile.utils import get_profile_dict
|
|||
|
||||
|
||||
def get_installed_services(types=None):
|
||||
from .models import AVAILABLE_SERVICES
|
||||
from .models import AVAILABLE_SERVICES, Hobo
|
||||
|
||||
installed_services = []
|
||||
for available_service in AVAILABLE_SERVICES:
|
||||
if types and available_service.Extra.service_id not in types:
|
||||
continue
|
||||
installed_services.extend(available_service.objects.all())
|
||||
if available_service is Hobo:
|
||||
installed_services.extend(available_service.objects.filter(local=False))
|
||||
else:
|
||||
installed_services.extend(available_service.objects.all())
|
||||
return installed_services
|
||||
|
||||
|
||||
|
@ -48,27 +51,40 @@ def get_local_key(url):
|
|||
return KnownServices.shared_secret(secret1, secret2)[:40]
|
||||
|
||||
|
||||
def get_or_create_local_hobo():
|
||||
from .models import Hobo
|
||||
|
||||
try:
|
||||
hobo = Hobo.objects.get(local=True)
|
||||
except Hobo.DoesNotExist:
|
||||
build_absolute_uri = None
|
||||
if hasattr(connection, 'get_tenant') and hasattr(connection.get_tenant(), 'build_absolute_uri'):
|
||||
build_absolute_uri = connection.get_tenant().build_absolute_uri
|
||||
else:
|
||||
request = StoreRequestMiddleware.get_request()
|
||||
if request:
|
||||
build_absolute_uri = request.build_absolute_uri
|
||||
|
||||
if not build_absolute_uri:
|
||||
return None
|
||||
|
||||
hobo = Hobo.objects.create(
|
||||
secret_key=get_local_key(build_absolute_uri('/')),
|
||||
title='Hobo',
|
||||
slug='hobo',
|
||||
base_url=build_absolute_uri(reverse('home')),
|
||||
secondary=False,
|
||||
local=True,
|
||||
)
|
||||
|
||||
return hobo
|
||||
|
||||
|
||||
def get_local_hobo_dict():
|
||||
build_absolute_uri = None
|
||||
if hasattr(connection, 'get_tenant') and hasattr(connection.get_tenant(), 'build_absolute_uri'):
|
||||
build_absolute_uri = connection.get_tenant().build_absolute_uri
|
||||
else:
|
||||
request = StoreRequestMiddleware.get_request()
|
||||
if request:
|
||||
build_absolute_uri = request.build_absolute_uri
|
||||
if not build_absolute_uri:
|
||||
return None
|
||||
# if there's a known base url hobo can advertise itself.
|
||||
return {
|
||||
'secret_key': get_local_key(build_absolute_uri('/')),
|
||||
'service-id': 'hobo',
|
||||
'title': 'Hobo',
|
||||
'slug': 'hobo',
|
||||
'base_url': build_absolute_uri(reverse('home')),
|
||||
'saml-sp-metadata-url': build_absolute_uri(reverse('mellon_metadata')),
|
||||
'backoffice-menu-url': build_absolute_uri(reverse('menu_json')),
|
||||
'provisionning-url': build_absolute_uri('/__provision__/'),
|
||||
}
|
||||
hobo = get_or_create_local_hobo()
|
||||
if hobo:
|
||||
return hobo.as_dict()
|
||||
return None
|
||||
|
||||
|
||||
def get_installed_services_dict():
|
||||
|
|
|
@ -233,7 +233,7 @@ def test_multipublik(tenants, mocker):
|
|||
assert combo.base_url == 'http://combo1.example.net/'
|
||||
assert combo.secondary is True
|
||||
|
||||
assert Hobo.objects.count() == 2
|
||||
assert Hobo.objects.count() == 3
|
||||
# interco hobo
|
||||
hobo = Hobo.objects.get(slug='_interco_hobo')
|
||||
assert hobo.title == 'Hobo'
|
||||
|
@ -274,7 +274,7 @@ def test_multipublik(tenants, mocker):
|
|||
# (no service creation recursion)
|
||||
HoboDeployCommand().handle(hobo2.base_url, get_hobo_json_filename(hobo1))
|
||||
with tenant_context(hobo2):
|
||||
assert Hobo.objects.filter().count() == 2
|
||||
assert Hobo.objects.filter().count() == 3
|
||||
assert Hobo.objects.filter(secondary=True).count() == 2
|
||||
assert Combo.objects.filter().count() == 2
|
||||
assert Combo.objects.filter(secondary=True).count() == 1
|
||||
|
@ -302,7 +302,7 @@ def test_multipublik(tenants, mocker):
|
|||
assert combo.base_url == 'http://combo1.example.net/'
|
||||
assert combo.secondary is True
|
||||
|
||||
assert Hobo.objects.count() == 2
|
||||
assert Hobo.objects.count() == 3
|
||||
# interco hobo
|
||||
hobo = Hobo.objects.get(slug='_interco_hobo')
|
||||
assert hobo.title == 'Hobo'
|
||||
|
|
|
@ -155,7 +155,8 @@
|
|||
"secret_key": "XXX",
|
||||
"service-id": "hobo",
|
||||
"slug": "hobo",
|
||||
"title": "Hobo"
|
||||
"title": "Hobo",
|
||||
"local": true
|
||||
},
|
||||
{
|
||||
"backoffice-menu-url": "https://connexion-instance-name.dev.signalpublik.com/manage/menu.json",
|
||||
|
|
Loading…
Reference in New Issue