mirror of
https://github.com/arcan1s/ahriman.git
synced 2026-04-01 06:03:39 +00:00
feat: make apispec dependency optional (#138)
This commit is contained in:
@@ -21,7 +21,9 @@ import aiohttp_jinja2
|
||||
|
||||
from typing import Any
|
||||
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.apispec import aiohttp_apispec
|
||||
from ahriman.web.views.base import BaseView
|
||||
|
||||
|
||||
@@ -36,6 +38,22 @@ class DocsView(BaseView):
|
||||
GET_PERMISSION = UserAccess.Unauthorized
|
||||
ROUTES = ["/api-docs"]
|
||||
|
||||
@classmethod
|
||||
def routes(cls, configuration: Configuration) -> list[str]:
|
||||
"""
|
||||
extract routes list for the view
|
||||
|
||||
Args:
|
||||
configuration(Configuration): configuration instance
|
||||
|
||||
Returns:
|
||||
list[str]: list of routes defined for the view. By default, it tries to read :attr:`ROUTES` option if set
|
||||
and returns empty list otherwise
|
||||
"""
|
||||
if aiohttp_apispec is None:
|
||||
return []
|
||||
return cls.ROUTES
|
||||
|
||||
@aiohttp_jinja2.template("api.jinja2")
|
||||
async def get(self) -> dict[str, Any]:
|
||||
"""
|
||||
|
||||
@@ -20,8 +20,10 @@
|
||||
from aiohttp.web import Response, json_response
|
||||
from collections.abc import Callable
|
||||
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.utils import partition
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.apispec import aiohttp_apispec
|
||||
from ahriman.web.views.base import BaseView
|
||||
|
||||
|
||||
@@ -36,6 +38,22 @@ class SwaggerView(BaseView):
|
||||
GET_PERMISSION = UserAccess.Unauthorized
|
||||
ROUTES = ["/api-docs/swagger.json"]
|
||||
|
||||
@classmethod
|
||||
def routes(cls, configuration: Configuration) -> list[str]:
|
||||
"""
|
||||
extract routes list for the view
|
||||
|
||||
Args:
|
||||
configuration(Configuration): configuration instance
|
||||
|
||||
Returns:
|
||||
list[str]: list of routes defined for the view. By default, it tries to read :attr:`ROUTES` option if set
|
||||
and returns empty list otherwise
|
||||
"""
|
||||
if aiohttp_apispec is None:
|
||||
return []
|
||||
return cls.ROUTES
|
||||
|
||||
async def get(self) -> Response:
|
||||
"""
|
||||
get api specification
|
||||
|
||||
@@ -23,6 +23,7 @@ from typing import Any
|
||||
|
||||
from ahriman.core.auth.helpers import authorized_userid
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.apispec import aiohttp_apispec
|
||||
from ahriman.web.views.base import BaseView
|
||||
|
||||
|
||||
@@ -36,6 +37,7 @@ class IndexView(BaseView):
|
||||
* control - HTML to insert for login control, HTML string, required
|
||||
* enabled - whether authorization is enabled by configuration or not, boolean, required
|
||||
* username - authenticated username if any, string, null means not authenticated
|
||||
* docs_enabled - indicates if api docs is enabled, boolean, required
|
||||
* index_url - url to the repository index, string, optional
|
||||
* repositories - list of repositories unique identifiers, required
|
||||
* id - unique repository identifier, string, required
|
||||
@@ -66,6 +68,7 @@ class IndexView(BaseView):
|
||||
|
||||
return {
|
||||
"auth": auth,
|
||||
"docs_enabled": aiohttp_apispec is not None,
|
||||
"index_url": self.configuration.get("web", "index_url", fallback=None),
|
||||
"repositories": [
|
||||
{
|
||||
|
||||
@@ -17,13 +17,12 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
import aiohttp_apispec # type: ignore[import-untyped]
|
||||
|
||||
from aiohttp.web import HTTPBadRequest, HTTPNoContent, Response, json_response
|
||||
|
||||
from ahriman.models.event import Event
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.schemas import AuthSchema, ErrorSchema, EventSchema, EventSearchSchema
|
||||
from ahriman.web.apispec.decorators import apidocs
|
||||
from ahriman.web.schemas import EventSchema, EventSearchSchema
|
||||
from ahriman.web.views.base import BaseView
|
||||
|
||||
|
||||
@@ -39,21 +38,15 @@ class EventsView(BaseView):
|
||||
GET_PERMISSION = POST_PERMISSION = UserAccess.Full
|
||||
ROUTES = ["/api/v1/events"]
|
||||
|
||||
@aiohttp_apispec.docs(
|
||||
@apidocs(
|
||||
tags=["Audit log"],
|
||||
summary="Get events",
|
||||
description="Retrieve events from audit log",
|
||||
responses={
|
||||
200: {"description": "Success response", "schema": EventSchema(many=True)},
|
||||
400: {"description": "Bad data is supplied", "schema": ErrorSchema},
|
||||
401: {"description": "Authorization required", "schema": ErrorSchema},
|
||||
403: {"description": "Access is forbidden", "schema": ErrorSchema},
|
||||
500: {"description": "Internal server error", "schema": ErrorSchema},
|
||||
},
|
||||
security=[{"token": [GET_PERMISSION]}],
|
||||
permission=GET_PERMISSION,
|
||||
error_400_enabled=True,
|
||||
schema=EventSchema(many=True),
|
||||
query_schema=EventSearchSchema,
|
||||
)
|
||||
@aiohttp_apispec.cookies_schema(AuthSchema)
|
||||
@aiohttp_apispec.querystring_schema(EventSearchSchema)
|
||||
async def get(self) -> Response:
|
||||
"""
|
||||
get events list
|
||||
@@ -78,21 +71,14 @@ class EventsView(BaseView):
|
||||
|
||||
return json_response(response)
|
||||
|
||||
@aiohttp_apispec.docs(
|
||||
@apidocs(
|
||||
tags=["Audit log"],
|
||||
summary="Create event",
|
||||
description="Add new event to the audit log",
|
||||
responses={
|
||||
204: {"description": "Success response"},
|
||||
400: {"description": "Bad data is supplied", "schema": ErrorSchema},
|
||||
401: {"description": "Authorization required", "schema": ErrorSchema},
|
||||
403: {"description": "Access is forbidden", "schema": ErrorSchema},
|
||||
500: {"description": "Internal server error", "schema": ErrorSchema},
|
||||
},
|
||||
security=[{"token": [POST_PERMISSION]}],
|
||||
permission=POST_PERMISSION,
|
||||
error_400_enabled=True,
|
||||
body_schema=EventSchema,
|
||||
)
|
||||
@aiohttp_apispec.cookies_schema(AuthSchema)
|
||||
@aiohttp_apispec.json_schema(EventSchema)
|
||||
async def post(self) -> None:
|
||||
"""
|
||||
add new audit log event
|
||||
|
||||
@@ -17,14 +17,13 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
import aiohttp_apispec # type: ignore[import-untyped]
|
||||
|
||||
from aiohttp.web import HTTPBadRequest, HTTPNoContent, Response, json_response
|
||||
from collections.abc import Callable
|
||||
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.models.worker import Worker
|
||||
from ahriman.web.schemas import AuthSchema, ErrorSchema, WorkerSchema
|
||||
from ahriman.web.apispec.decorators import apidocs
|
||||
from ahriman.web.schemas import WorkerSchema
|
||||
from ahriman.web.views.base import BaseView
|
||||
|
||||
|
||||
@@ -41,19 +40,12 @@ class WorkersView(BaseView):
|
||||
DELETE_PERMISSION = GET_PERMISSION = POST_PERMISSION = UserAccess.Full
|
||||
ROUTES = ["/api/v1/distributed"]
|
||||
|
||||
@aiohttp_apispec.docs(
|
||||
@apidocs(
|
||||
tags=["Distributed"],
|
||||
summary="Unregister all workers",
|
||||
description="Unregister and remove all known workers from the service",
|
||||
responses={
|
||||
204: {"description": "Success response"},
|
||||
401: {"description": "Authorization required", "schema": ErrorSchema},
|
||||
403: {"description": "Access is forbidden", "schema": ErrorSchema},
|
||||
500: {"description": "Internal server error", "schema": ErrorSchema},
|
||||
},
|
||||
security=[{"token": [DELETE_PERMISSION]}],
|
||||
permission=DELETE_PERMISSION,
|
||||
)
|
||||
@aiohttp_apispec.cookies_schema(AuthSchema)
|
||||
async def delete(self) -> None:
|
||||
"""
|
||||
unregister worker
|
||||
@@ -65,19 +57,13 @@ class WorkersView(BaseView):
|
||||
|
||||
raise HTTPNoContent
|
||||
|
||||
@aiohttp_apispec.docs(
|
||||
@apidocs(
|
||||
tags=["Distributed"],
|
||||
summary="Get workers",
|
||||
description="Retrieve registered workers",
|
||||
responses={
|
||||
200: {"description": "Success response", "schema": WorkerSchema(many=True)},
|
||||
401: {"description": "Authorization required", "schema": ErrorSchema},
|
||||
403: {"description": "Access is forbidden", "schema": ErrorSchema},
|
||||
500: {"description": "Internal server error", "schema": ErrorSchema},
|
||||
},
|
||||
security=[{"token": [GET_PERMISSION]}],
|
||||
permission=GET_PERMISSION,
|
||||
schema=WorkerSchema(many=True),
|
||||
)
|
||||
@aiohttp_apispec.cookies_schema(AuthSchema)
|
||||
async def get(self) -> Response:
|
||||
"""
|
||||
get workers list
|
||||
@@ -92,21 +78,14 @@ class WorkersView(BaseView):
|
||||
|
||||
return json_response(response)
|
||||
|
||||
@aiohttp_apispec.docs(
|
||||
@apidocs(
|
||||
tags=["Distributed"],
|
||||
summary="Register worker",
|
||||
description="Register or update remote worker",
|
||||
responses={
|
||||
204: {"description": "Success response"},
|
||||
400: {"description": "Bad data is supplied", "schema": ErrorSchema},
|
||||
401: {"description": "Authorization required", "schema": ErrorSchema},
|
||||
403: {"description": "Access is forbidden", "schema": ErrorSchema},
|
||||
500: {"description": "Internal server error", "schema": ErrorSchema},
|
||||
},
|
||||
security=[{"token": [POST_PERMISSION]}],
|
||||
permission=POST_PERMISSION,
|
||||
error_400_enabled=True,
|
||||
body_schema=WorkerSchema,
|
||||
)
|
||||
@aiohttp_apispec.cookies_schema(AuthSchema)
|
||||
@aiohttp_apispec.json_schema(WorkerSchema)
|
||||
async def post(self) -> None:
|
||||
"""
|
||||
register remote worker
|
||||
|
||||
@@ -17,13 +17,12 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
import aiohttp_apispec # type: ignore[import-untyped]
|
||||
|
||||
from aiohttp.web import HTTPBadRequest, HTTPNoContent, Response, json_response
|
||||
|
||||
from ahriman.models.changes import Changes
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.schemas import AuthSchema, ChangesSchema, ErrorSchema, PackageNameSchema, RepositoryIdSchema
|
||||
from ahriman.web.apispec.decorators import apidocs
|
||||
from ahriman.web.schemas import ChangesSchema, PackageNameSchema, RepositoryIdSchema
|
||||
from ahriman.web.views.base import BaseView
|
||||
from ahriman.web.views.status_view_guard import StatusViewGuard
|
||||
|
||||
@@ -41,22 +40,16 @@ class ChangesView(StatusViewGuard, BaseView):
|
||||
POST_PERMISSION = UserAccess.Full
|
||||
ROUTES = ["/api/v1/packages/{package}/changes"]
|
||||
|
||||
@aiohttp_apispec.docs(
|
||||
@apidocs(
|
||||
tags=["Packages"],
|
||||
summary="Get package changes",
|
||||
description="Retrieve package changes since the last build",
|
||||
responses={
|
||||
200: {"description": "Success response", "schema": ChangesSchema},
|
||||
401: {"description": "Authorization required", "schema": ErrorSchema},
|
||||
403: {"description": "Access is forbidden", "schema": ErrorSchema},
|
||||
404: {"description": "Package base and/or repository are unknown", "schema": ErrorSchema},
|
||||
500: {"description": "Internal server error", "schema": ErrorSchema},
|
||||
},
|
||||
security=[{"token": [GET_PERMISSION]}],
|
||||
permission=GET_PERMISSION,
|
||||
error_404_description="Package base and/or repository are unknown",
|
||||
schema=ChangesSchema,
|
||||
match_schema=PackageNameSchema,
|
||||
query_schema=RepositoryIdSchema,
|
||||
)
|
||||
@aiohttp_apispec.cookies_schema(AuthSchema)
|
||||
@aiohttp_apispec.match_info_schema(PackageNameSchema)
|
||||
@aiohttp_apispec.querystring_schema(RepositoryIdSchema)
|
||||
async def get(self) -> Response:
|
||||
"""
|
||||
get package changes
|
||||
@@ -73,24 +66,17 @@ class ChangesView(StatusViewGuard, BaseView):
|
||||
|
||||
return json_response(changes.view())
|
||||
|
||||
@aiohttp_apispec.docs(
|
||||
@apidocs(
|
||||
tags=["Packages"],
|
||||
summary="Update package changes",
|
||||
description="Update package changes to the new ones",
|
||||
responses={
|
||||
204: {"description": "Success response"},
|
||||
400: {"description": "Bad data is supplied", "schema": ErrorSchema},
|
||||
401: {"description": "Authorization required", "schema": ErrorSchema},
|
||||
403: {"description": "Access is forbidden", "schema": ErrorSchema},
|
||||
404: {"description": "Repository is unknown", "schema": ErrorSchema},
|
||||
500: {"description": "Internal server error", "schema": ErrorSchema},
|
||||
},
|
||||
security=[{"token": [POST_PERMISSION]}],
|
||||
permission=POST_PERMISSION,
|
||||
error_400_enabled=True,
|
||||
error_404_description="Repository is unknown",
|
||||
match_schema=PackageNameSchema,
|
||||
query_schema=RepositoryIdSchema,
|
||||
body_schema=ChangesSchema,
|
||||
)
|
||||
@aiohttp_apispec.cookies_schema(AuthSchema)
|
||||
@aiohttp_apispec.match_info_schema(PackageNameSchema)
|
||||
@aiohttp_apispec.querystring_schema(RepositoryIdSchema)
|
||||
@aiohttp_apispec.json_schema(ChangesSchema)
|
||||
async def post(self) -> None:
|
||||
"""
|
||||
insert new package changes
|
||||
|
||||
@@ -17,13 +17,12 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
import aiohttp_apispec # type: ignore[import-untyped]
|
||||
|
||||
from aiohttp.web import HTTPBadRequest, HTTPNoContent, Response, json_response
|
||||
|
||||
from ahriman.models.dependencies import Dependencies
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.schemas import AuthSchema, DependenciesSchema, ErrorSchema, PackageNameSchema, RepositoryIdSchema
|
||||
from ahriman.web.apispec.decorators import apidocs
|
||||
from ahriman.web.schemas import DependenciesSchema, PackageNameSchema, RepositoryIdSchema
|
||||
from ahriman.web.views.base import BaseView
|
||||
from ahriman.web.views.status_view_guard import StatusViewGuard
|
||||
|
||||
@@ -41,22 +40,16 @@ class DependenciesView(StatusViewGuard, BaseView):
|
||||
POST_PERMISSION = UserAccess.Full
|
||||
ROUTES = ["/api/v1/packages/{package}/dependencies"]
|
||||
|
||||
@aiohttp_apispec.docs(
|
||||
@apidocs(
|
||||
tags=["Packages"],
|
||||
summary="Get package dependencies",
|
||||
description="Retrieve package implicit dependencies",
|
||||
responses={
|
||||
200: {"description": "Success response", "schema": DependenciesSchema},
|
||||
401: {"description": "Authorization required", "schema": ErrorSchema},
|
||||
403: {"description": "Access is forbidden", "schema": ErrorSchema},
|
||||
404: {"description": "Package base and/or repository are unknown", "schema": ErrorSchema},
|
||||
500: {"description": "Internal server error", "schema": ErrorSchema},
|
||||
},
|
||||
security=[{"token": [GET_PERMISSION]}],
|
||||
permission=GET_PERMISSION,
|
||||
error_404_description="Package base and/or repository are unknown",
|
||||
schema=DependenciesSchema,
|
||||
match_schema=PackageNameSchema,
|
||||
query_schema=RepositoryIdSchema,
|
||||
)
|
||||
@aiohttp_apispec.cookies_schema(AuthSchema)
|
||||
@aiohttp_apispec.match_info_schema(PackageNameSchema)
|
||||
@aiohttp_apispec.querystring_schema(RepositoryIdSchema)
|
||||
async def get(self) -> Response:
|
||||
"""
|
||||
get package dependencies
|
||||
@@ -73,24 +66,17 @@ class DependenciesView(StatusViewGuard, BaseView):
|
||||
|
||||
return json_response(dependencies.view())
|
||||
|
||||
@aiohttp_apispec.docs(
|
||||
@apidocs(
|
||||
tags=["Packages"],
|
||||
summary="Update package dependencies",
|
||||
description="Set package implicit dependencies",
|
||||
responses={
|
||||
204: {"description": "Success response"},
|
||||
400: {"description": "Bad data is supplied", "schema": ErrorSchema},
|
||||
401: {"description": "Authorization required", "schema": ErrorSchema},
|
||||
403: {"description": "Access is forbidden", "schema": ErrorSchema},
|
||||
404: {"description": "Repository is unknown", "schema": ErrorSchema},
|
||||
500: {"description": "Internal server error", "schema": ErrorSchema},
|
||||
},
|
||||
security=[{"token": [POST_PERMISSION]}],
|
||||
permission=POST_PERMISSION,
|
||||
error_400_enabled=True,
|
||||
error_404_description="Repository is unknown",
|
||||
match_schema=PackageNameSchema,
|
||||
query_schema=RepositoryIdSchema,
|
||||
body_schema=DependenciesSchema,
|
||||
)
|
||||
@aiohttp_apispec.cookies_schema(AuthSchema)
|
||||
@aiohttp_apispec.match_info_schema(PackageNameSchema)
|
||||
@aiohttp_apispec.querystring_schema(RepositoryIdSchema)
|
||||
@aiohttp_apispec.json_schema(DependenciesSchema)
|
||||
async def post(self) -> None:
|
||||
"""
|
||||
insert new package dependencies
|
||||
|
||||
@@ -17,16 +17,15 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
import aiohttp_apispec # type: ignore[import-untyped]
|
||||
|
||||
from aiohttp.web import HTTPBadRequest, HTTPNoContent, HTTPNotFound, Response, json_response
|
||||
|
||||
from ahriman.core.exceptions import UnknownPackageError
|
||||
from ahriman.core.utils import pretty_datetime
|
||||
from ahriman.models.log_record_id import LogRecordId
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.schemas import AuthSchema, ErrorSchema, LogsSchema, PackageNameSchema, PackageVersionSchema, \
|
||||
RepositoryIdSchema, VersionedLogSchema
|
||||
from ahriman.web.apispec.decorators import apidocs
|
||||
from ahriman.web.schemas import LogsSchema, PackageNameSchema, PackageVersionSchema, RepositoryIdSchema, \
|
||||
VersionedLogSchema
|
||||
from ahriman.web.views.base import BaseView
|
||||
from ahriman.web.views.status_view_guard import StatusViewGuard
|
||||
|
||||
@@ -45,22 +44,15 @@ class LogsView(StatusViewGuard, BaseView):
|
||||
GET_PERMISSION = UserAccess.Reporter
|
||||
ROUTES = ["/api/v1/packages/{package}/logs"]
|
||||
|
||||
@aiohttp_apispec.docs(
|
||||
@apidocs(
|
||||
tags=["Packages"],
|
||||
summary="Delete package logs",
|
||||
description="Delete all logs which belong to the specified package",
|
||||
responses={
|
||||
204: {"description": "Success response"},
|
||||
401: {"description": "Authorization required", "schema": ErrorSchema},
|
||||
403: {"description": "Access is forbidden", "schema": ErrorSchema},
|
||||
404: {"description": "Repository is unknown", "schema": ErrorSchema},
|
||||
500: {"description": "Internal server error", "schema": ErrorSchema},
|
||||
},
|
||||
security=[{"token": [DELETE_PERMISSION]}],
|
||||
permission=DELETE_PERMISSION,
|
||||
error_404_description="Repository is unknown",
|
||||
match_schema=PackageNameSchema,
|
||||
query_schema=PackageVersionSchema,
|
||||
)
|
||||
@aiohttp_apispec.cookies_schema(AuthSchema)
|
||||
@aiohttp_apispec.match_info_schema(PackageNameSchema)
|
||||
@aiohttp_apispec.querystring_schema(PackageVersionSchema)
|
||||
async def delete(self) -> None:
|
||||
"""
|
||||
delete package logs
|
||||
@@ -74,22 +66,16 @@ class LogsView(StatusViewGuard, BaseView):
|
||||
|
||||
raise HTTPNoContent
|
||||
|
||||
@aiohttp_apispec.docs(
|
||||
@apidocs(
|
||||
tags=["Packages"],
|
||||
summary="Get package logs",
|
||||
description="Retrieve all package logs and the last package status",
|
||||
responses={
|
||||
200: {"description": "Success response", "schema": LogsSchema},
|
||||
401: {"description": "Authorization required", "schema": ErrorSchema},
|
||||
403: {"description": "Access is forbidden", "schema": ErrorSchema},
|
||||
404: {"description": "Package base and/or repository are unknown", "schema": ErrorSchema},
|
||||
500: {"description": "Internal server error", "schema": ErrorSchema},
|
||||
},
|
||||
security=[{"token": [GET_PERMISSION]}],
|
||||
permission=GET_PERMISSION,
|
||||
error_404_description="Package base and/or repository are unknown",
|
||||
schema=LogsSchema,
|
||||
match_schema=PackageNameSchema,
|
||||
query_schema=RepositoryIdSchema,
|
||||
)
|
||||
@aiohttp_apispec.cookies_schema(AuthSchema)
|
||||
@aiohttp_apispec.match_info_schema(PackageNameSchema)
|
||||
@aiohttp_apispec.querystring_schema(RepositoryIdSchema)
|
||||
async def get(self) -> Response:
|
||||
"""
|
||||
get last package logs
|
||||
@@ -115,23 +101,16 @@ class LogsView(StatusViewGuard, BaseView):
|
||||
}
|
||||
return json_response(response)
|
||||
|
||||
@aiohttp_apispec.docs(
|
||||
@apidocs(
|
||||
tags=["Packages"],
|
||||
summary="Add package logs",
|
||||
description="Insert new package log record",
|
||||
responses={
|
||||
204: {"description": "Success response"},
|
||||
400: {"description": "Bad data is supplied", "schema": ErrorSchema},
|
||||
401: {"description": "Authorization required", "schema": ErrorSchema},
|
||||
403: {"description": "Access is forbidden", "schema": ErrorSchema},
|
||||
404: {"description": "Repository is unknown", "schema": ErrorSchema},
|
||||
500: {"description": "Internal server error", "schema": ErrorSchema},
|
||||
},
|
||||
security=[{"token": [POST_PERMISSION]}],
|
||||
permission=POST_PERMISSION,
|
||||
error_400_enabled=True,
|
||||
error_404_description="Repository is unknown",
|
||||
match_schema=PackageNameSchema,
|
||||
body_schema=VersionedLogSchema,
|
||||
)
|
||||
@aiohttp_apispec.cookies_schema(AuthSchema)
|
||||
@aiohttp_apispec.match_info_schema(PackageNameSchema)
|
||||
@aiohttp_apispec.json_schema(VersionedLogSchema)
|
||||
async def post(self) -> None:
|
||||
"""
|
||||
create new package log record
|
||||
|
||||
@@ -17,16 +17,15 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
import aiohttp_apispec # type: ignore[import-untyped]
|
||||
|
||||
from aiohttp.web import HTTPBadRequest, HTTPNoContent, HTTPNotFound, Response, json_response
|
||||
|
||||
from ahriman.core.exceptions import UnknownPackageError
|
||||
from ahriman.models.build_status import BuildStatusEnum
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.schemas import AuthSchema, ErrorSchema, PackageNameSchema, PackageStatusSchema, \
|
||||
PackageStatusSimplifiedSchema, RepositoryIdSchema
|
||||
from ahriman.web.apispec.decorators import apidocs
|
||||
from ahriman.web.schemas import PackageNameSchema, PackageStatusSchema, PackageStatusSimplifiedSchema, \
|
||||
RepositoryIdSchema
|
||||
from ahriman.web.views.base import BaseView
|
||||
from ahriman.web.views.status_view_guard import StatusViewGuard
|
||||
|
||||
@@ -45,22 +44,15 @@ class PackageView(StatusViewGuard, BaseView):
|
||||
GET_PERMISSION = UserAccess.Read
|
||||
ROUTES = ["/api/v1/packages/{package}"]
|
||||
|
||||
@aiohttp_apispec.docs(
|
||||
@apidocs(
|
||||
tags=["Packages"],
|
||||
summary="Delete package",
|
||||
description="Delete package and its status from service",
|
||||
responses={
|
||||
204: {"description": "Success response"},
|
||||
401: {"description": "Authorization required", "schema": ErrorSchema},
|
||||
403: {"description": "Access is forbidden", "schema": ErrorSchema},
|
||||
404: {"description": "Repository is unknown", "schema": ErrorSchema},
|
||||
500: {"description": "Internal server error", "schema": ErrorSchema},
|
||||
},
|
||||
security=[{"token": [DELETE_PERMISSION]}],
|
||||
permission=DELETE_PERMISSION,
|
||||
error_404_description="Repository is unknown",
|
||||
match_schema=PackageNameSchema,
|
||||
query_schema=RepositoryIdSchema,
|
||||
)
|
||||
@aiohttp_apispec.cookies_schema(AuthSchema)
|
||||
@aiohttp_apispec.match_info_schema(PackageNameSchema)
|
||||
@aiohttp_apispec.querystring_schema(RepositoryIdSchema)
|
||||
async def delete(self) -> None:
|
||||
"""
|
||||
delete package base from status page
|
||||
@@ -73,22 +65,16 @@ class PackageView(StatusViewGuard, BaseView):
|
||||
|
||||
raise HTTPNoContent
|
||||
|
||||
@aiohttp_apispec.docs(
|
||||
@apidocs(
|
||||
tags=["Packages"],
|
||||
summary="Get package",
|
||||
description="Retrieve packages and its descriptor",
|
||||
responses={
|
||||
200: {"description": "Success response", "schema": PackageStatusSchema(many=True)},
|
||||
401: {"description": "Authorization required", "schema": ErrorSchema},
|
||||
403: {"description": "Access is forbidden", "schema": ErrorSchema},
|
||||
404: {"description": "Package base and/or repository are unknown", "schema": ErrorSchema},
|
||||
500: {"description": "Internal server error", "schema": ErrorSchema},
|
||||
},
|
||||
security=[{"token": [GET_PERMISSION]}],
|
||||
permission=GET_PERMISSION,
|
||||
error_404_description="Package base and/or repository are unknown",
|
||||
schema=PackageStatusSchema(many=True),
|
||||
match_schema=PackageNameSchema,
|
||||
query_schema=RepositoryIdSchema,
|
||||
)
|
||||
@aiohttp_apispec.cookies_schema(AuthSchema)
|
||||
@aiohttp_apispec.match_info_schema(PackageNameSchema)
|
||||
@aiohttp_apispec.querystring_schema(RepositoryIdSchema)
|
||||
async def get(self) -> Response:
|
||||
"""
|
||||
get current package base status
|
||||
@@ -116,24 +102,17 @@ class PackageView(StatusViewGuard, BaseView):
|
||||
]
|
||||
return json_response(response)
|
||||
|
||||
@aiohttp_apispec.docs(
|
||||
@apidocs(
|
||||
tags=["Packages"],
|
||||
summary="Update package",
|
||||
description="Update package status and set its descriptior optionally",
|
||||
responses={
|
||||
204: {"description": "Success response"},
|
||||
400: {"description": "Bad data is supplied", "schema": ErrorSchema},
|
||||
401: {"description": "Authorization required", "schema": ErrorSchema},
|
||||
403: {"description": "Access is forbidden", "schema": ErrorSchema},
|
||||
404: {"description": "Repository is unknown", "schema": ErrorSchema},
|
||||
500: {"description": "Internal server error", "schema": ErrorSchema},
|
||||
},
|
||||
security=[{"token": [POST_PERMISSION]}],
|
||||
permission=POST_PERMISSION,
|
||||
error_400_enabled=True,
|
||||
error_404_description="Repository is unknown",
|
||||
match_schema=PackageNameSchema,
|
||||
query_schema=RepositoryIdSchema,
|
||||
body_schema=PackageStatusSimplifiedSchema,
|
||||
)
|
||||
@aiohttp_apispec.cookies_schema(AuthSchema)
|
||||
@aiohttp_apispec.match_info_schema(PackageNameSchema)
|
||||
@aiohttp_apispec.querystring_schema(RepositoryIdSchema)
|
||||
@aiohttp_apispec.json_schema(PackageStatusSimplifiedSchema)
|
||||
async def post(self) -> None:
|
||||
"""
|
||||
update package build status
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
import aiohttp_apispec # type: ignore[import-untyped]
|
||||
import itertools
|
||||
|
||||
from aiohttp.web import HTTPNoContent, Response, json_response
|
||||
@@ -26,7 +25,8 @@ from collections.abc import Callable
|
||||
from ahriman.models.build_status import BuildStatus
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.schemas import AuthSchema, ErrorSchema, PackageStatusSchema, PaginationSchema, RepositoryIdSchema
|
||||
from ahriman.web.apispec.decorators import apidocs
|
||||
from ahriman.web.schemas import PackageStatusSchema, PaginationSchema, RepositoryIdSchema
|
||||
from ahriman.web.views.base import BaseView
|
||||
from ahriman.web.views.status_view_guard import StatusViewGuard
|
||||
|
||||
@@ -44,22 +44,16 @@ class PackagesView(StatusViewGuard, BaseView):
|
||||
POST_PERMISSION = UserAccess.Full
|
||||
ROUTES = ["/api/v1/packages"]
|
||||
|
||||
@aiohttp_apispec.docs(
|
||||
tags=["Packages"],
|
||||
@apidocs(
|
||||
tags=["packages"],
|
||||
summary="Get packages list",
|
||||
description="Retrieve packages and their descriptors",
|
||||
responses={
|
||||
200: {"description": "Success response", "schema": PackageStatusSchema(many=True)},
|
||||
400: {"description": "Bad data is supplied", "schema": ErrorSchema},
|
||||
401: {"description": "Authorization required", "schema": ErrorSchema},
|
||||
403: {"description": "Access is forbidden", "schema": ErrorSchema},
|
||||
404: {"description": "Repository is unknown", "schema": ErrorSchema},
|
||||
500: {"description": "Internal server error", "schema": ErrorSchema},
|
||||
},
|
||||
security=[{"token": [GET_PERMISSION]}],
|
||||
permission=GET_PERMISSION,
|
||||
error_400_enabled=True,
|
||||
error_404_description="Repository is unknown",
|
||||
schema=PackageStatusSchema(many=True),
|
||||
query_schema=PaginationSchema,
|
||||
)
|
||||
@aiohttp_apispec.cookies_schema(AuthSchema)
|
||||
@aiohttp_apispec.querystring_schema(PaginationSchema)
|
||||
async def get(self) -> Response:
|
||||
"""
|
||||
get current packages status
|
||||
@@ -84,21 +78,14 @@ class PackagesView(StatusViewGuard, BaseView):
|
||||
|
||||
return json_response(response)
|
||||
|
||||
@aiohttp_apispec.docs(
|
||||
@apidocs(
|
||||
tags=["Packages"],
|
||||
summary="Load packages",
|
||||
description="Load packages from cache",
|
||||
responses={
|
||||
204: {"description": "Success response"},
|
||||
401: {"description": "Authorization required", "schema": ErrorSchema},
|
||||
403: {"description": "Access is forbidden", "schema": ErrorSchema},
|
||||
404: {"description": "Repository is unknown", "schema": ErrorSchema},
|
||||
500: {"description": "Internal server error", "schema": ErrorSchema},
|
||||
},
|
||||
security=[{"token": [POST_PERMISSION]}],
|
||||
permission=POST_PERMISSION,
|
||||
error_404_description="Repository is unknown",
|
||||
query_schema=RepositoryIdSchema,
|
||||
)
|
||||
@aiohttp_apispec.cookies_schema(AuthSchema)
|
||||
@aiohttp_apispec.querystring_schema(RepositoryIdSchema)
|
||||
async def post(self) -> None:
|
||||
"""
|
||||
reload all packages from repository
|
||||
|
||||
@@ -17,12 +17,11 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
import aiohttp_apispec # type: ignore[import-untyped]
|
||||
|
||||
from aiohttp.web import HTTPNoContent, HTTPNotFound, Response, json_response
|
||||
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.schemas import AuthSchema, ErrorSchema, PatchNameSchema, PatchSchema
|
||||
from ahriman.web.apispec.decorators import apidocs
|
||||
from ahriman.web.schemas import PatchNameSchema, PatchSchema
|
||||
from ahriman.web.views.base import BaseView
|
||||
from ahriman.web.views.status_view_guard import StatusViewGuard
|
||||
|
||||
@@ -40,20 +39,13 @@ class PatchView(StatusViewGuard, BaseView):
|
||||
GET_PERMISSION = UserAccess.Reporter
|
||||
ROUTES = ["/api/v1/packages/{package}/patches/{patch}"]
|
||||
|
||||
@aiohttp_apispec.docs(
|
||||
@apidocs(
|
||||
tags=["Packages"],
|
||||
summary="Delete package patch",
|
||||
description="Delete package patch by variable",
|
||||
responses={
|
||||
204: {"description": "Success response"},
|
||||
401: {"description": "Authorization required", "schema": ErrorSchema},
|
||||
403: {"description": "Access is forbidden", "schema": ErrorSchema},
|
||||
500: {"description": "Internal server error", "schema": ErrorSchema},
|
||||
},
|
||||
security=[{"token": [DELETE_PERMISSION]}],
|
||||
permission=DELETE_PERMISSION,
|
||||
match_schema=PatchNameSchema,
|
||||
)
|
||||
@aiohttp_apispec.cookies_schema(AuthSchema)
|
||||
@aiohttp_apispec.match_info_schema(PatchNameSchema)
|
||||
async def delete(self) -> None:
|
||||
"""
|
||||
delete package patch
|
||||
@@ -68,21 +60,15 @@ class PatchView(StatusViewGuard, BaseView):
|
||||
|
||||
raise HTTPNoContent
|
||||
|
||||
@aiohttp_apispec.docs(
|
||||
@apidocs(
|
||||
tags=["Packages"],
|
||||
summary="Get package patch",
|
||||
description="Retrieve package patch by variable",
|
||||
responses={
|
||||
200: {"description": "Success response", "schema": PatchSchema},
|
||||
401: {"description": "Authorization required", "schema": ErrorSchema},
|
||||
403: {"description": "Access is forbidden", "schema": ErrorSchema},
|
||||
404: {"description": "Patch name is unknown", "schema": ErrorSchema},
|
||||
500: {"description": "Internal server error", "schema": ErrorSchema},
|
||||
},
|
||||
security=[{"token": [GET_PERMISSION]}],
|
||||
permission=GET_PERMISSION,
|
||||
error_404_description="Patch name is unknown",
|
||||
schema=PatchSchema,
|
||||
match_schema=PatchNameSchema,
|
||||
)
|
||||
@aiohttp_apispec.cookies_schema(AuthSchema)
|
||||
@aiohttp_apispec.match_info_schema(PatchNameSchema)
|
||||
async def get(self) -> Response:
|
||||
"""
|
||||
get package patch
|
||||
|
||||
@@ -17,13 +17,12 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
import aiohttp_apispec # type: ignore[import-untyped]
|
||||
|
||||
from aiohttp.web import HTTPBadRequest, HTTPNoContent, Response, json_response
|
||||
|
||||
from ahriman.models.pkgbuild_patch import PkgbuildPatch
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.schemas import AuthSchema, ErrorSchema, PackageNameSchema, PatchSchema
|
||||
from ahriman.web.apispec.decorators import apidocs
|
||||
from ahriman.web.schemas import PackageNameSchema, PatchSchema
|
||||
from ahriman.web.views.base import BaseView
|
||||
from ahriman.web.views.status_view_guard import StatusViewGuard
|
||||
|
||||
@@ -41,20 +40,14 @@ class PatchesView(StatusViewGuard, BaseView):
|
||||
POST_PERMISSION = UserAccess.Full
|
||||
ROUTES = ["/api/v1/packages/{package}/patches"]
|
||||
|
||||
@aiohttp_apispec.docs(
|
||||
@apidocs(
|
||||
tags=["Packages"],
|
||||
summary="Get package patches",
|
||||
description="Retrieve all package patches",
|
||||
responses={
|
||||
200: {"description": "Success response", "schema": PatchSchema(many=True)},
|
||||
401: {"description": "Authorization required", "schema": ErrorSchema},
|
||||
403: {"description": "Access is forbidden", "schema": ErrorSchema},
|
||||
500: {"description": "Internal server error", "schema": ErrorSchema},
|
||||
},
|
||||
security=[{"token": [GET_PERMISSION]}],
|
||||
permission=GET_PERMISSION,
|
||||
schema=PatchSchema(many=True),
|
||||
match_schema=PackageNameSchema,
|
||||
)
|
||||
@aiohttp_apispec.cookies_schema(AuthSchema)
|
||||
@aiohttp_apispec.match_info_schema(PackageNameSchema)
|
||||
async def get(self) -> Response:
|
||||
"""
|
||||
get package patches
|
||||
@@ -68,22 +61,15 @@ class PatchesView(StatusViewGuard, BaseView):
|
||||
response = [patch.view() for patch in patches]
|
||||
return json_response(response)
|
||||
|
||||
@aiohttp_apispec.docs(
|
||||
@apidocs(
|
||||
tags=["Packages"],
|
||||
summary="Update package patch",
|
||||
description="Update or create package patch",
|
||||
responses={
|
||||
204: {"description": "Success response"},
|
||||
400: {"description": "Bad data is supplied", "schema": ErrorSchema},
|
||||
401: {"description": "Authorization required", "schema": ErrorSchema},
|
||||
403: {"description": "Access is forbidden", "schema": ErrorSchema},
|
||||
500: {"description": "Internal server error", "schema": ErrorSchema},
|
||||
},
|
||||
security=[{"token": [GET_PERMISSION]}],
|
||||
permission=POST_PERMISSION,
|
||||
error_400_enabled=True,
|
||||
match_schema=PackageNameSchema,
|
||||
body_schema=PatchSchema,
|
||||
)
|
||||
@aiohttp_apispec.cookies_schema(AuthSchema)
|
||||
@aiohttp_apispec.match_info_schema(PackageNameSchema)
|
||||
@aiohttp_apispec.json_schema(PatchSchema)
|
||||
async def post(self) -> None:
|
||||
"""
|
||||
update or create package patch
|
||||
|
||||
@@ -17,13 +17,12 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
import aiohttp_apispec # type: ignore[import-untyped]
|
||||
|
||||
from aiohttp.web import HTTPBadRequest, Response, json_response
|
||||
|
||||
from ahriman.models.pkgbuild_patch import PkgbuildPatch
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.schemas import AuthSchema, ErrorSchema, PackagePatchSchema, ProcessIdSchema, RepositoryIdSchema
|
||||
from ahriman.web.apispec.decorators import apidocs
|
||||
from ahriman.web.schemas import PackagePatchSchema, ProcessIdSchema, RepositoryIdSchema
|
||||
from ahriman.web.views.base import BaseView
|
||||
|
||||
|
||||
@@ -38,23 +37,17 @@ class AddView(BaseView):
|
||||
POST_PERMISSION = UserAccess.Full
|
||||
ROUTES = ["/api/v1/service/add"]
|
||||
|
||||
@aiohttp_apispec.docs(
|
||||
@apidocs(
|
||||
tags=["Actions"],
|
||||
summary="Add new package",
|
||||
description="Add new package(s) from AUR",
|
||||
responses={
|
||||
200: {"description": "Success response", "schema": ProcessIdSchema},
|
||||
400: {"description": "Bad data is supplied", "schema": ErrorSchema},
|
||||
401: {"description": "Authorization required", "schema": ErrorSchema},
|
||||
403: {"description": "Access is forbidden", "schema": ErrorSchema},
|
||||
404: {"description": "Repository is unknown", "schema": ErrorSchema},
|
||||
500: {"description": "Internal server error", "schema": ErrorSchema},
|
||||
},
|
||||
security=[{"token": [POST_PERMISSION]}],
|
||||
permission=POST_PERMISSION,
|
||||
error_400_enabled=True,
|
||||
error_404_description="Repository is unknown",
|
||||
schema=ProcessIdSchema,
|
||||
query_schema=RepositoryIdSchema,
|
||||
body_schema=PackagePatchSchema,
|
||||
)
|
||||
@aiohttp_apispec.cookies_schema(AuthSchema)
|
||||
@aiohttp_apispec.querystring_schema(RepositoryIdSchema)
|
||||
@aiohttp_apispec.json_schema(PackagePatchSchema)
|
||||
async def post(self) -> Response:
|
||||
"""
|
||||
add new package
|
||||
|
||||
@@ -17,12 +17,11 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
import aiohttp_apispec # type: ignore[import-untyped]
|
||||
|
||||
from aiohttp.web import HTTPBadRequest, HTTPNotFound, Response, json_response
|
||||
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.schemas import AuthSchema, ErrorSchema, PGPKeyIdSchema, PGPKeySchema, ProcessIdSchema
|
||||
from ahriman.web.apispec.decorators import apidocs
|
||||
from ahriman.web.schemas import PGPKeyIdSchema, PGPKeySchema, ProcessIdSchema
|
||||
from ahriman.web.views.base import BaseView
|
||||
|
||||
|
||||
@@ -39,22 +38,16 @@ class PGPView(BaseView):
|
||||
POST_PERMISSION = UserAccess.Full
|
||||
ROUTES = ["/api/v1/service/pgp"]
|
||||
|
||||
@aiohttp_apispec.docs(
|
||||
@apidocs(
|
||||
tags=["Actions"],
|
||||
summary="Search for PGP key",
|
||||
description="Search for PGP key and retrieve its body",
|
||||
responses={
|
||||
200: {"description": "Success response", "schema": PGPKeySchema},
|
||||
400: {"description": "Bad data is supplied", "schema": ErrorSchema},
|
||||
401: {"description": "Authorization required", "schema": ErrorSchema},
|
||||
403: {"description": "Access is forbidden", "schema": ErrorSchema},
|
||||
404: {"description": "PGP key is unknown", "schema": ErrorSchema},
|
||||
500: {"description": "Internal server error", "schema": ErrorSchema},
|
||||
},
|
||||
security=[{"token": [GET_PERMISSION]}],
|
||||
permission=GET_PERMISSION,
|
||||
error_400_enabled=True,
|
||||
error_404_description="PGP key is unknown",
|
||||
schema=PGPKeySchema,
|
||||
query_schema=PGPKeyIdSchema,
|
||||
)
|
||||
@aiohttp_apispec.cookies_schema(AuthSchema)
|
||||
@aiohttp_apispec.querystring_schema(PGPKeyIdSchema)
|
||||
async def get(self) -> Response:
|
||||
"""
|
||||
retrieve key from the key server
|
||||
@@ -79,21 +72,15 @@ class PGPView(BaseView):
|
||||
|
||||
return json_response({"key": key})
|
||||
|
||||
@aiohttp_apispec.docs(
|
||||
@apidocs(
|
||||
tags=["Actions"],
|
||||
summary="Fetch PGP key",
|
||||
description="Fetch PGP key from the key server",
|
||||
responses={
|
||||
200: {"description": "Success response", "schema": ProcessIdSchema},
|
||||
400: {"description": "Bad data is supplied", "schema": ErrorSchema},
|
||||
401: {"description": "Authorization required", "schema": ErrorSchema},
|
||||
403: {"description": "Access is forbidden", "schema": ErrorSchema},
|
||||
500: {"description": "Internal server error", "schema": ErrorSchema},
|
||||
},
|
||||
security=[{"token": [POST_PERMISSION]}],
|
||||
permission=POST_PERMISSION,
|
||||
error_400_enabled=True,
|
||||
schema=ProcessIdSchema,
|
||||
body_schema=PGPKeyIdSchema,
|
||||
)
|
||||
@aiohttp_apispec.cookies_schema(AuthSchema)
|
||||
@aiohttp_apispec.json_schema(PGPKeyIdSchema)
|
||||
async def post(self) -> Response:
|
||||
"""
|
||||
store key to the local service environment
|
||||
|
||||
@@ -17,12 +17,11 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
import aiohttp_apispec # type: ignore[import-untyped]
|
||||
|
||||
from aiohttp.web import HTTPNotFound, Response, json_response
|
||||
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.schemas import AuthSchema, ErrorSchema, ProcessIdSchema, ProcessSchema
|
||||
from ahriman.web.apispec.decorators import apidocs
|
||||
from ahriman.web.schemas import ProcessIdSchema, ProcessSchema
|
||||
from ahriman.web.views.base import BaseView
|
||||
|
||||
|
||||
@@ -37,21 +36,15 @@ class ProcessView(BaseView):
|
||||
GET_PERMISSION = UserAccess.Reporter
|
||||
ROUTES = ["/api/v1/service/process/{process_id}"]
|
||||
|
||||
@aiohttp_apispec.docs(
|
||||
@apidocs(
|
||||
tags=["Actions"],
|
||||
summary="Get process",
|
||||
description="Get process information",
|
||||
responses={
|
||||
200: {"description": "Success response", "schema": ProcessSchema},
|
||||
401: {"description": "Authorization required", "schema": ErrorSchema},
|
||||
403: {"description": "Access is forbidden", "schema": ErrorSchema},
|
||||
404: {"description": "Process is unknown", "schema": ErrorSchema},
|
||||
500: {"description": "Internal server error", "schema": ErrorSchema},
|
||||
},
|
||||
security=[{"token": [GET_PERMISSION]}],
|
||||
permission=GET_PERMISSION,
|
||||
error_404_description="Process is unknown",
|
||||
schema=ProcessSchema,
|
||||
match_schema=ProcessIdSchema,
|
||||
)
|
||||
@aiohttp_apispec.cookies_schema(AuthSchema)
|
||||
@aiohttp_apispec.match_info_schema(ProcessIdSchema)
|
||||
async def get(self) -> Response:
|
||||
"""
|
||||
get spawned process status
|
||||
|
||||
@@ -17,12 +17,11 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
import aiohttp_apispec # type: ignore[import-untyped]
|
||||
|
||||
from aiohttp.web import HTTPBadRequest, Response, json_response
|
||||
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.schemas import AuthSchema, ErrorSchema, PackageNamesSchema, ProcessIdSchema, RepositoryIdSchema
|
||||
from ahriman.web.apispec.decorators import apidocs
|
||||
from ahriman.web.schemas import PackageNamesSchema, ProcessIdSchema, RepositoryIdSchema
|
||||
from ahriman.web.views.base import BaseView
|
||||
|
||||
|
||||
@@ -37,23 +36,17 @@ class RebuildView(BaseView):
|
||||
POST_PERMISSION = UserAccess.Full
|
||||
ROUTES = ["/api/v1/service/rebuild"]
|
||||
|
||||
@aiohttp_apispec.docs(
|
||||
@apidocs(
|
||||
tags=["Actions"],
|
||||
summary="Rebuild packages",
|
||||
description="Rebuild packages which depend on specified one",
|
||||
responses={
|
||||
200: {"description": "Success response", "schema": ProcessIdSchema},
|
||||
400: {"description": "Bad data is supplied", "schema": ErrorSchema},
|
||||
401: {"description": "Authorization required", "schema": ErrorSchema},
|
||||
403: {"description": "Access is forbidden", "schema": ErrorSchema},
|
||||
404: {"description": "Repository is unknown", "schema": ErrorSchema},
|
||||
500: {"description": "Internal server error", "schema": ErrorSchema},
|
||||
},
|
||||
security=[{"token": [POST_PERMISSION]}],
|
||||
permission=POST_PERMISSION,
|
||||
error_400_enabled=True,
|
||||
error_404_description="Repository is unknown",
|
||||
schema=ProcessIdSchema,
|
||||
query_schema=RepositoryIdSchema,
|
||||
body_schema=PackageNamesSchema,
|
||||
)
|
||||
@aiohttp_apispec.cookies_schema(AuthSchema)
|
||||
@aiohttp_apispec.querystring_schema(RepositoryIdSchema)
|
||||
@aiohttp_apispec.json_schema(PackageNamesSchema)
|
||||
async def post(self) -> Response:
|
||||
"""
|
||||
rebuild packages based on their dependency
|
||||
|
||||
@@ -17,12 +17,11 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
import aiohttp_apispec # type: ignore[import-untyped]
|
||||
|
||||
from aiohttp.web import HTTPBadRequest, Response, json_response
|
||||
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.schemas import AuthSchema, ErrorSchema, PackageNamesSchema, ProcessIdSchema, RepositoryIdSchema
|
||||
from ahriman.web.apispec.decorators import apidocs
|
||||
from ahriman.web.schemas import PackageNamesSchema, ProcessIdSchema, RepositoryIdSchema
|
||||
from ahriman.web.views.base import BaseView
|
||||
|
||||
|
||||
@@ -37,23 +36,17 @@ class RemoveView(BaseView):
|
||||
POST_PERMISSION = UserAccess.Full
|
||||
ROUTES = ["/api/v1/service/remove"]
|
||||
|
||||
@aiohttp_apispec.docs(
|
||||
@apidocs(
|
||||
tags=["Actions"],
|
||||
summary="Remove packages",
|
||||
description="Remove specified packages from the repository",
|
||||
responses={
|
||||
200: {"description": "Success response", "schema": ProcessIdSchema},
|
||||
400: {"description": "Bad data is supplied", "schema": ErrorSchema},
|
||||
401: {"description": "Authorization required", "schema": ErrorSchema},
|
||||
403: {"description": "Access is forbidden", "schema": ErrorSchema},
|
||||
404: {"description": "Repository is unknown", "schema": ErrorSchema},
|
||||
500: {"description": "Internal server error", "schema": ErrorSchema},
|
||||
},
|
||||
security=[{"token": [POST_PERMISSION]}],
|
||||
permission=POST_PERMISSION,
|
||||
error_400_enabled=True,
|
||||
error_404_description="Repository is unknown",
|
||||
schema=ProcessIdSchema,
|
||||
query_schema=RepositoryIdSchema,
|
||||
body_schema=PackageNamesSchema,
|
||||
)
|
||||
@aiohttp_apispec.cookies_schema(AuthSchema)
|
||||
@aiohttp_apispec.querystring_schema(RepositoryIdSchema)
|
||||
@aiohttp_apispec.json_schema(PackageNamesSchema)
|
||||
async def post(self) -> Response:
|
||||
"""
|
||||
remove existing packages
|
||||
|
||||
@@ -17,13 +17,12 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
import aiohttp_apispec # type: ignore[import-untyped]
|
||||
|
||||
from aiohttp.web import HTTPBadRequest, Response, json_response
|
||||
|
||||
from ahriman.models.pkgbuild_patch import PkgbuildPatch
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.schemas import AuthSchema, ErrorSchema, PackagePatchSchema, ProcessIdSchema, RepositoryIdSchema
|
||||
from ahriman.web.apispec.decorators import apidocs
|
||||
from ahriman.web.schemas import PackagePatchSchema, ProcessIdSchema, RepositoryIdSchema
|
||||
from ahriman.web.views.base import BaseView
|
||||
|
||||
|
||||
@@ -38,23 +37,17 @@ class RequestView(BaseView):
|
||||
POST_PERMISSION = UserAccess.Reporter
|
||||
ROUTES = ["/api/v1/service/request"]
|
||||
|
||||
@aiohttp_apispec.docs(
|
||||
@apidocs(
|
||||
tags=["Actions"],
|
||||
summary="Request new package",
|
||||
description="Request new package(s) to be added from AUR",
|
||||
responses={
|
||||
200: {"description": "Success response", "schema": ProcessIdSchema},
|
||||
400: {"description": "Bad data is supplied", "schema": ErrorSchema},
|
||||
401: {"description": "Authorization required", "schema": ErrorSchema},
|
||||
403: {"description": "Access is forbidden", "schema": ErrorSchema},
|
||||
404: {"description": "Repository is unknown", "schema": ErrorSchema},
|
||||
500: {"description": "Internal server error", "schema": ErrorSchema},
|
||||
},
|
||||
security=[{"token": [POST_PERMISSION]}],
|
||||
permission=POST_PERMISSION,
|
||||
error_400_enabled=True,
|
||||
error_404_description="Repository is unknown",
|
||||
schema=ProcessIdSchema,
|
||||
query_schema=RepositoryIdSchema,
|
||||
body_schema=PackagePatchSchema,
|
||||
)
|
||||
@aiohttp_apispec.cookies_schema(AuthSchema)
|
||||
@aiohttp_apispec.querystring_schema(RepositoryIdSchema)
|
||||
@aiohttp_apispec.json_schema(PackagePatchSchema)
|
||||
async def post(self) -> Response:
|
||||
"""
|
||||
request to add new package
|
||||
|
||||
@@ -17,15 +17,14 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
import aiohttp_apispec # type: ignore[import-untyped]
|
||||
|
||||
from aiohttp.web import HTTPBadRequest, HTTPNotFound, Response, json_response
|
||||
from collections.abc import Callable
|
||||
|
||||
from ahriman.core.alpm.remote import AUR
|
||||
from ahriman.models.aur_package import AURPackage
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.schemas import AURPackageSchema, AuthSchema, ErrorSchema, SearchSchema
|
||||
from ahriman.web.apispec.decorators import apidocs
|
||||
from ahriman.web.schemas import AURPackageSchema, SearchSchema
|
||||
from ahriman.web.views.base import BaseView
|
||||
|
||||
|
||||
@@ -40,22 +39,16 @@ class SearchView(BaseView):
|
||||
GET_PERMISSION = UserAccess.Reporter
|
||||
ROUTES = ["/api/v1/service/search"]
|
||||
|
||||
@aiohttp_apispec.docs(
|
||||
@apidocs(
|
||||
tags=["Actions"],
|
||||
summary="Search for package",
|
||||
description="Search for package in AUR",
|
||||
responses={
|
||||
200: {"description": "Success response", "schema": AURPackageSchema(many=True)},
|
||||
400: {"description": "Bad data is supplied", "schema": ErrorSchema},
|
||||
401: {"description": "Authorization required", "schema": ErrorSchema},
|
||||
403: {"description": "Access is forbidden", "schema": ErrorSchema},
|
||||
404: {"description": "Package base is unknown", "schema": ErrorSchema},
|
||||
500: {"description": "Internal server error", "schema": ErrorSchema},
|
||||
},
|
||||
security=[{"token": [GET_PERMISSION]}],
|
||||
permission=GET_PERMISSION,
|
||||
error_400_enabled=True,
|
||||
error_404_description="Package base is unknown",
|
||||
schema=AURPackageSchema(many=True),
|
||||
query_schema=SearchSchema,
|
||||
)
|
||||
@aiohttp_apispec.cookies_schema(AuthSchema)
|
||||
@aiohttp_apispec.querystring_schema(SearchSchema)
|
||||
async def get(self) -> Response:
|
||||
"""
|
||||
search packages in AUR
|
||||
|
||||
@@ -17,12 +17,11 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
import aiohttp_apispec # type: ignore[import-untyped]
|
||||
|
||||
from aiohttp.web import HTTPBadRequest, Response, json_response
|
||||
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.schemas import AuthSchema, ErrorSchema, ProcessIdSchema, RepositoryIdSchema, UpdateFlagsSchema
|
||||
from ahriman.web.apispec.decorators import apidocs
|
||||
from ahriman.web.schemas import ProcessIdSchema, RepositoryIdSchema, UpdateFlagsSchema
|
||||
from ahriman.web.views.base import BaseView
|
||||
|
||||
|
||||
@@ -37,23 +36,17 @@ class UpdateView(BaseView):
|
||||
POST_PERMISSION = UserAccess.Full
|
||||
ROUTES = ["/api/v1/service/update"]
|
||||
|
||||
@aiohttp_apispec.docs(
|
||||
@apidocs(
|
||||
tags=["Actions"],
|
||||
summary="Update packages",
|
||||
description="Run repository update process",
|
||||
responses={
|
||||
200: {"description": "Success response", "schema": ProcessIdSchema},
|
||||
400: {"description": "Bad data is supplied", "schema": ErrorSchema},
|
||||
401: {"description": "Authorization required", "schema": ErrorSchema},
|
||||
403: {"description": "Access is forbidden", "schema": ErrorSchema},
|
||||
404: {"description": "Repository is unknown", "schema": ErrorSchema},
|
||||
500: {"description": "Internal server error", "schema": ErrorSchema},
|
||||
},
|
||||
security=[{"token": [POST_PERMISSION]}],
|
||||
permission=POST_PERMISSION,
|
||||
error_400_enabled=True,
|
||||
error_404_description="Repository is unknown",
|
||||
schema=ProcessIdSchema,
|
||||
query_schema=RepositoryIdSchema,
|
||||
body_schema=UpdateFlagsSchema,
|
||||
)
|
||||
@aiohttp_apispec.cookies_schema(AuthSchema)
|
||||
@aiohttp_apispec.querystring_schema(RepositoryIdSchema)
|
||||
@aiohttp_apispec.json_schema(UpdateFlagsSchema)
|
||||
async def post(self) -> Response:
|
||||
"""
|
||||
run repository update. No parameters supported here
|
||||
|
||||
@@ -17,17 +17,18 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
import aiohttp_apispec # type: ignore[import-untyped]
|
||||
import shutil
|
||||
|
||||
from aiohttp import BodyPartReader
|
||||
from aiohttp.web import HTTPBadRequest, HTTPCreated, HTTPNotFound
|
||||
from aiohttp.web import HTTPBadRequest, HTTPCreated
|
||||
from pathlib import Path
|
||||
from tempfile import NamedTemporaryFile
|
||||
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.models.repository_paths import RepositoryPaths
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.schemas import AuthSchema, ErrorSchema, FileSchema, RepositoryIdSchema
|
||||
from ahriman.web.apispec.decorators import apidocs
|
||||
from ahriman.web.schemas import FileSchema, RepositoryIdSchema
|
||||
from ahriman.web.views.base import BaseView
|
||||
|
||||
|
||||
@@ -42,6 +43,22 @@ class UploadView(BaseView):
|
||||
POST_PERMISSION = UserAccess.Full
|
||||
ROUTES = ["/api/v1/service/upload"]
|
||||
|
||||
@classmethod
|
||||
def routes(cls, configuration: Configuration) -> list[str]:
|
||||
"""
|
||||
extract routes list for the view
|
||||
|
||||
Args:
|
||||
configuration(Configuration): configuration instance
|
||||
|
||||
Returns:
|
||||
list[str]: list of routes defined for the view. By default, it tries to read :attr:`ROUTES` option if set
|
||||
and returns empty list otherwise
|
||||
"""
|
||||
if not configuration.getboolean("web", "enable_archive_upload", fallback=False):
|
||||
return []
|
||||
return cls.ROUTES
|
||||
|
||||
@staticmethod
|
||||
async def save_file(part: BodyPartReader, target: Path, *, max_body_size: int | None = None) -> tuple[str, Path]:
|
||||
"""
|
||||
@@ -92,23 +109,18 @@ class UploadView(BaseView):
|
||||
|
||||
return archive_name, temporary_output
|
||||
|
||||
@aiohttp_apispec.docs(
|
||||
@apidocs(
|
||||
tags=["Actions"],
|
||||
summary="Upload package",
|
||||
description="Upload package to local filesystem",
|
||||
responses={
|
||||
201: {"description": "Success response"},
|
||||
400: {"description": "Bad data is supplied", "schema": ErrorSchema},
|
||||
401: {"description": "Authorization required", "schema": ErrorSchema},
|
||||
403: {"description": "Access is forbidden", "schema": ErrorSchema},
|
||||
404: {"description": "Repository is unknown or endpoint is disabled", "schema": ErrorSchema},
|
||||
500: {"description": "Internal server error", "schema": ErrorSchema},
|
||||
},
|
||||
security=[{"token": [POST_PERMISSION]}],
|
||||
permission=POST_PERMISSION,
|
||||
response_code=HTTPCreated,
|
||||
error_400_enabled=True,
|
||||
error_404_description="Repository is unknown",
|
||||
query_schema=RepositoryIdSchema,
|
||||
body_schema=FileSchema,
|
||||
body_location="form",
|
||||
)
|
||||
@aiohttp_apispec.cookies_schema(AuthSchema)
|
||||
@aiohttp_apispec.querystring_schema(RepositoryIdSchema)
|
||||
@aiohttp_apispec.form_schema(FileSchema)
|
||||
async def post(self) -> None:
|
||||
"""
|
||||
upload file from another instance to the server
|
||||
@@ -118,9 +130,6 @@ class UploadView(BaseView):
|
||||
HTTPCreated: on success response
|
||||
HTTPNotFound: method is disabled by configuration
|
||||
"""
|
||||
if not self.configuration.getboolean("web", "enable_archive_upload", fallback=False):
|
||||
raise HTTPNotFound
|
||||
|
||||
try:
|
||||
reader = await self.request.multipart()
|
||||
except Exception as ex:
|
||||
|
||||
@@ -17,13 +17,12 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
import aiohttp_apispec # type: ignore[import-untyped]
|
||||
|
||||
from aiohttp.web import Response, json_response
|
||||
|
||||
from ahriman import __version__
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.schemas import AuthSchema, ErrorSchema, InfoSchema
|
||||
from ahriman.web.apispec.decorators import apidocs
|
||||
from ahriman.web.schemas import InfoSchema
|
||||
from ahriman.web.views.base import BaseView
|
||||
|
||||
|
||||
@@ -38,19 +37,13 @@ class InfoView(BaseView):
|
||||
GET_PERMISSION = UserAccess.Unauthorized
|
||||
ROUTES = ["/api/v1/info"]
|
||||
|
||||
@aiohttp_apispec.docs(
|
||||
@apidocs(
|
||||
tags=["Status"],
|
||||
summary="Service information",
|
||||
description="Perform basic service health check and returns its information",
|
||||
responses={
|
||||
200: {"description": "Success response", "schema": InfoSchema},
|
||||
401: {"description": "Authorization required", "schema": ErrorSchema},
|
||||
403: {"description": "Access is forbidden", "schema": ErrorSchema},
|
||||
500: {"description": "Internal server error", "schema": ErrorSchema},
|
||||
},
|
||||
security=[{"token": [GET_PERMISSION]}],
|
||||
permission=GET_PERMISSION,
|
||||
schema=InfoSchema,
|
||||
)
|
||||
@aiohttp_apispec.cookies_schema(AuthSchema)
|
||||
async def get(self) -> Response:
|
||||
"""
|
||||
get service information
|
||||
|
||||
@@ -17,12 +17,11 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
import aiohttp_apispec # type: ignore[import-untyped]
|
||||
|
||||
from aiohttp.web import Response, json_response
|
||||
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.schemas import AuthSchema, ErrorSchema, RepositoryIdSchema
|
||||
from ahriman.web.apispec.decorators import apidocs
|
||||
from ahriman.web.schemas import RepositoryIdSchema
|
||||
from ahriman.web.views.base import BaseView
|
||||
|
||||
|
||||
@@ -37,19 +36,13 @@ class RepositoriesView(BaseView):
|
||||
GET_PERMISSION = UserAccess.Read
|
||||
ROUTES = ["/api/v1/repositories"]
|
||||
|
||||
@aiohttp_apispec.docs(
|
||||
@apidocs(
|
||||
tags=["Status"],
|
||||
summary="Available repositories",
|
||||
description="List available repositories",
|
||||
responses={
|
||||
200: {"description": "Success response", "schema": RepositoryIdSchema(many=True)},
|
||||
401: {"description": "Authorization required", "schema": ErrorSchema},
|
||||
403: {"description": "Access is forbidden", "schema": ErrorSchema},
|
||||
500: {"description": "Internal server error", "schema": ErrorSchema},
|
||||
},
|
||||
security=[{"token": [GET_PERMISSION]}],
|
||||
permission=GET_PERMISSION,
|
||||
schema=RepositoryIdSchema(many=True),
|
||||
)
|
||||
@aiohttp_apispec.cookies_schema(AuthSchema)
|
||||
async def get(self) -> Response:
|
||||
"""
|
||||
get list of available repositories
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
import aiohttp_apispec # type: ignore[import-untyped]
|
||||
|
||||
from aiohttp.web import HTTPBadRequest, HTTPNoContent, Response, json_response
|
||||
|
||||
from ahriman import __version__
|
||||
@@ -26,7 +24,8 @@ from ahriman.models.build_status import BuildStatusEnum
|
||||
from ahriman.models.counters import Counters
|
||||
from ahriman.models.internal_status import InternalStatus
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.schemas import AuthSchema, ErrorSchema, InternalStatusSchema, RepositoryIdSchema, StatusSchema
|
||||
from ahriman.web.apispec.decorators import apidocs
|
||||
from ahriman.web.schemas import InternalStatusSchema, RepositoryIdSchema, StatusSchema
|
||||
from ahriman.web.views.base import BaseView
|
||||
from ahriman.web.views.status_view_guard import StatusViewGuard
|
||||
|
||||
@@ -44,20 +43,15 @@ class StatusView(StatusViewGuard, BaseView):
|
||||
POST_PERMISSION = UserAccess.Full
|
||||
ROUTES = ["/api/v1/status"]
|
||||
|
||||
@aiohttp_apispec.docs(
|
||||
@apidocs(
|
||||
tags=["Status"],
|
||||
summary="Web service status",
|
||||
description="Get web service status counters",
|
||||
responses={
|
||||
200: {"description": "Success response", "schema": InternalStatusSchema},
|
||||
401: {"description": "Authorization required", "schema": ErrorSchema},
|
||||
403: {"description": "Access is forbidden", "schema": ErrorSchema},
|
||||
404: {"description": "Repository is unknown", "schema": ErrorSchema},
|
||||
500: {"description": "Internal server error", "schema": ErrorSchema},
|
||||
},
|
||||
security=[{"token": [GET_PERMISSION]}],
|
||||
permission=GET_PERMISSION,
|
||||
error_404_description="Repository is unknown",
|
||||
schema=InternalStatusSchema,
|
||||
query_schema=RepositoryIdSchema,
|
||||
)
|
||||
@aiohttp_apispec.cookies_schema(AuthSchema)
|
||||
async def get(self) -> Response:
|
||||
"""
|
||||
get current service status
|
||||
@@ -77,23 +71,16 @@ class StatusView(StatusViewGuard, BaseView):
|
||||
|
||||
return json_response(status.view())
|
||||
|
||||
@aiohttp_apispec.docs(
|
||||
@apidocs(
|
||||
tags=["Status"],
|
||||
summary="Set web service status",
|
||||
description="Update web service status. Counters will remain unchanged",
|
||||
responses={
|
||||
204: {"description": "Success response"},
|
||||
400: {"description": "Bad data is supplied", "schema": ErrorSchema},
|
||||
401: {"description": "Authorization required", "schema": ErrorSchema},
|
||||
403: {"description": "Access is forbidden", "schema": ErrorSchema},
|
||||
404: {"description": "Repository is unknown", "schema": ErrorSchema},
|
||||
500: {"description": "Internal server error", "schema": ErrorSchema},
|
||||
},
|
||||
security=[{"token": [POST_PERMISSION]}],
|
||||
permission=POST_PERMISSION,
|
||||
error_400_enabled=True,
|
||||
error_404_description="Repository is unknown",
|
||||
query_schema=RepositoryIdSchema,
|
||||
body_schema=StatusSchema,
|
||||
)
|
||||
@aiohttp_apispec.cookies_schema(AuthSchema)
|
||||
@aiohttp_apispec.querystring_schema(RepositoryIdSchema)
|
||||
@aiohttp_apispec.json_schema(StatusSchema)
|
||||
async def post(self) -> None:
|
||||
"""
|
||||
update service status
|
||||
|
||||
@@ -17,13 +17,12 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
import aiohttp_apispec # type: ignore[import-untyped]
|
||||
|
||||
from aiohttp.web import HTTPBadRequest, HTTPFound, HTTPMethodNotAllowed, HTTPUnauthorized
|
||||
|
||||
from ahriman.core.auth.helpers import remember
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.schemas import ErrorSchema, LoginSchema, OAuth2Schema
|
||||
from ahriman.web.apispec.decorators import apidocs
|
||||
from ahriman.web.schemas import LoginSchema, OAuth2Schema
|
||||
from ahriman.web.views.base import BaseView
|
||||
|
||||
|
||||
@@ -39,18 +38,14 @@ class LoginView(BaseView):
|
||||
GET_PERMISSION = POST_PERMISSION = UserAccess.Unauthorized
|
||||
ROUTES = ["/api/v1/login"]
|
||||
|
||||
@aiohttp_apispec.docs(
|
||||
@apidocs(
|
||||
tags=["Login"],
|
||||
summary="Login via OAuth2",
|
||||
description="Login by using OAuth2 authorization code. Only available if OAuth2 is enabled",
|
||||
responses={
|
||||
302: {"description": "Success response"},
|
||||
401: {"description": "Authorization required", "schema": ErrorSchema},
|
||||
500: {"description": "Internal server error", "schema": ErrorSchema},
|
||||
},
|
||||
security=[{"token": [GET_PERMISSION]}],
|
||||
permission=GET_PERMISSION,
|
||||
response_code=HTTPFound,
|
||||
query_schema=OAuth2Schema,
|
||||
)
|
||||
@aiohttp_apispec.querystring_schema(OAuth2Schema)
|
||||
async def get(self) -> None:
|
||||
"""
|
||||
OAuth2 response handler
|
||||
@@ -87,19 +82,15 @@ class LoginView(BaseView):
|
||||
|
||||
raise HTTPUnauthorized
|
||||
|
||||
@aiohttp_apispec.docs(
|
||||
@apidocs(
|
||||
tags=["Login"],
|
||||
summary="Login via basic authorization",
|
||||
description="Login by using username and password",
|
||||
responses={
|
||||
302: {"description": "Success response"},
|
||||
400: {"description": "Bad data is supplied", "schema": ErrorSchema},
|
||||
401: {"description": "Authorization required", "schema": ErrorSchema},
|
||||
500: {"description": "Internal server error", "schema": ErrorSchema},
|
||||
},
|
||||
security=[{"token": [POST_PERMISSION]}],
|
||||
permission=POST_PERMISSION,
|
||||
response_code=HTTPFound,
|
||||
error_400_enabled=True,
|
||||
body_schema=LoginSchema,
|
||||
)
|
||||
@aiohttp_apispec.json_schema(LoginSchema)
|
||||
async def post(self) -> None:
|
||||
"""
|
||||
login user to service. The authentication session will be passed in ``Set-Cookie`` header.
|
||||
|
||||
@@ -17,13 +17,11 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
import aiohttp_apispec # type: ignore[import-untyped]
|
||||
|
||||
from aiohttp.web import HTTPFound, HTTPUnauthorized
|
||||
|
||||
from ahriman.core.auth.helpers import check_authorized, forget
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.schemas import AuthSchema, ErrorSchema
|
||||
from ahriman.web.apispec.decorators import apidocs
|
||||
from ahriman.web.views.base import BaseView
|
||||
|
||||
|
||||
@@ -38,18 +36,13 @@ class LogoutView(BaseView):
|
||||
POST_PERMISSION = UserAccess.Unauthorized
|
||||
ROUTES = ["/api/v1/logout"]
|
||||
|
||||
@aiohttp_apispec.docs(
|
||||
@apidocs(
|
||||
tags=["Login"],
|
||||
summary="Logout",
|
||||
description="Logout user and remove authorization cookies",
|
||||
responses={
|
||||
302: {"description": "Success response"},
|
||||
401: {"description": "Authorization required", "schema": ErrorSchema},
|
||||
500: {"description": "Internal server error", "schema": ErrorSchema},
|
||||
},
|
||||
security=[{"token": [POST_PERMISSION]}],
|
||||
permission=POST_PERMISSION,
|
||||
response_code=HTTPFound,
|
||||
)
|
||||
@aiohttp_apispec.cookies_schema(AuthSchema)
|
||||
async def post(self) -> None:
|
||||
"""
|
||||
logout user from the service
|
||||
|
||||
@@ -17,12 +17,11 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
import aiohttp_apispec # type: ignore[import-untyped]
|
||||
|
||||
from aiohttp.web import Response, json_response
|
||||
|
||||
from ahriman.models.user_access import UserAccess
|
||||
from ahriman.web.schemas import AuthSchema, ErrorSchema, LogSchema, PackageNameSchema, PaginationSchema
|
||||
from ahriman.web.apispec.decorators import apidocs
|
||||
from ahriman.web.schemas import LogSchema, PackageNameSchema, PaginationSchema
|
||||
from ahriman.web.views.base import BaseView
|
||||
from ahriman.web.views.status_view_guard import StatusViewGuard
|
||||
|
||||
@@ -38,23 +37,17 @@ class LogsView(StatusViewGuard, BaseView):
|
||||
GET_PERMISSION = UserAccess.Reporter
|
||||
ROUTES = ["/api/v2/packages/{package}/logs"]
|
||||
|
||||
@aiohttp_apispec.docs(
|
||||
@apidocs(
|
||||
tags=["Packages"],
|
||||
summary="Get paginated package logs",
|
||||
description="Retrieve package logs and the last package status",
|
||||
responses={
|
||||
200: {"description": "Success response", "schema": LogSchema(many=True)},
|
||||
400: {"description": "Bad data is supplied", "schema": ErrorSchema},
|
||||
401: {"description": "Authorization required", "schema": ErrorSchema},
|
||||
403: {"description": "Access is forbidden", "schema": ErrorSchema},
|
||||
404: {"description": "Package base and/or repository are unknown", "schema": ErrorSchema},
|
||||
500: {"description": "Internal server error", "schema": ErrorSchema},
|
||||
},
|
||||
security=[{"token": [GET_PERMISSION]}],
|
||||
permission=GET_PERMISSION,
|
||||
error_400_enabled=True,
|
||||
error_404_description="Package base and/or repository are unknown",
|
||||
schema=LogSchema(many=True),
|
||||
match_schema=PackageNameSchema,
|
||||
query_schema=PaginationSchema,
|
||||
)
|
||||
@aiohttp_apispec.cookies_schema(AuthSchema)
|
||||
@aiohttp_apispec.match_info_schema(PackageNameSchema)
|
||||
@aiohttp_apispec.querystring_schema(PaginationSchema)
|
||||
async def get(self) -> Response:
|
||||
"""
|
||||
get last package logs
|
||||
|
||||
Reference in New Issue
Block a user