Skip to content

Commit

Permalink
Merge pull request #45 from synkd/accept_offline_token_arg_for_invent…
Browse files Browse the repository at this point in the history
…ory_command

Add offline token argument to inventory command
  • Loading branch information
synkd authored Aug 1, 2024
2 parents 4401c8a + 94a9f71 commit 8cb287c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
5 changes: 3 additions & 2 deletions manifester/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
11 changes: 9 additions & 2 deletions manifester/manifester.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 8cb287c

Please sign in to comment.