Skip to content

Commit eac5a3b

Browse files
committed
wip
1 parent 40d39fe commit eac5a3b

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

common.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from functools import lru_cache
2+
import os
3+
from time import time
4+
5+
import jwt
6+
import requests
7+
8+
ZOOM_API = "https://api.zoom.us/v2/"
9+
SPEAKERS_CORNER_USER_ID = "D0n5UNEHQiajWtgdWLlNSA"
10+
11+
@lru_cache()
12+
def zoom_headers(duration: int=10) -> dict:
13+
zoom_api_key = os.getenv("ZOOM_API_KEY")
14+
zoom_api_secret = os.getenv("ZOOM_API_SECRET")
15+
token = jwt.encode(
16+
# Create a payload of the token containing API Key & expiration time
17+
{"iss": zoom_api_key, "exp": time() + duration},
18+
zoom_api_secret,
19+
algorithm='HS256'
20+
).decode('utf-8')
21+
22+
return {'authorization': f'Bearer {token}', 'content-type': 'application/json'}
23+
24+
25+
def speakers_corner_user_id() -> str:
26+
users = requests.get(ZOOM_API + "users", headers=zoom_headers()).json()["users"]
27+
sc_user_id = next(
28+
u["id"] for u in users
29+
if u["first_name"] == "Speakers'" and u["last_name"] == "Corner"
30+
)
31+
return sc_user_id

host_key_rotation.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env python
2+
3+
import os
4+
import hashlib
5+
import datetime
6+
7+
import requests
8+
import pytz
9+
10+
import common
11+
12+
def host_key(salt: str, timeslot: datetime.datetime) -> int:
13+
key_salt = os.getenv("HOST_KEY_SALT").encode()
14+
timestamp = timeslot.replace(second=0, microsecond=0, minute=0).timestamp()
15+
hashed = hashlib.sha512(int(timestamp.to_bytes(5, "big")) + key_salt)
16+
return int(hashed.hexdigest(), 16) % int(1e7)
17+
18+
19+
def update_host_key():
20+
headers = common.zoom_headers()

0 commit comments

Comments
 (0)