mirror of
https://github.com/arcan1s/ahriman.git
synced 2026-04-07 19:03:38 +00:00
Compare commits
3 Commits
a69e3338b1
...
feature/ss
| Author | SHA1 | Date | |
|---|---|---|---|
| a170e43073 | |||
| 190b6665de | |||
| 71f9044f27 |
@@ -188,6 +188,7 @@ Web server settings. This feature requires ``aiohttp`` libraries to be installed
|
||||
* ``host`` - host to bind, string, optional.
|
||||
* ``index_url`` - full URL of the repository index page, string, optional.
|
||||
* ``max_body_size`` - max body size in bytes to be validated for archive upload, integer, optional. If not set, validation will be disabled.
|
||||
* ``max_queue_size`` - max queue size for server sent event streams, integer, optional, default ``0``. If set to ``0``, queue is unlimited.
|
||||
* ``port`` - port to bind, integer, optional.
|
||||
* ``service_only`` - disable status routes (including logs), boolean, optional, default ``no``.
|
||||
* ``static_path`` - path to directory with static files, string, required.
|
||||
@@ -195,7 +196,7 @@ Web server settings. This feature requires ``aiohttp`` libraries to be installed
|
||||
* ``templates`` - path to templates directories, space separated list of paths, required.
|
||||
* ``unix_socket`` - path to the listening unix socket, string, optional. If set, server will create the socket on the specified address which can (and will) be used by application. Note, that unlike usual host/port configuration, unix socket allows to perform requests without authorization.
|
||||
* ``unix_socket_unsafe`` - set unsafe (o+w) permissions to unix socket, boolean, optional, default ``yes``. This option is enabled by default, because it is supposed that unix socket is created in safe environment (only web service is supposed to be used in unsafe), but it can be disabled by configuration.
|
||||
* ``wait_timeout`` - wait timeout in seconds, maximum amount of time to be waited before lock will be free, integer, optional.
|
||||
* ``wait_timeout`` - wait timeout in seconds, maximum amount of time to be waited before lock will be free, integer, optional. If set to ``0``, wait infinitely.
|
||||
|
||||
``archive`` group
|
||||
-----------------
|
||||
|
||||
@@ -46,6 +46,8 @@ host = 127.0.0.1
|
||||
;index_url =
|
||||
; Max file size in bytes which can be uploaded to the server. Requires ${web:enable_archive_upload} to be enabled.
|
||||
;max_body_size =
|
||||
; Max event queue size used for server sent event endpoints (0 is infinite)
|
||||
;max_queue_size = 0
|
||||
; Port to listen. Must be set, if the web service is enabled.
|
||||
;port =
|
||||
; Disable status (e.g. package status, logs, etc) endpoints. Useful for build only modes.
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#
|
||||
import json
|
||||
|
||||
from aiohttp.web import StreamResponse
|
||||
from aiohttp.web import HTTPBadRequest, StreamResponse
|
||||
from aiohttp_sse import EventSourceResponse, sse_response
|
||||
from asyncio import Queue, QueueShutDown, wait_for
|
||||
from typing import ClassVar
|
||||
@@ -69,6 +69,7 @@ class EventBusView(BaseView):
|
||||
summary="Live updates",
|
||||
description="Stream live updates via SSE",
|
||||
permission=GET_PERMISSION,
|
||||
error_400_enabled=True,
|
||||
error_404_description="Repository is unknown",
|
||||
schema=SSESchema(many=True),
|
||||
query_schema=EventBusFilterSchema,
|
||||
@@ -79,8 +80,14 @@ class EventBusView(BaseView):
|
||||
|
||||
Returns:
|
||||
StreamResponse: 200 with streaming updates
|
||||
|
||||
Raises:
|
||||
HTTPBadRequest: if invalid event type is supplied
|
||||
"""
|
||||
topics = [EventType(event) for event in self.request.query.getall("event", [])] or None
|
||||
try:
|
||||
topics = [EventType(event) for event in self.request.query.getall("event", [])] or None
|
||||
except ValueError as ex:
|
||||
raise HTTPBadRequest(reason=str(ex))
|
||||
event_bus = self.service().event_bus
|
||||
|
||||
async with sse_response(self.request) as response:
|
||||
|
||||
@@ -23,7 +23,7 @@ def event_bus() -> EventBus:
|
||||
fixture for event bus
|
||||
|
||||
Returns:
|
||||
EventBus: even bus test instance
|
||||
EventBus: event bus test instance
|
||||
"""
|
||||
return EventBus(0)
|
||||
|
||||
|
||||
@@ -33,8 +33,9 @@ async def test_get_permission() -> None:
|
||||
"""
|
||||
must return correct permission for the request
|
||||
"""
|
||||
request = pytest.helpers.request("", "", "GET")
|
||||
assert await EventBusView.get_permission(request) == UserAccess.Full
|
||||
for method in ("GET",):
|
||||
request = pytest.helpers.request("", "", method)
|
||||
assert await EventBusView.get_permission(request) == UserAccess.Full
|
||||
|
||||
|
||||
def test_routes() -> None:
|
||||
@@ -98,6 +99,17 @@ async def test_get_with_topic_filter(client: TestClient, package_ahriman: Packag
|
||||
assert EventType.PackageRemoved not in body
|
||||
|
||||
|
||||
async def test_get_bad_request(client: TestClient) -> None:
|
||||
"""
|
||||
must return bad request for invalid event type
|
||||
"""
|
||||
response_schema = pytest.helpers.schema_response(EventBusView.get, code=400)
|
||||
|
||||
response = await client.get("/api/v1/events/stream", params={"event": "invalid"})
|
||||
assert response.status == 400
|
||||
assert not response_schema.validate(await response.json())
|
||||
|
||||
|
||||
async def test_get_not_found(client: TestClient) -> None:
|
||||
"""
|
||||
must return not found for unknown repository
|
||||
@@ -114,6 +126,5 @@ async def test_get_connection_reset(client: TestClient, mocker: MockerFixture) -
|
||||
must handle connection reset
|
||||
"""
|
||||
mocker.patch.object(EventBusView, "_run", side_effect=ConnectionResetError)
|
||||
|
||||
response = await client.get("/api/v1/events/stream")
|
||||
assert response.status == 200
|
||||
|
||||
Reference in New Issue
Block a user