Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add offline token argument to inventory command #45

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions manifester/commands.py
Original file line number Diff line number Diff line change
@@ -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")
11 changes: 9 additions & 2 deletions manifester/manifester.py
Original file line number Diff line number Diff line change
@@ -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: