Skip to content

Commit 420b254

Browse files
Karolk99claude
andcommitted
Add ttl to create_moq_access
Regenerated MoqAccessConfig from fishjam openapi.yaml (fce-3832/moq-token-ttl). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013EKXgj4SvESh4S99791s1N
1 parent 5773fb2 commit 420b254

3 files changed

Lines changed: 41 additions & 1 deletion

File tree

‎fishjam/_fishjam_openapi_client/models/moq_access_config.py‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@ class MoqAccessConfig:
1818
publish_path (None | str | Unset): Path under the root the token grants publish access to Example: my-stream.
1919
subscribe_path (None | str | Unset): Path under the root the token grants subscribe access to Example: my-
2020
stream.
21+
ttl (int | None | Unset): Token time to live in seconds. Defaults to 3600 (1 hour), maximum is 86400 (24 hours).
22+
Example: 3600.
2123
"""
2224

2325
publish_path: None | str | Unset = UNSET
2426
subscribe_path: None | str | Unset = UNSET
27+
ttl: int | None | Unset = UNSET
2528

2629
def to_dict(self) -> dict[str, Any]:
2730
publish_path: None | str | Unset
@@ -36,13 +39,21 @@ def to_dict(self) -> dict[str, Any]:
3639
else:
3740
subscribe_path = self.subscribe_path
3841

42+
ttl: int | None | Unset
43+
if isinstance(self.ttl, Unset):
44+
ttl = UNSET
45+
else:
46+
ttl = self.ttl
47+
3948
field_dict: dict[str, Any] = {}
4049

4150
field_dict.update({})
4251
if publish_path is not UNSET:
4352
field_dict["publishPath"] = publish_path
4453
if subscribe_path is not UNSET:
4554
field_dict["subscribePath"] = subscribe_path
55+
if ttl is not UNSET:
56+
field_dict["ttl"] = ttl
4657

4758
return field_dict
4859

@@ -68,9 +79,19 @@ def _parse_subscribe_path(data: object) -> None | str | Unset:
6879

6980
subscribe_path = _parse_subscribe_path(d.pop("subscribePath", UNSET))
7081

82+
def _parse_ttl(data: object) -> int | None | Unset:
83+
if data is None:
84+
return data
85+
if isinstance(data, Unset):
86+
return data
87+
return cast(int | None | Unset, data)
88+
89+
ttl = _parse_ttl(d.pop("ttl", UNSET))
90+
7191
moq_access_config = cls(
7292
publish_path=publish_path,
7393
subscribe_path=subscribe_path,
94+
ttl=ttl,
7495
)
7596

7697
return moq_access_config

‎fishjam/api/_fishjam_client.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,20 +514,25 @@ def create_moq_access(
514514
self,
515515
publish_path: str | None = None,
516516
subscribe_path: str | None = None,
517+
ttl: int | None = None,
517518
) -> MoqAccess:
518519
"""Generates MoQ relay connection details.
519520
520521
Args:
521522
publish_path: Path the access grants publish access to.
522523
subscribe_path: Path the access grants subscribe access to.
524+
ttl: Token time to live in seconds. Defaults to 3600 (1 hour),
525+
maximum is 86400 (24 hours).
523526
524527
Returns:
525528
MoqAccess: The relay connection details, containing the
526529
``connection_url`` (with the JWT embedded as a ``?jwt=`` query
527530
parameter) and the ``token`` itself.
528531
"""
529532
config = MoqAccessConfig(
530-
publish_path=publish_path, subscribe_path=subscribe_path
533+
publish_path=publish_path,
534+
subscribe_path=subscribe_path,
535+
ttl=ttl if ttl is not None else UNSET,
531536
)
532537
response = cast(
533538
MoqAccess,

‎tests/test_room_api.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import base64
2+
import json
13
from unittest.mock import Mock, patch
24

35
import httpx
@@ -342,6 +344,18 @@ def test_valid_both(self, room_api: FishjamClient):
342344
assert isinstance(access.connection_url, str)
343345
assert isinstance(access.token, str)
344346

347+
def test_ttl_sets_token_expiry(self, room_api: FishjamClient):
348+
access = room_api.create_moq_access(publish_path="test-stream", ttl=120)
349+
350+
_header, payload, _signature = access.token.split(".")
351+
payload += "=" * (-len(payload) % 4)
352+
claims = json.loads(base64.urlsafe_b64decode(payload))
353+
assert claims["exp"] - claims["iat"] == 120
354+
355+
def test_invalid_ttl(self, room_api: FishjamClient):
356+
with pytest.raises(BadRequestError):
357+
room_api.create_moq_access(publish_path="test-stream", ttl=0)
358+
345359
def test_unauthorized(self):
346360
room_api = FishjamClient(FISHJAM_ID, "invalid")
347361

0 commit comments

Comments
 (0)