refactor(playout): update liquidsoap input auth handler

This commit is contained in:
jo 2023-03-01 16:35:08 +01:00 committed by Kyle Robbertze
parent ac8917e3fc
commit 4a14b6b01f
2 changed files with 42 additions and 40 deletions

View File

@ -120,29 +120,19 @@ def input_main_on_disconnect() update_source_status("master_dj", false) end
def input_show_on_connect(header) update_source_status("live_dj", true) end def input_show_on_connect(header) update_source_status("live_dj", true) end
def input_show_on_disconnect() update_source_status("live_dj", false) end def input_show_on_disconnect() update_source_status("live_dj", false) end
# Auth function for live stream def make_input_auth_handler(input_name)
# @Category LiveStream def auth_handler(user, password)
# @param user Username to check against LibreTime API log("user '#{user}' connected", label="#{input_name}_input")
# @param password Password to check against LibreTime API
# @param ~type Type of password to check, "dj" or "master, default: "master"
def input_check_auth(user="", password="", ~type="master") =
log("#{type} user #{user} connected",label="#{type}_source")
# Check auth based on return value from auth script # Check auth based on return value from auth script
ret = test_process("python3 #{auth_path} --#{type} #{user} #{password}") ret = test_process("python3 '#{auth_path}' '#{input_name}' '#{user}' '#{password}'")
if ret then
log("user '#{user}' authenticated", label="#{input_name}_input")
else
log("user '#{user}' auth failed", label="#{input_name}_input",level=2)
end
if ret then ret
log("#{type} user #{user} authenticated",label="#{type}_source")
else
log("#{type} user #{user} auth failed",label="#{type}_source",level=2)
end
ret
end
def make_input_auth_handler(source_name)
def auth_handler(user, password) =
input_check_auth(user, password, type=source_name)
end end
auth_handler auth_handler
end end
@ -159,7 +149,7 @@ s = if input_show_port != 0 and input_show_mount != "" then
input.harbor(id="harbor:input_show", input.harbor(id="harbor:input_show",
input_show_mount, input_show_mount,
port=input_show_port, port=input_show_port,
auth=make_input_auth_handler("dj"), auth=make_input_auth_handler("show"),
max=40., max=40.,
on_connect=input_show_on_connect, on_connect=input_show_on_connect,
on_disconnect=input_show_on_disconnect)) on_disconnect=input_show_on_disconnect))
@ -181,7 +171,7 @@ s = if input_main_port != 0 and input_main_mount != "" then
input.harbor(id="harbor:input_main", input.harbor(id="harbor:input_main",
input_main_mount, input_main_mount,
port=input_main_port, port=input_main_port,
auth=make_input_auth_handler("master"), auth=make_input_auth_handler("main"),
max=40., max=40.,
on_connect=input_main_on_connect, on_connect=input_main_on_connect,
on_disconnect=input_main_on_disconnect)) on_disconnect=input_main_on_disconnect))

View File

@ -1,24 +1,36 @@
import sys from argparse import ArgumentParser
from typing import Literal
from libretime_api_client.v1 import ApiClient as LegacyClient from libretime_api_client.v1 import ApiClient as LegacyClient
legacy_client = LegacyClient()
dj_type = sys.argv[1] def main(input_name: Literal["main", "show"], username: str, password: str) -> int:
username = sys.argv[2] legacy_client = LegacyClient()
password = sys.argv[3]
source_type = "" input_name_map = {"main": "master", "show": "dj"}
if dj_type == "--master": response: dict = legacy_client.check_live_stream_auth(
source_type = "master" username,
elif dj_type == "--dj": password,
source_type = "dj" input_name_map[input_name],
)
response = legacy_client.check_live_stream_auth(username, password, source_type) if response.get("msg", False) is True:
return 0
return 1
if "msg" in response and response["msg"] == True:
print(response["msg"]) if __name__ == "__main__":
sys.exit(0) parser = ArgumentParser()
else:
print(False) parser.add_argument("input_name", choices=["main", "show"])
sys.exit(1) parser.add_argument("username")
parser.add_argument("password")
args = parser.parse_args()
raise SystemExit(
main(
input_name=args.input_name,
username=args.username,
password=args.password,
)
)