Skip to content

Commit

Permalink
refactor: BBB get_params_with_checksum factorization
Browse files Browse the repository at this point in the history
  • Loading branch information
azmeuk committed Jan 24, 2024
1 parent 5b6e6df commit 26bfe0e
Showing 1 changed file with 7 additions and 29 deletions.
36 changes: 7 additions & 29 deletions web/b3desk/models/bbb.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@ class BBB:
def __init__(self, meeting):
self.meeting = meeting

def get_params_with_checksum(self, action, params):
def get_params_with_checksum(self, action, params, method="GET"):
request = requests.Request(
"GET",
method,
"{}/{}".format(current_app.config["BIGBLUEBUTTON_ENDPOINT"], action),
params=params,
)
pr = request.prepare()
bigbluebutton_secret = current_app.config["BIGBLUEBUTTON_SECRET"]
secret = "{}{}".format(
# TODO: isn't this just 'action' in the end?
pr.url.replace("?", "").replace(
f'{current_app.config["BIGBLUEBUTTON_ENDPOINT"]}/', ""
),
Expand Down Expand Up @@ -62,7 +63,6 @@ def insertDocsNoDefault(self):
SERVER_FQDN = current_app.config["SERVER_FQDN"]
SECRET_KEY = current_app.config["SECRET_KEY"]
BIGBLUEBUTTON_ENDPOINT = current_app.config["BIGBLUEBUTTON_ENDPOINT"]
BIGBLUEBUTTON_SECRET = current_app.config["BIGBLUEBUTTON_SECRET"]

insertAction = "insertDocument"
xml_beg = "<?xml version='1.0' encoding='UTF-8'?> <modules> <module name='presentation'> "
Expand All @@ -80,20 +80,9 @@ def insertDocsNoDefault(self):
xml_mid += f"<document downloadable='{'true' if meeting_file.is_downloadable else 'false'}' url='{SERVER_FQDN}/ncdownload/0/{meeting_file.id}/{filehash}' filename='{meeting_file.title}' />"

xml = xml_beg + xml_mid + xml_end
params = {"meetingID": self.meeting.meetingID}
request = requests.Request(
"POST",
f"{BIGBLUEBUTTON_ENDPOINT}/{insertAction}",
params=params,
)
pr = request.prepare()
bigbluebutton_secret = BIGBLUEBUTTON_SECRET
secret = "{}{}".format(
pr.url.replace("?", "").replace(BIGBLUEBUTTON_ENDPOINT + "/", ""),
bigbluebutton_secret,
params = self.get_params_with_checksum(
insertAction, {"meetingID": self.meeting.meetingID}, "POST"
)
params["checksum"] = hashlib.sha1(secret.encode("utf-8")).hexdigest()

requests.post(
f"{BIGBLUEBUTTON_ENDPOINT}/{insertAction}",
headers={"Content-Type": "application/xml"},
Expand Down Expand Up @@ -223,7 +212,6 @@ def create(self):
# ADDING ALL FILES EXCEPT DEFAULT
SERVER_FQDN = current_app.config["SERVER_FQDN"]
BIGBLUEBUTTON_ENDPOINT = current_app.config["BIGBLUEBUTTON_ENDPOINT"]
BIGBLUEBUTTON_SECRET = current_app.config["BIGBLUEBUTTON_SECRET"]

insertAction = "insertDocument"
xml_beg = "<?xml version='1.0' encoding='UTF-8'?> <modules> <module name='presentation'> "
Expand All @@ -241,19 +229,9 @@ def create(self):
xml_mid += f"<document downloadable='{'true' if meeting_file.is_downloadable else 'false'}' url='{SERVER_FQDN}/ncdownload/0/{meeting_file.id}/{filehash}' filename='{meeting_file.title}' />"

xml = xml_beg + xml_mid + xml_end
params = {"meetingID": self.meeting.meetingID}
request = requests.Request(
"POST",
f"{BIGBLUEBUTTON_ENDPOINT}/{insertAction}",
params=params,
)
pr = request.prepare()
bigbluebutton_secret = BIGBLUEBUTTON_SECRET
secret = "{}{}".format(
pr.url.replace("?", "").replace(f"{BIGBLUEBUTTON_ENDPOINT}/", ""),
bigbluebutton_secret,
params = self.get_params_with_checksum(
insertAction, {"meetingID": self.meeting.meetingID}, "POST"
)
params["checksum"] = hashlib.sha1(secret.encode("utf-8")).hexdigest()
background_upload.delay(f"{BIGBLUEBUTTON_ENDPOINT}/{insertAction}", xml, params)

data = {c.tag: c.text for c in ElementTree.fromstring(response.content)}
Expand Down

0 comments on commit 26bfe0e

Please sign in to comment.