From dcf73ade1f4aa5a7f67119f22e7ca5f5110b3b2b Mon Sep 17 00:00:00 2001 From: Logan Cary Date: Wed, 3 Jul 2024 09:15:04 -0400 Subject: [PATCH] shift `vendor.py` to use new api style --- src/middlewared/middlewared/api/v25_04_0/__init__.py | 1 + src/middlewared/middlewared/api/v25_04_0/common.py | 10 +++++++++- src/middlewared/middlewared/api/v25_04_0/vendor.py | 5 +++++ .../middlewared/plugins/system/vendor/vendor.py | 8 +++++--- 4 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 src/middlewared/middlewared/api/v25_04_0/vendor.py diff --git a/src/middlewared/middlewared/api/v25_04_0/__init__.py b/src/middlewared/middlewared/api/v25_04_0/__init__.py index ca1f985d122bc..00b50af35cbaf 100644 --- a/src/middlewared/middlewared/api/v25_04_0/__init__.py +++ b/src/middlewared/middlewared/api/v25_04_0/__init__.py @@ -1,3 +1,4 @@ from .cloud_sync import * # noqa from .common import * # noqa from .user import * # noqa +from .vendor import * # noqa diff --git a/src/middlewared/middlewared/api/v25_04_0/common.py b/src/middlewared/middlewared/api/v25_04_0/common.py index e3f857e894097..69f233553eee4 100644 --- a/src/middlewared/middlewared/api/v25_04_0/common.py +++ b/src/middlewared/middlewared/api/v25_04_0/common.py @@ -2,7 +2,7 @@ from middlewared.api.base import BaseModel -__all__ = ["QueryOptions", "QueryArgs"] +__all__ = ["QueryOptions", "QueryArgs", "NoArgs", "NoneReturn"] class QueryOptions(BaseModel): @@ -23,3 +23,11 @@ class QueryOptions(BaseModel): class QueryArgs(BaseModel): filters: list[Any] = [] # FIXME: Add validation here options: QueryOptions = QueryOptions() + + +class NoArgs(BaseModel): + pass + + +class NoneReturn(BaseModel): + result: None diff --git a/src/middlewared/middlewared/api/v25_04_0/vendor.py b/src/middlewared/middlewared/api/v25_04_0/vendor.py new file mode 100644 index 0000000000000..02eb4215c949b --- /dev/null +++ b/src/middlewared/middlewared/api/v25_04_0/vendor.py @@ -0,0 +1,5 @@ +from middlewared.api.base import BaseModel + + +class VendorNameResult(BaseModel): + result: str | None diff --git a/src/middlewared/middlewared/plugins/system/vendor/vendor.py b/src/middlewared/middlewared/plugins/system/vendor/vendor.py index fe84225750de0..2ae1dcf4e39c6 100644 --- a/src/middlewared/middlewared/plugins/system/vendor/vendor.py +++ b/src/middlewared/middlewared/plugins/system/vendor/vendor.py @@ -1,6 +1,8 @@ import os -from middlewared.service import private, Service +from middlewared.api import api_method +from middlewared.api.current import NoArgs, NoneReturn, VendorNameResult +from middlewared.service import Service SENTINEL_FILE_PATH = '/data/.vendor' @@ -8,7 +10,7 @@ class VendorService(Service): - @private + @api_method(NoArgs, VendorNameResult, private=True) def name(self) -> str | None: try: with open(SENTINEL_FILE_PATH, 'r') as file: @@ -17,7 +19,7 @@ def name(self) -> str | None: except FileNotFoundError: return None - @private + @api_method(NoArgs, NoneReturn, private=True) def unvendor(self): try: os.remove(SENTINEL_FILE_PATH)