Skip to content
This repository was archived by the owner on Apr 15, 2024. It is now read-only.

Commit 9d6a147

Browse files
Heuriskeinvagrant
authored andcommitted
Added keys_only and separator options to kv.get
1 parent 890f950 commit 9d6a147

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,7 @@ pip-log.txt
4343

4444
# Ropemacs
4545
.ropeproject
46+
47+
# IntelliJ project files
48+
*.iml
49+
.idea/

consul/base.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ def get(
121121
wait=None,
122122
token=None,
123123
consistency=None,
124+
keys=False,
125+
separator=None,
124126
dc=None):
125127
"""
126128
Returns a tuple of (*index*, *value[s]*)
@@ -169,6 +171,10 @@ def get(
169171
dc = dc or self.agent.dc
170172
if dc:
171173
params['dc'] = dc
174+
if keys:
175+
params['keys'] = True
176+
if separator:
177+
params['separator'] = separator
172178
consistency = consistency or self.agent.consistency
173179
if consistency in ('consistent', 'stale'):
174180
params[consistency] = '1'
@@ -180,11 +186,12 @@ def callback(response):
180186
data = None
181187
else:
182188
data = json.loads(response.body)
183-
for item in data:
184-
if item.get('Value') is not None:
185-
item['Value'] = base64.b64decode(item['Value'])
186-
if not recurse:
187-
data = data[0]
189+
if not keys_only:
190+
for item in data:
191+
if item.get('Value') is not None:
192+
item['Value'] = base64.b64decode(item['Value'])
193+
if not recurse:
194+
data = data[0]
188195
return response.headers['X-Consul-Index'], data
189196

190197
return self.agent.http.get(

0 commit comments

Comments
 (0)