Revert "environment: store local hobo info in Hobo model (#60572)"

This reverts commit 00f897753b.
This commit is contained in:
Frédéric Péters 2022-02-18 08:28:27 +01:00
parent f8c4071994
commit 700e91af3d
6 changed files with 25 additions and 120 deletions

View File

@ -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, local=False).count() == 0:
if Hobo.objects.filter(secondary=False).count() == 0:
return
is_primary_hobo = True
# on the primary hobo, notify other primary services, this will

View File

@ -1,18 +0,0 @@
# Generated by Django 2.2.24 on 2022-02-15 10:33
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('environment', '0021_base_url_validators'),
]
operations = [
migrations.AddField(
model_name='hobo',
name='local',
field=models.BooleanField(default=False),
),
]

View File

@ -1,43 +0,0 @@
# Generated by Django 2.2.24 on 2022-02-15 10:36
from django.db import connection, migrations
from django.urls import reverse
from hobo.environment.utils import get_local_key
def populate_local_hobo(apps, schema_editor):
Hobo = apps.get_model('environment', 'Hobo')
try:
Hobo.objects.get(local=True)
return
except Hobo.DoesNotExist:
pass
if hasattr(connection, 'get_tenant'):
build_absolute_uri = getattr(connection.get_tenant(), 'build_absolute_uri', None)
if build_absolute_uri:
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,
)
def clean_local_hobo(apps, schema_editor):
Hobo = apps.get_model('environment', 'Hobo')
Hobo.objects.filter(local=True).delete()
class Migration(migrations.Migration):
dependencies = [
('environment', '0022_local_hobo'),
]
operations = [
migrations.RunPython(populate_local_hobo, clean_local_hobo),
]

View File

@ -459,11 +459,6 @@ class Hobo(ServiceBase):
service_label = _('Deployment Server')
service_default_slug = 'hobo'
# historically an hobo instance did not store information about itself,
# it only stored info about other hobo's.
# now we also store info about an instance on the instance itself, via local=True
local = models.BooleanField(default=False)
def get_admin_zones(self):
return [Zone(self.title, 'hobo', self.get_base_url_path())]
@ -471,19 +466,7 @@ class Hobo(ServiceBase):
return self.get_base_url_path() + 'accounts/mellon/metadata/'
def get_backoffice_menu_url(self):
return self.get_base_url_path() + 'menu.json'
def as_dict(self):
res = super().as_dict()
del res['local']
if self.local:
del res['id']
del res['secret_key']
del res['secondary']
del res['service-label']
del res['template_name']
del res['variables']
return res
return None
class BiJoe(ServiceBase):

View File

@ -28,16 +28,13 @@ from hobo.profile.utils import get_profile_dict
def get_installed_services(types=None):
from .models import AVAILABLE_SERVICES, Hobo
from .models import AVAILABLE_SERVICES
installed_services = []
for available_service in AVAILABLE_SERVICES:
if types and available_service.Extra.service_id not in types:
continue
if available_service is Hobo:
installed_services.extend(available_service.objects.filter(local=False))
else:
installed_services.extend(available_service.objects.all())
installed_services.extend(available_service.objects.all())
return installed_services
@ -51,39 +48,27 @@ 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():
hobo = get_or_create_local_hobo()
if hobo:
return hobo.as_dict()
return None
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__/'),
}
def get_installed_services_dict():

View File

@ -88,9 +88,7 @@ def test_multipublik(tenants, mocker):
# (no service creation recursion)
HoboDeployCommand().handle(hobo2.base_url, get_hobo_json_filename(hobo1))
with tenant_context(hobo2):
# +1 on hobo since we last checked because the local hobo
# is not stored in DB until the first hobo_json is generated
assert Hobo.objects.filter().count() == 3
assert Hobo.objects.filter().count() == 2
assert Hobo.objects.filter(secondary=True).count() == 2
assert Combo.objects.filter().count() == 2
assert Combo.objects.filter(secondary=True).count() == 1