Commit d7f83956 authored by Ryan Petrello's avatar Ryan Petrello

implement `tower-cli logout` to clear oauth_token config

parent 23214bea
......@@ -189,7 +189,7 @@ class Client(Session):
# Piece together the full URL.
use_version = not url.endswith('/o/')
use_version = not url.startswith('/o/')
url = '%s%s' % (self.get_prefix(use_version), url.lstrip('/'))
# Ansible Tower expects authenticated requests; add the authentication
......@@ -30,7 +30,7 @@ from tower_cli.conf import with_global_options, Parser, settings, _apply_runtime
from tower_cli.utils import secho, supports_oauth
from tower_cli.constants import CUR_API_VERSION
__all__ = ['version', 'config', 'login']
__all__ = ['version', 'config', 'login', 'logout']
......@@ -236,7 +236,7 @@ def login(username, password, scope, verbose):
if r.status_code == 201:
if r.ok:
result = r.json()
result.pop('summary_fields', None)
result.pop('related', None)
......@@ -246,3 +246,15 @@ def login(username, password, scope, verbose):
result['token'] = token
secho(json.dumps(result, indent=1), fg='blue', bold=True)
config.main(['oauth_token', token, '--scope=user'])
def logout():
Removes an OAuth2 personal auth token from config.
if not supports_oauth():
raise exc.TowerCLIError(
'This version of Tower does not support OAuth2.0'
config.main(['oauth_token', '--unset', '--scope=user'])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment