From 6aa7eb2ee174e500fe6fd3908cdfdaa56a65152e Mon Sep 17 00:00:00 2001 From: Joao Victor Portal Date: Thu, 27 Jul 2023 21:21:24 -0300 Subject: [PATCH] Add default parameters to oidc-auth command This commit adds default values for parameters "--client" and "--username" of oidc-auth command. The value of parameter "--client" is usually the floating IP of the controller. The value of parameter "--username" is usually the same as the current logged in username. Test Plan: PASS: In an IPv6 AIO-SX, execute command "oidc-auth -v", type the password and successfully get the token. Verify in the output that the value printed for parameter "client" is "https://oamcontroller:30555" and for parameter "username" is the currently logged in username. PASS: Repeat the test above in an IPv4 AIO-DX. Story: 2010738 Task: 48481 Signed-off-by: Joao Victor Portal Change-Id: I0c5540066142201044b875f9dd3cc50cc5435fcc --- .../oidcauthtools/oidcauthtools/oidc_auth.py | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/oidc-auth-tools/oidcauthtools/oidcauthtools/oidc_auth.py b/oidc-auth-tools/oidcauthtools/oidcauthtools/oidc_auth.py index 0caa241..31717bc 100644 --- a/oidc-auth-tools/oidcauthtools/oidcauthtools/oidc_auth.py +++ b/oidc-auth-tools/oidcauthtools/oidcauthtools/oidc_auth.py @@ -1,7 +1,7 @@ #!/usr/bin/python3 # -# Copyright (c) 2020 Wind River Systems, Inc. +# Copyright (c) 2020-2023 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -20,14 +20,15 @@ def main(): parser = ArgumentParser(description="OIDC authentication") + # The alias "oamcontroller" is present in "/etc/hosts" and points to the + # controller OAM floating address. parser.add_argument("-c", "--client", dest="client", - help="OIDC client IP address", - required=True) + help="OIDC client IP address (default: controller " + "floating OAM IP)", default="oamcontroller") parser.add_argument("-u", "--username", dest="username", - help="Username", - required=True) + help="Username (default: current logged in username)") parser.add_argument("-p", "--password", dest="password", - help="Password") + help="Password. Prompted if not present.") parser.add_argument("-b", "--backend", dest="backend", help="Dex configured backend name") @@ -39,11 +40,21 @@ def main(): password = args.password client = args.client + if not username: + try: + username = getpass.getuser() + # Unclear which exception(s) to expect. + except Exception as error: + print('ERROR', error) + sys.exit(1) + print('Using "' + username + '" as username.') + if not password: try: password = getpass.getpass() except Exception as error: print('ERROR', error) + sys.exit(1) dexClientUrl = "https://" + client + ":30555" if verbose: