Skip to content

Commit 19472e4

Browse files
committed
add cors, slightly refactor, test and update client
1 parent 23259e9 commit 19472e4

File tree

15 files changed

+830
-8
lines changed

15 files changed

+830
-8
lines changed

examples/room_manager/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import logging
22

33
from flask import Flask
4+
from flask_cors import CORS
45

56
from .arguments import parse_arguments
67
from .room_service import RoomService
78
from .routes import setup_routes
89

910
app = Flask(__name__)
11+
CORS(app)
1012
app.logger.setLevel(logging.INFO)
1113

1214

examples/room_manager/room_service.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ def get_peer_access(
4545
username: str,
4646
room_type: RoomConfigRoomType | None,
4747
) -> PeerAccess:
48-
room = self.__find_or_create_room(
49-
room_name, room_type or RoomConfigRoomType.FULL_FEATURE
50-
)
48+
room = self.__find_or_create_room(room_name, room_type)
5149
peer_access = self.peer_name_to_access.get(username)
5250
peer_in_room = self.__is_in_room(room, peer_access)
5351

@@ -72,7 +70,7 @@ def handle_notification(self, notification: betterproto.Message):
7270
pass
7371

7472
def __find_or_create_room(
75-
self, room_name: str, room_type: RoomConfigRoomType
73+
self, room_name: str, room_type: RoomConfigRoomType | None
7674
) -> Room:
7775
if room_name in self.room_name_to_room_id:
7876
self.logger.info("Room %s, already exists in the Fishjam", room_name)
@@ -84,8 +82,9 @@ def __find_or_create_room(
8482
max_peers=self.config.max_peers,
8583
webhook_url=self.config.webhook_url,
8684
peerless_purge_timeout=self.config.peerless_purge_timeout,
87-
room_type=room_type.value,
85+
room_type=room_type.value if room_type else "full_feature",
8886
)
87+
8988
new_room = self.fishjam_client.create_room(options=options)
9089

9190
self.room_name_to_room_id[room_name] = new_room.id

fishjam/_openapi_client/api/default/__init__.py

