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

cli: add the ability to specify a token description w/ awx login #6124

Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion awxkit/awxkit/api/pages/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def load_authtoken(self, username='', password=''):
load_default_authtoken = load_authtoken

def get_oauth2_token(self, username='', password='', client_id=None,
description='AWX CLI',
client_secret=None, scope='write'):
default_cred = config.credentials.default
username = username or default_cred.username
Expand Down Expand Up @@ -176,7 +177,7 @@ def get_oauth2_token(self, username='', password='', client_id=None,
resp = self.connection.post(
'/api/v2/users/{}/personal_tokens/'.format(username),
json={
"description": "Tower CLI",
"description": description,
"application": None,
"scope": scope
},
Expand Down
3 changes: 3 additions & 0 deletions awxkit/awxkit/cli/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def print_help(self, parser):

def handle(self, client, parser):
auth = parser.add_argument_group('OAuth2.0 Options')
auth.add_argument('--description', help='description of the generated OAuth2.0 token', metavar='TEXT')
auth.add_argument('--conf.client_id', metavar='TEXT')
auth.add_argument('--conf.client_secret', metavar='TEXT')
auth.add_argument(
Expand All @@ -90,6 +91,8 @@ def handle(self, client, parser):
'client_secret': getattr(parsed, 'conf.client_secret', None),
'scope': getattr(parsed, 'conf.scope', None),
}
if getattr(parsed, 'description', None):
kwargs['description'] = parsed.description
try:
token = api.Api().get_oauth2_token(**kwargs)
except Exception as e:
Expand Down