Allows multiple user credentials in same session
This change adds the user identification to the key name used to manage
the credentials stored in the keyring, allowing multiple user
credentials in the same terminal session.
TEST PLAN:
PASS: Build package and ISO.
PASS: Without source and passing the user credentials on the command
line, check if the user has the expected permissions.
PASS: Source and verify that the user permissions are in place.
PASS: Switch users and verify that the correct credentials are being
used.
Closes-Bug: 2120721
Change-Id: Iaf2d61bf02c7075ef22bdb3ac95aa9137f51e192
Signed-off-by: Reynaldo P Gomes <reynaldo.patronegomes@windriver.com>
This commit is contained in:
@@ -288,8 +288,9 @@ class CgtsShell(object):
|
||||
system_url = None
|
||||
|
||||
if not (args.refresh_cache or args.no_cache):
|
||||
os_auth_token, system_url = \
|
||||
utils.load_auth_session_keyring_by_name(self.CACHE_KEY)
|
||||
os_auth_token, system_url = utils.load_auth_session_keyring_by_name(
|
||||
self._cache_key(args.os_username))
|
||||
|
||||
if os_auth_token and system_url:
|
||||
self.keyring = True
|
||||
|
||||
@@ -342,7 +343,7 @@ class CgtsShell(object):
|
||||
timeout = str(int((expires_at - now).total_seconds()))
|
||||
|
||||
utils.persist_auth_session_keyring(
|
||||
self.CACHE_KEY,
|
||||
self._cache_key(args.os_username),
|
||||
client.http_client.session.get_token(),
|
||||
client.http_client.endpoint_override,
|
||||
timeout)
|
||||
@@ -355,7 +356,7 @@ class CgtsShell(object):
|
||||
args.os_auth_token = None
|
||||
args.system_url = None
|
||||
self.keyring = False
|
||||
utils.revoke_keyring_by_name(self.CACHE_KEY)
|
||||
utils.revoke_keyring_by_name(self._cache_key(args.os_username))
|
||||
client = cgclient.get_client(api_version, **(args.__dict__))
|
||||
try:
|
||||
args.func(client, args)
|
||||
@@ -390,6 +391,10 @@ class CgtsShell(object):
|
||||
else:
|
||||
self.parser.print_help()
|
||||
|
||||
def _cache_key(self, username: str) -> str:
|
||||
"""Define the name of the key used to store user credentials in the cache."""
|
||||
return self.CACHE_KEY if not username else self.CACHE_KEY + ':' + username
|
||||
|
||||
|
||||
class HelpFormatter(argparse.HelpFormatter):
|
||||
def start_section(self, heading):
|
||||
|
||||
Reference in New Issue
Block a user