From 48a876e105bfeb07ef1b0402933280121c982ea9 Mon Sep 17 00:00:00 2001 From: Christopher Krause Date: Sun, 23 Feb 2025 12:52:30 +0100 Subject: [PATCH] 17508 FIX REST-API: change DCD request and response types This werk changes the connector configuration for create and get DCD endpoints. Change-Id: I4f97cdecf9f778a78ee4ee30321025c2bb86c9b8 JIRA-Ref: SUP-22388 --- .werks/17508.md | 127 ++++++++++++++++++++++++++ tests/testlib/unit/rest_api_client.py | 30 +++--- 2 files changed, 142 insertions(+), 15 deletions(-) create mode 100644 .werks/17508.md diff --git a/.werks/17508.md b/.werks/17508.md new file mode 100644 index 00000000000..5d314263af0 --- /dev/null +++ b/.werks/17508.md @@ -0,0 +1,127 @@ +[//]: # (werk v2) +# REST-API: change DCD request and response types + +key | value +---------- | --- +date | 2025-02-23T11:43:14+00:00 +version | 2.4.0b1 +class | fix +edition | cee +component | rest-api +level | 1 +compatible | no + +This werk changes the connector configuration for create and get DCD endpoints. + +For the create request: + +1. the connector specific configuration is now nested under the `connector` key +2. the validation for `restrict_source_hosts` and `matching_hosts` was changed +to only allow valid regular expressions +3. the `exclude_time_ranges` field was removed, as it is now a global setting + +Before: +```json5 +{ + "title": "my-title", + "site": "my-site", + "dcd_id": "connection_1", + "connector_type": "piggyback", + // other connector keys, like interval, creation_rules etc. +} +``` + +After: +```json5 +{ + "title": "my-title", + "site": "my-site", + "dcd_id": "connection_1", + "connector": { + "connector_type": "piggyback", + // other connector keys, like interval, creation_rules etc. + } +} +``` + +For the responses of both create and get endpoints, the schema was adjusted to +reflect the create endpoint. It is also now correctly documented. + +Before: +```json5 +{ + // other keys omitted, as they didn't change + "extensions": { + "title": "my-title", + "comment": "...", + "docu_url": "...", + "disabled": false, + "site": "my-site", + "connector": [ + "piggyback", + { + "source_filters": [ + "some.+regex" + ], + "interval": 60.0, + "creation_rules": [ + { + "create_folder_path": "sub/folder", + "host_attributes": [ + [ + "tag_address_family", + "no-ip" + ] + ], + "delete_hosts": true, + "host_filters": [ + "another.+regex" + ] + } + ], + "discover_on_creation": true, + "no_deletion_time_after_init": 600.0, + "max_cache_age": 3600.0, + "validity_period": 60.0 + } + ] + } +} +``` + +After: +```json5 +{ + // other keys omitted, as they didn't change + "extensions": { + "title": "my-title", + "comment": "...", + "documentation_url": "...", // renamed from docu_url + "disabled": false, + "site": "my-site", + "connector": { // now an object, not an array + "connector_type": "piggyback", + "restrict_source_hosts": [ // renamed from source_filters + "some.+regex" + ], + "interval": 60, // now an integer, not a float + "creation_rules": [ + { + "folder_path": "/sub/folder", // renamed from create_folder_path + "host_attributes": { // now an object, not an array + "tag_address_family": "no-ip" + }, + "delete_hosts": true, + "matching_hosts": [ // renamed from host_filters + "another.+regex" + ] + } + ], + "discover_on_creation": true, + "no_deletion_time_after_init": 600, // now an integer, not a float + "max_cache_age": 3600, // now an integer, not a float + "validity_period": 60 // now an integer, not a float + } + } +} +``` diff --git a/tests/testlib/unit/rest_api_client.py b/tests/testlib/unit/rest_api_client.py index d32ba893eb3..1a77af93117 100644 --- a/tests/testlib/unit/rest_api_client.py +++ b/tests/testlib/unit/rest_api_client.py @@ -2370,31 +2370,31 @@ def create( discover_on_creation: bool | None = None, no_deletion_time_after_init: int | None = None, validity_period: int | None = None, - exclude_time_ranges: list[dict[str, str]] | None = None, creation_rules: list[dict[str, Any]] | None = None, restrict_source_hosts: list[str] | None = None, expect_ok: bool = True, ) -> Response: - body: dict[str, Any] = { - k: v - for k, v in { + body: dict[str, Any] = _only_set_keys( + { "dcd_id": dcd_id, "title": title, "site": site, "comment": comment, "documentation_url": documentation_url, "disabled": disabled, - "interval": interval, - "discover_on_creation": discover_on_creation, - "no_deletion_time_after_init": no_deletion_time_after_init, - "validity_period": validity_period, - "creation_rules": creation_rules, - "exclude_time_ranges": exclude_time_ranges, - "connector_type": connector_type, - "restrict_source_hosts": restrict_source_hosts, - }.items() - if v is not None - } + "connector": _only_set_keys( + { + "connector_type": connector_type, + "interval": interval, + "discover_on_creation": discover_on_creation, + "no_deletion_time_after_init": no_deletion_time_after_init, + "validity_period": validity_period, + "creation_rules": creation_rules, + "restrict_source_hosts": restrict_source_hosts, + } + ), + } + ) return self.request( "post",