Skip to content

Commit 8cb287c

Browse files
authored
Merge pull request #45 from synkd/accept_offline_token_arg_for_inventory_command
Add offline token argument to inventory command
2 parents 4401c8a + 94a9f71 commit 8cb287c

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

manifester/commands.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,12 @@ def delete(allocations, all_, remove_manifest_file):
7373
@cli.command()
7474
@click.option("--details", is_flag=True, help="Display full inventory details")
7575
@click.option("--sync", is_flag=True, help="Fetch inventory data from RHSM before displaying")
76-
def inventory(details, sync):
76+
@click.option("--offline-token", type=str, default=None)
77+
def inventory(details, sync, offline_token):
7778
"""Display the local inventory file's contents."""
7879
border = "-" * 38
7980
if sync:
80-
helpers.update_inventory(Manifester(minimal_init=True).subscription_allocations)
81+
helpers.update_inventory(Manifester(minimal_init=True, offline_token=offline_token).subscription_allocations)
8182
inv = helpers.load_inventory_file(Path(settings.inventory_path))
8283
if not details:
8384
logger.info("Displaying local inventory data")

manifester/manifester.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import string
1010

1111
from dynaconf.utils.boxing import DynaBox
12-
from requests.exceptions import Timeout
12+
from requests.exceptions import RequestException, Timeout
1313

1414
from manifester.helpers import (
1515
fetch_paginated_data,
@@ -33,7 +33,12 @@ def __init__(
3333
**kwargs,
3434
):
3535
if minimal_init:
36-
self.offline_token = settings.get("offline_token")
36+
if kwargs.get("offline_token") is not None:
37+
self.offline_token = kwargs.get("offline_token")
38+
elif settings.get("offline_token") is not None:
39+
self.offline_token = settings.get("offline_token")
40+
else:
41+
raise KeyError("Offline token not defined.")
3742
self.token_request_url = settings.get("url").get("token_request")
3843
self.allocations_url = settings.get("url").get("allocations")
3944
self._access_token = None
@@ -110,6 +115,8 @@ def access_token(self):
110115
cmd_args=[f"{self.token_request_url}"],
111116
cmd_kwargs=token_request_data,
112117
).json()
118+
if "error" in token_data:
119+
raise RequestException(f"{token_data['error']}: {token_data['error_description']}")
113120
if self.is_mock:
114121
self._access_token = token_data.access_token
115122
else:

0 commit comments

Comments
 (0)