From ea8460a43b3d4e7df603ab29255a8e516972c9ce Mon Sep 17 00:00:00 2001 From: Christopher Krause Date: Wed, 20 Nov 2024 13:22:04 +0100 Subject: [PATCH] rest-api: revert include_links and include_extensions changes This reverts commit d2a2d2f8 This reverts commit 6ec1bf4e4408ac3d3e866a233b09c18bf68006f2. This reverts commit 32b6dc77434afd24ff6ab0b2b54f2bd1f11a2b41. This reverts commit bebbd92a1e02db112ca26c58389b589e3ef026e6. This reverts commit 7681766f47069baf4284bbb16e2612fafb72ce88. This reverts commit d2ffd820 This reverts commit ee0f10f3b590aa8fb8a3f693e60d3b4980b409c1. This reverts commit 9d5e9051095aa9409d4fd6fc31197a5f989043cc. This reverts commit 2866c5b00b1faade9a4a05539412b53ca32b8c9a. This reverts commit 2ccb8807da2234d0afa97c48bf79d2367ac24e31. This reverts commit 60d7af9525d030e1511cf22c146f3d93fe3ba8bb. This reverts commit 0911a7e9df5bd4ef9a254e88c879407d7807f2b4. This reverts commit 7ccb7172 This reverts commit 05628cf532e3fe771f2d78510a95e9a5dfa28c02. This reverts commit e3f260ff2f500e913904314790f6b0f700c7597a. This reverts commit a6ef57163993c58c7be73227e2ad5caaca2f4950. This reverts commit f97389f6 This reverts commit 6835103bb299a83b2c9d5fbc324b38efb5b727e9. This reverts commit 0e81ac67 This reverts commit ca40c640f70a9031dc8fcf892606cfb5079bb34d. This reverts commit d027dc65 This reverts commit 0b14d02203221405adabe7cb0708f9e75b99566b. This reverts commit e1bdb9bf97d5d60128dae0d9241a65e3d6895504. This reverts commit a002d5f570555394b225e33c1e86e0305da642b6. This reverts commit e0fe2a52 This reverts commit e25ec25c567aec83c939924c63c3c33103c29ea5. This reverts commit df1b891d59a2277d3a058e2df0d0d0489246c810. This reverts commit 446eb7c4d616d227e2b2c876d8e586fd7dce0b0c. Change-Id: Ic4bb956a4cc70c8b0bfc3367b2d5949412a0e236 JIRA-Ref: CMK-20151 --- .werks/17266.md | 21 -- .werks/17267.md | 24 --- cmk/gui/mkeventd/_openapi/__init__.py | 16 +- .../endpoints/activate_changes/__init__.py | 19 +- .../openapi/endpoints/aux_tags/__init__.py | 28 +-- .../endpoints/broker_connection/__init__.py | 11 +- cmk/gui/openapi/endpoints/comment/__init__.py | 35 +--- cmk/gui/openapi/endpoints/common_fields.py | 14 +- .../contact_group_config/__init__.py | 16 +- .../openapi/endpoints/downtime/__init__.py | 63 ++---- .../endpoints/folder_config/__init__.py | 47 +---- cmk/gui/openapi/endpoints/host/__init__.py | 24 +-- .../openapi/endpoints/host_config/__init__.py | 52 ++--- .../endpoints/host_group_config/__init__.py | 11 +- .../endpoints/host_tag_group/__init__.py | 18 +- .../endpoints/ldap_connection/__init__.py | 21 +- .../endpoints/notification_rules/__init__.py | 16 +- .../openapi/endpoints/password/__init__.py | 43 ++-- cmk/gui/openapi/endpoints/rule/__init__.py | 52 ++--- cmk/gui/openapi/endpoints/ruleset/__init__.py | 38 ++-- cmk/gui/openapi/endpoints/service/__init__.py | 35 ++-- .../service_group_config/__init__.py | 11 +- .../endpoints/site_management/__init__.py | 18 +- .../endpoints/time_periods/__init__.py | 15 +- .../openapi/endpoints/user_config/__init__.py | 19 +- .../openapi/endpoints/user_role/__init__.py | 16 +- cmk/gui/openapi/endpoints/utils.py | 12 +- tests/testlib/rest_api_client.py | 193 ++---------------- .../cmk/gui/openapi/test_event_console.py | 48 +---- .../cmk/gui/openapi/test_ldap_connection.py | 26 --- .../gui/openapi/test_notification_rules.py | 28 --- .../cmk/gui/openapi/test_openapi_auxtags.py | 24 --- .../cmk/gui/openapi/test_openapi_downtime.py | 52 +---- .../gui/openapi/test_openapi_folder_config.py | 52 ----- .../gui/openapi/test_openapi_group_config.py | 29 +-- .../unit/cmk/gui/openapi/test_openapi_host.py | 72 +------ .../gui/openapi/test_openapi_host_config.py | 31 +-- .../openapi/test_openapi_host_tag_group.py | 26 --- .../cmk/gui/openapi/test_openapi_password.py | 30 --- .../cmk/gui/openapi/test_openapi_rules.py | 64 +----- .../cmk/gui/openapi/test_openapi_service.py | 82 +------- .../gui/openapi/test_openapi_time_period.py | 24 --- .../unit/cmk/gui/openapi/test_openapi_user.py | 26 +-- .../cmk/gui/openapi/test_openapi_userroles.py | 24 --- .../openapi/test_service_and_host_comments.py | 48 +---- .../cmk/gui/openapi/test_site_management.py | 24 --- 46 files changed, 187 insertions(+), 1411 deletions(-) delete mode 100644 .werks/17266.md delete mode 100644 .werks/17267.md diff --git a/.werks/17266.md b/.werks/17266.md deleted file mode 100644 index 0c3813258a7..00000000000 --- a/.werks/17266.md +++ /dev/null @@ -1,21 +0,0 @@ -[//]: # (werk v2) -# REST-API: Include links for get hosts by default - -key | value ----------- | --- -date | 2024-09-03T13:16:41+00:00 -version | 2.4.0b1 -class | fix -edition | cre -component | rest-api -level | 1 -compatible | no - -[Werk #16756](https://checkmk.com/werk/16756) introduced the `include_links` -flag to the `Show all hosts` endpoint -(`GET .../domain-types/host_config/collections/all`). The flag was disabled -by default. - -This werk changes the default to enabled again. As this comes with a -performance impact, it is recommended to disable it explicitly, if links are not -needed. diff --git a/.werks/17267.md b/.werks/17267.md deleted file mode 100644 index 3261a128d31..00000000000 --- a/.werks/17267.md +++ /dev/null @@ -1,24 +0,0 @@ -[//]: # (werk v2) -# REST-API: Introduce include_links and include_extensions to list endpoints - -key | value ----------- | --- -date | 2024-09-03T13:25:46+00:00 -version | 2.4.0b1 -class | feature -edition | cre -component | rest-api -level | 1 -compatible | yes - -This Werk introduces two flags to most list endpoints. - -The first flag `include_links` was already present for list host configs. It -controls whether the links of the individual values should be included. -This flag is enabled by default. - -The second flag `include_extensions` toggles the inclusion of the extensions, -which contain most of the attributes. This flag is also enabled by default. - -Both of these flags give users options to improve performance and reduce -response sizes. diff --git a/cmk/gui/mkeventd/_openapi/__init__.py b/cmk/gui/mkeventd/_openapi/__init__.py index d48673e9128..a2b0bbfe0dc 100644 --- a/cmk/gui/mkeventd/_openapi/__init__.py +++ b/cmk/gui/mkeventd/_openapi/__init__.py @@ -43,7 +43,6 @@ update_and_acknowledge, ) from cmk.gui.logged_in import user -from cmk.gui.openapi.endpoints.common_fields import field_include_extensions, field_include_links from cmk.gui.openapi.restful_objects import constructors, Endpoint from cmk.gui.openapi.restful_objects.registry import EndpointRegistry from cmk.gui.openapi.restful_objects.type_defs import DomainObject @@ -140,15 +139,12 @@ def event_id_not_found_problem(event_id: str) -> Response: ) -def _serialize_event( - event: ECEvent, *, include_links: bool = True, include_extensions: bool = True -) -> DomainObject: +def _serialize_event(event: ECEvent) -> DomainObject: return constructors.domain_object( domain_type="event_console", identifier=str(event.event_id), title=event.event_text, - extensions=dict(event) if include_extensions else None, - include_links=include_links, + extensions=dict(event), editable=False, deletable=True, ) @@ -201,14 +197,10 @@ def show_event(params: Mapping[str, Any]) -> Response: presence="should_exist", ) }, - field_include_links(), - field_include_extensions(), ], ) def show_events(params: Mapping[str, Any]) -> Response: """Show events""" - include_links: bool = params["include_links"] - include_extensions: bool = params["include_extensions"] query = filter_event_table( host=params.get("host"), state=params.get("state"), @@ -220,9 +212,7 @@ def show_events(params: Mapping[str, Any]) -> Response: constructors.collection_object( domain_type="event_console", value=[ - _serialize_event( - ev, include_links=include_links, include_extensions=include_extensions - ) + _serialize_event(ev) for _, ev in get_all_events(sites.live(), query, params.get("site_id")).items() ], ) diff --git a/cmk/gui/openapi/endpoints/activate_changes/__init__.py b/cmk/gui/openapi/endpoints/activate_changes/__init__.py index 91898f7afd9..c300203b558 100644 --- a/cmk/gui/openapi/endpoints/activate_changes/__init__.py +++ b/cmk/gui/openapi/endpoints/activate_changes/__init__.py @@ -29,7 +29,6 @@ ActivationRunResponse, PendingChangesCollection, ) -from cmk.gui.openapi.endpoints.common_fields import field_include_extensions, field_include_links from cmk.gui.openapi.endpoints.utils import may_fail from cmk.gui.openapi.restful_objects import constructors, Endpoint from cmk.gui.openapi.restful_objects.registry import EndpointRegistry @@ -149,9 +148,6 @@ def _completion_link(activation_id: str) -> LinkType: def _activation_run_domain_object( activation_response: ActivationRestAPIResponseExtensions, - *, - include_links: bool = True, - include_extensions: bool = True, ) -> DomainObject: return constructors.domain_object( domain_type="activation_run", @@ -161,15 +157,14 @@ def _activation_run_domain_object( if activation_response.is_running else "Activation status: Complete." ), - extensions=asdict(activation_response) if include_extensions else None, + extensions=asdict(activation_response), deletable=False, editable=False, links=( [_completion_link(activation_response.activation_id)] - if include_links and activation_response.is_running + if activation_response.is_running else [] ), - include_links=include_links, ) @@ -252,21 +247,15 @@ def show_activation(params: Mapping[str, Any]) -> Response: method="get", permissions_required=RO_PERMISSIONS, response_schema=ActivationRunCollection, - query_params=[field_include_links(), field_include_extensions()], ) def list_activations(params: Mapping[str, Any]) -> Response: """Show all currently running activations""" - include_links: bool = params["include_links"] - include_extensions: bool = params["include_extensions"] + value = [] for activation_id in get_activation_ids(): try: value.append( - _activation_run_domain_object( - get_restapi_response_for_activation_id(activation_id), - include_links=include_links, - include_extensions=include_extensions, - ) + _activation_run_domain_object(get_restapi_response_for_activation_id(activation_id)) ) except MKUserError: pass diff --git a/cmk/gui/openapi/endpoints/aux_tags/__init__.py b/cmk/gui/openapi/endpoints/aux_tags/__init__.py index 617e783d5f1..c3971dce397 100644 --- a/cmk/gui/openapi/endpoints/aux_tags/__init__.py +++ b/cmk/gui/openapi/endpoints/aux_tags/__init__.py @@ -34,7 +34,6 @@ AuxTagResponse, AuxTagResponseCollection, ) -from cmk.gui.openapi.endpoints.common_fields import field_include_extensions, field_include_links from cmk.gui.openapi.restful_objects import constructors, Endpoint from cmk.gui.openapi.restful_objects.registry import EndpointRegistry from cmk.gui.openapi.restful_objects.type_defs import DomainObject @@ -80,23 +79,15 @@ def show_aux_tag(params: Mapping[str, Any]) -> Response: response_schema=AuxTagResponseCollection, update_config_generation=False, permissions_required=PERMISSIONS, - query_params=[field_include_links(), field_include_extensions()], ) def show_aux_tags(params: Mapping[str, Any]) -> Response: """Show Auxiliary Tags""" user.need_permission("wato.hosttags") - include_links: bool = params["include_links"] - include_extensions: bool = params["include_extensions"] return serve_json( constructors.collection_object( domain_type="aux_tag", - value=[ - _serialize_aux_tag( - tag, include_links=include_links, include_extensions=include_extensions - ) - for tag in load_all_tag_config_read_only().aux_tag_list - ], + value=[_serialize_aux_tag(tag) for tag in load_all_tag_config_read_only().aux_tag_list], ) ) @@ -193,24 +184,17 @@ def delete_aux_tag(params: Mapping[str, Any]) -> Response: return Response(status=204) -def _serialize_aux_tag( - aux_tag: AuxTag, *, include_links: bool = True, include_extensions: bool = True -) -> DomainObject: +def _serialize_aux_tag(aux_tag: AuxTag) -> DomainObject: return constructors.domain_object( domain_type="aux_tag", identifier=aux_tag.id, title=aux_tag.title, - extensions=( - { - "topic": "Tags" if aux_tag.topic is None else aux_tag.topic, - "help": "" if aux_tag.help is None else aux_tag.help, - } - if include_extensions - else None - ), + extensions={ + "topic": "Tags" if aux_tag.topic is None else aux_tag.topic, + "help": "" if aux_tag.help is None else aux_tag.help, + }, editable=True, deletable=True, - include_links=include_links, ) diff --git a/cmk/gui/openapi/endpoints/broker_connection/__init__.py b/cmk/gui/openapi/endpoints/broker_connection/__init__.py index ad4db8c849c..3303bc3d6c9 100644 --- a/cmk/gui/openapi/endpoints/broker_connection/__init__.py +++ b/cmk/gui/openapi/endpoints/broker_connection/__init__.py @@ -34,7 +34,6 @@ BrokerConnectionResponse, BrokerConnectionResponseCollection, ) -from cmk.gui.openapi.endpoints.common_fields import field_include_extensions from cmk.gui.openapi.restful_objects import constructors, Endpoint from cmk.gui.openapi.restful_objects.constructors import ( domain_object, @@ -95,7 +94,6 @@ def _serialize_broker_connection( tag_group="Checkmk Internal", response_schema=BrokerConnectionResponseCollection, permissions_required=PERMISSIONS, - query_params=[field_include_extensions()], ) def show_broker_connections(params: Mapping[str, Any]) -> Response: """Show all peer to peer broker connections""" @@ -109,13 +107,7 @@ def show_broker_connections(params: Mapping[str, Any]) -> Response: return serve_json( constructors.collection_object( domain_type="broker_connection", - value=[ - _serialize_broker_connection( - connection, - include_extensions=params["include_extensions"], - ) - for connection in all_connections_objs - ], + value=[_serialize_broker_connection(connection) for connection in all_connections_objs], ) ) @@ -128,7 +120,6 @@ def show_broker_connections(params: Mapping[str, Any]) -> Response: path_params=[CONNECTION_ID_SHOULD_EXIST], response_schema=BrokerConnectionResponse, permissions_required=PERMISSIONS, - query_params=[field_include_extensions()], etag="output", ) def show_broker_connection(params: Mapping[str, Any]) -> Response: diff --git a/cmk/gui/openapi/endpoints/comment/__init__.py b/cmk/gui/openapi/endpoints/comment/__init__.py index f3346376832..56b065f20d9 100644 --- a/cmk/gui/openapi/endpoints/comment/__init__.py +++ b/cmk/gui/openapi/endpoints/comment/__init__.py @@ -49,7 +49,6 @@ DeleteComments, ) from cmk.gui.openapi.endpoints.comment.response_schemas import CommentCollection, CommentObject -from cmk.gui.openapi.endpoints.common_fields import field_include_extensions, field_include_links from cmk.gui.openapi.restful_objects import constructors, Endpoint from cmk.gui.openapi.restful_objects.registry import EndpointRegistry from cmk.gui.openapi.restful_objects.type_defs import DomainObject @@ -72,28 +71,23 @@ RW_PERMISSIONS = permissions.AllPerm([permissions.Perm("action.addcomment"), PERMISSIONS]) -def _serialize_comment_extensions(comment: Comment) -> dict[str, Any]: - dict_comment: dict[str, Any] = dict(comment) +def _serialize_comment(comment: Comment) -> DomainObject: + dict_comment = dict(comment) + if "site" in dict_comment: dict_comment["site_id"] = dict_comment.pop("site") dict_comment["entry_time"] = ( datetime.strptime(dict_comment["entry_time"], "%b %d %Y %H:%M:%S").isoformat() + "+00:00" ) - return dict_comment - -def _serialize_comment( - comment: Comment, *, include_links: bool = True, include_extensions: bool = True -) -> DomainObject: return constructors.domain_object( domain_type="comment", identifier=str(comment.id), title=comment.comment, - extensions=_serialize_comment_extensions(comment) if include_extensions else None, + extensions=dict_comment, editable=False, deletable=True, - include_links=include_links, ) @@ -195,19 +189,11 @@ def show_comment(params: Mapping[str, Any]) -> Response: response_schema=CommentCollection, update_config_generation=False, path_params=[COLLECTION_NAME], - query_params=[ - GetCommentsByQuery, - HOST_NAME_SHOW, - SERVICE_DESCRIPTION_SHOW, - OPTIONAL_SITE_ID, - field_include_links(), - field_include_extensions(), - ], + query_params=[GetCommentsByQuery, HOST_NAME_SHOW, SERVICE_DESCRIPTION_SHOW, OPTIONAL_SITE_ID], ) def show_comments(params: Mapping[str, Any]) -> Response: """Show comments""" - include_links: bool = params["include_links"] - include_extensions: bool = params["include_extensions"] + try: sites_to_query = params.get("site_id") live = sites.live() @@ -231,14 +217,7 @@ def show_comments(params: Mapping[str, Any]) -> Response: return serve_json( constructors.collection_object( domain_type="comment", - value=[ - _serialize_comment( - comment, - include_links=include_links, - include_extensions=include_extensions, - ) - for _, comment in sorted(comments_dict.items()) - ], + value=[_serialize_comment(comment) for _, comment in sorted(comments_dict.items())], ) ) diff --git a/cmk/gui/openapi/endpoints/common_fields.py b/cmk/gui/openapi/endpoints/common_fields.py index e57db09a95b..a0666c6a781 100644 --- a/cmk/gui/openapi/endpoints/common_fields.py +++ b/cmk/gui/openapi/endpoints/common_fields.py @@ -20,22 +20,10 @@ def field_include_links(description: str | None = None) -> Mapping[str, Boolean]: return { "include_links": Boolean( - load_default=True, + load_default=False, required=False, example=False, description=description or "Flag which toggles whether the links field of the individual values should be populated.", ) } - - -def field_include_extensions(description: str | None = None) -> Mapping[str, Boolean]: - return { - "include_extensions": Boolean( - load_default=True, - required=False, - example=True, - description=description - or "Flag which toggles whether the extensions field of the individual values should be populated.", - ) - } diff --git a/cmk/gui/openapi/endpoints/contact_group_config/__init__.py b/cmk/gui/openapi/endpoints/contact_group_config/__init__.py index 4c64d1436ea..ac4bde19769 100644 --- a/cmk/gui/openapi/endpoints/contact_group_config/__init__.py +++ b/cmk/gui/openapi/endpoints/contact_group_config/__init__.py @@ -30,7 +30,6 @@ from cmk.gui.groups import GroupSpec from cmk.gui.http import Response from cmk.gui.logged_in import user -from cmk.gui.openapi.endpoints.common_fields import field_include_extensions, field_include_links from cmk.gui.openapi.endpoints.contact_group_config.common import ( APIGroupSpec, APIInventoryPaths, @@ -245,22 +244,15 @@ def bulk_create(params: Mapping[str, Any]) -> Response: method="get", response_schema=ContactGroupCollection, permissions_required=PERMISSIONS, - query_params=[field_include_links(), field_include_extensions()], ) def list_group(params: Mapping[str, Any]) -> Response: """Show all contact groups""" user.need_permission("wato.users") - include_extensions: bool = params["include_extensions"] - collection = build_group_list(load_contact_group_information()) - if include_extensions: - collection = [_group_to_api(value) for value in collection] + collection = [ + _group_to_api(group) for group in build_group_list(load_contact_group_information()) + ] return serve_json( - serialize_group_list( - "contact_group_config", - collection, - include_links=params["include_links"], - include_extensions=include_extensions, - ), + serialize_group_list("contact_group_config", collection), ) diff --git a/cmk/gui/openapi/endpoints/downtime/__init__.py b/cmk/gui/openapi/endpoints/downtime/__init__.py index 81558be68ea..fc9d5452967 100644 --- a/cmk/gui/openapi/endpoints/downtime/__init__.py +++ b/cmk/gui/openapi/endpoints/downtime/__init__.py @@ -47,7 +47,6 @@ from cmk.gui.livestatus_utils.commands import downtimes as downtime_commands from cmk.gui.livestatus_utils.commands.downtimes import QueryException from cmk.gui.logged_in import user -from cmk.gui.openapi.endpoints.common_fields import field_include_extensions, field_include_links from cmk.gui.openapi.endpoints.downtime.request_schemas import ( CreateHostRelatedDowntime, CreateServiceRelatedDowntime, @@ -340,8 +339,6 @@ def create_service_related_downtime(params: Mapping[str, Any]) -> Response: presence="should_exist", ) }, - field_include_links(), - field_include_extensions(), ], response_schema=DowntimeCollection, permissions_required=PERMISSIONS, @@ -401,9 +398,7 @@ def _show_downtimes(param: Mapping[str, Any]) -> Response: _site_id: SiteId | None = param.get("site_id") return serve_json( _serialize_downtimes( - q.fetchall(sites.live(), True, [_site_id] if _site_id is not None else _site_id), - include_links=param["include_links"], - include_extensions=param["include_extensions"], + q.fetchall(sites.live(), True, [_site_id] if _site_id is not None else _site_id) ) ) @@ -565,58 +560,44 @@ def _generate_target_downtimes_query( return query_expr, site_id -def _serialize_downtimes( - downtimes: Iterable[ResultRow], *, include_links: bool = True, include_extensions: bool = True -) -> CollectionObject: +def _serialize_downtimes(downtimes: Iterable[ResultRow]) -> CollectionObject: return constructors.collection_object( "downtime", - value=[ - _serialize_single_downtime( - downtime, include_links=include_links, include_extensions=include_extensions - ) - for downtime in downtimes - ], + value=[_serialize_single_downtime(downtime) for downtime in downtimes], ) -def _serialize_single_downtime( - downtime: ResultRow, *, include_links: bool = True, include_extensions: bool = True -) -> DomainObject: - downtime_id = downtime["id"] +def _serialize_single_downtime(downtime: ResultRow) -> DomainObject: links = [] - if include_links: - links.append( - constructors.link_rel( - rel=".../delete", - href=constructors.domain_type_action_href("downtime", "delete"), - method="post", - title="Delete the downtime", - body_params={"delete_type": "by_id", "downtime_id": downtime_id}, - ) - ) - if downtime["is_service"]: downtime_detail = f"service: {downtime['service_description']}" else: host_name = downtime["host_name"] downtime_detail = f"host: {host_name}" - if include_links: - links.append( - constructors.link_rel( - rel="cmk/host_config", - href=constructors.object_href("host_config", host_name), - title="This host of this downtime.", - method="get", - ) + links.append( + constructors.link_rel( + rel="cmk/host_config", + href=constructors.object_href("host_config", host_name), + title="This host of this downtime.", + method="get", ) + ) + downtime_id = downtime["id"] return constructors.domain_object( domain_type="downtime", identifier=str(downtime_id), title="Downtime for %s" % downtime_detail, - extensions=_downtime_properties(downtime) if include_extensions else None, - links=links, - include_links=include_links, + extensions=_downtime_properties(downtime), + links=[ + constructors.link_rel( + rel=".../delete", + href=constructors.domain_type_action_href("downtime", "delete"), + method="post", + title="Delete the downtime", + body_params={"delete_type": "by_id", "downtime_id": downtime_id}, + ), + ], editable=False, deletable=False, ) diff --git a/cmk/gui/openapi/endpoints/folder_config/__init__.py b/cmk/gui/openapi/endpoints/folder_config/__init__.py index 06d9e94655d..f6d4a72df59 100644 --- a/cmk/gui/openapi/endpoints/folder_config/__init__.py +++ b/cmk/gui/openapi/endpoints/folder_config/__init__.py @@ -42,11 +42,7 @@ from cmk.gui.exceptions import MKUserError from cmk.gui.http import Response from cmk.gui.logged_in import user -from cmk.gui.openapi.endpoints.common_fields import ( - EXISTING_FOLDER_PATTERN, - field_include_extensions, - field_include_links, -) +from cmk.gui.openapi.endpoints.common_fields import EXISTING_FOLDER_PATTERN from cmk.gui.openapi.endpoints.folder_config.request_schemas import ( BulkUpdateFolder, CreateFolder, @@ -142,23 +138,14 @@ def create(params: Mapping[str, Any]) -> Response: path_params=[PATH_FOLDER_FIELD], response_schema=HostConfigCollection, permissions_required=permissions.Optional(permissions.Perm("wato.see_all_folders")), - query_params=[ - EFFECTIVE_ATTRIBUTES, - field_include_links( - "Flag which toggles whether the links field of the individual hosts should be populated." - ), - field_include_extensions(), - ], + query_params=[EFFECTIVE_ATTRIBUTES], ) def hosts_of_folder(params: Mapping[str, Any]) -> Response: """Show all hosts in a folder""" folder: Folder = params["folder"] folder.permissions.need_permission("read") return serve_host_collection( - folder.hosts().values(), - effective_attributes=params["effective_attributes"], - include_links=params["include_links"], - include_extensions=params["include_extensions"], + folder.hosts().values(), effective_attributes=params["effective_attributes"] ) @@ -371,9 +358,7 @@ def move(params: Mapping[str, Any]) -> Response: example=False, load_default=False, ), - }, - field_include_links(), - field_include_extensions(), + } ], response_schema=FolderCollection, permissions_required=permissions.Optional(permissions.Perm("wato.see_all_folders")), @@ -387,22 +372,13 @@ def list_folders(params: Mapping[str, Any]) -> Response: else: parent.permissions.need_permission("read") folders = parent.subfolders() - return serve_json( - _folders_collection( - folders, - show_hosts=params["show_hosts"], - include_links=params["include_links"], - include_extensions=params["include_extensions"], - ) - ) + return serve_json(_folders_collection(folders, show_hosts=params["show_hosts"])) def _folders_collection( folders: list[Folder], *, show_hosts: bool = False, - include_links: bool = True, - include_extensions: bool = True, ) -> CollectionObject: folders_ = [] for folder in folders: @@ -426,16 +402,11 @@ def _folders_collection( domain_type="folder_config", identifier=folder_slug(folder), title=folder.title(), - extensions=( - { - "path": "/" + folder.path(), - "attributes": folder.attributes.copy(), - } - if include_extensions - else None - ), + extensions={ + "path": "/" + folder.path(), + "attributes": folder.attributes.copy(), + }, members=members, - include_links=include_links, ) ) # diff --git a/cmk/gui/openapi/endpoints/host/__init__.py b/cmk/gui/openapi/endpoints/host/__init__.py index 5a7823cfb64..b0cb5d2f49d 100644 --- a/cmk/gui/openapi/endpoints/host/__init__.py +++ b/cmk/gui/openapi/endpoints/host/__init__.py @@ -49,7 +49,6 @@ from cmk.gui import sites from cmk.gui.fields.utils import BaseSchema from cmk.gui.http import Response -from cmk.gui.openapi.endpoints.common_fields import field_include_extensions, field_include_links from cmk.gui.openapi.restful_objects import constructors, Endpoint, response_schemas from cmk.gui.openapi.restful_objects.registry import EndpointRegistry from cmk.gui.openapi.restful_objects.type_defs import DomainObject @@ -105,7 +104,7 @@ class SingleHostParameters(BaseSchema): method="get", tag_group="Monitoring", blacklist_in=["swagger-ui"], - query_params=[HostParameters, field_include_links(), field_include_extensions()], + query_params=[HostParameters], response_schema=response_schemas.DomainObjectCollection, permissions_required=PERMISSIONS, ) @@ -132,15 +131,7 @@ def list_hosts(params: Mapping[str, Any]) -> Response: return serve_json( constructors.collection_object( domain_type="host", - value=[ - _host_object( - entry["name"], - entry, - include_links=params["include_links"], - include_extensions=params["include_extensions"], - ) - for entry in result - ], + value=[_host_object(entry["name"], entry) for entry in result], ) ) @@ -186,19 +177,12 @@ def show_host(params: Mapping[str, Any]) -> Response: return serve_json(_host_object(host_name, host)) -def _host_object( - host_name: str, - host: dict, - *, - include_links: bool = True, - include_extensions: bool = True, -) -> DomainObject: +def _host_object(host_name: str, host: dict) -> DomainObject: return constructors.domain_object( domain_type="host", identifier=host_name, title=host_name, - extensions=host if include_extensions else None, - include_links=include_links, + extensions=host, editable=False, deletable=False, ) diff --git a/cmk/gui/openapi/endpoints/host_config/__init__.py b/cmk/gui/openapi/endpoints/host_config/__init__.py index f39d32ab576..f2617806773 100644 --- a/cmk/gui/openapi/endpoints/host_config/__init__.py +++ b/cmk/gui/openapi/endpoints/host_config/__init__.py @@ -54,7 +54,7 @@ from cmk.gui.fields.utils import BaseSchema from cmk.gui.http import request, Response from cmk.gui.logged_in import user -from cmk.gui.openapi.endpoints.common_fields import field_include_extensions, field_include_links +from cmk.gui.openapi.endpoints.common_fields import field_include_links from cmk.gui.openapi.endpoints.host_config.request_schemas import ( BulkCreateHost, BulkDeleteHost, @@ -368,7 +368,6 @@ def _iter_hosts_with_permission(folder: Folder) -> Iterable[Host]: field_include_links( "Flag which toggles whether the links field of the individual hosts should be populated." ), - field_include_extensions(), ], ) def list_hosts(params: Mapping[str, Any]) -> Response: @@ -384,43 +383,28 @@ def list_hosts(params: Mapping[str, Any]) -> Response: hosts, effective_attributes=params["effective_attributes"], include_links=params["include_links"], - include_extensions=params["include_extensions"], ) def serve_host_collection( - hosts: Iterable[Host], - *, - effective_attributes: bool = False, - include_links: bool = False, - include_extensions: bool = True, + hosts: Iterable[Host], *, effective_attributes: bool = False, include_links: bool = False ) -> Response: return serve_json( _host_collection( - hosts, - effective_attributes=effective_attributes, - include_links=include_links, - include_extensions=include_extensions, + hosts, effective_attributes=effective_attributes, include_links=include_links ) ) def _host_collection( - hosts: Iterable[Host], - *, - effective_attributes: bool = False, - include_links: bool = False, - include_extensions: bool = True, + hosts: Iterable[Host], *, effective_attributes: bool = False, include_links: bool = False ) -> dict[str, Any]: return { "id": "host", "domainType": "host_config", "value": [ serialize_host( - host, - effective_attributes=effective_attributes, - include_links=include_links, - include_extensions=include_extensions, + host, effective_attributes=effective_attributes, include_links=include_links ) for host in hosts ], @@ -844,24 +828,16 @@ def _serve_host(host: Host, effective_attributes: bool = False) -> Response: def serialize_host( - host: Host, - *, - effective_attributes: bool, - include_links: bool = True, - include_extensions: bool = True, + host: Host, *, effective_attributes: bool, include_links: bool = True ) -> DomainObject: - extensions = ( - { - "folder": "/" + host.folder().path(), - "attributes": host.attributes, - "effective_attributes": host.effective_attributes() if effective_attributes else None, - "is_cluster": host.is_cluster(), - "is_offline": host.is_offline(), - "cluster_nodes": host.cluster_nodes(), - } - if include_extensions - else None - ) + extensions = { + "folder": "/" + host.folder().path(), + "attributes": host.attributes, + "effective_attributes": host.effective_attributes() if effective_attributes else None, + "is_cluster": host.is_cluster(), + "is_offline": host.is_offline(), + "cluster_nodes": host.cluster_nodes(), + } if include_links: links = [ diff --git a/cmk/gui/openapi/endpoints/host_group_config/__init__.py b/cmk/gui/openapi/endpoints/host_group_config/__init__.py index 463ec4fa9d5..9ec8ed19046 100644 --- a/cmk/gui/openapi/endpoints/host_group_config/__init__.py +++ b/cmk/gui/openapi/endpoints/host_group_config/__init__.py @@ -27,7 +27,6 @@ from cmk.gui.http import Response from cmk.gui.logged_in import user -from cmk.gui.openapi.endpoints.common_fields import field_include_extensions, field_include_links from cmk.gui.openapi.endpoints.host_group_config.request_schemas import ( BulkDeleteHostGroup, BulkInputHostGroup, @@ -124,20 +123,12 @@ def bulk_create(params: Mapping[str, Any]) -> Response: method="get", response_schema=HostGroupCollection, permissions_required=PERMISSIONS, - query_params=[field_include_links(), field_include_extensions()], ) def list_groups(params: Mapping[str, Any]) -> Response: """Show all host groups""" user.need_permission("wato.groups") collection = build_group_list(load_host_group_information()) - return serve_json( - serialize_group_list( - "host_group_config", - collection, - include_links=params["include_links"], - include_extensions=params["include_extensions"], - ) - ) + return serve_json(serialize_group_list("host_group_config", collection)) @Endpoint( diff --git a/cmk/gui/openapi/endpoints/host_tag_group/__init__.py b/cmk/gui/openapi/endpoints/host_tag_group/__init__.py index 759aa57c28c..45eac431e66 100644 --- a/cmk/gui/openapi/endpoints/host_tag_group/__init__.py +++ b/cmk/gui/openapi/endpoints/host_tag_group/__init__.py @@ -21,7 +21,6 @@ from cmk.gui.http import Response from cmk.gui.logged_in import user -from cmk.gui.openapi.endpoints.common_fields import field_include_extensions, field_include_links from cmk.gui.openapi.endpoints.host_tag_group.request_schemas import ( DeleteHostTagGroup, InputHostTagGroup, @@ -133,7 +132,6 @@ def show_host_tag_group(params: Mapping[str, Any]) -> Response: method="get", response_schema=HostTagGroupCollection, permissions_required=PERMISSIONS, - query_params=[field_include_links(), field_include_extensions()], ) def list_host_tag_groups(params: Mapping[str, Any]) -> Response: """Show all host tag groups""" @@ -144,11 +142,7 @@ def list_host_tag_groups(params: Mapping[str, Any]) -> Response: "id": "host_tag", "domainType": "host_tag_group", "value": [ - serialize_host_tag_group( - tag_group_obj.get_dict_format(), - include_links=params["include_links"], - include_extensions=params["include_extensions"], - ) + serialize_host_tag_group(tag_group_obj.get_dict_format()) for tag_group_obj in tag_config.get_tag_groups() ], "links": [constructors.link_rel("self", constructors.collection_href("host_tag_group"))], @@ -281,19 +275,14 @@ def _serve_host_tag_group(tag_details: TagGroupSpec) -> Response: return constructors.response_with_etag_created_from_dict(response, dict(tag_details)) -def _serialize_host_tag_group_extensions(details: TagGroupSpec) -> dict[str, Any]: +def serialize_host_tag_group(details: TagGroupSpec) -> DomainObject: extensions = { "topic": details.get("topic", "Tags"), "tags": details["tags"], } if details.get("help") is not None: extensions.update({"help": details["help"]}) - return extensions - -def serialize_host_tag_group( - details: TagGroupSpec, *, include_links: bool = True, include_extensions: bool = True -) -> DomainObject: return constructors.domain_object( domain_type="host_tag_group", identifier=details["id"], @@ -306,8 +295,7 @@ def serialize_host_tag_group( base=constructors.object_href("host_tag_group", details["id"]), ) }, - extensions=_serialize_host_tag_group_extensions(details) if include_extensions else None, - include_links=include_links, + extensions=extensions, ) diff --git a/cmk/gui/openapi/endpoints/ldap_connection/__init__.py b/cmk/gui/openapi/endpoints/ldap_connection/__init__.py index 1da2312cce1..52d633ad707 100644 --- a/cmk/gui/openapi/endpoints/ldap_connection/__init__.py +++ b/cmk/gui/openapi/endpoints/ldap_connection/__init__.py @@ -26,7 +26,6 @@ from cmk.gui.fields.custom_fields import LDAPConnectionID from cmk.gui.http import Response from cmk.gui.logged_in import user -from cmk.gui.openapi.endpoints.common_fields import field_include_extensions, field_include_links from cmk.gui.openapi.endpoints.ldap_connection.error_schemas import GETLdapConnection404 from cmk.gui.openapi.endpoints.ldap_connection.internal_to_restapi_interface import ( LDAPConnectionInterface, @@ -115,7 +114,6 @@ def show_ldap_connection(params: Mapping[str, Any]) -> Response: tag_group="Setup", response_schema=LDAPConnectionResponseCollection, permissions_required=RO_PERMISSIONS, - query_params=[field_include_links(), field_include_extensions()], ) def show_ldap_connections(params: Mapping[str, Any]) -> Response: """Show all LDAP connections""" @@ -124,14 +122,7 @@ def show_ldap_connections(params: Mapping[str, Any]) -> Response: return serve_json( collection_object( domain_type="ldap_connection", - value=[ - _serialize_ldap_connection( - cnx, - include_links=params["include_links"], - include_extensions=params["include_extensions"], - ) - for cnx in request_ldap_connections().values() - ], + value=[_serialize_ldap_connection(cnx) for cnx in request_ldap_connections().values()], ) ) @@ -216,18 +207,12 @@ def edit_ldap_connection(params: Mapping[str, Any]) -> Response: ) -def _serialize_ldap_connection( - connection: LDAPConnectionInterface, - *, - include_links: bool = True, - include_extensions: bool = True, -) -> DomainObject: +def _serialize_ldap_connection(connection: LDAPConnectionInterface) -> DomainObject: return domain_object( domain_type="ldap_connection", identifier=connection.general_properties.id, title=connection.general_properties.description, - extensions=connection.api_response() if include_extensions else None, - include_links=include_links, + extensions=connection.api_response(), editable=True, deletable=True, ) diff --git a/cmk/gui/openapi/endpoints/notification_rules/__init__.py b/cmk/gui/openapi/endpoints/notification_rules/__init__.py index efaaf6e5f66..db4cde2b5e8 100644 --- a/cmk/gui/openapi/endpoints/notification_rules/__init__.py +++ b/cmk/gui/openapi/endpoints/notification_rules/__init__.py @@ -23,7 +23,6 @@ from cmk.gui.http import Response from cmk.gui.i18n import _ from cmk.gui.logged_in import user -from cmk.gui.openapi.endpoints.common_fields import field_include_extensions, field_include_links from cmk.gui.openapi.endpoints.notification_rules.request_schemas import NotificationRuleRequest from cmk.gui.openapi.endpoints.notification_rules.response_schemas import ( NotificationRuleResponse, @@ -129,7 +128,6 @@ def show_rule(params: Mapping[str, Any]) -> Response: tag_group="Setup", response_schema=NotificationRuleResponseCollection, permissions_required=RO_PERMISSIONS, - query_params=[field_include_links(), field_include_extensions()], ) def show_rules(params: Mapping[str, Any]) -> Response: """Show all notification rules""" @@ -138,12 +136,7 @@ def show_rules(params: Mapping[str, Any]) -> Response: constructors.collection_object( domain_type="notification_rule", value=[ - _serialize_notification_rule( - rule, - include_links=params["include_links"], - include_extensions=params["include_extensions"], - ) - for rule in get_notification_rules().values() + _serialize_notification_rule(rule) for rule in get_notification_rules().values() ], ) ) @@ -217,15 +210,12 @@ def delete_rule(params: Mapping[str, Any]) -> Response: return Response(status=204) -def _serialize_notification_rule( - rule: NotificationRule, *, include_links: bool = True, include_extensions: bool = True -) -> DomainObject: +def _serialize_notification_rule(rule: NotificationRule) -> DomainObject: return domain_object( domain_type="notification_rule", identifier=str(rule.rule_id), title=rule.rule_properties.description, - extensions={"rule_config": rule.api_response()} if include_extensions else None, - include_links=include_links, + extensions={"rule_config": rule.api_response()}, editable=True, deletable=True, ) diff --git a/cmk/gui/openapi/endpoints/password/__init__.py b/cmk/gui/openapi/endpoints/password/__init__.py index afc2052536d..5ecb3287b95 100644 --- a/cmk/gui/openapi/endpoints/password/__init__.py +++ b/cmk/gui/openapi/endpoints/password/__init__.py @@ -25,7 +25,6 @@ from cmk.gui.http import Response from cmk.gui.logged_in import user -from cmk.gui.openapi.endpoints.common_fields import field_include_extensions, field_include_links from cmk.gui.openapi.endpoints.password.request_schemas import InputPassword, UpdatePassword from cmk.gui.openapi.endpoints.password.response_schemas import PasswordCollection, PasswordObject from cmk.gui.openapi.endpoints.utils import complement_customer, update_customer_info @@ -181,7 +180,6 @@ def show_password(params: Mapping[str, Any]) -> Response: method="get", response_schema=PasswordCollection, permissions_required=PERMISSIONS, - query_params=[field_include_links(), field_include_extensions()], ) def list_passwords(params: Mapping[str, Any]) -> Response: """Show all passwords""" @@ -190,13 +188,7 @@ def list_passwords(params: Mapping[str, Any]) -> Response: constructors.collection_object( domain_type="password", value=[ - serialize_password( - ident, - details, - include_links=params["include_links"], - include_extensions=params["include_extensions"], - ) - for ident, details in load_passwords().items() + serialize_password(ident, details) for ident, details in load_passwords().items() ], ) ) @@ -208,9 +200,7 @@ def _serve_password(ident: str, password_details: Password) -> Response: return constructors.response_with_etag_created_from_dict(response, password_as_dict) -def serialize_password( - ident: str, details: Password, *, include_links: bool = True, include_extensions: bool = True -) -> DomainObject: +def serialize_password(ident: str, details: Password) -> DomainObject: if details["owned_by"] is None: details["owned_by"] = "admin" @@ -219,23 +209,18 @@ def serialize_password( identifier=ident, title=details["title"], members={}, - extensions=( - { - k: v - for k, v in complement_customer(details).items() - if k - in ( - "comment", - "docu_url", - "owned_by", - "shared_with", - "customer", - ) - } - if include_extensions - else None - ), - include_links=include_links, + extensions={ + k: v + for k, v in complement_customer(details).items() + if k + in ( + "comment", + "docu_url", + "owned_by", + "shared_with", + "customer", + ) + }, editable=True, deletable=True, ) diff --git a/cmk/gui/openapi/endpoints/rule/__init__.py b/cmk/gui/openapi/endpoints/rule/__init__.py index f0cc5411820..50a94638c28 100644 --- a/cmk/gui/openapi/endpoints/rule/__init__.py +++ b/cmk/gui/openapi/endpoints/rule/__init__.py @@ -23,7 +23,6 @@ from cmk.gui import exceptions, http from cmk.gui.i18n import _l from cmk.gui.logged_in import user -from cmk.gui.openapi.endpoints.common_fields import field_include_extensions, field_include_links from cmk.gui.openapi.endpoints.rule.fields import ( APILabelGroupCondition, InputRuleObject, @@ -250,15 +249,13 @@ def create_rule(param): method="get", response_schema=RuleCollection, permissions_required=PERMISSIONS, - query_params=[RuleSearchOptions, field_include_links(), field_include_extensions()], + query_params=[RuleSearchOptions], ) def list_rules(param): """List rules""" user.need_permission("wato.rulesets") all_rulesets = AllRulesets.load_all_rulesets() ruleset_name = param["ruleset_name"] - include_links: bool = param["include_links"] - include_extensions: bool = param["include_extensions"] ruleset = _retrieve_from_rulesets(all_rulesets, ruleset_name) @@ -270,9 +267,7 @@ def list_rules(param): folder=folder, index_nr=index, all_rulesets=all_rulesets, - ), - include_links=include_links, - include_extensions=include_extensions, + ) ) for folder, index, rule in ruleset.get_rules() ] @@ -548,38 +543,29 @@ def _retrieve_from_rulesets(rulesets: RulesetCollection, ruleset_name: str) -> R return ruleset -def _serialize_rule( - rule_entry: RuleEntry, *, include_links: bool = True, include_extensions: bool = True -) -> DomainObject: +def _serialize_rule(rule_entry: RuleEntry) -> DomainObject: rule = rule_entry.rule return constructors.domain_object( domain_type="rule", editable=False, identifier=rule.id, title=rule.description(), - extensions=( - { - "ruleset": rule.ruleset.name, - "folder": "/" + rule_entry.folder.path(), - "folder_index": rule_entry.index_nr, - "properties": rule.rule_options.to_config(), - "value_raw": repr(rule.ruleset.valuespec().mask(rule.value)), - "conditions": denilled( - { - "host_name": rule.conditions.host_name, - "host_tags": rule.conditions.host_tags, - "host_label_groups": _internal_to_api(rule.conditions.host_label_groups), - "service_description": rule.conditions.service_description, - "service_label_groups": _internal_to_api( - rule.conditions.service_label_groups - ), - } - ), - } - if include_extensions - else None - ), - include_links=include_links, + extensions={ + "ruleset": rule.ruleset.name, + "folder": "/" + rule_entry.folder.path(), + "folder_index": rule_entry.index_nr, + "properties": rule.rule_options.to_config(), + "value_raw": repr(rule.ruleset.valuespec().mask(rule.value)), + "conditions": denilled( + { + "host_name": rule.conditions.host_name, + "host_tags": rule.conditions.host_tags, + "host_label_groups": _internal_to_api(rule.conditions.host_label_groups), + "service_description": rule.conditions.service_description, + "service_label_groups": _internal_to_api(rule.conditions.service_label_groups), + } + ), + }, ) diff --git a/cmk/gui/openapi/endpoints/ruleset/__init__.py b/cmk/gui/openapi/endpoints/ruleset/__init__.py index e76d66688a2..6455147877d 100644 --- a/cmk/gui/openapi/endpoints/ruleset/__init__.py +++ b/cmk/gui/openapi/endpoints/ruleset/__init__.py @@ -7,7 +7,6 @@ from __future__ import annotations from cmk.gui.logged_in import user -from cmk.gui.openapi.endpoints.common_fields import field_include_extensions, field_include_links from cmk.gui.openapi.endpoints.ruleset.fields import ( RULESET_NAME, RulesetCollection, @@ -43,15 +42,13 @@ constructors.collection_href(domain_type="ruleset"), ".../collection", method="get", - query_params=[RulesetSearchOptions, field_include_links(), field_include_extensions()], + query_params=[RulesetSearchOptions], response_schema=RulesetCollection, permissions_required=LIST_PERMISSIONS, ) def list_rulesets(param): """Search rule sets""" user.need_permission("wato.rulesets") - include_links: bool = param["include_links"] - include_extensions: bool = param["include_extensions"] all_sets = ( FolderRulesets.load_folder_rulesets(param["folder"]) if param.get("folder") @@ -81,9 +78,7 @@ def _get_search_options(params): constructors.collection_object( domain_type="ruleset", value=[ - _serialize_ruleset( - ruleset, include_links=include_links, include_extensions=include_extensions - ) + _serialize_ruleset(ruleset) for ruleset in visible_rulesets(rulesets.get_rulesets()).values() ], ) @@ -122,9 +117,7 @@ def show_ruleset(param): return serve_json(_serialize_ruleset(ruleset)) -def _serialize_ruleset( - ruleset: Ruleset, *, include_links: bool = True, include_extensions: bool = True -) -> DomainObject: +def _serialize_ruleset(ruleset: Ruleset) -> DomainObject: members = {} if ruleset.num_rules() > 0: members["rules"] = constructors.collection_property( @@ -140,21 +133,16 @@ def _serialize_ruleset( editable=False, deletable=False, members=members, - extensions=( - { - "name": ruleset.name, - "title": ruleset.title(), - "item_type": ruleset.item_type(), - "item_name": ruleset.item_name(), - "item_enum": ruleset.item_enum(), - "match_type": ruleset.match_type(), - "help": strip_tags(ruleset.help()), - "number_of_rules": ruleset.num_rules(), - } - if include_extensions - else None - ), - include_links=include_links, + extensions={ + "name": ruleset.name, + "title": ruleset.title(), + "item_type": ruleset.item_type(), + "item_name": ruleset.item_name(), + "item_enum": ruleset.item_enum(), + "match_type": ruleset.match_type(), + "help": strip_tags(ruleset.help()), + "number_of_rules": ruleset.num_rules(), + }, ) diff --git a/cmk/gui/openapi/endpoints/service/__init__.py b/cmk/gui/openapi/endpoints/service/__init__.py index c1ad1c85b59..98e9c3b6649 100644 --- a/cmk/gui/openapi/endpoints/service/__init__.py +++ b/cmk/gui/openapi/endpoints/service/__init__.py @@ -31,7 +31,6 @@ from cmk.gui import sites from cmk.gui.fields import HostField from cmk.gui.http import Response -from cmk.gui.openapi.endpoints.common_fields import field_include_extensions, field_include_links from cmk.gui.openapi.restful_objects import constructors, Endpoint, response_schemas from cmk.gui.openapi.restful_objects.constructors import object_action_href from cmk.gui.openapi.restful_objects.registry import EndpointRegistry @@ -71,9 +70,7 @@ ], example=["host_name", "description"], ), - }, - field_include_links(), - field_include_extensions(), + } ] HOST_NAME = { @@ -208,9 +205,6 @@ def _list_services(params: Mapping[str, Any]) -> Response: result = q.iterate(live) - include_links: bool = params["include_links"] - include_extensions: bool = params["include_extensions"] - return serve_json( constructors.collection_object( domain_type="service", @@ -221,23 +215,18 @@ def _list_services(params: Mapping[str, Any]) -> Response: identifier=f"{entry['host_name']}:{entry['description']}", editable=False, deletable=False, - extensions=entry if include_extensions else None, - self_link=( - constructors.link_rel( - rel="cmk/show", - href=constructors.object_action_href( - "host", - entry["host_name"], - "show_service", - query_params=[("service_description", entry["description"])], - ), - method="get", - title=f"Show the service {entry['description']}", - ) - if include_links - else None + extensions=entry, + self_link=constructors.link_rel( + rel="cmk/show", + href=constructors.object_action_href( + "host", + entry["host_name"], + "show_service", + query_params=[("service_description", entry["description"])], + ), + method="get", + title=f"Show the service {entry['description']}", ), - include_links=include_links, ) for entry in result ], diff --git a/cmk/gui/openapi/endpoints/service_group_config/__init__.py b/cmk/gui/openapi/endpoints/service_group_config/__init__.py index a1d1c7816ba..e866978f1d8 100644 --- a/cmk/gui/openapi/endpoints/service_group_config/__init__.py +++ b/cmk/gui/openapi/endpoints/service_group_config/__init__.py @@ -27,7 +27,6 @@ from cmk.gui.http import Response from cmk.gui.logged_in import user -from cmk.gui.openapi.endpoints.common_fields import field_include_extensions, field_include_links from cmk.gui.openapi.endpoints.service_group_config.request_schemas import ( BulkDeleteServiceGroup, BulkInputServiceGroup, @@ -124,20 +123,12 @@ def bulk_create(params: Mapping[str, Any]) -> Response: method="get", response_schema=ServiceGroupCollection, permissions_required=PERMISSIONS, - query_params=[field_include_links(), field_include_extensions()], ) def list_groups(params: Mapping[str, Any]) -> Response: """Show all service groups""" user.need_permission("wato.groups") collection = build_group_list(load_service_group_information()) - return serve_json( - serialize_group_list( - "service_group_config", - collection, - include_links=params["include_links"], - include_extensions=params["include_extensions"], - ) - ) + return serve_json(serialize_group_list("service_group_config", collection)) @Endpoint( diff --git a/cmk/gui/openapi/endpoints/site_management/__init__.py b/cmk/gui/openapi/endpoints/site_management/__init__.py index c84b5ec7e27..cf1ac70c821 100644 --- a/cmk/gui/openapi/endpoints/site_management/__init__.py +++ b/cmk/gui/openapi/endpoints/site_management/__init__.py @@ -27,7 +27,6 @@ from cmk.gui.exceptions import MKUserError from cmk.gui.http import Response from cmk.gui.logged_in import user -from cmk.gui.openapi.endpoints.common_fields import field_include_extensions, field_include_links from cmk.gui.openapi.endpoints.site_management.request_schemas import ( SITE_ID, SITE_ID_EXISTS, @@ -95,7 +94,6 @@ def show_site(params: Mapping[str, Any]) -> Response: tag_group="Setup", response_schema=SiteConnectionResponseCollection, permissions_required=PERMISSIONS, - query_params=[field_include_links(), field_include_extensions()], ) def show_sites(params: Mapping[str, Any]) -> Response: """Show all site connections""" @@ -107,14 +105,7 @@ def show_sites(params: Mapping[str, Any]) -> Response: return serve_json( constructors.collection_object( domain_type="site_connection", - value=[ - _serialize_site( - site, - include_links=params["include_links"], - include_extensions=params["include_extensions"], - ) - for site in all_site_objs - ], + value=[_serialize_site(site) for site in all_site_objs], ) ) @@ -225,15 +216,12 @@ def site_logout(params: Mapping[str, Any]) -> Response: return Response(status=204) -def _serialize_site( - site: SiteConfig, *, include_links: bool = True, include_extensions: bool = True -) -> DomainObject: +def _serialize_site(site: SiteConfig) -> DomainObject: return domain_object( domain_type="site_connection", identifier=site.basic_settings.site_id, title=site.basic_settings.alias, - extensions=dict(site.to_external()) if include_extensions else None, - include_links=include_links, + extensions=dict(site.to_external()), editable=True, deletable=True, ) diff --git a/cmk/gui/openapi/endpoints/time_periods/__init__.py b/cmk/gui/openapi/endpoints/time_periods/__init__.py index 4b68493e111..e1c8710c6e9 100644 --- a/cmk/gui/openapi/endpoints/time_periods/__init__.py +++ b/cmk/gui/openapi/endpoints/time_periods/__init__.py @@ -21,7 +21,6 @@ from cmk.gui.http import Response from cmk.gui.logged_in import user -from cmk.gui.openapi.endpoints.common_fields import field_include_extensions, field_include_links from cmk.gui.openapi.endpoints.time_periods.request_schemas import ( CreateTimePeriod, UpdateTimePeriod, @@ -71,16 +70,12 @@ def time_period_not_found_problem(time_period_id: str) -> Response: def _get_time_period_domain_object( name: str, time_period: TimeperiodSpec, - *, - include_links: bool = True, - include_extensions: bool = True, ) -> DomainObject: return constructors.domain_object( domain_type="time_period", identifier=name, title=time_period["alias"], - extensions=_to_api_format(time_period, name == "24X7") if include_extensions else None, - include_links=include_links, + extensions=_to_api_format(time_period, name == "24X7"), deletable=True, editable=True, ) @@ -222,7 +217,6 @@ def show_time_period(params: Mapping[str, Any]) -> Response: method="get", response_schema=TimePeriodResponseCollection, permissions_required=PERMISSIONS, - query_params=[field_include_links(), field_include_extensions()], ) def list_time_periods(params: Mapping[str, Any]) -> Response: """Show all time periods""" @@ -231,12 +225,7 @@ def list_time_periods(params: Mapping[str, Any]) -> Response: constructors.collection_object( domain_type="time_period", value=[ - _get_time_period_domain_object( - name, - time_period, - include_links=params["include_links"], - include_extensions=params["include_extensions"], - ) + _get_time_period_domain_object(name, time_period) for name, time_period in load_timeperiods().items() ], ) diff --git a/cmk/gui/openapi/endpoints/user_config/__init__.py b/cmk/gui/openapi/endpoints/user_config/__init__.py index 6bb59450247..fa0d30ef5db 100644 --- a/cmk/gui/openapi/endpoints/user_config/__init__.py +++ b/cmk/gui/openapi/endpoints/user_config/__init__.py @@ -15,7 +15,6 @@ from cmk.gui.fields import Username from cmk.gui.http import Response from cmk.gui.logged_in import user -from cmk.gui.openapi.endpoints.common_fields import field_include_extensions, field_include_links from cmk.gui.openapi.endpoints.user_config.request_schemas import CreateUser, UpdateUser from cmk.gui.openapi.endpoints.user_config.response_schemas import UserCollection, UserObject from cmk.gui.openapi.endpoints.utils import complement_customer, update_customer_info @@ -102,19 +101,11 @@ def show_user(params: Mapping[str, Any]) -> Response: method="get", response_schema=UserCollection, permissions_required=PERMISSIONS, - query_params=[field_include_links(), field_include_extensions()], ) def list_users(params: Mapping[str, Any]) -> Response: """Show all users""" user.need_permission("wato.users") - include_links: bool = params["include_links"] - include_extensions: bool = params["include_extensions"] - users = [ - serialize_user( - user_id, spec, include_links=include_links, include_extensions=include_extensions - ) - for user_id, spec in load_users(False).items() - ] + users = [serialize_user(user_id, spec) for user_id, spec in load_users(False).items()] return serve_json(constructors.collection_object(domain_type="user_config", value=users)) @@ -240,18 +231,12 @@ def serve_user(user_id): def serialize_user( user_id: UserId, user_spec: UserSpec, - *, - include_links: bool = True, - include_extensions: bool = True, ) -> DomainObject: return constructors.domain_object( domain_type="user_config", identifier=user_id, title=user_spec["alias"], - extensions=( - complement_customer(_internal_to_api_format(user_spec)) if include_extensions else None - ), - include_links=include_links, + extensions=complement_customer(_internal_to_api_format(user_spec)), ) diff --git a/cmk/gui/openapi/endpoints/user_role/__init__.py b/cmk/gui/openapi/endpoints/user_role/__init__.py index 6ecb0a0d81a..8396e91f9b8 100644 --- a/cmk/gui/openapi/endpoints/user_role/__init__.py +++ b/cmk/gui/openapi/endpoints/user_role/__init__.py @@ -39,7 +39,6 @@ from cmk.gui.fields.definitions import UserRoleID from cmk.gui.http import Response from cmk.gui.logged_in import user -from cmk.gui.openapi.endpoints.common_fields import field_include_extensions, field_include_links from cmk.gui.openapi.endpoints.user_role.request_schemas import CreateUserRole, EditUserRole from cmk.gui.openapi.endpoints.user_role.response_schemas import UserRoleCollection, UserRoleObject from cmk.gui.openapi.restful_objects import constructors, Endpoint @@ -74,15 +73,12 @@ def _serialize_user_role_extensions(user_role: UserRole) -> dict[str, Any]: return extensions -def serialize_user_role( - user_role: UserRole, *, include_links: bool = True, include_extensions: bool = True -) -> DomainObject: +def serialize_user_role(user_role: UserRole) -> DomainObject: return constructors.domain_object( domain_type="user_role", identifier=user_role.name, title=user_role.alias, - extensions=_serialize_user_role_extensions(user_role) if include_extensions else None, - include_links=include_links, + extensions=_serialize_user_role_extensions(user_role), editable=True, deletable=not user_role.builtin, ) @@ -122,7 +118,6 @@ def show_user_role(params: Mapping[str, Any]) -> Response: tag_group="Setup", response_schema=UserRoleCollection, permissions_required=PERMISSIONS, - query_params=[field_include_links(), field_include_extensions()], ) def list_user_roles(params: Mapping[str, Any]) -> Response: """Show all user roles""" @@ -134,12 +129,7 @@ def list_user_roles(params: Mapping[str, Any]) -> Response: constructors.collection_object( domain_type="user_role", value=[ - serialize_user_role( - user_role, - include_links=params["include_links"], - include_extensions=params["include_extensions"], - ) - for user_role in userroles.get_all_roles().values() + serialize_user_role(user_role) for user_role in userroles.get_all_roles().values() ], ) ) diff --git a/cmk/gui/openapi/endpoints/utils.py b/cmk/gui/openapi/endpoints/utils.py index 98a0d8751e7..8fa4f882db5 100644 --- a/cmk/gui/openapi/endpoints/utils.py +++ b/cmk/gui/openapi/endpoints/utils.py @@ -60,9 +60,6 @@ def build_group_list(groups: GroupSpecs) -> list[GroupSpec]: def serialize_group_list( domain_type: GroupDomainType, collection: Sequence[GroupSpec], - *, - include_links: bool = True, - include_extensions: bool = True, ) -> CollectionObject: return constructors.collection_object( domain_type=domain_type, @@ -71,13 +68,8 @@ def serialize_group_list( domain_type=domain_type, title=group["alias"], identifier=group["id"], - include_links=include_links, - extensions=( - complement_customer( - {key: value for key, value in group.items() if key not in ("id", "alias")} - ) - if include_extensions - else None + extensions=complement_customer( + {key: value for key, value in group.items() if key not in ("id", "alias")} ), ) for group in collection diff --git a/tests/testlib/rest_api_client.py b/tests/testlib/rest_api_client.py index a68798e1257..1809efd9205 100644 --- a/tests/testlib/rest_api_client.py +++ b/tests/testlib/rest_api_client.py @@ -461,23 +461,11 @@ def get_activation(self, activation_id: str, expect_ok: bool = True) -> Response expect_ok=expect_ok, ) - def get_running_activations( - self, - *, - include_links: bool | None = None, - include_extensions: bool | None = None, - expect_ok: bool = True, - ) -> Response: + def get_running_activations(self, expect_ok: bool = True) -> Response: return self.request( "get", url=f"/domain-types/{self.domain}/collections/running", expect_ok=expect_ok, - query_params=_only_set_keys( - { - "include_links": include_links, - "include_extensions": include_extensions, - } - ), ) def activate_changes( @@ -645,22 +633,11 @@ def get( expect_ok=expect_ok, ) - def get_all( - self, - *, - include_links: bool | None = None, - include_extensions: bool | None = None, - expect_ok: bool = True, - ) -> Response: + def get_all(self, effective_attributes: bool = False, expect_ok: bool = True) -> Response: return self.request( "get", url=f"/domain-types/{self.domain}/collections/all", - query_params=_only_set_keys( - { - "include_links": include_links, - "include_extensions": include_extensions, - } - ), + query_params={"effective_attributes": "true" if effective_attributes else "false"}, expect_ok=expect_ok, ) @@ -753,20 +730,18 @@ def get_all( *, effective_attributes: bool = False, include_links: bool | None = None, - include_extensions: bool | None = None, expect_ok: bool = True, ) -> Response: return self.request( "get", url=f"/domain-types/{self.domain}/collections/all", - expect_ok=expect_ok, query_params=_only_set_keys( { "effective_attributes": effective_attributes, "include_links": include_links, - "include_extensions": include_extensions, } ), + expect_ok=expect_ok, ) def create( @@ -976,23 +951,19 @@ def get_all( parent: str | None = None, recursive: bool = False, show_hosts: bool = False, - include_links: bool | None = None, - include_extensions: bool | None = None, expect_ok: bool = True, ) -> Response: return self.request( "get", url=f"/domain-types/{self.domain}/collections/all", - expect_ok=expect_ok, query_params=_only_set_keys( { "parent": parent, "recursive": recursive, "show_hosts": show_hosts, - "include_links": include_links, - "include_extensions": include_extensions, } ), + expect_ok=expect_ok, ) def get_hosts( @@ -1001,7 +972,6 @@ def get_hosts( *, effective_attributes: bool | None = None, include_links: bool | None = None, - include_extensions: bool | None = None, expect_ok: bool = True, ) -> Response: return self.request( @@ -1012,7 +982,6 @@ def get_hosts( { "effective_attributes": effective_attributes, "include_links": include_links, - "include_extensions": include_extensions, } ), ) @@ -1128,23 +1097,11 @@ def get(self, aux_tag_id: str, expect_ok: bool = True) -> Response: expect_ok=expect_ok, ) - def get_all( - self, - *, - include_links: bool | None = None, - include_extensions: bool | None = None, - expect_ok: bool = True, - ) -> Response: + def get_all(self, expect_ok: bool = True) -> Response: return self.request( "get", url=f"/domain-types/{self.domain}/collections/all", expect_ok=expect_ok, - query_params=_only_set_keys( - { - "include_links": include_links, - "include_extensions": include_extensions, - } - ), ) def create(self, tag_data: dict[str, Any], expect_ok: bool = True) -> Response: @@ -1196,23 +1153,11 @@ def get(self, time_period_id: str, expect_ok: bool = True) -> Response: expect_ok=expect_ok, ) - def get_all( - self, - *, - include_links: bool | None = None, - include_extensions: bool | None = None, - expect_ok: bool = True, - ) -> Response: + def get_all(self, expect_ok: bool = True) -> Response: return self.request( "get", url=f"/domain-types/{self.domain}/collections/all", expect_ok=expect_ok, - query_params=_only_set_keys( - { - "include_links": include_links, - "include_extensions": include_extensions, - } - ), ) def delete(self, time_period_id: str, expect_ok: bool = True) -> Response: @@ -1255,14 +1200,7 @@ def get(self, rule_id: str, expect_ok: bool = True) -> Response: expect_ok=expect_ok, ) - def list( - self, - ruleset: str, - *, - include_links: bool | None = None, - include_extensions: bool | None = None, - expect_ok: bool = True, - ) -> Response: + def list(self, ruleset: str, expect_ok: bool = True) -> Response: return self.request( "get", url=f"/domain-types/{self.domain}/collections/all", @@ -1270,8 +1208,6 @@ def list( query_params=_only_set_keys( { "ruleset_name": ruleset, - "include_links": include_links, - "include_extensions": include_extensions, } ), ) @@ -1365,8 +1301,6 @@ def list( used: bool | None = None, group: str | None = None, name: str | None = None, - include_links: bool | None = None, - include_extensions: bool | None = None, expect_ok: bool = True, ) -> Response: return self.request( @@ -1381,8 +1315,6 @@ def list( "used": used, "group": group, "name": name, - "include_links": include_links, - "include_extensions": include_extensions, } ), ) @@ -1423,17 +1355,12 @@ def get(self, ident: str, expect_ok: bool = True) -> Response: def get_all( self, *, - include_links: bool | None = None, - include_extensions: bool | None = None, expect_ok: bool = True, ) -> Response: return self.request( "get", f"/domain-types/{self.domain}/collections/all", expect_ok=expect_ok, - query_params=_only_set_keys( - {"include_links": include_links, "include_extensions": include_extensions} - ), ) def delete( @@ -1518,17 +1445,12 @@ def get(self, ident: str, expect_ok: bool = True) -> Response: def get_all( self, *, - include_links: bool | None = None, - include_extensions: bool | None = None, expect_ok: bool = True, ) -> Response: return self.request( "get", f"/domain-types/{self.domain}/collections/all", expect_ok=expect_ok, - query_params=_only_set_keys( - {"include_links": include_links, "include_extensions": include_extensions} - ), ) def edit( @@ -1584,20 +1506,12 @@ def bake_and_sign(self, key_id: int, passphrase: str, expect_ok: bool = True) -> def get_all( self, *, - include_links: bool | None = None, - include_extensions: bool | None = None, expect_ok: bool = True, ) -> Response: return self.request( "get", url=f"/domain-types/{self.domain}/collections/all", expect_ok=expect_ok, - query_params=_only_set_keys( - { - "include_links": include_links, - "include_extensions": include_extensions, - } - ), ) @@ -1619,8 +1533,6 @@ def get_all( query: str | None = None, downtime_type: Literal["host", "service", "both"] = "both", site_id: str | None = None, - include_links: bool | None = None, - include_extensions: bool | None = None, expect_ok: bool = True, ) -> Response: return self.request( @@ -1634,8 +1546,6 @@ def get_all( "service_description": service_description, "query": query, "site_id": site_id, - "include_links": include_links, - "include_extensions": include_extensions, } ), ) @@ -1841,20 +1751,11 @@ def bulk_create(self, groups: tuple[dict[str, str], ...], expect_ok: bool = True expect_ok=expect_ok, ) - def list( - self, - *, - include_links: bool | None = None, - include_extensions: bool | None = None, - expect_ok: bool = True, - ) -> Response: + def list(self, expect_ok: bool = True) -> Response: return self.request( "get", f"/domain-types/{self.domain}/collections/all", expect_ok=expect_ok, - query_params=_only_set_keys( - {"include_links": include_links, "include_extensions": include_extensions} - ), ) def bulk_edit(self, groups: tuple[dict[str, str], ...], expect_ok: bool = True) -> Response: @@ -1909,20 +1810,11 @@ def get(self, site_id: str, expect_ok: bool = True) -> Response: expect_ok=expect_ok, ) - def get_all( - self, - *, - include_links: bool | None = None, - include_extensions: bool | None = None, - expect_ok: bool = True, - ) -> Response: + def get_all(self, expect_ok: bool = True) -> Response: return self.request( "get", url=f"/domain-types/{self.domain}/collections/all", expect_ok=expect_ok, - query_params=_only_set_keys( - {"include_links": include_links, "include_extensions": include_extensions} - ), ) def login(self, site_id: str, username: str, password: str, expect_ok: bool = True) -> Response: @@ -1980,21 +1872,11 @@ def get(self, host_name: str, columns: Sequence[str], expect_ok: bool = True) -> def get_all( self, - *, - query: dict[str, Any] | None = None, + query: dict[str, Any], columns: Sequence[str] = ("name",), - include_links: bool | None = None, - include_extensions: bool | None = None, expect_ok: bool = True, ) -> Response: - params = _only_set_keys( - { - "query": json.dumps(query), - "columns": columns, - "include_links": include_links, - "include_extensions": include_extensions, - } - ) + params = {"query": json.dumps(query), "columns": columns} return self.request( "get", url="/domain-types/host/collections/all", @@ -2013,20 +1895,11 @@ def get(self, rule_id: str, expect_ok: bool = True) -> Response: expect_ok=expect_ok, ) - def get_all( - self, - *, - include_links: bool | None = None, - include_extensions: bool | None = None, - expect_ok: bool = True, - ) -> Response: + def get_all(self, expect_ok: bool = True) -> Response: return self.request( "get", url=f"/domain-types/{self.domain}/collections/all", expect_ok=expect_ok, - query_params=_only_set_keys( - {"include_links": include_links, "include_extensions": include_extensions} - ), ) def create(self, rule_config: APINotificationRule, expect_ok: bool = True) -> Response: @@ -2079,8 +1952,6 @@ def get_all( state: Literal["warning", "ok", "critical", "unknown"] | None = None, phase: Literal["open", "ack"] | None = None, site_id: str | None = None, - include_links: bool | None = None, - include_extensions: bool | None = None, expect_ok: bool = True, ) -> Response: return self.request( @@ -2095,8 +1966,6 @@ def get_all( "state": state, "phase": phase, "site_id": site_id, - "include_links": include_links, - "include_extensions": include_extensions, } ), ) @@ -2338,8 +2207,6 @@ def get_all( service_description: str | None = None, query: Mapping[str, Any] | str | None = None, site_id: str | None = None, - include_links: bool | None = None, - include_extensions: bool | None = None, expect_ok: bool = True, ) -> Response: q: Mapping[str, Any] = _only_set_keys( @@ -2348,8 +2215,6 @@ def get_all( "service_description": service_description, "query": query, "site_id": site_id, - "include_links": include_links, - "include_extensions": include_extensions, } ) @@ -2701,20 +2566,11 @@ def get(self, role_id: str, expect_ok: bool = True) -> Response: expect_ok=expect_ok, ) - def get_all( - self, - *, - include_links: bool | None = None, - include_extensions: bool | None = None, - expect_ok: bool = True, - ) -> Response: + def get_all(self, expect_ok: bool = True) -> Response: return self.request( "get", url=f"/domain-types/{self.domain}/collections/all", expect_ok=expect_ok, - query_params=_only_set_keys( - {"include_links": include_links, "include_extensions": include_extensions} - ), ) def clone(self, body: dict[str, Any], expect_ok: bool = True) -> Response: @@ -2769,20 +2625,11 @@ def get(self, saml_connection_id: str, expect_ok: bool = True) -> Response: expect_ok=expect_ok, ) - def get_all( - self, - *, - include_links: bool | None = None, - include_extensions: bool | None = None, - expect_ok: bool = True, - ) -> Response: + def get_all(self, expect_ok: bool = True) -> Response: return self.request( "get", url=f"/domain-types/{self.domain}/collections/all", expect_ok=expect_ok, - query_params=_only_set_keys( - {"include_links": include_links, "include_extensions": include_extensions} - ), ) def create( @@ -2827,8 +2674,6 @@ def get_all( self, *, host_name: str | None = None, - include_links: bool | None = None, - include_extensions: bool | None = None, expect_ok: bool = True, ) -> Response: return self.request( @@ -2838,8 +2683,6 @@ def get_all( query_params=_only_set_keys( { "host_name": host_name, - "include_links": include_links, - "include_extensions": include_extensions, } ), ) @@ -2909,18 +2752,12 @@ def get( def get_all( self, - *, - include_links: bool | None = None, - include_extensions: bool | None = None, expect_ok: bool = True, ) -> Response: return self.request( "get", url=f"/domain-types/{self.domain}/collections/all", expect_ok=expect_ok, - query_params=_only_set_keys( - {"include_links": include_links, "include_extensions": include_extensions} - ), ) def create( diff --git a/tests/unit/cmk/gui/openapi/test_event_console.py b/tests/unit/cmk/gui/openapi/test_event_console.py index 3eeb9145665..0daa358e565 100644 --- a/tests/unit/cmk/gui/openapi/test_event_console.py +++ b/tests/unit/cmk/gui/openapi/test_event_console.py @@ -7,7 +7,7 @@ from time import time from typing import Any -from tests.testlib.rest_api_client import ClientRegistry, Response +from tests.testlib.rest_api_client import ClientRegistry from cmk.utils.livestatus_helpers.testing import MockLiveStatusConnection @@ -81,52 +81,6 @@ def test_get_all_ec_events( } -def test_list_ec_events_include_links( - clients: ClientRegistry, mock_livestatus: MockLiveStatusConnection -) -> None: - add_event_console_events_to_live_status_table(mock_livestatus) - - def _request(include_links: bool | None = None) -> Response: - mock_livestatus.expect_query( - "GET eventconsoleevents\nColumns: event_id event_state event_sl event_host event_rule_id event_application event_comment event_contact event_ipaddress event_facility event_priority event_last event_first event_count event_phase event_text" - ) - with mock_livestatus: - return clients.EventConsole.get_all(include_links=include_links) - - default_response = _request() - enabled_response = _request(include_links=True) - disabled_response = _request(include_links=False) - - assert len(default_response.json["value"]) > 0 - - assert default_response.json == enabled_response.json - assert any(bool(value["links"]) for value in enabled_response.json["value"]) - assert all(value["links"] == [] for value in disabled_response.json["value"]) - - -def test_list_ec_events_include_extensions( - clients: ClientRegistry, mock_livestatus: MockLiveStatusConnection -) -> None: - add_event_console_events_to_live_status_table(mock_livestatus) - - def _request(include_extensions: bool | None = None) -> Response: - mock_livestatus.expect_query( - "GET eventconsoleevents\nColumns: event_id event_state event_sl event_host event_rule_id event_application event_comment event_contact event_ipaddress event_facility event_priority event_last event_first event_count event_phase event_text" - ) - with mock_livestatus: - return clients.EventConsole.get_all(include_extensions=include_extensions) - - default_response = _request() - enabled_response = _request(include_extensions=True) - disabled_response = _request(include_extensions=False) - - assert len(default_response.json["value"]) > 0 - - assert default_response.json == enabled_response.json - assert any(bool(value["extensions"]) for value in enabled_response.json["value"]) - assert all("extensions" not in value for value in disabled_response.json["value"]) - - def test_get_all_ec_events_host( clients: ClientRegistry, mock_livestatus: MockLiveStatusConnection, diff --git a/tests/unit/cmk/gui/openapi/test_ldap_connection.py b/tests/unit/cmk/gui/openapi/test_ldap_connection.py index 5fa903fa313..70c110f9df9 100644 --- a/tests/unit/cmk/gui/openapi/test_ldap_connection.py +++ b/tests/unit/cmk/gui/openapi/test_ldap_connection.py @@ -258,32 +258,6 @@ def test_get_ldap_connections(clients: ClientRegistry) -> None: assert resp.json["value"][3]["extensions"] == cnx4 -def test_list_ldap_connections_include_links(clients: ClientRegistry) -> None: - create_ldap_connections(clients) - default_response = clients.LdapConnection.get_all() - enabled_response = clients.LdapConnection.get_all(include_links=True) - disabled_response = clients.LdapConnection.get_all(include_links=False) - - assert len(default_response.json["value"]) > 0 - - assert default_response.json == enabled_response.json - assert any(bool(value["links"]) for value in enabled_response.json["value"]) - assert all(value["links"] == [] for value in disabled_response.json["value"]) - - -def test_list_ldap_connections_include_extensions(clients: ClientRegistry) -> None: - create_ldap_connections(clients) - default_response = clients.LdapConnection.get_all() - enabled_response = clients.LdapConnection.get_all(include_extensions=True) - disabled_response = clients.LdapConnection.get_all(include_extensions=False) - - assert len(default_response.json["value"]) > 0 - - assert default_response.json == enabled_response.json - assert any(bool(value["extensions"]) for value in enabled_response.json["value"]) - assert all("extensions" not in value for value in disabled_response.json["value"]) - - def test_create_ldap_connection_existing_id(clients: ClientRegistry) -> None: create_ldap_connections(clients) clients.LdapConnection.create( diff --git a/tests/unit/cmk/gui/openapi/test_notification_rules.py b/tests/unit/cmk/gui/openapi/test_notification_rules.py index 63330eff230..50aa7269c5d 100644 --- a/tests/unit/cmk/gui/openapi/test_notification_rules.py +++ b/tests/unit/cmk/gui/openapi/test_notification_rules.py @@ -80,34 +80,6 @@ def test_get_notification_rules(clients: ClientRegistry) -> None: assert rules[1]["id"] == r2.json["id"] -def test_list_notification_rules_include_links(clients: ClientRegistry) -> None: - config = notification_rule_request_example() - clients.RuleNotification.create(config) - default_response = clients.RuleNotification.get_all() - enabled_response = clients.RuleNotification.get_all(include_links=True) - disabled_response = clients.RuleNotification.get_all(include_links=False) - - assert len(default_response.json["value"]) > 0 - - assert default_response.json == enabled_response.json - assert any(bool(value["links"]) for value in enabled_response.json["value"]) - assert all(value["links"] == [] for value in disabled_response.json["value"]) - - -def test_list_notification_rules_include_extensions(clients: ClientRegistry) -> None: - config = notification_rule_request_example() - clients.RuleNotification.create(config) - default_response = clients.RuleNotification.get_all() - enabled_response = clients.RuleNotification.get_all(include_extensions=True) - disabled_response = clients.RuleNotification.get_all(include_extensions=False) - - assert len(default_response.json["value"]) > 0 - - assert default_response.json == enabled_response.json - assert any(bool(value["extensions"]) for value in enabled_response.json["value"]) - assert all("extensions" not in value for value in disabled_response.json["value"]) - - def test_create_notification_rule(clients: ClientRegistry) -> None: config = notification_rule_request_example() r1 = clients.RuleNotification.create(config) diff --git a/tests/unit/cmk/gui/openapi/test_openapi_auxtags.py b/tests/unit/cmk/gui/openapi/test_openapi_auxtags.py index 03ffa781af5..be2541eb420 100644 --- a/tests/unit/cmk/gui/openapi/test_openapi_auxtags.py +++ b/tests/unit/cmk/gui/openapi/test_openapi_auxtags.py @@ -349,27 +349,3 @@ def test_id_in_use_by_builtin_aux_tag(clients: ClientRegistry) -> None: f"The aux_tag '{builtin_aux_tag}' should not exist but it does." in builtin_aux_tag_resp.json["fields"]["aux_tag_id"] ) - - -def test_list_aux_tags_include_links(clients: ClientRegistry) -> None: - default_response = clients.AuxTag.get_all() - enabled_response = clients.AuxTag.get_all(include_links=True) - disabled_response = clients.AuxTag.get_all(include_links=False) - - assert len(default_response.json["value"]) > 0 - - assert default_response.json == enabled_response.json - assert any(bool(value["links"]) for value in enabled_response.json["value"]) - assert all(value["links"] == [] for value in disabled_response.json["value"]) - - -def test_list_aux_tags_include_extensions(clients: ClientRegistry) -> None: - default_response = clients.AuxTag.get_all() - enabled_response = clients.AuxTag.get_all(include_extensions=True) - disabled_response = clients.AuxTag.get_all(include_extensions=False) - - assert len(default_response.json["value"]) > 0 - - assert default_response.json == enabled_response.json - assert any(bool(value["extensions"]) for value in enabled_response.json["value"]) - assert all("extensions" not in value for value in disabled_response.json["value"]) diff --git a/tests/unit/cmk/gui/openapi/test_openapi_downtime.py b/tests/unit/cmk/gui/openapi/test_openapi_downtime.py index 614db201117..341aa793c6c 100644 --- a/tests/unit/cmk/gui/openapi/test_openapi_downtime.py +++ b/tests/unit/cmk/gui/openapi/test_openapi_downtime.py @@ -6,7 +6,7 @@ import pytest -from tests.testlib.rest_api_client import ClientRegistry, Response +from tests.testlib.rest_api_client import ClientRegistry from tests.unit.cmk.gui.conftest import SetConfig @@ -1622,53 +1622,3 @@ def test_openapi_downtime_fields_format( attributes = dt["extensions"] assert isinstance(attributes["recurring"], bool) assert isinstance(attributes["is_service"], bool) - - -@pytest.mark.usefixtures("suppress_remote_automation_calls", "with_host") -def test_list_downtimes_include_links( - mock_livestatus: MockLiveStatusConnection, clients: ClientRegistry -) -> None: - def _request(include_links: bool | None = None) -> Response: - mock_livestatus.expect_query( - [ - "GET downtimes", - "Columns: id host_name service_description is_service author start_time end_time recurring comment", - ] - ) - with mock_livestatus: - return clients.Downtime.get_all(include_links=include_links) - - default_response = _request() - enabled_response = _request(include_links=True) - disabled_response = _request(include_links=False) - - assert len(default_response.json["value"]) > 0 - - assert default_response.json == enabled_response.json - assert any(bool(value["links"]) for value in enabled_response.json["value"]) - assert all(value["links"] == [] for value in disabled_response.json["value"]) - - -@pytest.mark.usefixtures("suppress_remote_automation_calls", "with_host") -def test_list_downtimes_include_extensions( - mock_livestatus: MockLiveStatusConnection, clients: ClientRegistry -) -> None: - def _request(include_extensions: bool | None = None) -> Response: - mock_livestatus.expect_query( - [ - "GET downtimes", - "Columns: id host_name service_description is_service author start_time end_time recurring comment", - ] - ) - with mock_livestatus: - return clients.Downtime.get_all(include_extensions=include_extensions) - - default_response = _request() - enabled_response = _request(include_extensions=True) - disabled_response = _request(include_extensions=False) - - assert len(default_response.json["value"]) > 0 - - assert default_response.json == enabled_response.json - assert any(bool(value["extensions"]) for value in enabled_response.json["value"]) - assert all("extensions" not in value for value in disabled_response.json["value"]) diff --git a/tests/unit/cmk/gui/openapi/test_openapi_folder_config.py b/tests/unit/cmk/gui/openapi/test_openapi_folder_config.py index fe81b4267ca..331153e0e57 100644 --- a/tests/unit/cmk/gui/openapi/test_openapi_folder_config.py +++ b/tests/unit/cmk/gui/openapi/test_openapi_folder_config.py @@ -213,32 +213,6 @@ def test_openapi_folders(clients: ClientRegistry) -> None: clients.Folder.delete(folder_name=folder_obj["id"]) -def test_openapi_list_folders_include_links(clients: ClientRegistry) -> None: - clients.Folder.create(parent="/", title="test_folder") - default_response = clients.Folder.get_all() - enabled_response = clients.Folder.get_all(include_links=True) - disabled_response = clients.Folder.get_all(include_links=False) - - assert len(default_response.json["value"]) > 0 - - assert default_response.json == enabled_response.json - assert any(bool(value["links"]) for value in enabled_response.json["value"]) - assert all(value["links"] == [] for value in disabled_response.json["value"]) - - -def test_openapi_list_folders_include_extensions(clients: ClientRegistry) -> None: - clients.Folder.create(parent="/", title="test_folder") - default_response = clients.Folder.get_all() - enabled_response = clients.Folder.get_all(include_extensions=True) - disabled_response = clients.Folder.get_all(include_extensions=False) - - assert len(default_response.json["value"]) > 0 - - assert default_response.json == enabled_response.json - assert any(bool(value["extensions"]) for value in enabled_response.json["value"]) - assert all("extensions" not in value for value in disabled_response.json["value"]) - - def test_openapi_folder_non_existent_site(clients: ClientRegistry) -> None: folder_name = "my_folder" non_existing_site_name = "i_am_not_existing" @@ -298,32 +272,6 @@ def test_openapi_hosts_in_folder(clients: ClientRegistry) -> None: clients.Folder.get_hosts("~") -@pytest.mark.usefixtures("with_host") -def test_openapi_hosts_in_folder_include_links(clients: ClientRegistry) -> None: - default_response = clients.Folder.get_hosts("~") - enabled_response = clients.Folder.get_hosts("~", include_links=True) - disabled_response = clients.Folder.get_hosts("~", include_links=False) - - assert len(default_response.json["value"]) > 0 - - assert default_response.json == enabled_response.json - assert any(bool(value["links"]) for value in enabled_response.json["value"]) - assert all(value["links"] == [] for value in disabled_response.json["value"]) - - -@pytest.mark.usefixtures("with_host") -def test_openapi_hosts_in_folder_include_extensions(clients: ClientRegistry) -> None: - default_response = clients.Folder.get_hosts("~") - enabled_response = clients.Folder.get_hosts("~", include_extensions=True) - disabled_response = clients.Folder.get_hosts("~", include_extensions=False) - - assert len(default_response.json["value"]) > 0 - - assert default_response.json == enabled_response.json - assert any(bool(value["extensions"]) for value in enabled_response.json["value"]) - assert all("extensions" not in value for value in disabled_response.json["value"]) - - def test_openapi_hosts_in_folder_collection(aut_user_auth_wsgi_app: WebTestAppForCMK) -> None: aut_user_auth_wsgi_app.call_method( "post", diff --git a/tests/unit/cmk/gui/openapi/test_openapi_group_config.py b/tests/unit/cmk/gui/openapi/test_openapi_group_config.py index 0e97d5f13c1..847a8f494bc 100644 --- a/tests/unit/cmk/gui/openapi/test_openapi_group_config.py +++ b/tests/unit/cmk/gui/openapi/test_openapi_group_config.py @@ -295,7 +295,7 @@ def test_openapi_group_values_are_links(group_client: GroupConfig, group_type: s customer="global", ) - response = group_client.list(include_links=True) + response = group_client.list() assert len(response.json["value"]) == 1 assert response.json["value"][0]["links"][0]["domainType"] == "link" @@ -584,30 +584,3 @@ def test_contact_group_inventory_paths( path.setdefault("nodes", {"type": "no_restriction"}) assert group.json["extensions"]["inventory_paths"] == inventory_paths - - -def test_list_group_include_links(group_client: GroupConfig) -> None: - group_client.create(name="test_group", alias="test_alias") - default_response = group_client.list() - enabled_response = group_client.list(include_links=True) - disabled_response = group_client.list(include_links=False) - - assert len(default_response.json["value"]) > 0 - - assert default_response.json == enabled_response.json - assert any(bool(value["links"]) for value in enabled_response.json["value"]) - assert all(value["links"] == [] for value in disabled_response.json["value"]) - - -@managedtest -def test_list_group_include_extensions(group_client: GroupConfig) -> None: - group_client.create(name="test_group", alias="test_alias") - default_response = group_client.list() - enabled_response = group_client.list(include_extensions=True) - disabled_response = group_client.list(include_extensions=False) - - assert len(default_response.json["value"]) > 0 - - assert default_response.json == enabled_response.json - assert any(bool(value["extensions"]) for value in enabled_response.json["value"]) - assert all("extensions" not in value for value in disabled_response.json["value"]) diff --git a/tests/unit/cmk/gui/openapi/test_openapi_host.py b/tests/unit/cmk/gui/openapi/test_openapi_host.py index ef983b4bc62..7361443b88c 100644 --- a/tests/unit/cmk/gui/openapi/test_openapi_host.py +++ b/tests/unit/cmk/gui/openapi/test_openapi_host.py @@ -7,7 +7,7 @@ import pytest -from tests.testlib.rest_api_client import ClientRegistry, Response +from tests.testlib.rest_api_client import ClientRegistry from tests.unit.cmk.gui.conftest import WebTestAppForCMK @@ -74,76 +74,6 @@ def test_openapi_livestatus_hosts_generic_filter( assert len(resp.json["value"]) == 1 -@pytest.mark.usefixtures("suppress_remote_automation_calls") -def test_openapi_list_hosts_include_links( - clients: ClientRegistry, - mock_livestatus: MockLiveStatusConnection, -) -> None: - mock_livestatus.add_table( - "hosts", - [ - { - "name": "heute", - }, - ], - ) - - def _request(include_links: bool | None = None) -> Response: - mock_livestatus.expect_query( - [ - "GET hosts", - "Columns: name", - ], - ) - with mock_livestatus: - return clients.Host.get_all(include_links=include_links) - - default_response = _request() - enabled_response = _request(include_links=True) - disabled_response = _request(include_links=False) - - assert len(default_response.json["value"]) > 0 - - assert default_response.json == enabled_response.json - assert any(bool(value["links"]) for value in enabled_response.json["value"]) - assert all(value["links"] == [] for value in disabled_response.json["value"]) - - -@pytest.mark.usefixtures("suppress_remote_automation_calls") -def test_openapi_list_hosts_include_extensions( - clients: ClientRegistry, - mock_livestatus: MockLiveStatusConnection, -) -> None: - mock_livestatus.add_table( - "hosts", - [ - { - "name": "heute", - }, - ], - ) - - def _request(include_extensions: bool | None = None) -> Response: - mock_livestatus.expect_query( - [ - "GET hosts", - "Columns: name", - ], - ) - with mock_livestatus: - return clients.Host.get_all(include_extensions=include_extensions) - - default_response = _request() - enabled_response = _request(include_extensions=True) - disabled_response = _request(include_extensions=False) - - assert len(default_response.json["value"]) > 0 - - assert default_response.json == enabled_response.json - assert any(bool(value["extensions"]) for value in enabled_response.json["value"]) - assert all("extensions" not in value for value in disabled_response.json["value"]) - - @pytest.mark.usefixtures("suppress_remote_automation_calls") def test_openapi_livestatus_hosts_empty_query( aut_user_auth_wsgi_app: WebTestAppForCMK, diff --git a/tests/unit/cmk/gui/openapi/test_openapi_host_config.py b/tests/unit/cmk/gui/openapi/test_openapi_host_config.py index 0880ea24ba9..145749635a5 100644 --- a/tests/unit/cmk/gui/openapi/test_openapi_host_config.py +++ b/tests/unit/cmk/gui/openapi/test_openapi_host_config.py @@ -586,7 +586,7 @@ def test_openapi_host_custom_attributes(clients: ClientRegistry) -> None: @pytest.mark.usefixtures("with_host") def test_openapi_host_collection(clients: ClientRegistry) -> None: - resp = clients.HostConfig.get_all(include_links=False) + resp = clients.HostConfig.get_all() for host in resp.json["value"]: # Check that all entries are domain objects @@ -599,11 +599,11 @@ def test_openapi_host_collection(clients: ClientRegistry) -> None: @pytest.mark.usefixtures("with_host") def test_openapi_host_collection_effective_attributes(clients: ClientRegistry) -> None: - resp1 = clients.HostConfig.get_all(effective_attributes=True, include_links=False) + resp1 = clients.HostConfig.get_all(effective_attributes=True) for host in resp1.json["value"]: assert isinstance(host["extensions"]["effective_attributes"], dict) - resp2 = clients.HostConfig.get_all(effective_attributes=False, include_links=False) + resp2 = clients.HostConfig.get_all(effective_attributes=False) for host in resp2.json["value"]: assert host["extensions"]["effective_attributes"] is None @@ -616,24 +616,11 @@ def test_openapi_list_hosts_include_links(clients: ClientRegistry) -> None: assert len(default_response.json["value"]) > 0 - assert default_response.json == enabled_response.json + assert default_response.json == disabled_response.json assert any(bool(value["links"]) for value in enabled_response.json["value"]) assert all(value["links"] == [] for value in disabled_response.json["value"]) -@pytest.mark.usefixtures("with_host") -def test_openapi_list_hosts_include_extensions(clients: ClientRegistry) -> None: - default_response = clients.HostConfig.get_all() - enabled_response = clients.HostConfig.get_all(include_extensions=True) - disabled_response = clients.HostConfig.get_all(include_extensions=False) - - assert len(default_response.json["value"]) > 0 - - assert default_response.json == enabled_response.json - assert any(bool(value["extensions"]) for value in enabled_response.json["value"]) - assert all("extensions" not in value for value in disabled_response.json["value"]) - - @pytest.mark.usefixtures("inline_background_jobs") def test_openapi_host_rename( clients: ClientRegistry, @@ -1007,7 +994,7 @@ def mock_all_hosts_recursively(_cls): } monkeypatch.setattr(Folder, "all_hosts_recursively", mock_all_hosts_recursively) - clients.HostConfig.get_all(include_links=False) + clients.HostConfig.get_all() def test_openapi_host_with_non_existing_site( @@ -1124,7 +1111,7 @@ def test_openapi_list_hosts_does_not_show_inaccessible_hosts(clients: ClientRegi ) clients.Host.set_credentials("unable_to_see_all_host", "supersecretish") - resp = clients.HostConfig.get_all(include_links=False, include_extensions=False) + resp = clients.HostConfig.get_all() host_names = [entry["id"] for entry in resp.json["value"]] assert "should_be_visible" in host_names assert "should_not_be_invisible" not in host_names @@ -1159,10 +1146,8 @@ def test_openapi_effective_attributes_are_transformed_on_their_way_out_regressio == resp_without_effective_attributes.json["extensions"]["attributes"]["meta_data"] ) - resp_with_effective_attributes = clients.HostConfig.get_all( - effective_attributes=True, include_links=False - ) - resp_without_effective_attributes = clients.HostConfig.get_all(include_links=False) + resp_with_effective_attributes = clients.HostConfig.get_all(effective_attributes=True) + resp_without_effective_attributes = clients.HostConfig.get_all() assert resp_with_effective_attributes.json["value"][0]["extensions"]["effective_attributes"][ "meta_data" ] == { diff --git a/tests/unit/cmk/gui/openapi/test_openapi_host_tag_group.py b/tests/unit/cmk/gui/openapi/test_openapi_host_tag_group.py index 0191d0394de..89596635069 100644 --- a/tests/unit/cmk/gui/openapi/test_openapi_host_tag_group.py +++ b/tests/unit/cmk/gui/openapi/test_openapi_host_tag_group.py @@ -98,32 +98,6 @@ def test_openapi_host_tag_group_get_collection(aut_user_auth_wsgi_app: WebTestAp assert len(col_resp.json_body["value"]) == builtin_groups_count -@pytest.mark.usefixtures("suppress_remote_automation_calls") -def test_openapi_list_host_tag_groups_include_links(clients: ClientRegistry) -> None: - default_response = clients.HostTagGroup.get_all() - enabled_response = clients.HostTagGroup.get_all(include_links=True) - disabled_response = clients.HostTagGroup.get_all(include_links=False) - - assert len(default_response.json["value"]) > 0 - - assert default_response.json == enabled_response.json - assert any(bool(value["links"]) for value in enabled_response.json["value"]) - assert all(value["links"] == [] for value in disabled_response.json["value"]) - - -@pytest.mark.usefixtures("suppress_remote_automation_calls") -def test_openapi_list_host_tag_groups_include_extensions(clients: ClientRegistry) -> None: - default_response = clients.HostTagGroup.get_all() - enabled_response = clients.HostTagGroup.get_all(include_extensions=True) - disabled_response = clients.HostTagGroup.get_all(include_extensions=False) - - assert len(default_response.json["value"]) > 0 - - assert default_response.json == enabled_response.json - assert any(bool(value["extensions"]) for value in enabled_response.json["value"]) - assert all("extensions" not in value for value in disabled_response.json["value"]) - - @pytest.mark.usefixtures( "suppress_remote_automation_calls", "suppress_spec_generation_in_background", diff --git a/tests/unit/cmk/gui/openapi/test_openapi_password.py b/tests/unit/cmk/gui/openapi/test_openapi_password.py index 64e5d58c4b0..dabb38352f8 100644 --- a/tests/unit/cmk/gui/openapi/test_openapi_password.py +++ b/tests/unit/cmk/gui/openapi/test_openapi_password.py @@ -335,33 +335,3 @@ def test_password_identifier_regex(clients: ClientRegistry) -> None: "'abcâ„•' does not match pattern. An identifier must only consist of letters, digits, dash and underscore and it must start with a letter or underscore." ] } - - -@managedtest -@pytest.mark.usefixtures("mock_password_file_regeneration") -def test_list_passwords_include_links(clients: ClientRegistry) -> None: - clients.Password.create("test_password", "Test Password", "admin", "secret", ["all"]) - default_response = clients.Password.get_all() - enabled_response = clients.Password.get_all(include_links=True) - disabled_response = clients.Password.get_all(include_links=False) - - assert len(default_response.json["value"]) > 0 - - assert default_response.json == enabled_response.json - assert any(bool(value["links"]) for value in enabled_response.json["value"]) - assert all(value["links"] == [] for value in disabled_response.json["value"]) - - -@managedtest -@pytest.mark.usefixtures("mock_password_file_regeneration") -def test_list_passwords_include_extensions(clients: ClientRegistry) -> None: - clients.Password.create("test_password", "Test Password", "admin", "secret", ["all"]) - default_response = clients.Password.get_all() - enabled_response = clients.Password.get_all(include_extensions=True) - disabled_response = clients.Password.get_all(include_extensions=False) - - assert len(default_response.json["value"]) > 0 - - assert default_response.json == enabled_response.json - assert any(bool(value["extensions"]) for value in enabled_response.json["value"]) - assert all("extensions" not in value for value in disabled_response.json["value"]) diff --git a/tests/unit/cmk/gui/openapi/test_openapi_rules.py b/tests/unit/cmk/gui/openapi/test_openapi_rules.py index 34330ea59ac..2f772b1b249 100644 --- a/tests/unit/cmk/gui/openapi/test_openapi_rules.py +++ b/tests/unit/cmk/gui/openapi/test_openapi_rules.py @@ -187,7 +187,7 @@ def test_openapi_value_active_check_http(clients: ClientRegistry) -> None: def test_openapi_rules_href_escaped(clients: ClientRegistry) -> None: - resp = clients.Ruleset.list(used=False, include_links=True) + resp = clients.Ruleset.list(used=False) ruleset = next(r for r in resp.json["value"] if RuleGroup.SpecialAgents("gcp") == r["id"]) assert ( ruleset["links"][0]["href"] @@ -267,40 +267,6 @@ def test_openapi_list_rules( assert stored["conditions"]["host_tags"] == values["conditions"]["host_tags"] -def test_openapi_list_rules_include_links( - clients: ClientRegistry, - new_rule: tuple[Response, dict[str, typing.Any]], -) -> None: - _, values = new_rule - rule_set = values["ruleset"] - default_response = clients.Rule.list(ruleset=rule_set) - enabled_response = clients.Rule.list(ruleset=rule_set, include_links=True) - disabled_response = clients.Rule.list(ruleset=rule_set, include_links=False) - - assert len(default_response.json["value"]) > 0 - - assert default_response.json == enabled_response.json - assert any(bool(value["links"]) for value in enabled_response.json["value"]) - assert all(value["links"] == [] for value in disabled_response.json["value"]) - - -def test_openapi_list_rules_include_extensions( - clients: ClientRegistry, - new_rule: tuple[Response, dict[str, typing.Any]], -) -> None: - _, values = new_rule - rule_set = values["ruleset"] - default_response = clients.Rule.list(ruleset=rule_set) - enabled_response = clients.Rule.list(ruleset=rule_set, include_extensions=True) - disabled_response = clients.Rule.list(ruleset=rule_set, include_extensions=False) - - assert len(default_response.json["value"]) > 0 - - assert default_response.json == enabled_response.json - assert any(bool(value["extensions"]) for value in enabled_response.json["value"]) - assert all("extensions" not in value for value in disabled_response.json["value"]) - - def test_openapi_delete_rule( api_client: RestApiClient, clients: ClientRegistry, @@ -340,34 +306,6 @@ def test_openapi_list_rulesets(clients: ClientRegistry) -> None: assert len(resp.json["value"]) == 2 -def test_openapi_list_rulesets_include_links(clients: ClientRegistry) -> None: - default_response = clients.Ruleset.list(fulltext="cisco_qos", used=False) - enabled_response = clients.Ruleset.list(fulltext="cisco_qos", used=False, include_links=True) - disabled_response = clients.Ruleset.list(fulltext="cisco_qos", used=False, include_links=False) - - assert len(default_response.json["value"]) > 0 - - assert default_response.json == enabled_response.json - assert any(bool(value["links"]) for value in enabled_response.json["value"]) - assert all(value["links"] == [] for value in disabled_response.json["value"]) - - -def test_openapi_list_rulesets_include_extensions(clients: ClientRegistry) -> None: - default_response = clients.Ruleset.list(fulltext="cisco_qos", used=False) - enabled_response = clients.Ruleset.list( - fulltext="cisco_qos", used=False, include_extensions=True - ) - disabled_response = clients.Ruleset.list( - fulltext="cisco_qos", used=False, include_extensions=False - ) - - assert len(default_response.json["value"]) > 0 - - assert default_response.json == enabled_response.json - assert any(bool(value["extensions"]) for value in enabled_response.json["value"]) - assert all("extensions" not in value for value in disabled_response.json["value"]) - - def test_create_rule_old_label_format( clients: ClientRegistry, new_rule: tuple[Response, dict[str, typing.Any]], diff --git a/tests/unit/cmk/gui/openapi/test_openapi_service.py b/tests/unit/cmk/gui/openapi/test_openapi_service.py index 3cbb2b3616a..1d42d0c54c5 100644 --- a/tests/unit/cmk/gui/openapi/test_openapi_service.py +++ b/tests/unit/cmk/gui/openapi/test_openapi_service.py @@ -7,7 +7,7 @@ import pytest -from tests.testlib.rest_api_client import ClientRegistry, Response +from tests.testlib.rest_api_client import ClientRegistry from tests.unit.cmk.gui.conftest import CmkTestResponse, WebTestAppForCMK @@ -160,86 +160,6 @@ def test_openapi_livestatus_collection_link( ) -def test_openapi_list_services_include_links( - clients: ClientRegistry, - mock_livestatus: MockLiveStatusConnection, -) -> None: - mock_livestatus.add_table( - "services", - [ - { - "host_name": "heute", - "host_alias": "heute", - "description": "Filesystem /opt/omd/sites/heute/tmp", - "state": 0, - "state_type": "hard", - "last_check": 1593697877, - "acknowledged": 0, - }, - ], - ) - - def _request(include_links: bool | None = None) -> Response: - mock_livestatus.expect_query( - [ - "GET services", - "Columns: host_name description", - ], - ) - with mock_livestatus: - return clients.Service.get_all(include_links=include_links) - - default_response = _request() - enabled_response = _request(include_links=True) - disabled_response = _request(include_links=False) - - assert len(default_response.json["value"]) > 0 - - assert default_response.json == enabled_response.json - assert any(bool(value["links"]) for value in enabled_response.json["value"]) - assert all(value["links"] == [] for value in disabled_response.json["value"]) - - -def test_openapi_list_services_include_extensions( - clients: ClientRegistry, - mock_livestatus: MockLiveStatusConnection, -) -> None: - mock_livestatus.add_table( - "services", - [ - { - "host_name": "heute", - "host_alias": "heute", - "description": "Filesystem /opt/omd/sites/heute/tmp", - "state": 0, - "state_type": "hard", - "last_check": 1593697877, - "acknowledged": 0, - }, - ], - ) - - def _request(include_extensions: bool | None = None) -> Response: - mock_livestatus.expect_query( - [ - "GET services", - "Columns: host_name description", - ], - ) - with mock_livestatus: - return clients.Service.get_all(include_extensions=include_extensions) - - default_response = _request() - enabled_response = _request(include_extensions=True) - disabled_response = _request(include_extensions=False) - - assert len(default_response.json["value"]) > 0 - - assert default_response.json == enabled_response.json - assert any(bool(value["extensions"]) for value in enabled_response.json["value"]) - assert all("extensions" not in value for value in disabled_response.json["value"]) - - @pytest.mark.usefixtures("suppress_remote_automation_calls", "with_host") def test_openapi_specific_service( aut_user_auth_wsgi_app: WebTestAppForCMK, diff --git a/tests/unit/cmk/gui/openapi/test_openapi_time_period.py b/tests/unit/cmk/gui/openapi/test_openapi_time_period.py index f4fb6ccf0d7..ca229dd575c 100644 --- a/tests/unit/cmk/gui/openapi/test_openapi_time_period.py +++ b/tests/unit/cmk/gui/openapi/test_openapi_time_period.py @@ -19,30 +19,6 @@ def test_get_all_time_periods(clients: ClientRegistry) -> None: clients.TimePeriod.get_all() -def test_openapi_list_time_periods_include_links(clients: ClientRegistry) -> None: - default_response = clients.TimePeriod.get_all() - enabled_response = clients.TimePeriod.get_all(include_links=True) - disabled_response = clients.TimePeriod.get_all(include_links=False) - - assert len(default_response.json["value"]) > 0 - - assert default_response.json == enabled_response.json - assert any(bool(value["links"]) for value in enabled_response.json["value"]) - assert all(value["links"] == [] for value in disabled_response.json["value"]) - - -def test_openapi_list_time_periods_include_extensions(clients: ClientRegistry) -> None: - default_response = clients.TimePeriod.get_all() - enabled_response = clients.TimePeriod.get_all(include_extensions=True) - disabled_response = clients.TimePeriod.get_all(include_extensions=False) - - assert len(default_response.json["value"]) > 0 - - assert default_response.json == enabled_response.json - assert any(bool(value["extensions"]) for value in enabled_response.json["value"]) - assert all("extensions" not in value for value in disabled_response.json["value"]) - - @pytest.mark.usefixtures("suppress_remote_automation_calls") def test_get_a_time_period(clients: ClientRegistry) -> None: clients.TimePeriod.get(time_period_id="24X7") diff --git a/tests/unit/cmk/gui/openapi/test_openapi_user.py b/tests/unit/cmk/gui/openapi/test_openapi_user.py index d6a35595a24..7c4d6ccdd73 100644 --- a/tests/unit/cmk/gui/openapi/test_openapi_user.py +++ b/tests/unit/cmk/gui/openapi/test_openapi_user.py @@ -239,7 +239,7 @@ def test_openapi_user_minimal_password_settings( def test_openapi_all_users(clients: ClientRegistry) -> None: - resp = clients.User.get_all(include_links=True) + resp = clients.User.get_all() users = resp.json["value"] assert len(users) == 1 @@ -247,30 +247,6 @@ def test_openapi_all_users(clients: ClientRegistry) -> None: assert user.json == users[0] -def test_openapi_list_users_include_links(clients: ClientRegistry) -> None: - default_response = clients.User.get_all() - enabled_response = clients.User.get_all(include_links=True) - disabled_response = clients.User.get_all(include_links=False) - - assert len(default_response.json["value"]) > 0 - - assert default_response.json == enabled_response.json - assert any(bool(value["links"]) for value in enabled_response.json["value"]) - assert all(value["links"] == [] for value in disabled_response.json["value"]) - - -def test_openapi_list_users_include_extensions(clients: ClientRegistry) -> None: - default_response = clients.User.get_all() - enabled_response = clients.User.get_all(include_extensions=True) - disabled_response = clients.User.get_all(include_extensions=False) - - assert len(default_response.json["value"]) > 0 - - assert default_response.json == enabled_response.json - assert any(bool(value["extensions"]) for value in enabled_response.json["value"]) - assert all("extensions" not in value for value in disabled_response.json["value"]) - - @managedtest def test_openapi_user_config( clients: ClientRegistry, diff --git a/tests/unit/cmk/gui/openapi/test_openapi_userroles.py b/tests/unit/cmk/gui/openapi/test_openapi_userroles.py index cdb7e711a23..0716cead0be 100644 --- a/tests/unit/cmk/gui/openapi/test_openapi_userroles.py +++ b/tests/unit/cmk/gui/openapi/test_openapi_userroles.py @@ -19,30 +19,6 @@ def test_get_userroles_endpoint(clients: ClientRegistry) -> None: assert {user_role["id"] for user_role in resp.json["value"]} == set(builtin_role_ids) -def test_list_userroles_include_links(clients: ClientRegistry) -> None: - default_response = clients.UserRole.get_all() - enabled_response = clients.UserRole.get_all(include_links=True) - disabled_response = clients.UserRole.get_all(include_links=False) - - assert len(default_response.json["value"]) > 0 - - assert default_response.json == enabled_response.json - assert any(bool(value["links"]) for value in enabled_response.json["value"]) - assert all(value["links"] == [] for value in disabled_response.json["value"]) - - -def test_list_userroles_include_extensions(clients: ClientRegistry) -> None: - default_response = clients.UserRole.get_all() - enabled_response = clients.UserRole.get_all(include_extensions=True) - disabled_response = clients.UserRole.get_all(include_extensions=False) - - assert len(default_response.json["value"]) > 0 - - assert default_response.json == enabled_response.json - assert any(bool(value["extensions"]) for value in enabled_response.json["value"]) - assert all("extensions" not in value for value in disabled_response.json["value"]) - - def test_post_userrole_endpoint(clients: ClientRegistry) -> None: clients.UserRole.clone(body={"role_id": "admin"}) resp = clients.UserRole.get(role_id="adminx") diff --git a/tests/unit/cmk/gui/openapi/test_service_and_host_comments.py b/tests/unit/cmk/gui/openapi/test_service_and_host_comments.py index fe2151f2f7d..122bbec90de 100644 --- a/tests/unit/cmk/gui/openapi/test_service_and_host_comments.py +++ b/tests/unit/cmk/gui/openapi/test_service_and_host_comments.py @@ -10,7 +10,7 @@ import pytest from faker import Faker -from tests.testlib.rest_api_client import ClientRegistry, Response +from tests.testlib.rest_api_client import ClientRegistry from cmk.utils.livestatus_helpers.testing import MockLiveStatusConnection @@ -54,52 +54,6 @@ def test_get_all_comments( assert resp.json["value"][0]["extensions"]["site_id"] == SITE_ID -def test_list_comments_include_links( - mock_livestatus: MockLiveStatusConnection, clients: ClientRegistry -) -> None: - add_service_and_host_comments_to_live_status_table(mock_livestatus) - - def _request(include_links: bool | None = None) -> Response: - mock_livestatus.expect_query( - "GET comments\nColumns: host_name id author comment persistent service_description entry_time is_service" - ) - with mock_livestatus: - return clients.Comment.get_all(include_links=include_links) - - default_response = _request() - enabled_response = _request(include_links=True) - disabled_response = _request(include_links=False) - - assert len(default_response.json["value"]) > 0 - - assert default_response.json == enabled_response.json - assert any(bool(value["links"]) for value in enabled_response.json["value"]) - assert all(value["links"] == [] for value in disabled_response.json["value"]) - - -def test_list_comments_include_extensions( - mock_livestatus: MockLiveStatusConnection, clients: ClientRegistry -) -> None: - add_service_and_host_comments_to_live_status_table(mock_livestatus) - - def _request(include_extensions: bool | None = None) -> Response: - mock_livestatus.expect_query( - "GET comments\nColumns: host_name id author comment persistent service_description entry_time is_service" - ) - with mock_livestatus: - return clients.Comment.get_all(include_extensions=include_extensions) - - default_response = _request() - enabled_response = _request(include_extensions=True) - disabled_response = _request(include_extensions=False) - - assert len(default_response.json["value"]) > 0 - - assert default_response.json == enabled_response.json - assert any(bool(value["extensions"]) for value in enabled_response.json["value"]) - assert all("extensions" not in value for value in disabled_response.json["value"]) - - def test_get_host_comments( mock_livestatus: MockLiveStatusConnection, clients: ClientRegistry ) -> None: diff --git a/tests/unit/cmk/gui/openapi/test_site_management.py b/tests/unit/cmk/gui/openapi/test_site_management.py index e6b64c4d69b..9782ba210d0 100644 --- a/tests/unit/cmk/gui/openapi/test_site_management.py +++ b/tests/unit/cmk/gui/openapi/test_site_management.py @@ -64,30 +64,6 @@ def test_get_site_connections(clients: ClientRegistry) -> None: assert resp.json["value"][0]["id"] == "NO_SITE" -def test_list_sites_include_links(clients: ClientRegistry) -> None: - default_response = clients.SiteManagement.get_all() - enabled_response = clients.SiteManagement.get_all(include_links=True) - disabled_response = clients.SiteManagement.get_all(include_links=False) - - assert len(default_response.json["value"]) > 0 - - assert default_response.json == enabled_response.json - assert any(bool(value["links"]) for value in enabled_response.json["value"]) - assert all(value["links"] == [] for value in disabled_response.json["value"]) - - -def test_list_sites_include_extensions(clients: ClientRegistry) -> None: - default_response = clients.SiteManagement.get_all() - enabled_response = clients.SiteManagement.get_all(include_extensions=True) - disabled_response = clients.SiteManagement.get_all(include_extensions=False) - - assert len(default_response.json["value"]) > 0 - - assert default_response.json == enabled_response.json - assert any(bool(value["extensions"]) for value in enabled_response.json["value"]) - assert all("extensions" not in value for value in disabled_response.json["value"]) - - def test_login( clients: ClientRegistry, monkeypatch: MonkeyPatch,