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_disconnect() update_source_status("live_dj", false) end
# Auth function for live stream
# @Category LiveStream
# @param user Username to check against LibreTime API
# @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")
def make_input_auth_handler(input_name)
def auth_handler(user, password)
log("user '#{user}' connected", label="#{input_name}_input")
# Check auth based on return value from auth script
ret = test_process("python3 #{auth_path} --#{type} #{user} #{password}")
# Check auth based on return value from auth script
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
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)
ret
end
auth_handler
end
@ -159,7 +149,7 @@ s = if input_show_port != 0 and input_show_mount != "" then
input.harbor(id="harbor:input_show",
input_show_mount,
port=input_show_port,
auth=make_input_auth_handler("dj"),
auth=make_input_auth_handler("show"),
max=40.,
on_connect=input_show_on_connect,
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_main_mount,
port=input_main_port,
auth=make_input_auth_handler("master"),
auth=make_input_auth_handler("main"),
max=40.,
on_connect=input_main_on_connect,
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
legacy_client = LegacyClient()
dj_type = sys.argv[1]
username = sys.argv[2]
password = sys.argv[3]
def main(input_name: Literal["main", "show"], username: str, password: str) -> int:
legacy_client = LegacyClient()
source_type = ""
if dj_type == "--master":
source_type = "master"
elif dj_type == "--dj":
source_type = "dj"
input_name_map = {"main": "master", "show": "dj"}
response: dict = legacy_client.check_live_stream_auth(
username,
password,
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"])
sys.exit(0)
else:
print(False)
sys.exit(1)
if __name__ == "__main__":
parser = ArgumentParser()
parser.add_argument("input_name", choices=["main", "show"])
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,
)
)