Whitespace-only changes.
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
from http import HTTPStatus
2+
from typing import Any, Dict, Optional, Union, cast
3+
4+
import httpx
5+
6+
from ... import errors
7+
from ...client import AuthenticatedClient, Client
8+
from ...models.error import Error
9+
from ...types import Response
10+
11+
12+
def _get_kwargs() -> Dict[str, Any]:
13+
return {
14+
"method": "post",
15+
"url": "/admin/shutdown/drain",
16+
}
17+
18+
19+
def _parse_response(
20+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
21+
) -> Optional[Union[Any, Error]]:
22+
if response.status_code == HTTPStatus.OK:
23+
response_200 = cast(Any, None)
24+
return response_200
25+
if response.status_code == HTTPStatus.UNAUTHORIZED:
26+
response_401 = Error.from_dict(response.json())
27+
28+
return response_401
29+
if client.raise_on_unexpected_status:
30+
raise errors.UnexpectedStatus(response.status_code, response.content)
31+
else:
32+
return None
33+
34+
35+
def _build_response(
36+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
37+
) -> Response[Union[Any, Error]]:
38+
return Response(
39+
status_code=HTTPStatus(response.status_code),
40+
content=response.content,
41+
headers=response.headers,
42+
parsed=_parse_response(client=client, response=response),
43+
)
44+
45+
46+
def sync_detailed(
47+
*,
48+
client: AuthenticatedClient,
49+
) -> Response[Union[Any, Error]]:
50+
"""Marks node as draining, making it the last in the load balancing order.
51+
52+
Raises:
53+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
54+
httpx.TimeoutException: If the request takes longer than Client.timeout.
55+
56+
Returns:
57+
Response[Union[Any, Error]]
58+
"""
59+
60+
kwargs = _get_kwargs()
61+
62+
response = client.get_httpx_client().request(
63+
**kwargs,
64+
)
65+
66+
return _build_response(client=client, response=response)
67+
68+
69+
def sync(
70+
*,
71+
client: AuthenticatedClient,
72+
) -> Optional[Union[Any, Error]]:
73+
"""Marks node as draining, making it the last in the load balancing order.
74+
75+
Raises:
76+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
77+
httpx.TimeoutException: If the request takes longer than Client.timeout.
78+
79+
Returns:
80+
Union[Any, Error]
81+
"""
82+
83+
return sync_detailed(
84+
client=client,
85+
).parsed
86+
87+
88+
async def asyncio_detailed(
89+
*,
90+
client: AuthenticatedClient,
91+
) -> Response[Union[Any, Error]]:
92+
"""Marks node as draining, making it the last in the load balancing order.
93+
94+
Raises:
95+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
96+
httpx.TimeoutException: If the request takes longer than Client.timeout.
97+
98+
Returns:
99+
Response[Union[Any, Error]]
100+
"""
101+
102+
kwargs = _get_kwargs()
103+
104+
response = await client.get_async_httpx_client().request(**kwargs)
105+
106+
return _build_response(client=client, response=response)
107+
108+
109+
async def asyncio(
110+
*,
111+
client: AuthenticatedClient,
112+
) -> Optional[Union[Any, Error]]:
113+
"""Marks node as draining, making it the last in the load balancing order.
114+
115+
Raises:
116+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
117+
httpx.TimeoutException: If the request takes longer than Client.timeout.
118+
119+
Returns:
120+
Union[Any, Error]
121+
"""
122+
123+
return (
124+
await asyncio_detailed(
125+
client=client,
126+
)
127+
).parsed
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
from http import HTTPStatus
2+
from typing import Any, Dict, Optional, Union
3+
4+
import httpx
5+
6+
from ... import errors
7+
from ...client import AuthenticatedClient, Client
8+
from ...models.error import Error
9+
from ...models.shutdown_status_response import ShutdownStatusResponse
10+
from ...types import Response
11+
12+
13+
def _get_kwargs() -> Dict[str, Any]:
14+
return {
15+
"method": "get",
16+
"url": "/admin/shutdown/status",
17+
}
18+
19+
20+
def _parse_response(
21+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
22+
) -> Optional[Union[Error, ShutdownStatusResponse]]:
23+
if response.status_code == HTTPStatus.OK:
24+
response_200 = ShutdownStatusResponse.from_dict(response.json())
25+
26+
return response_200
27+
if response.status_code == HTTPStatus.UNAUTHORIZED:
28+
response_401 = Error.from_dict(response.json())
29+
30+
return response_401
31+
if client.raise_on_unexpected_status:
32+
raise errors.UnexpectedStatus(response.status_code, response.content)
33+
else:
34+
return None
35+
36+
37+
def _build_response(
38+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
39+
) -> Response[Union[Error, ShutdownStatusResponse]]:
40+
return Response(
41+
status_code=HTTPStatus(response.status_code),
42+
content=response.content,
43+
headers=response.headers,
44+
parsed=_parse_response(client=client, response=response),
45+
)
46+
47+
48+
def sync_detailed(
49+
*,
50+
client: AuthenticatedClient,
51+
) -> Response[Union[Error, ShutdownStatusResponse]]:
52+
"""Returns status information for the shutdown process of Fishjam.
53+
54+
Raises:
55+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
56+
httpx.TimeoutException: If the request takes longer than Client.timeout.
57+
58+
Returns:
59+
Response[Union[Error, ShutdownStatusResponse]]
60+
"""
61+
62+
kwargs = _get_kwargs()
63+
64+
response = client.get_httpx_client().request(
65+
**kwargs,
66+
)
67+
68+
return _build_response(client=client, response=response)
69+
70+
71+
def sync(
72+
*,
73+
client: AuthenticatedClient,
74+
) -> Optional[Union[Error, ShutdownStatusResponse]]:
75+
"""Returns status information for the shutdown process of Fishjam.
76+
77+
Raises:
78+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
79+
httpx.TimeoutException: If the request takes longer than Client.timeout.
80+
81+
Returns:
82+
Union[Error, ShutdownStatusResponse]
83+
"""
84+
85+
return sync_detailed(
86+
client=client,
87+
).parsed
88+
89+
90+
async def asyncio_detailed(
91+
*,
92+
client: AuthenticatedClient,
93+
) -> Response[Union[Error, ShutdownStatusResponse]]:
94+
"""Returns status information for the shutdown process of Fishjam.
95+
96+
Raises:
97+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
98+
httpx.TimeoutException: If the request takes longer than Client.timeout.
99+
100+
Returns:
101+
Response[Union[Error, ShutdownStatusResponse]]
102+
"""
103+
104+
kwargs = _get_kwargs()
105+
106+
response = await client.get_async_httpx_client().request(**kwargs)
107+
108+
return _build_response(client=client, response=response)
109+
110+
111+
async def asyncio(
112+
*,
113+
client: AuthenticatedClient,
114+
) -> Optional[Union[Error, ShutdownStatusResponse]]:
115+
"""Returns status information for the shutdown process of Fishjam.
116+
117+
Raises:
118+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
119+
httpx.TimeoutException: If the request takes longer than Client.timeout.
120+
121+
Returns:
122+
Union[Error, ShutdownStatusResponse]
123+
"""
124+
125+
return (
126+
await asyncio_detailed(
127+
client=client,
128+
)
129+
).parsed

fishjam/_openapi_client/api/health/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)