2
0
mirror of https://github.com/xcat2/confluent.git synced 2024-11-22 09:32:21 +00:00

Add cli support for 'show'

confetty interactive mode can now do 'show' (aka read, retrieve, whatever) on
more abritrary resources.
This commit is contained in:
Jarrod Johnson 2014-02-10 19:36:18 -05:00
parent 2e2451a638
commit 0d425f1f9f
4 changed files with 42 additions and 23 deletions

View File

@ -100,18 +100,32 @@ def do_command(command, server):
sys.exit(0)
if argv[0] == "cd":
otarget = target
target = fullpath_target(argv[1])
target = fullpath_target(argv[1], forcepath=True)
for res in send_request('retrieve', target, server):
if 'error' in res:
print target + ': ' + res['error']
target = otarget
if argv[0] in ('show', 'ls'):
for res in send_request('retrieve', target, server):
if type(res['item']) == dict:
print res['item']["href"]
else:
for item in res['item']:
print item["href"]
if len(argv) > 1:
targpath = fullpath_target(argv[1])
else:
targpath = target
for res in send_request('retrieve', targpath, server):
if 'item' in res: # a link relation
if type(res['item']) == dict:
print res['item']["href"]
else:
for item in res['item']:
print item["href"]
else: # generic attributes to list
for key in res.iterkeys():
if 'value' in res[key]:
print "%s=%s" % (key, res[key]['value'])
else:
if 'isset' in res[key] and res[key]['isset']:
print "%s=********" % key
else:
print "%s=" % key
if argv[0] == 'start':
targpath = fullpath_target(argv[1])
currconsole = targpath
@ -126,7 +140,7 @@ def do_command(command, server):
prompt()
def fullpath_target(path):
def fullpath_target(path, forcepath=False):
global target
pathcomponents = path.split("/")
if pathcomponents[0] == "": # absolute path
@ -141,9 +155,10 @@ def fullpath_target(path):
del targparts[-1]
else:
targparts.append(component)
targparts.append('')
if forcepath:
targparts.append('')
ntarget = '/'.join(targparts)
if len(ntarget) ==0 or ntarget[-1] != '/':
if forcepath and (len(ntarget) == 0 or ntarget[-1] != '/'):
ntarget += '/'
return ntarget

View File

@ -352,7 +352,7 @@ def _assemble_json(responses, resource, url):
else:
links[hk] = haldata[hk]
else:
rsp = rsp.rawdata()
rsp = rsp.raw()
for dk in rsp.iterkeys():
if dk in rspdata:
if isinstance(rspdata[dk], list):

View File

@ -19,7 +19,7 @@ class ConfluentMessage(object):
jsonsnippet = json.dumps(self.kvpairs, separators=(',', ':'))[1:-1]
return jsonsnippet
def rawdata(self):
def raw(self):
"""Return pythonic representation of the response.
Used by httpapi while assembling data prior to json serialization"""
@ -34,7 +34,6 @@ class ConfluentMessage(object):
for key in self.kvpairs.iterkeys():
val = self.kvpairs[key]
value = self.defaultvalue
note = ''
type = self.defaulttype
try:
desc = self.desc
@ -44,24 +43,26 @@ class ConfluentMessage(object):
value = val['value']
if value is None:
value = ''
if 'note' in val:
note = '(' + val['note'] + ')'
if value == '' and 'isset' in val and val['isset'] is True:
# an encrypted value, put some *** to show it is set
# in the explorer
value = '********'
if isinstance(val, list):
snippet += key + ":"
for v in val:
snippet += ('<input type="{0}" name="{1}" value="{2}" '
' "title="{3}">{4}'
).format(type, key, v, desc, note)
' "title="{3}">'
).format(type, key, v, desc)
snippet += (
'<input type="{0}" name="{1}" value="" title="{2}">{3}'
'<input type="{0}" name="{1}" value="" title="{2}">'
'<input type="checkbox" name="restexplorerhonorkey" '
'value="{1}">').format(type, key, desc, note)
'value="{1}">').format(type, key, desc)
return snippet
snippet += (key + ":" +
'<input type="{0}" name="{1}" value="{2}" '
'title="{3}">{4}<input type="checkbox" '
'title="{3}"><input type="checkbox" '
'name="restexplorerhonorkey" value="{1}">'
).format(type, key, value, desc, note)
).format(type, key, value, desc)
return snippet
@ -291,7 +292,10 @@ class CryptedAttributes(Attributes):
self.desc = desc
nkv = {}
for key in kv.iterkeys():
nkv[key] = {'note': 'Encrypted'}
if kv[key]['cryptvalue'] != '':
nkv[key] = {'isset': True}
else:
nkv[key] = {'isset': False}
if node is None:
self.kvpairs = nkv
else:

View File

@ -30,7 +30,7 @@ def retrieve(nodes, element, configmanager, inputdata):
{attribute: currattr['value']})
elif 'cryptvalue' in currattr:
yield msg.CryptedAttributes(node,
{attribute: currattr['cryptvalue']})
{attribute: currattr})
elif isinstance(currattr, list):
yield msg.ListAttributes(node,
{attribute: currattr})