Support multiple dex back ends with CLI tool

This commit modifies the CLI tool to support multiple dex backends.
Users with multiple backends configured can select one with "-b".
If only one backend is configured, it will be used if no "-b" is
specified. If multiple backends are configured and "-b" is not
used, the command will fail, and present a list of backends for
the user to pick from.

Story: 2006711
Task: 39696

Change-Id: I532a18a6ec12181a1f3e201374e5e719575cf2fa
Signed-off-by: Jerry Sun <jerry.sun@windriver.com>
This commit is contained in:
Jerry Sun 2020-05-07 16:16:40 -04:00
parent 69c3fe858c
commit cfb8352a9e
1 changed files with 27 additions and 0 deletions

View File

@ -23,6 +23,8 @@ def main():
required=True)
parser.add_argument("-p", "--password", dest="password",
help="Password")
parser.add_argument("-b", "--backend", dest="backend",
help="Dex configured backend name")
parser.add_argument("-v", "--verbose", action='count')
args = parser.parse_args()
@ -52,6 +54,31 @@ def main():
# Open browser on dexClientUrl
dexLoginPage = br.open(dexClientUrl)
# If there are links on this page, then more than one
# backends are configured. Pick the correct backend
if len(br.links()) > 0:
if not args.backend:
print("Multiple backends detected, please select one with -b")
sys.exit(1)
found_backend = False
all_backends = []
for link in br.links():
if not link.text.startswith("Log in with "):
print("Error reading backend: %s" % link.text)
all_backends.append(link.text[len("Log in with "):])
if verbose:
print("backend: %s" % all_backends[-1])
if all_backends[-1] == args.backend:
br.follow_link(link)
found_backend = True
if not found_backend:
print("Backend not found, please choose one of: %s" % all_backends)
sys.exit(1)
# NOW ON DEX LOGIN PAGE
if verbose:
print("\ndexLoginPage:")