diff --git a/b3lb/requirements.txt b/b3lb/requirements.txt index dfa06f5..886af3d 100644 --- a/b3lb/requirements.txt +++ b/b3lb/requirements.txt @@ -15,6 +15,7 @@ django-environ==0.11.2 django-redis==5.4.0 django-storages==1.14.2 intervaltree==3.1.0 +pyjwt==2.8.0 psycopg2cffi==2.9.0 requests==2.31.0 uvicorn[standard]==0.23.2 diff --git a/b3lb/rest/models.py b/b3lb/rest/models.py index 7727763..47ed0fb 100644 --- a/b3lb/rest/models.py +++ b/b3lb/rest/models.py @@ -400,6 +400,12 @@ class Meta(object): def __str__(self): return "{}-{}".format(self.tenant.slug, str(self.sub_id).zfill(3)) + @property + def get_valid_secret(self) -> str: + if self.secret2: + return str(self.secret2) + return str(self.secret) + @property def endpoint(self) -> str: if self.sub_id == 0: diff --git a/b3lb/rest/task/recording.py b/b3lb/rest/task/recording.py index d508ea7..cab7719 100644 --- a/b3lb/rest/task/recording.py +++ b/b3lb/rest/task/recording.py @@ -18,7 +18,8 @@ from django.utils import timezone as tz from django.conf import settings from os import makedirs, path -from requests import get +from jwt import encode as jwt_encode +from requests import post if settings.B3LB_RENDERING: from rest.b3lb.make_xges import render_xges from rest.models import Record, RecordSet, RecordProfile, SecretRecordProfileRelation @@ -26,7 +27,7 @@ from tempfile import TemporaryDirectory -def render_by_profile(record_set: RecordSet, record_profile: RecordProfile, tempdir: str): +def render_by_profile(record_set: RecordSet, record_profile: RecordProfile, tempdir: str) -> str: """ Render RecordSet with given RecordProfile in tempdir with @@ -59,6 +60,7 @@ def render_by_profile(record_set: RecordSet, record_profile: RecordProfile, temp record.published = True record.save() print(f"Finished rendering {record_set.__str__()} with profile {record_profile.name}") + return str(record.uuid) def render_record(record_set: RecordSet): @@ -79,20 +81,21 @@ def render_record(record_set: RecordSet): profile_relations = SecretRecordProfileRelation.objects.filter(secret=record_set.secret) if profile_relations.count() > 0: for profile_relation in profile_relations: - render_by_profile(record_set, profile_relation.record_profile, tempdir) + record_id = render_by_profile(record_set, profile_relation.record_profile, tempdir) else: for record_profile in RecordProfile.objects.filter(is_default=True): - render_by_profile(record_set, record_profile, tempdir) + record_id = render_by_profile(record_set, record_profile, tempdir) + + # Greenlight v3 sends a record ready URL, Greenlight v2 doesn't send one + if record_set.recording_ready_origin_url: + body = {"signed_parameters": jwt_encode({"meeting_id": record_set.meta_meeting_id, "record_id": record_id}, record_set.secret.get_valid_secret)} + response = post(record_set.recording_ready_origin_url, json=body) + print(f"Send record ready callback to: {record_set.recording_ready_origin_url} with return code: {response.status_code}") + if response.status_code < 200 or 299 < response.status_code: + return False record_set.status = RecordSet.RENDERED record_set.save() - print("Send record ready to Greenlight, if url exists") - if record_set.recording_ready_origin_url: - try: - print(f"send GET to: {record_set.recording_ready_origin_url}") - print(f"Status code: {get(record_set.recording_ready_origin_url).status_code}") - except: - pass return True