Merge "Add wrap option to nova credentials for humans"
This commit is contained in:
commit
2f2f4fcf2b
@ -1,6 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
import textwrap
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import prettytable
|
import prettytable
|
||||||
@ -168,13 +169,15 @@ def print_list(objs, fields, formatters={}, sortby_index=0):
|
|||||||
print(strutils.safe_encode(pt.get_string()))
|
print(strutils.safe_encode(pt.get_string()))
|
||||||
|
|
||||||
|
|
||||||
def print_dict(d, dict_property="Property"):
|
def print_dict(d, dict_property="Property", wrap=0):
|
||||||
pt = prettytable.PrettyTable([dict_property, 'Value'], caching=False)
|
pt = prettytable.PrettyTable([dict_property, 'Value'], caching=False)
|
||||||
pt.align = 'l'
|
pt.align = 'l'
|
||||||
for k, v in d.iteritems():
|
for k, v in d.iteritems():
|
||||||
# convert dict to str to check length
|
# convert dict to str to check length
|
||||||
if isinstance(v, dict):
|
if isinstance(v, dict):
|
||||||
v = str(v)
|
v = str(v)
|
||||||
|
if wrap > 0:
|
||||||
|
v = textwrap.fill(str(v), wrap)
|
||||||
# if value has a newline, add in multiple rows
|
# if value has a newline, add in multiple rows
|
||||||
# e.g. fault with stacktrace
|
# e.g. fault with stacktrace
|
||||||
if v and isinstance(v, basestring) and r'\n' in v:
|
if v and isinstance(v, basestring) and r'\n' in v:
|
||||||
|
@ -2608,12 +2608,15 @@ def do_endpoints(cs, _args):
|
|||||||
utils.print_dict(e['endpoints'][0], e['name'])
|
utils.print_dict(e['endpoints'][0], e['name'])
|
||||||
|
|
||||||
|
|
||||||
|
@utils.arg('--wrap', dest='wrap', metavar='<integer>', default=64,
|
||||||
|
help='wrap PKI tokens to a specified length, or 0 to disable')
|
||||||
def do_credentials(cs, _args):
|
def do_credentials(cs, _args):
|
||||||
"""Show user credentials returned from auth"""
|
"""Show user credentials returned from auth"""
|
||||||
ensure_service_catalog_present(cs)
|
ensure_service_catalog_present(cs)
|
||||||
catalog = cs.client.service_catalog.catalog
|
catalog = cs.client.service_catalog.catalog
|
||||||
utils.print_dict(catalog['access']['user'], "User Credentials")
|
utils.print_dict(catalog['access']['user'], "User Credentials",
|
||||||
utils.print_dict(catalog['access']['token'], "Token")
|
wrap=int(_args.wrap))
|
||||||
|
utils.print_dict(catalog['access']['token'], "Token", wrap=int(_args.wrap))
|
||||||
|
|
||||||
|
|
||||||
@utils.arg('server', metavar='<server>', help='Name or ID of server.')
|
@utils.arg('server', metavar='<server>', help='Name or ID of server.')
|
||||||
|
@ -102,7 +102,7 @@ class ShellTest(utils.TestCase):
|
|||||||
def test_bash_completion(self):
|
def test_bash_completion(self):
|
||||||
stdout, stderr = self.shell('bash-completion')
|
stdout, stderr = self.shell('bash-completion')
|
||||||
# just check we have some output
|
# just check we have some output
|
||||||
required = ['--matching help secgroup-delete-rule --priority']
|
required = ['--matching --wrap help secgroup-delete-rule --priority']
|
||||||
for r in required:
|
for r in required:
|
||||||
self.assertThat((stdout + stderr),
|
self.assertThat((stdout + stderr),
|
||||||
matchers.MatchesRegex(r, re.DOTALL | re.MULTILINE))
|
matchers.MatchesRegex(r, re.DOTALL | re.MULTILINE))
|
||||||
|
Loading…
Reference in New Issue
Block a user