Add option to pass password as file
This commit is contained in:
@@ -2,12 +2,14 @@ from . import Mu5001Tool
|
||||
from .prometheus_exporter import prometheus_exporter
|
||||
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
from pprint import pprint
|
||||
|
||||
parser = argparse.ArgumentParser(prog="mu5001tool")
|
||||
|
||||
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-file", dest="password_file", type=Path, help="Password for authentication against the device, passed as path to file")
|
||||
|
||||
subparsers = parser.add_subparsers()
|
||||
|
||||
@@ -47,6 +49,7 @@ def main():
|
||||
function_arguments.pop("func")
|
||||
function_arguments.pop("stok")
|
||||
function_arguments.pop("password")
|
||||
function_arguments.pop("password_file")
|
||||
|
||||
m = Mu5001Tool()
|
||||
|
||||
@@ -55,6 +58,12 @@ def main():
|
||||
|
||||
if args.password is not None:
|
||||
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()
|
||||
|
||||
args.func(m=m, **function_arguments)
|
||||
|
Reference in New Issue
Block a user