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 <Joao.VictorPortal@windriver.com>
Change-Id: I0c5540066142201044b875f9dd3cc50cc5435fcc
This commit is contained in:
Joao Victor Portal 2023-07-27 21:21:24 -03:00
parent f5dc413053
commit 6aa7eb2ee1

View File

@ -1,7 +1,7 @@
#!/usr/bin/python3 #!/usr/bin/python3
# #
# Copyright (c) 2020 Wind River Systems, Inc. # Copyright (c) 2020-2023 Wind River Systems, Inc.
# #
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
# #
@ -20,14 +20,15 @@ def main():
parser = ArgumentParser(description="OIDC authentication") 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", parser.add_argument("-c", "--client", dest="client",
help="OIDC client IP address", help="OIDC client IP address (default: controller "
required=True) "floating OAM IP)", default="oamcontroller")
parser.add_argument("-u", "--username", dest="username", parser.add_argument("-u", "--username", dest="username",
help="Username", help="Username (default: current logged in username)")
required=True)
parser.add_argument("-p", "--password", dest="password", parser.add_argument("-p", "--password", dest="password",
help="Password") help="Password. Prompted if not present.")
parser.add_argument("-b", "--backend", dest="backend", parser.add_argument("-b", "--backend", dest="backend",
help="Dex configured backend name") help="Dex configured backend name")
@ -39,11 +40,21 @@ def main():
password = args.password password = args.password
client = args.client 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: if not password:
try: try:
password = getpass.getpass() password = getpass.getpass()
except Exception as error: except Exception as error:
print('ERROR', error) print('ERROR', error)
sys.exit(1)
dexClientUrl = "https://" + client + ":30555" dexClientUrl = "https://" + client + ":30555"
if verbose: if verbose: