Add wrap option to keystone token-get for humans
When using Keystone PKI, a token ID can be over 3200 chars long. Add optional --wrap option to make 'keystone token-get' human readable fix bug 1053728 Change-Id: Ic3dffa773f9b8fc227a8fe7592a3d87e8e22e510
This commit is contained in:
parent
0a8c96073c
commit
33a0f73113
@ -39,12 +39,25 @@ def print_list(objs, fields, formatters={}):
|
||||
print pt.get_string(sortby=fields[0])
|
||||
|
||||
|
||||
def print_dict(d):
|
||||
def _word_wrap(string, max_length=0):
|
||||
"""wrap long strings to be no longer then max_length"""
|
||||
if max_length <= 0:
|
||||
return string
|
||||
return '\n'.join([string[i:i + max_length] for i in
|
||||
range(0, len(string), max_length)])
|
||||
|
||||
|
||||
def print_dict(d, wrap=0):
|
||||
"""pretty table prints dictionaries.
|
||||
|
||||
Wrap values to max_length wrap if wrap>0
|
||||
"""
|
||||
pt = prettytable.PrettyTable(['Property', 'Value'], caching=False)
|
||||
pt.aligns = ['l', 'l']
|
||||
for (prop, value) in d.iteritems():
|
||||
if value is None:
|
||||
value = ''
|
||||
value = _word_wrap(value, max_length=wrap)
|
||||
pt.add_row([prop, value])
|
||||
print pt.get_string(sortby='Property')
|
||||
|
||||
|
@ -406,6 +406,9 @@ def do_endpoint_delete(kc, args):
|
||||
print 'Unable to delete endpoint.'
|
||||
|
||||
|
||||
@utils.arg('--wrap', metavar='<integer>', default=79,
|
||||
help='wrap PKI tokens to a specified length, or 0 to disable')
|
||||
def do_token_get(kc, args):
|
||||
"""Display the current user token"""
|
||||
utils.print_dict(kc.service_catalog.get_token())
|
||||
utils.print_dict(kc.service_catalog.get_token(),
|
||||
wrap=int(args.wrap))
|
||||
|
Loading…
x
Reference in New Issue
Block a user