Add filtering CLI options to 'secrets list' sub command.

Change-Id: I14265ad277a02f93af98312e139dc19e23382edd
Implements: blueprint secret-list-add-criteria
This commit is contained in:
Wyllys Ingersoll
2013-12-11 13:07:06 -05:00
parent 7d02541047
commit 5f555c7ced
2 changed files with 29 additions and 2 deletions

View File

@@ -209,6 +209,18 @@ class Keep:
list_parser.add_argument('--offset', '-o', default=0, help='specify t'
'he page offset (default: %(default)s)',
type=int)
list_parser.add_argument('--name', '-n', default=None, help='specify t'
'he secret name (default: %(default)s)')
list_parser.add_argument('--algorithm', '-a', default=None,
help='the algorithm filter for the list'
'(default: %(default)s).')
list_parser.add_argument('--bit-length', '-b', default=0,
help='the bit length filter for the list'
' (default: %(default)s).',
type=int)
list_parser.add_argument('--mode', '-m', default=None,
help='the algorithmm mode filter for the'
' list (default: %(default)s).')
list_parser.set_defaults(func=self.list)
def store(self, args):
@@ -269,7 +281,12 @@ class Keep:
def list(self, args):
if args.command == 'secret':
ls = self.client.secrets.list(args.limit, args.offset)
ls = self.client.secrets.list(limit=args.limit,
offset=args.offset,
name=args.name,
mode=args.mode,
algorithm=args.algorithm,
bits=args.bit_length)
elif args.command == 'verification':
ls = self.client.verifications.list(args.limit, args.offset)
elif args.command == 'order':

View File

@@ -175,7 +175,8 @@ class SecretManager(base.BaseEntityManager):
raise ValueError('secret_ref is required.')
self.api.delete(secret_ref)
def list(self, limit=10, offset=0):
def list(self, limit=10, offset=0, name=None, algorithm=None,
mode=None, bits=0):
"""
List all secrets for the tenant
@@ -187,6 +188,15 @@ class SecretManager(base.BaseEntityManager):
limit))
href = '{0}/{1}'.format(self.api.base_url, self.entity)
params = {'limit': limit, 'offset': offset}
if name:
params['name'] = name
if algorithm:
params['alg'] = algorithm
if mode:
params['mode'] = mode
if bits > 0:
params['bits'] = bits
resp = self.api.get(href, params)
return [Secret(s) for s in resp['secrets']]