Add option to pass password as file

This commit is contained in:
2025-09-08 22:42:23 +02:00
parent 99b0ca4fcc
commit 9d57dab5c9

View File

@@ -2,12 +2,14 @@ from . import Mu5001Tool
from .prometheus_exporter import prometheus_exporter from .prometheus_exporter import prometheus_exporter
import argparse import argparse
from pathlib import Path
from pprint import pprint from pprint import pprint
parser = argparse.ArgumentParser(prog="mu5001tool") parser = argparse.ArgumentParser(prog="mu5001tool")
parser.add_argument("--stok", dest="stok", help="Initial session token to use for commands") parser.add_argument("--stok", dest="stok", help="Initial session token to use for commands")
parser.add_argument("--password", dest="password", help="Password for authentication against the device") parser.add_argument("--password", dest="password", help="Password for authentication against the device")
parser.add_argument("--password-file", dest="password_file", type=Path, help="Password for authentication against the device, passed as path to file")
subparsers = parser.add_subparsers() subparsers = parser.add_subparsers()
@@ -47,6 +49,7 @@ def main():
function_arguments.pop("func") function_arguments.pop("func")
function_arguments.pop("stok") function_arguments.pop("stok")
function_arguments.pop("password") function_arguments.pop("password")
function_arguments.pop("password_file")
m = Mu5001Tool() m = Mu5001Tool()
@@ -55,6 +58,12 @@ def main():
if args.password is not None: if args.password is not None:
m.set_password(args.password) m.set_password(args.password)
if args.password_file is not None:
password = args.password_file.read_text()
m.set_password(password)
if args.password is not None or args.password_file is not None:
m.login() m.login()
args.func(m=m, **function_arguments) args.func(m=m, **function_arguments)