Skip to content

Commit

Permalink
17508 FIX REST-API: change DCD request and response types
Browse files Browse the repository at this point in the history
This werk changes the connector configuration for create and get DCD endpoints.

Change-Id: I4f97cdecf9f778a78ee4ee30321025c2bb86c9b8
JIRA-Ref: SUP-22388
  • Loading branch information
ottermata committed Feb 24, 2025
1 parent 3543b94 commit 48a876e
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 15 deletions.
127 changes: 127 additions & 0 deletions .werks/17508.md
Original file line number Diff line number Diff line change
@@ -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
}
}
}
```
30 changes: 15 additions & 15 deletions tests/testlib/unit/rest_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 48a876e

Please sign in to comment.