From 6d8486a409538cb5ef22d7fca5a93d9d5db91ed9 Mon Sep 17 00:00:00 2001 From: "Caleb St. John" <30729806+yocalebo@users.noreply.github.com> Date: Tue, 19 Nov 2024 09:02:24 -0500 Subject: [PATCH] add core.ping to new api (#14980) --- .../middlewared/api/v25_04_0/core.py | 22 +++++++++++++++++-- .../middlewared/service/core_service.py | 11 +++++++--- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/middlewared/middlewared/api/v25_04_0/core.py b/src/middlewared/middlewared/api/v25_04_0/core.py index 202f3f292e81..4b58ffc83ad2 100644 --- a/src/middlewared/middlewared/api/v25_04_0/core.py +++ b/src/middlewared/middlewared/api/v25_04_0/core.py @@ -1,7 +1,25 @@ +from typing import Literal + from middlewared.api.base import BaseModel, ForUpdateMetaclass, single_argument_result -__all__ = ["CoreSetOptionsArgs", "CoreSetOptionsResult", "CoreSubscribeArgs", "CoreSubscribeResult", - "CoreUnsubscribeArgs", "CoreUnsubscribeResult"] +__all__ = [ + "CorePingArgs", + "CorePingResult", + "CoreSetOptionsArgs", + "CoreSetOptionsResult", + "CoreSubscribeArgs", + "CoreSubscribeResult", + "CoreUnsubscribeArgs", + "CoreUnsubscribeResult", +] + + +class CorePingArgs(BaseModel): + pass + + +class CorePingResult(BaseModel): + result: Literal["pong"] class CoreSetOptionsOptions(BaseModel, metaclass=ForUpdateMetaclass): diff --git a/src/middlewared/middlewared/service/core_service.py b/src/middlewared/middlewared/service/core_service.py index be9317566222..86ba073dd60a 100644 --- a/src/middlewared/middlewared/service/core_service.py +++ b/src/middlewared/middlewared/service/core_service.py @@ -19,7 +19,13 @@ from middlewared.api import api_method from middlewared.api.base.jsonschema import get_json_schema from middlewared.api.current import ( - CoreSetOptionsArgs, CoreSetOptionsResult, CoreSubscribeArgs, CoreSubscribeResult, CoreUnsubscribeArgs, + CorePingArgs, + CorePingResult, + CoreSetOptionsArgs, + CoreSetOptionsResult, + CoreSubscribeArgs, + CoreSubscribeResult, + CoreUnsubscribeArgs, CoreUnsubscribeResult, ) from middlewared.common.environ import environ_update @@ -522,8 +528,7 @@ async def event_send(self, name, event_type, kwargs=None): kwargs = kwargs or {} self.middleware.send_event(name, event_type, **kwargs) - @no_authz_required - @accepts() + @api_method(CorePingArgs, CorePingResult, authorization_required=False) def ping(self): """ Utility method which just returns "pong".