Skip to content

Commit

Permalink
rest-api: revert include_links and include_extensions changes
Browse files Browse the repository at this point in the history
This reverts commit d2a2d2f8
This reverts commit 6ec1bf4.
This reverts commit 32b6dc7.
This reverts commit bebbd92.
This reverts commit 7681766.
This reverts commit d2ffd820
This reverts commit ee0f10f.
This reverts commit 9d5e905.
This reverts commit 2866c5b.
This reverts commit 2ccb880.
This reverts commit 60d7af9.
This reverts commit 0911a7e.
This reverts commit 7ccb7172
This reverts commit 05628cf.
This reverts commit e3f260f.
This reverts commit a6ef571.
This reverts commit f97389f6
This reverts commit 6835103.
This reverts commit 0e81ac67
This reverts commit ca40c64.
This reverts commit d027dc65
This reverts commit 0b14d02.
This reverts commit e1bdb9b.
This reverts commit a002d5f.
This reverts commit e0fe2a52
This reverts commit e25ec25.
This reverts commit df1b891.
This reverts commit 446eb7c.

Change-Id: Ic4bb956a4cc70c8b0bfc3367b2d5949412a0e236
JIRA-Ref: CMK-20151
  • Loading branch information
ottermata committed Nov 25, 2024
1 parent fede9c9 commit ea8460a
Show file tree
Hide file tree
Showing 46 changed files with 187 additions and 1,411 deletions.
21 changes: 0 additions & 21 deletions .werks/17266.md

This file was deleted.

24 changes: 0 additions & 24 deletions .werks/17267.md

This file was deleted.

16 changes: 3 additions & 13 deletions cmk/gui/mkeventd/_openapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -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"),
Expand All @@ -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()
],
)
Expand Down
19 changes: 4 additions & 15 deletions cmk/gui/openapi/endpoints/activate_changes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand All @@ -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,
)


Expand Down Expand Up @@ -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
Expand Down
28 changes: 6 additions & 22 deletions cmk/gui/openapi/endpoints/aux_tags/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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],
)
)

Expand Down Expand Up @@ -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,
)


Expand Down
11 changes: 1 addition & 10 deletions cmk/gui/openapi/endpoints/broker_connection/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"""
Expand All @@ -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],
)
)

Expand All @@ -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:
Expand Down
35 changes: 7 additions & 28 deletions cmk/gui/openapi/endpoints/comment/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
)


Expand Down Expand Up @@ -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()
Expand All @@ -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())],
)
)

Expand Down
14 changes: 1 addition & 13 deletions cmk/gui/openapi/endpoints/common_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
)
}
16 changes: 4 additions & 12 deletions cmk/gui/openapi/endpoints/contact_group_config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
)


Expand Down
Loading

0 comments on commit ea8460a

Please sign in to comment.