diff --git a/manifester/commands.py b/manifester/commands.py index 9e1a0c2..28d87b9 100644 --- a/manifester/commands.py +++ b/manifester/commands.py @@ -73,11 +73,12 @@ def delete(allocations, all_, remove_manifest_file): @cli.command() @click.option("--details", is_flag=True, help="Display full inventory details") @click.option("--sync", is_flag=True, help="Fetch inventory data from RHSM before displaying") -def inventory(details, sync): +@click.option("--offline-token", type=str, default=None) +def inventory(details, sync, offline_token): """Display the local inventory file's contents.""" border = "-" * 38 if sync: - helpers.update_inventory(Manifester(minimal_init=True).subscription_allocations) + helpers.update_inventory(Manifester(minimal_init=True, offline_token=offline_token).subscription_allocations) inv = helpers.load_inventory_file(Path(settings.inventory_path)) if not details: logger.info("Displaying local inventory data") diff --git a/manifester/manifester.py b/manifester/manifester.py index c32594d..010e879 100644 --- a/manifester/manifester.py +++ b/manifester/manifester.py @@ -9,7 +9,7 @@ import string from dynaconf.utils.boxing import DynaBox -from requests.exceptions import Timeout +from requests.exceptions import RequestException, Timeout from manifester.helpers import ( fetch_paginated_data, @@ -33,7 +33,12 @@ def __init__( **kwargs, ): if minimal_init: - self.offline_token = settings.get("offline_token") + if kwargs.get("offline_token") is not None: + self.offline_token = kwargs.get("offline_token") + elif settings.get("offline_token") is not None: + self.offline_token = settings.get("offline_token") + else: + raise KeyError("Offline token not defined.") self.token_request_url = settings.get("url").get("token_request") self.allocations_url = settings.get("url").get("allocations") self._access_token = None @@ -110,6 +115,8 @@ def access_token(self): cmd_args=[f"{self.token_request_url}"], cmd_kwargs=token_request_data, ).json() + if "error" in token_data: + raise RequestException(f"{token_data['error']}: {token_data['error_description']}") if self.is_mock: self._access_token = token_data.access_token else: