Skip to content

Commit

Permalink
shift vendor.py to use new api style
Browse files Browse the repository at this point in the history
  • Loading branch information
creatorcary committed Jul 3, 2024
1 parent 8fa76c9 commit dcf73ad
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/middlewared/middlewared/api/v25_04_0/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .cloud_sync import * # noqa
from .common import * # noqa
from .user import * # noqa
from .vendor import * # noqa
10 changes: 9 additions & 1 deletion src/middlewared/middlewared/api/v25_04_0/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from middlewared.api.base import BaseModel

__all__ = ["QueryOptions", "QueryArgs"]
__all__ = ["QueryOptions", "QueryArgs", "NoArgs", "NoneReturn"]


class QueryOptions(BaseModel):
Expand All @@ -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
5 changes: 5 additions & 0 deletions src/middlewared/middlewared/api/v25_04_0/vendor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from middlewared.api.base import BaseModel


class VendorNameResult(BaseModel):
result: str | None
8 changes: 5 additions & 3 deletions src/middlewared/middlewared/plugins/system/vendor/vendor.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
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'


class VendorService(Service):

@private
@api_method(NoArgs, VendorNameResult, private=True)
def name(self) -> str | None:
try:
with open(SENTINEL_FILE_PATH, 'r') as file:
Expand All @@ -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)
Expand Down

0 comments on commit dcf73ad

Please sign in to comment.