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: Ibe00b6c67d71f6bb9ce2e64c6058466cafc4b5f3
Signed-off-by: Reynaldo P Gomes <reynaldo.patronegomes@windriver.com>
This commit is contained in:
@@ -269,8 +269,9 @@ class FmShell(object):
|
||||
fm_url = None
|
||||
|
||||
if not (args.refresh_cache or args.no_cache):
|
||||
os_auth_token, fm_url = \
|
||||
utils.load_auth_session_keyring_by_name(self.CACHE_KEY)
|
||||
os_auth_token, fm_url = utils.load_auth_session_keyring_by_name(
|
||||
self._cache_key(args.os_username))
|
||||
|
||||
if os_auth_token and fm_url:
|
||||
self.keyring = True
|
||||
|
||||
@@ -331,7 +332,7 @@ class FmShell(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)
|
||||
@@ -344,7 +345,7 @@ class FmShell(object):
|
||||
args.os_auth_token = None
|
||||
args.fm_url = None
|
||||
self.keyring = False
|
||||
utils.revoke_keyring_by_name(self.CACHE_KEY)
|
||||
utils.revoke_keyring_by_name(self._cache_key(args.os_username))
|
||||
kwargs = {}
|
||||
for key in client_args:
|
||||
client_key = key.replace("os_", "", 1)
|
||||
@@ -384,6 +385,10 @@ class FmShell(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