Skip to content

Commit

Permalink
Support for ?keys=XXX&separator=/ to query for lists of keys without …
Browse files Browse the repository at this point in the history
…values.
  • Loading branch information
Matthew Finlayson committed Aug 6, 2014
1 parent 23723de commit 35e1cf8
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions consulate/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,18 +234,25 @@ def set_record(self, item, flags=0, value=None):
raise AttributeError('Error setting "%s" (%s)' %
(item, response.status_code))

def find(self, prefix):
def find(self, prefix, separator=None):
"""Find all keys with the specified prefix, returning a dict of
matches.
:param str prefix: The prefix to search with
:rtype: dict
:rtype: mixed
"""
response = self._get_list([prefix.lstrip('/')], {'recurse': None})
results = {}
for r in response:
results[r['Key']] = r['Value']
query_params = {'recurse': None}
if separator:
query_params['keys'] = prefix
query_params['separator'] = separator
response = self._get_list([prefix.lstrip('/')], query_params)
if separator:
results = response
else:
results = {}
for r in response:
results[r['Key']] = r['Value']
return results

def items(self):
Expand Down

0 comments on commit 35e1cf8

Please sign in to comment.