diff --git a/docker/setup_configuration/data.yaml b/docker/setup_configuration/data.yaml index 34766a54..2c732bd1 100644 --- a/docker/setup_configuration/data.yaml +++ b/docker/setup_configuration/data.yaml @@ -34,15 +34,3 @@ vng_api_common_credentials: # Credentials for Open Notificaties, required for autorisaties subscription - identifier: open-notificaties secret: oPMsHCEuoP9Qh8vP06D7 - -# notifications_config_enable: True -# notifications_config: -# notifications_api_service_identifier: notificaties-api -# notification_delivery_max_retries: 5 -# notification_delivery_retry_backoff: 3 -# notification_delivery_retry_backoff_max: 30 - -# site_config_enable: True -# site_config: -# domain: localhost:8001 -# organization: Demodam diff --git a/docs/installation/configuration/env_config.rst b/docs/installation/configuration/env_config.rst index ebb79cec..4eca0904 100644 --- a/docs/installation/configuration/env_config.rst +++ b/docs/installation/configuration/env_config.rst @@ -110,7 +110,6 @@ Optional * ``LOG_OUTGOING_REQUESTS_MAX_AGE``: The amount of time after which request logs should be deleted from the database. Defaults to: ``7``. * ``SENTRY_DSN``: URL of the sentry project to send error reports to. Default empty, i.e. -> no monitoring set up. Highly recommended to configure this. * ``EXTRA_VERIFY_CERTS``: a comma-separated list of paths to certificates to trust, If you're using self-signed certificates for the services that Open Notificaties communicates with, specify the path to those (root) certificates here, rather than disabling SSL certificate verification. Example: ``EXTRA_VERIFY_CERTS=/etc/ssl/root1.crt,/etc/ssl/root2.crt``. Defaults to: ``(empty string)``. -* ``OPENNOTIFICATIES_DOMAIN``: The domain for this Open Notificaties instance (``[host]:[port]`` or ``[host]``). Defaults to: ``(empty string)``. diff --git a/src/nrc/conf/includes/base.py b/src/nrc/conf/includes/base.py index cd5598c5..404db3e2 100644 --- a/src/nrc/conf/includes/base.py +++ b/src/nrc/conf/includes/base.py @@ -135,10 +135,6 @@ "zgw_consumers.contrib.setup_configuration.steps.ServiceConfigurationStep", "vng_api_common.contrib.setup_configuration.steps.JWTSecretsConfigurationStep", "nrc.setup_configuration.authorization.AuthorizationStep", - # TODO these need to be implemented later - # "notifications_api_common.contrib.setup_configuration.steps.NotificationConfigurationStep", - # TODO this should be moved to `django-setup-configuration` - # "nrc.config.site.SiteConfigurationStep", ] # @@ -156,13 +152,3 @@ "``EXTRA_VERIFY_CERTS=/etc/ssl/root1.crt,/etc/ssl/root2.crt``." ), ) - -# -# Open Notificaties settings -# - -OPENNOTIFICATIES_DOMAIN = config( - "OPENNOTIFICATIES_DOMAIN", - "", - help_text="The domain for this Open Notificaties instance (``[host]:[port]`` or ``[host]``)", -) diff --git a/src/nrc/setup_configuration/models.py b/src/nrc/setup_configuration/models.py index 6aa6e6d5..dec101c6 100644 --- a/src/nrc/setup_configuration/models.py +++ b/src/nrc/setup_configuration/models.py @@ -1,8 +1,5 @@ -from django.contrib.sites.models import Site - from django_setup_configuration.fields import DjangoModelRef from django_setup_configuration.models import ConfigurationModel -from pydantic import Field from vng_api_common.authorizations.models import AuthorizationsConfig @@ -10,11 +7,3 @@ class AuthorizationsConfigModel(ConfigurationModel): authorizations_api_service_identifier: str = DjangoModelRef( AuthorizationsConfig, "authorizations_api_service" ) - - -class SiteConfigModel(ConfigurationModel): - organization: str = Field() - """The name of the organization that owns this Open Notificaties instance""" - - class Meta: - django_model_refs = {Site: ("domain",)} diff --git a/src/nrc/setup_configuration/site.py b/src/nrc/setup_configuration/site.py deleted file mode 100644 index e472982f..00000000 --- a/src/nrc/setup_configuration/site.py +++ /dev/null @@ -1,24 +0,0 @@ -from django.contrib.sites.models import Site - -from django_setup_configuration.configuration import BaseConfigurationStep - -from .models import SiteConfigModel - - -class SiteConfigurationStep(BaseConfigurationStep[SiteConfigModel]): - """ - Configure the application site/domain. - - **NOTE:** Site configuration will be depreciated - """ - - verbose_name = "Site Configuration" - config_model = SiteConfigModel - namespace = "site_config" - enable_setting = "site_config_enable" - - def execute(self, model: SiteConfigModel) -> None: - site = Site.objects.get_current() - site.domain = model.domain - site.name = f"Open Notificaties {model.organization}".strip() - site.save() diff --git a/src/nrc/tests/commands/files/setup_config_full.yaml b/src/nrc/tests/commands/files/setup_config_full.yaml deleted file mode 100644 index e65f118c..00000000 --- a/src/nrc/tests/commands/files/setup_config_full.yaml +++ /dev/null @@ -1,37 +0,0 @@ -zgw_consumers_config_enable: True -zgw_consumers: - services: - - identifier: autorisaties-api - label: Objecttypen API test - api_root: http://localhost:8001/autorisaties/api/v1/ - api_type: ac - auth_type: zgw - client_id: open-notificaties - secret: oPMsHCEuoP9Qh8vP06D7 - user_id: open-notificaties - user_representation: Open Notificaties Demodam - -autorisaties_api_config_enable: True -autorisaties_api: - # Configure Open Notificaties to make use of Open Zaak's Autorisaties API - authorizations_api_service_identifier: autorisaties-api - -vng_api_common_credentials_config_enable: True -vng_api_common_credentials: - items: - # Credentials for Open Zaak to be able to make requests to Open Notificaties - - identifier: open-zaak - secret: G2LIVfXal1J93puQkV3O - -# notifications_config_enable: True -# notifications_config: -# # No notifications_api_service necessary, because Open Notificaties doesn't send -# # notifications to itself -# notification_delivery_max_retries: 5 -# notification_delivery_retry_backoff: 3 -# notification_delivery_retry_backoff_max: 30 - -# site_config_enable: True -# site_config: -# domain: opennotificaties.local:8000 -# organization: Demodam diff --git a/src/nrc/tests/commands/test_setup_configuration.py b/src/nrc/tests/commands/test_setup_configuration.py deleted file mode 100644 index 532d17bd..00000000 --- a/src/nrc/tests/commands/test_setup_configuration.py +++ /dev/null @@ -1,120 +0,0 @@ -import uuid -from io import StringIO -from pathlib import Path - -from django.contrib.sites.models import Site -from django.core.management import call_command -from django.test import TestCase -from django.urls import reverse - -import requests_mock -from jwt import decode -from rest_framework import status -from vng_api_common.authorizations.models import AuthorizationsConfig -from vng_api_common.authorizations.utils import generate_jwt -from vng_api_common.contrib.setup_configuration.steps import JWTSecretsConfigurationStep -from zgw_consumers.contrib.setup_configuration.steps import ServiceConfigurationStep - -from nrc.setup_configuration.authorization import AuthorizationStep - -CONFIG_FILE_PATH = Path("src/nrc/tests/commands/files/setup_config_full.yaml").resolve() - - -class SetupConfigurationTests(TestCase): - maxDiff = None - - def setUp(self): - super().setUp() - - self.addCleanup(Site.objects.clear_cache) - - @requests_mock.Mocker() - def test_setup_configuration(self, m): - stdout = StringIO() - # mocks - _uuid = uuid.uuid4() - m.get("http://opennotificaties.local:8000/", status_code=200) - m.get("http://opennotificaties.local:8000/api/v1/kanaal", json=[]) - m.get( - "http://localhost:8001/autorisaties/api/v1/applicaties", - json={ - "count": 1, - "results": [ - { - "url": f"http://localhost:8001/autorisaties/api/v1/applicaties/{_uuid}", - "clientIds": ["oz-client-id"], - "label": "OZ for ON", - "heeftAlleAutorisaties": True, - "autorisaties": [], - } - ], - }, - ) - - call_command( - "setup_configuration", - yaml_file=CONFIG_FILE_PATH, - stdout=stdout, - no_color=True, - ) - - with self.subTest("Command output"): - command_output = stdout.getvalue().splitlines() - expected_output = [ - f"Loading config settings from {CONFIG_FILE_PATH}", - "The following steps are configured:", - f"{ServiceConfigurationStep()}", - f"{JWTSecretsConfigurationStep()}", - f"{AuthorizationStep()}", - # f"{NotificationConfigurationStep()}", - # f"{SiteConfigurationStep()}", - "Executing steps...", - f"Successfully executed step: {ServiceConfigurationStep()}", - f"Successfully executed step: {JWTSecretsConfigurationStep()}", - f"Successfully executed step: {AuthorizationStep()}", - # f"Successfully executed step: {NotificationConfigurationStep()}", - # f"Successfully executed step: {SiteConfigurationStep()}", - "Instance configuration completed.", - ] - - self.assertEqual(command_output, expected_output) - - with self.subTest("Authorization API client configured correctly"): - ac_client = AuthorizationsConfig.get_client() - self.assertIsNotNone(ac_client) - - ac_client.get("applicaties") - - create_call = m.last_request - self.assertEqual( - create_call.url, - "http://localhost:8001/autorisaties/api/v1/applicaties", - ) - self.assertIn("Authorization", create_call.headers) - - header_jwt = create_call.headers["Authorization"].split(" ")[1] - decoded_jwt = decode(header_jwt, options={"verify_signature": False}) - - self.assertEqual(decoded_jwt["client_id"], "open-notificaties") - - with self.subTest("Open Zaak can query Notification API"): - token = generate_jwt("open-zaak", "G2LIVfXal1J93puQkV3O", "", "") - - response = self.client.get( - reverse("kanaal-list", kwargs={"version": 1}), - HTTP_AUTHORIZATION=token, - ) - - self.assertEqual(response.status_code, status.HTTP_200_OK) - - # with self.subTest("Notifications configured correctly"): - # config = NotificationsConfig.get_solo() - # self.assertEqual(config.notifications_api_service, None) - # self.assertEqual(config.notification_delivery_max_retries, 5) - # self.assertEqual(config.notification_delivery_retry_backoff, 3) - # self.assertEqual(config.notification_delivery_retry_backoff_max, 30) - - # with self.subTest("Site configured correctly"): - # site = Site.objects.get_current() - # self.assertEqual(site.domain, "opennotificaties.local:8000") - # self.assertEqual(site.name, "Open Notificaties Demodam") diff --git a/src/nrc/tests/setup_configuration/files/setup_config_sites.yaml b/src/nrc/tests/setup_configuration/files/setup_config_sites.yaml deleted file mode 100644 index 32ab4db5..00000000 --- a/src/nrc/tests/setup_configuration/files/setup_config_sites.yaml +++ /dev/null @@ -1,4 +0,0 @@ -site_config_enable: True -site_config: - domain: opennotificaties.local:8000 - organization: Demodam diff --git a/src/nrc/tests/setup_configuration/test_authorization_configuration.py b/src/nrc/tests/setup_configuration/test_authorization_configuration.py index dd04f2d7..95398147 100644 --- a/src/nrc/tests/setup_configuration/test_authorization_configuration.py +++ b/src/nrc/tests/setup_configuration/test_authorization_configuration.py @@ -6,7 +6,9 @@ from nrc.setup_configuration.authorization import AuthorizationStep -CONFIG_FILE_PATH = "src/nrc/tests/config/files/setup_config_auth_config.yaml" +CONFIG_FILE_PATH = ( + "src/nrc/tests/setup_configuration/files/setup_config_auth_config.yaml" +) class AuthorizationConfigurationTests(TestCase): diff --git a/src/nrc/tests/setup_configuration/test_site_configuration.py b/src/nrc/tests/setup_configuration/test_site_configuration.py deleted file mode 100644 index 29e73489..00000000 --- a/src/nrc/tests/setup_configuration/test_site_configuration.py +++ /dev/null @@ -1,51 +0,0 @@ -from django.contrib.sites.models import Site -from django.test import TestCase - -from django_setup_configuration.test_utils import execute_single_step - -from nrc.setup_configuration.site import SiteConfigurationStep - -CONFIG_FILE_PATH = "src/nrc/tests/config/files/setup_config_sites.yaml" - - -class SiteConfigurationTests(TestCase): - def setUp(self): - super().setUp() - - self.addCleanup(Site.objects.clear_cache) - - def test_execute_configuration_step_success(self): - execute_single_step(SiteConfigurationStep, yaml_source=CONFIG_FILE_PATH) - - site = Site.objects.get_current() - - self.assertEqual(site.domain, "opennotificaties.local:8000") - self.assertEqual(site.name, "Open Notificaties Demodam") - - def test_execute_configuration_step_update_existing(self): - site = Site.objects.get_current() - site.domain = "other-domain.local:8000" - site.name = "some other names" - site.save() - - execute_single_step(SiteConfigurationStep, yaml_source=CONFIG_FILE_PATH) - - site = Site.objects.get_current() - - self.assertEqual(site.domain, "opennotificaties.local:8000") - self.assertEqual(site.name, "Open Notificaties Demodam") - - def test_execute_configuration_step_idempotent(self): - def make_assertions(): - site = Site.objects.get_current() - - self.assertEqual(site.domain, "opennotificaties.local:8000") - self.assertEqual(site.name, "Open Notificaties Demodam") - - execute_single_step(SiteConfigurationStep, yaml_source=CONFIG_FILE_PATH) - - make_assertions() - - execute_single_step(SiteConfigurationStep, yaml_source=CONFIG_FILE_PATH) - - make_assertions() diff --git a/src/nrc/utils/__init__.py b/src/nrc/utils/__init__.py index 44cfa3b2..e69de29b 100644 --- a/src/nrc/utils/__init__.py +++ b/src/nrc/utils/__init__.py @@ -1,29 +0,0 @@ -from django.conf import settings -from django.http import HttpRequest - -from furl import furl - - -def get_domain() -> str: - """ - Obtain the domain/netloc of Open Notificaties according to settings or configuration. - """ - from django.contrib.sites.models import Site - - if settings.OPENNOTIFICATIES_DOMAIN: - return settings.OPENNOTIFICATIES_DOMAIN - - return Site.objects.get_current().domain - - -def build_absolute_url(path: str, request: HttpRequest | None = None) -> str: - if request is not None: - return request.build_absolute_uri(path) - - domain = get_domain() - _furl = furl( - scheme="https" if settings.IS_HTTPS else "http", - netloc=domain, - path=path, - ) - return _furl.url