From 48cb351263ff788332727c7ba09969b47b6933f9 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 30 Jan 2025 10:20:53 +0100 Subject: [PATCH 1/6] add key for open service --- idhub/management/commands/open_service.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 idhub/management/commands/open_service.py diff --git a/idhub/management/commands/open_service.py b/idhub/management/commands/open_service.py new file mode 100644 index 0000000..1cc04d6 --- /dev/null +++ b/idhub/management/commands/open_service.py @@ -0,0 +1,15 @@ +from django.core.management.base import BaseCommand +from django.core.management import call_command +from django.core.cache import cache + + +class Command(BaseCommand): + help = "Command for open de service" + + def add_arguments(self, parser): + parser.add_argument('key', nargs='?', default='', type=str, help='key') + + def handle(self, *args, **kwargs): + PASSWORD = kwargs["key"] + cache.set("KEY_DIDS", PASSWORD, None) + call_command('runserver') From 7155a309b5438618aa1d2a302f65acef5e368487 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 30 Jan 2025 10:37:50 +0100 Subject: [PATCH 2/6] fix flow for a bad key --- idhub/management/commands/open_service.py | 29 +++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/idhub/management/commands/open_service.py b/idhub/management/commands/open_service.py index 1cc04d6..dd15c5c 100644 --- a/idhub/management/commands/open_service.py +++ b/idhub/management/commands/open_service.py @@ -1,7 +1,15 @@ +import logging + +from nacl.exceptions import CryptoError from django.core.management.base import BaseCommand from django.core.management import call_command from django.core.cache import cache +from idhub.models import DID + + +logger = logging.getLogger(__name__) + class Command(BaseCommand): help = "Command for open de service" @@ -10,6 +18,23 @@ class Command(BaseCommand): parser.add_argument('key', nargs='?', default='', type=str, help='key') def handle(self, *args, **kwargs): - PASSWORD = kwargs["key"] - cache.set("KEY_DIDS", PASSWORD, None) + self._key = kwargs["key"] + cache.set("KEY_DIDS", self._key, None) + + if not DID.objects.exists(): + cache.set("KEY_DIDS", self._key, None) + call_command('runserver') + return + + did = DID.objects.first() + cache.set("KEY_DIDS", self._key, None) + try: + did.get_key_material() + except CryptoError: + cache.set("KEY_DIDS", None) + txt = "Key no valid!" + logger.error(txt) + return + + cache.set("KEY_DIDS", self._key, None) call_command('runserver') From c45f8ff530e4b93ced494338ed16ddf15f23f983 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 30 Jan 2025 12:57:31 +0100 Subject: [PATCH 3/6] fix port and ip --- idhub/management/commands/open_service.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/idhub/management/commands/open_service.py b/idhub/management/commands/open_service.py index dd15c5c..8b1e112 100644 --- a/idhub/management/commands/open_service.py +++ b/idhub/management/commands/open_service.py @@ -16,14 +16,16 @@ class Command(BaseCommand): def add_arguments(self, parser): parser.add_argument('key', nargs='?', default='', type=str, help='key') + parser.add_argument('ip_port', nargs='?', default='', type=str, help='ip_port') def handle(self, *args, **kwargs): self._key = kwargs["key"] + self.p_port = kwargs["ip_port"] cache.set("KEY_DIDS", self._key, None) if not DID.objects.exists(): cache.set("KEY_DIDS", self._key, None) - call_command('runserver') + call_command('runserver', self.ip_port) return did = DID.objects.first() @@ -37,4 +39,4 @@ class Command(BaseCommand): return cache.set("KEY_DIDS", self._key, None) - call_command('runserver') + call_command('runserver', self.ip_port) From 3b7fbaf99c160a0bdf3ead9c229db3dc01f2f809 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 30 Jan 2025 13:01:28 +0100 Subject: [PATCH 4/6] fix name --- idhub/management/commands/open_service.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/idhub/management/commands/open_service.py b/idhub/management/commands/open_service.py index 8b1e112..91c08f7 100644 --- a/idhub/management/commands/open_service.py +++ b/idhub/management/commands/open_service.py @@ -20,7 +20,7 @@ class Command(BaseCommand): def handle(self, *args, **kwargs): self._key = kwargs["key"] - self.p_port = kwargs["ip_port"] + self.ip_port = kwargs["ip_port"] cache.set("KEY_DIDS", self._key, None) if not DID.objects.exists(): From e25b68035df6f269cad52a0b9878a2545655d699 Mon Sep 17 00:00:00 2001 From: pedro Date: Thu, 30 Jan 2025 13:03:42 +0100 Subject: [PATCH 5/6] demo purpose: use open_service --- docker/idhub.entrypoint.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/docker/idhub.entrypoint.sh b/docker/idhub.entrypoint.sh index b7ebd78..bf076b0 100755 --- a/docker/idhub.entrypoint.sh +++ b/docker/idhub.entrypoint.sh @@ -45,10 +45,11 @@ deployment_strategy() { echo "INFO detected NEW deployment" ./manage.py migrate - printf "This is DEVELOPMENT/PILOTS_EARLY DEPLOYMENT: including demo hardcoded data\n" >&2 - - PREDEFINED_TOKEN="${PREDEFINED_TOKEN:-}" - ./manage.py demo_data "${PREDEFINED_TOKEN}" + if [ "${DEMO:-}" = 'true' ]; then + printf "This is DEVELOPMENT/PILOTS_EARLY DEPLOYMENT: including demo hardcoded data\n" >&2 + PREDEFINED_TOKEN="${PREDEFINED_TOKEN:-}" + ./manage.py demo_data "${PREDEFINED_TOKEN}" + fi if [ "${OIDC_ORGS:-}" ]; then config_oidc4vp From f39061206fca3bf144e7761d4a96e5e46f19984c Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 30 Jan 2025 13:19:32 +0100 Subject: [PATCH 6/6] accept gdpr for admin --- idhub/management/commands/open_service.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/idhub/management/commands/open_service.py b/idhub/management/commands/open_service.py index 91c08f7..95ec093 100644 --- a/idhub/management/commands/open_service.py +++ b/idhub/management/commands/open_service.py @@ -6,6 +6,7 @@ from django.core.management import call_command from django.core.cache import cache from idhub.models import DID +from idhub_auth.models import User logger = logging.getLogger(__name__) @@ -23,6 +24,10 @@ class Command(BaseCommand): self.ip_port = kwargs["ip_port"] cache.set("KEY_DIDS", self._key, None) + admin = User.objects.filter(is_admin=True).first() + admin.accept_gdpr = True + admin.save() + if not DID.objects.exists(): cache.set("KEY_DIDS", self._key, None) call_command('runserver', self.ip_port) @@ -30,6 +35,7 @@ class Command(BaseCommand): did = DID.objects.first() cache.set("KEY_DIDS", self._key, None) + try: did.get_key_material() except CryptoError: