From 0c5ab949d919ab24f336f32b774408af42bbdb61 Mon Sep 17 00:00:00 2001 From: Philipp Kilian Date: Thu, 16 May 2024 11:34:36 +0200 Subject: [PATCH] recording: fix record ready callback --- b3lb/requirements.txt | 1 + b3lb/rest/models.py | 7 ++++++- b3lb/rest/task/recording.py | 30 +++++++++++++++++++++--------- docker/Dockerfile | 8 ++++---- docker/Dockerfile.dev | 4 ++-- docker/Dockerfile.pypy | 7 ++++--- docker/Dockerfile.static | 4 ++-- 7 files changed, 40 insertions(+), 21 deletions(-) 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..b1c40f8 100644 --- a/b3lb/rest/models.py +++ b/b3lb/rest/models.py @@ -37,7 +37,7 @@ from rest.classes.storage import DBStorage from storages.backends.s3 import ClientError, S3Storage from textwrap import wrap -from typing import Any, Dict +from typing import Any, Dict, List import rest.b3lb.constants as cst import uuid as uid @@ -418,6 +418,11 @@ def records_effective_hold_time(self) -> int: else: return min(self.records_hold_time, self.tenant.records_hold_time) + @property + def secrets(self) -> List[str]: + # returns all secrets for secret rollover use-cases + return [self.secret, self.secret2] + class SecretAdmin(admin.ModelAdmin): model = Secret diff --git a/b3lb/rest/task/recording.py b/b3lb/rest/task/recording.py index f6fd453..c212bd8 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,18 +81,28 @@ 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) + + # implementation of recording ready callback url + # https://docs.bigbluebutton.org/development/api/#recording-ready-callback-url + if record_set.recording_ready_origin_url: + success = False + for secret in record_set.secret.secrets: + body = {"signed_parameters": jwt_encode({"meeting_id": record_set.meta_meeting_id, "record_id": record_id}, 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 200 <= response.status_code <= 299: + success = True + break + + if not success: + return False record_set.status = RecordSet.RENDERED record_set.save() - if record_set.recording_ready_origin_url: - try: - get(record_set.recording_ready_origin_url) - except: - pass return True diff --git a/docker/Dockerfile b/docker/Dockerfile index 3c91a5c..3cfbc91 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -15,12 +15,12 @@ # along with this program. If not, see . -FROM alpine:3.17 AS build +FROM alpine:3.19 AS build RUN apk --no-cache add build-base python3 python3-dev postgresql-dev libffi-dev py3-pip py3-wheel gcc gobject-introspection-dev ENV PYTHONUNBUFFERED 1 -ENV PYTHONPATH /usr/local/lib/python3.10/site-packages +ENV PYTHONPATH /usr/local/lib/python3.11/site-packages WORKDIR /usr/src/app @@ -28,13 +28,13 @@ COPY b3lb/requirements.txt ./ RUN pip3 install --no-cache-dir --prefix=/usr/local -r requirements.txt -FROM alpine:3.17 +FROM alpine:3.19 RUN apk --no-cache add python3 postgresql-libs libffi py3-pip tar ARG B3LBUID=8318 ENV PYTHONUNBUFFERED 1 -ENV PYTHONPATH /usr/local/lib/python3.10/site-packages +ENV PYTHONPATH /usr/local/lib/python3.11/site-packages WORKDIR /usr/src/app diff --git a/docker/Dockerfile.dev b/docker/Dockerfile.dev index 7f5e7b4..4ea1e85 100644 --- a/docker/Dockerfile.dev +++ b/docker/Dockerfile.dev @@ -15,12 +15,12 @@ # along with this program. If not, see . -FROM alpine:3.17 AS build +FROM alpine:3.19 AS build RUN apk --no-cache add build-base python3 python3-dev postgresql-dev libffi-dev py3-pip py3-wheel tar gcc gobject-introspection-dev ENV PYTHONUNBUFFERED 1 -ENV PYTHONPATH /usr/local/lib/python3.10/site-packages +ENV PYTHONPATH /usr/local/lib/python3.11/site-packages ENV ENV_FILE .env.dev WORKDIR /usr/src/app diff --git a/docker/Dockerfile.pypy b/docker/Dockerfile.pypy index 8ff0542..8715bd5 100644 --- a/docker/Dockerfile.pypy +++ b/docker/Dockerfile.pypy @@ -15,11 +15,12 @@ # along with this program. If not, see . -FROM pypy:3.9-slim AS build +FROM pypy:3.10-slim AS build RUN apt-get update && apt-get install -y build-essential libpq-dev libcairo2-dev gcc python3-dev libgirepository1.0-dev ENV PYTHONUNBUFFERED 1 +ENV PYTHONPATH /usr/local/lib/pypy3.10/site-packages WORKDIR /usr/src/app @@ -27,14 +28,14 @@ COPY b3lb/requirements.txt ./ RUN pip3 install --no-cache-dir --prefix=/usr/local -r requirements.txt -FROM pypy:3.9-slim +FROM pypy:3.10-slim RUN apt-get update && apt-get install -y libpq5 tar ARG B3LBUID=8318 ARG ENV_FILE=.env.dev ENV PYTHONUNBUFFERED 1 -ENV PYTHONPATH /usr/local/lib/pypy3.9/site-packages +ENV PYTHONPATH /usr/local/lib/pypy3.10/site-packages WORKDIR /usr/src/app diff --git a/docker/Dockerfile.static b/docker/Dockerfile.static index c60a94e..f398c0e 100644 --- a/docker/Dockerfile.static +++ b/docker/Dockerfile.static @@ -15,12 +15,12 @@ # along with this program. If not, see . -FROM alpine:3.17 AS build +FROM alpine:3.19 AS build RUN apk --no-cache add build-base python3 python3-dev postgresql-dev libffi-dev py3-pip py3-wheel gcc gobject-introspection-dev ENV PYTHONUNBUFFERED 1 -ENV PYTHONPATH /usr/local/lib/python3.10/site-packages +ENV PYTHONPATH /usr/local/lib/python3.11/site-packages WORKDIR /usr/src/app