-
Notifications
You must be signed in to change notification settings - Fork 490
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove accepts style decorator from catalog plugin (#14951)
- Loading branch information
Showing
9 changed files
with
187 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from middlewared.api.base import BaseModel, NonEmptyString | ||
|
||
from .catalog import CatalogAppInfo | ||
|
||
|
||
__all__ = [ | ||
'AppCategoriesArgs', 'AppCategoriesResult', 'AppSimilarArgs', 'AppSimilarResult', 'AppAvailableResponse', | ||
] | ||
|
||
|
||
class AppAvailableResponse(CatalogAppInfo): | ||
catalog: NonEmptyString | ||
installed: bool | ||
train: NonEmptyString | ||
|
||
|
||
class AppCategoriesArgs(BaseModel): | ||
pass | ||
|
||
|
||
class AppCategoriesResult(BaseModel): | ||
result: list[NonEmptyString] | ||
|
||
|
||
class AppSimilarArgs(BaseModel): | ||
app_name: NonEmptyString | ||
train: NonEmptyString | ||
|
||
|
||
class AppSimilarResult(BaseModel): | ||
result: list[AppAvailableResponse] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
from datetime import datetime | ||
|
||
from pydantic import ConfigDict, Field, RootModel | ||
|
||
from middlewared.api.base import BaseModel, ForUpdateMetaclass, NonEmptyString, single_argument_args, LongString | ||
|
||
|
||
__all__ = [ | ||
'CatalogEntry', 'CatalogUpdateArgs', 'CatalogUpdateResult', 'CatalogTrainsArgs', 'CatalogTrainsResult', | ||
'CatalogSyncArgs', 'CatalogSyncResult', 'CatalogAppInfo', 'CatalogAppsArgs', 'CatalogAppsResult', | ||
'CatalogAppDetailsArgs', 'CatalogAppDetailsResult', | ||
] | ||
|
||
|
||
class CatalogEntry(BaseModel): | ||
id: NonEmptyString | ||
label: NonEmptyString = Field(pattern=r'^\w+[\w.-]*$') | ||
preferred_trains: list[NonEmptyString] | ||
|
||
|
||
@single_argument_args('catalog_update') | ||
class CatalogUpdateArgs(BaseModel, metaclass=ForUpdateMetaclass): | ||
preferred_trains: list[NonEmptyString] | ||
|
||
|
||
class CatalogUpdateResult(BaseModel): | ||
result: CatalogEntry | ||
|
||
|
||
class CatalogTrainsArgs(BaseModel): | ||
pass | ||
|
||
|
||
class CatalogTrainsResult(BaseModel): | ||
result: list[NonEmptyString] | ||
|
||
|
||
class CatalogSyncArgs(BaseModel): | ||
pass | ||
|
||
|
||
class CatalogSyncResult(BaseModel): | ||
result: None | ||
|
||
|
||
class Maintainer(BaseModel): | ||
name: str | ||
email: str | ||
url: str | None | ||
|
||
|
||
class CatalogAppInfo(BaseModel): | ||
app_readme: LongString | None | ||
'''HTML content of the app README.''' | ||
categories: list[str] | ||
'''List of categories for the app.''' | ||
description: str | ||
'''Short description of the app.''' | ||
healthy: bool | ||
'''Health status of the app.''' | ||
healthy_error: str | None = None | ||
'''Error if app is not healthy.''' | ||
home: str | ||
'''Homepage URL of the app.''' | ||
location: str | ||
'''Local path to the app's location.''' | ||
latest_version: str | None | ||
'''Latest available app version.''' | ||
latest_app_version: str | None | ||
'''Latest available app version in repository.''' | ||
latest_human_version: str | None | ||
'''Human-readable version of the app.''' | ||
last_update: datetime | None | ||
'''Timestamp of the last update in ISO format.''' | ||
name: str | ||
'''Name of the app.''' | ||
recommended: bool | ||
'''Indicates if the app is recommended.''' | ||
title: str | ||
'''Title of the app.''' | ||
maintainers: list[Maintainer] | ||
'''List of app maintainers.''' | ||
tags: list[str] | ||
'''Tags associated with the app.''' | ||
screenshots: list[str] | ||
'''List of screenshot URLs.''' | ||
sources: list[str] | ||
'''List of source URLs.''' | ||
icon_url: str | None = None | ||
'''URL of the app icon''' | ||
|
||
# We do this because if we change anything in catalog.json, even older releases will | ||
# get this new field and different roles will start breaking due to this | ||
model_config = ConfigDict(extra='allow') | ||
|
||
|
||
@single_argument_args('catalog_apps_options') | ||
class CatalogAppsArgs(BaseModel): | ||
cache: bool = True | ||
cache_only: bool = False | ||
retrieve_all_trains: bool = True | ||
trains: list[NonEmptyString] = Field(default_factory=list) | ||
|
||
|
||
class CatalogTrainInfo(RootModel[dict[str, CatalogAppInfo]]): | ||
pass | ||
|
||
|
||
class CatalogAppsResult(BaseModel): | ||
result: dict[str, CatalogTrainInfo] | ||
|
||
|
||
class CatalogAppVersionDetails(BaseModel): | ||
train: NonEmptyString | ||
|
||
|
||
class CatalogAppDetailsArgs(BaseModel): | ||
app_name: NonEmptyString | ||
app_version_details: CatalogAppVersionDetails | ||
|
||
|
||
class CatalogAppDetailsResult(BaseModel): | ||
result: CatalogAppInfo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,8 @@ | |
from datetime import datetime | ||
from jsonschema import validate as json_schema_validate, ValidationError as JsonValidationError | ||
|
||
from middlewared.schema import accepts, Bool, Dict, List, returns, Str | ||
from middlewared.api import api_method | ||
from middlewared.api.current import CatalogAppsArgs, CatalogAppsResult | ||
from middlewared.service import private, Service | ||
|
||
from .apps_util import get_app_version_details | ||
|
@@ -45,47 +46,7 @@ def train_to_apps_version_mapping(self): | |
def cached(self, label): | ||
return self.middleware.call_sync('cache.has_key', get_cache_key(label)) | ||
|
||
@accepts( | ||
Dict( | ||
'options', | ||
Bool('cache', default=True), | ||
Bool('cache_only', default=False), | ||
Bool('retrieve_all_trains', default=True), | ||
List('trains', items=[Str('train_name')]), | ||
), | ||
roles=['CATALOG_READ'] | ||
) | ||
@returns(Dict( | ||
'trains', | ||
additional_attrs=True, | ||
example={ | ||
'stable': { | ||
'plex': { | ||
'app_readme': '<h1>Plex</h1>', | ||
'categories': ['media'], | ||
'description': 'Plex is a media server that allows you to stream your media to any Plex client.', | ||
'healthy': True, | ||
'healthy_error': None, | ||
'home': 'https://plex.tv', | ||
'location': '/mnt/.ix-apps/truenas_catalog/stable/plex', | ||
'latest_version': '1.0.0', | ||
'latest_app_version': '1.40.2.8395', | ||
'latest_human_version': '1.40.2.8395_1.0.0', | ||
'last_update': '2024-07-30 13:40:47+00:00', | ||
'name': 'plex', | ||
'recommended': False, | ||
'title': 'Plex', | ||
'maintainers': [ | ||
{'email': '[email protected]', 'name': 'truenas', 'url': 'https://www.truenas.com/'}, | ||
], | ||
'tags': ['plex', 'media', 'entertainment', 'movies', 'series', 'tv', 'streaming'], | ||
'screenshots': ['https://media.sys.truenas.net/apps/plex/screenshots/screenshot2.png'], | ||
'sources': ['https://plex.tv', 'https://hub.docker.com/r/plexinc/pms-docker'], | ||
'icon_url': 'https://media.sys.truenas.net/apps/plex/icons/icon.png' | ||
}, | ||
}, | ||
} | ||
)) | ||
@api_method(CatalogAppsArgs, CatalogAppsResult, roles=['CATALOG_READ']) | ||
def apps(self, options): | ||
""" | ||
Retrieve apps details for `label` catalog. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.