From a4047e414f22e8dfcfa57644d95b0b2e341cebed Mon Sep 17 00:00:00 2001 From: Ryan Petrello Date: Mon, 30 Sep 2019 15:37:35 -0400 Subject: [PATCH] cli: make `awx login` respect the -f flag see: https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/awx-project/ZAlhpLMBzVw/fUSqujoWBQAJ --- awxkit/awxkit/cli/docs/source/authentication.rst | 4 ++-- awxkit/awxkit/cli/resource.py | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/awxkit/awxkit/cli/docs/source/authentication.rst b/awxkit/awxkit/cli/docs/source/authentication.rst index ec9698fd26..8106eb326b 100644 --- a/awxkit/awxkit/cli/docs/source/authentication.rst +++ b/awxkit/awxkit/cli/docs/source/authentication.rst @@ -17,7 +17,7 @@ The preferred mechanism for authenticating with AWX and |RHAT| is by generating TOWER_PASSWORD=secret \ awx login -As a convenience, the ``awx login`` command prints a shell-formatted token +As a convenience, the ``awx login -h human`` command prints a shell-formatted token value: .. code:: bash @@ -30,7 +30,7 @@ specify your username and password each time: .. code:: bash export TOWER_HOST=https://awx.example.org - $(TOWER_USERNAME=alice TOWER_PASSWORD=secret awx login) + $(TOWER_USERNAME=alice TOWER_PASSWORD=secret awx login -h) awx config Working with OAuth2.0 Applications diff --git a/awxkit/awxkit/cli/resource.py b/awxkit/awxkit/cli/resource.py index 9b4d031b7b..1fea0133a8 100644 --- a/awxkit/awxkit/cli/resource.py +++ b/awxkit/awxkit/cli/resource.py @@ -3,8 +3,9 @@ import os from six import PY3, with_metaclass from awxkit import api, config +from awxkit.utils import to_str from awxkit.api.pages import Page -from awxkit.cli.format import format_response, add_authentication_arguments +from awxkit.cli.format import FORMATTERS, format_response, add_authentication_arguments from awxkit.cli.utils import CustomRegistryMeta, cprint @@ -98,7 +99,11 @@ class Login(CustomCommand): 'red' ) else: - print('export TOWER_TOKEN={}'.format(token)) + fmt = client.get_config('format') + if fmt == 'human': + print('export TOWER_TOKEN={}'.format(token)) + else: + print(to_str(FORMATTERS[fmt]({'token': token}, '.')).strip()) class Config(CustomCommand):