Skip to content

Commit

Permalink
use env at runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
theomonnom committed Dec 4, 2023
1 parent a13ab4c commit 50c86f0
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
Binary file added examples/face_landmark/face_landmarker.task
Binary file not shown.
28 changes: 22 additions & 6 deletions livekit-api/livekit/api/access_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,21 @@ class Claims:
class AccessToken:
def __init__(
self,
api_key: str = os.getenv("LIVEKIT_API_KEY", ""),
api_secret: str = os.getenv("LIVEKIT_API_SECRET", ""),
api_key: Optional[str] = None,

Check failure on line 77 in livekit-api/livekit/api/access_token.py

View workflow job for this annotation

GitHub Actions / build

Ruff (F821)

livekit-api/livekit/api/access_token.py:77:18: F821 Undefined name `Optional`
api_secret: Optional[str] = None,

Check failure on line 78 in livekit-api/livekit/api/access_token.py

View workflow job for this annotation

GitHub Actions / build

Ruff (F821)

livekit-api/livekit/api/access_token.py:78:21: F821 Undefined name `Optional`
) -> None:
if not api_key:
api_key = os.getenv("LIVEKIT_API_KEY", "")

if not api_secret:
api_secret = os.getenv("LIVEKIT_API_SECRET", "")

if not api_key or not api_secret:
raise ValueError("api_key and api_secret must be set")

self.api_key = api_key # iss
self.api_secret = api_secret
self.claims = Claims()
if not api_key or not api_secret:
raise ValueError("api_key and api_secret must be set")

# default jwt claims
self.identity = "" # sub
Expand Down Expand Up @@ -137,11 +144,20 @@ def to_jwt(self) -> str:
class TokenVerifier:
def __init__(
self,
api_key: str = os.getenv("LIVEKIT_API_KEY", ""),
api_secret: str = os.getenv("LIVEKIT_API_SECRET", ""),
api_key: Optional[str] = None,

Check failure on line 147 in livekit-api/livekit/api/access_token.py

View workflow job for this annotation

GitHub Actions / build

Ruff (F821)

livekit-api/livekit/api/access_token.py:147:18: F821 Undefined name `Optional`
api_secret: Optional[str] = None,

Check failure on line 148 in livekit-api/livekit/api/access_token.py

View workflow job for this annotation

GitHub Actions / build

Ruff (F821)

livekit-api/livekit/api/access_token.py:148:21: F821 Undefined name `Optional`
*,
leeway: datetime.timedelta = DEFAULT_LEEWAY,
) -> None:
if not api_key:
api_key = os.getenv("LIVEKIT_API_KEY", "")

if not api_secret:
api_secret = os.getenv("LIVEKIT_API_SECRET", "")

if not api_key or not api_secret:
raise ValueError("api_key and api_secret must be set")

self.api_key = api_key
self.api_secret = api_secret
self._leeway = leeway
Expand Down
21 changes: 18 additions & 3 deletions livekit-api/livekit/api/livekit_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,27 @@
class LiveKitAPI:
def __init__(
self,
url: str = os.getenv("LIVEKIT_URL", "http://localhost:7880"),
api_key: str = os.getenv("LIVEKIT_API_KEY", ""),
api_secret: str = os.getenv("LIVEKIT_API_SECRET", ""),
url: Optional[str] = None,

Check failure on line 11 in livekit-api/livekit/api/livekit_api.py

View workflow job for this annotation

GitHub Actions / build

Ruff (F821)

livekit-api/livekit/api/livekit_api.py:11:14: F821 Undefined name `Optional`
api_key: Optional[str] = None,

Check failure on line 12 in livekit-api/livekit/api/livekit_api.py

View workflow job for this annotation

GitHub Actions / build

Ruff (F821)

livekit-api/livekit/api/livekit_api.py:12:18: F821 Undefined name `Optional`
api_secret: Optional[str] = None,

Check failure on line 13 in livekit-api/livekit/api/livekit_api.py

View workflow job for this annotation

GitHub Actions / build

Ruff (F821)

livekit-api/livekit/api/livekit_api.py:13:21: F821 Undefined name `Optional`
*,
timeout: float = 60, # 1 minutes by default
):
if not url:
url = os.getenv("LIVEKIT_URL", "")

if not api_key:
api_key = os.getenv("LIVEKIT_API_KEY", "")

if not api_secret:
api_secret = os.getenv("LIVEKIT_API_SECRET", "")

if not url:
raise ValueError("url must be set")

if not api_key or not api_secret:
raise ValueError("api_key and api_secret must be set")

self._session = aiohttp.ClientSession(timeout=timeout)
self._room = RoomService(url, api_key, api_secret, self._session)
self._ingress = IngressService(url, api_key, api_secret, self._session)
Expand Down

0 comments on commit 50c86f0

Please sign in to comment.