diff --git a/docker/setup_configuration/data.yaml b/docker/setup_configuration/data.yaml index 4691e1e6..3853ff5f 100644 --- a/docker/setup_configuration/data.yaml +++ b/docker/setup_configuration/data.yaml @@ -4,19 +4,12 @@ sites_config: - domain: example.com name: Example site -objects_api_objecttypes_connection_config_enable: true -objects_api_objecttypes_connection: - identifier: objecttypes-api - label: Objecttypen API - api_root: https://objecttypes.nl/api/v1/ - api_connection_check_path: objecttypes - api_type: orc - auth_type: zgw - header_key: Authorization - header_value: Token foo - client_id: client - secret: secret - nlx: http://some-outway-adress.local:8080/ - user_id: objects-api - user_representation: Objects API - timeout: 60 +zgw_consumers_config_enable: true +zgw_consumers: + services: + - identifier: objecttypes-api + label: Objecttypes API + api_root: http://objecttypes.local/api/v1/ + api_connection_check_path: objecttypes + api_type: orc + auth_type: api_key diff --git a/docs/installation/config_cli.rst b/docs/installation/config_cli.rst index c6504f7c..46d76a15 100644 --- a/docs/installation/config_cli.rst +++ b/docs/installation/config_cli.rst @@ -54,21 +54,28 @@ Create or update a (single) YAML configuration file with your settings: Objecttypes connection configuration ------------------------- -Create or update a (single) YAML configuration file with your settings: +In order to be able to retrieve objecttypes, a corresponding ``Service`` should be +created. An example of a configuration could be seen below: .. code-block:: yaml - objects_api_objecttypes_connection_config_enable: true - objects_api_objecttypes_connection: - identifier: objecttypen - label: ObjectTypen API - api_root: http://objecttypen.nl/api/v1/ - api_connection_check_path: objecttypes - api_type: orc - auth_type: api_key - header_key: Authorization - header_value: Token foo ... + zgw_consumers_config_enable: true + zgw_consumers: + services: + - identifier: objecttypes-api-1 + label: Objecttypes API 1 + api_root: http://objecttypes-1.local/api/v1/ + api_connection_check_path: objecttypes + api_type: orc + auth_type: api_key + - identifier: objecttypes-api-2 + label: Objecttypes API 2 + api_root: http://objecttypes-2.local/api/v1/ + api_connection_check_path: objecttypes + api_type: orc + auth_type: api_key + .... Execution ========= diff --git a/src/objects/conf/base.py b/src/objects/conf/base.py index 5ad3e3ca..b9bfa55a 100644 --- a/src/objects/conf/base.py +++ b/src/objects/conf/base.py @@ -84,6 +84,6 @@ # Django setup configuration # SETUP_CONFIGURATION_STEPS = ( + "zgw_consumers.contrib.setup_configuration.steps.ServiceConfigurationStep" "objects.setup_configuration.steps.sites.SitesConfigurationStep", - "objects.setup_configuration.steps.objecttypes.ObjectTypesConnectionConfigurationStep", ) diff --git a/src/objects/core/tests/files/objecttypes_connection.yaml b/src/objects/core/tests/files/objecttypes_connection.yaml deleted file mode 100644 index 0cf3177f..00000000 --- a/src/objects/core/tests/files/objecttypes_connection.yaml +++ /dev/null @@ -1,16 +0,0 @@ -objects_api_objecttypes_connection_config_enable: true -objects_api_objecttypes_connection: - identifier: objecttypes-api - label: Objecttypen API - api_root: https://objecttypes.nl/api/v1/ - api_connection_check_path: objecttypes - api_type: orc - auth_type: zgw - header_key: Authorization - header_value: Token foo - client_id: client - secret: secret - nlx: http://some-outway-adress.local:8080/ - user_id: objects-api - user_representation: Objects API - timeout: 60 diff --git a/src/objects/core/tests/files/objecttypes_connection_invalid.yaml b/src/objects/core/tests/files/objecttypes_connection_invalid.yaml deleted file mode 100644 index 6394bed1..00000000 --- a/src/objects/core/tests/files/objecttypes_connection_invalid.yaml +++ /dev/null @@ -1,16 +0,0 @@ -objects_api_objecttypes_connection_config_enable: true -objects_api_objecttypes_connection: - identifier: identifier with whitespace in between - label: Objecttypen API - api_root: https://objecttypes.nl/api/v1/ - api_connection_check_path: objectttypes - api_type: orc - auth_type: zgw - header_key: Authorization - header_value: Token foo - client_id: client - secret: super-secret - nlx: http://some-outway-adress.local:8080/ - user_id: objects-api - user_representation: Objects API - timeout: foobar diff --git a/src/objects/core/tests/test_objecttype_config.py b/src/objects/core/tests/test_objecttype_config.py deleted file mode 100644 index e5751f9a..00000000 --- a/src/objects/core/tests/test_objecttype_config.py +++ /dev/null @@ -1,137 +0,0 @@ -from pathlib import Path - -from django.test import TestCase - -from django_setup_configuration.exceptions import PrerequisiteFailed -from django_setup_configuration.test_utils import execute_single_step -from zgw_consumers.constants import APITypes, AuthTypes -from zgw_consumers.models import Service -from zgw_consumers.test.factories import ServiceFactory - -from objects.setup_configuration.steps.objecttypes import ( - ObjectTypesConnectionConfigurationStep, -) - -TEST_FILES = (Path(__file__).parent / "files").resolve() - - -class ObjectTypesConnectionConfigurationStepTests(TestCase): - def test_create_connection(self): - test_file_path = str(TEST_FILES / "objecttypes_connection.yaml") - - execute_single_step( - ObjectTypesConnectionConfigurationStep, yaml_source=test_file_path - ) - - service = Service.objects.get(slug="objecttypes-api") - - self.assertEqual(service.label, "Objecttypen API") - self.assertEqual(service.api_type, APITypes.orc) - self.assertEqual(service.api_root, "https://objecttypes.nl/api/v1/") - self.assertEqual(service.api_connection_check_path, "objecttypes") - self.assertEqual(service.auth_type, AuthTypes.zgw) - self.assertEqual(service.client_id, "client") - self.assertEqual(service.secret, "secret") - self.assertEqual(service.header_key, "Authorization") - self.assertEqual(service.header_value, "Token foo") - self.assertEqual(service.nlx, "http://some-outway-adress.local:8080/") - self.assertEqual(service.user_id, "objects-api") - self.assertEqual(service.user_representation, "Objects API") - self.assertEqual(service.timeout, 60) - - def test_update_connection(self): - test_file_path = str(TEST_FILES / "objecttypes_connection.yaml") - - service: Service = ServiceFactory( - slug="objecttypes-api", - label="Objecttypen API Test", - api_type=APITypes.zrc, - api_root="https://test.objecttypes.nl/api/v1/", - api_connection_check_path="objecttype", - auth_type=AuthTypes.api_key, - client_id="test-client", - secret="test-secret", - header_key="authorization", - header_value="Token foobar", - nlx="http://test.some-outway-adress.local:8080/", - user_id="test-objects-api", - user_representation="Test Objects API", - timeout=30, - ) - - execute_single_step( - ObjectTypesConnectionConfigurationStep, yaml_source=test_file_path - ) - - self.assertEqual(Service.objects.count(), 1) - - service.refresh_from_db() - - self.assertEqual(service.label, "Objecttypen API") - self.assertEqual(service.api_type, APITypes.orc) - self.assertEqual(service.api_root, "https://objecttypes.nl/api/v1/") - self.assertEqual(service.api_connection_check_path, "objecttypes") - self.assertEqual(service.auth_type, AuthTypes.zgw) - self.assertEqual(service.client_id, "client") - self.assertEqual(service.secret, "secret") - self.assertEqual(service.header_key, "Authorization") - self.assertEqual(service.header_value, "Token foo") - self.assertEqual(service.nlx, "http://some-outway-adress.local:8080/") - self.assertEqual(service.user_id, "objects-api") - self.assertEqual(service.user_representation, "Objects API") - self.assertEqual(service.timeout, 60) - - def test_invalid_connection(self): - test_file_path = str(TEST_FILES / "objecttypes_connection_invalid.yaml") - - with self.assertRaises(PrerequisiteFailed): - execute_single_step( - ObjectTypesConnectionConfigurationStep, yaml_source=test_file_path - ) - - self.assertEqual(Service.objects.count(), 0) - - def test_idempotent_step(self): - test_file_path = str(TEST_FILES / "objecttypes_connection.yaml") - - execute_single_step( - ObjectTypesConnectionConfigurationStep, yaml_source=test_file_path - ) - - service = Service.objects.get(slug="objecttypes-api") - - self.assertEqual(service.label, "Objecttypen API") - self.assertEqual(service.api_type, APITypes.orc) - self.assertEqual(service.api_root, "https://objecttypes.nl/api/v1/") - self.assertEqual(service.api_connection_check_path, "objecttypes") - self.assertEqual(service.auth_type, AuthTypes.zgw) - self.assertEqual(service.client_id, "client") - self.assertEqual(service.secret, "secret") - self.assertEqual(service.header_key, "Authorization") - self.assertEqual(service.header_value, "Token foo") - self.assertEqual(service.nlx, "http://some-outway-adress.local:8080/") - self.assertEqual(service.user_id, "objects-api") - self.assertEqual(service.user_representation, "Objects API") - self.assertEqual(service.timeout, 60) - - execute_single_step( - ObjectTypesConnectionConfigurationStep, yaml_source=test_file_path - ) - - self.assertEqual(Service.objects.count(), 1) - - service.refresh_from_db() - - self.assertEqual(service.label, "Objecttypen API") - self.assertEqual(service.api_type, APITypes.orc) - self.assertEqual(service.api_root, "https://objecttypes.nl/api/v1/") - self.assertEqual(service.api_connection_check_path, "objecttypes") - self.assertEqual(service.auth_type, AuthTypes.zgw) - self.assertEqual(service.client_id, "client") - self.assertEqual(service.secret, "secret") - self.assertEqual(service.header_key, "Authorization") - self.assertEqual(service.header_value, "Token foo") - self.assertEqual(service.nlx, "http://some-outway-adress.local:8080/") - self.assertEqual(service.user_id, "objects-api") - self.assertEqual(service.user_representation, "Objects API") - self.assertEqual(service.timeout, 60) diff --git a/src/objects/setup_configuration/steps/objecttypes.py b/src/objects/setup_configuration/steps/objecttypes.py deleted file mode 100644 index e99f3061..00000000 --- a/src/objects/setup_configuration/steps/objecttypes.py +++ /dev/null @@ -1,51 +0,0 @@ -from django.db import IntegrityError - -from django_setup_configuration.configuration import BaseConfigurationStep -from django_setup_configuration.exceptions import ConfigurationRunFailed -from zgw_consumers.contrib.setup_configuration.models import ( - SingleServiceConfigurationModel, -) -from zgw_consumers.models import Service - - -class ObjectTypesConnectionConfigurationStep( - BaseConfigurationStep[SingleServiceConfigurationModel] -): - config_model = SingleServiceConfigurationModel - verbose_name = "Objecttypes connection configuration" - - namespace = "objects_api_objecttypes_connection" - enable_setting = "objects_api_objecttypes_connection_config_enable" - - def execute(self, model: SingleServiceConfigurationModel) -> None: - service_kwargs = dict( - slug=model.identifier, - label=model.label, - api_type=model.api_type, - api_root=model.api_root, - api_connection_check_path=model.api_connection_check_path, - auth_type=model.auth_type, - client_id=model.client_id, - secret=model.secret, - header_key=model.header_key, - header_value=model.header_value, - nlx=model.nlx, - user_id=model.user_id, - user_representation=model.user_representation, - timeout=model.timeout, - ) - - service = Service(**service_kwargs) - - try: - Service.objects.update_or_create( - slug=service.slug, - defaults={ - key: value for key, value in service_kwargs.items() if key != "slug" - }, - ) - except IntegrityError as exception: - exception_message = ( - f"Failed configuring ObjectType connection {service.slug}." - ) - raise ConfigurationRunFailed(exception_message) from exception