diff --git a/bin/confetty b/bin/confetty index a9565432..711d39fc 100755 --- a/bin/confetty +++ b/bin/confetty @@ -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 diff --git a/confluent/httpapi.py b/confluent/httpapi.py index 145250f0..debd4dd7 100644 --- a/confluent/httpapi.py +++ b/confluent/httpapi.py @@ -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): diff --git a/confluent/messages.py b/confluent/messages.py index 06733ceb..3d5c80cd 100644 --- a/confluent/messages.py +++ b/confluent/messages.py @@ -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 += ('{4}' - ).format(type, key, v, desc, note) + ' "title="{3}">' + ).format(type, key, v, desc) snippet += ( - '{3}' + '' '').format(type, key, desc, note) + 'value="{1}">').format(type, key, desc) return snippet snippet += (key + ":" + '{4}' - ).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: diff --git a/plugins/configuration/attributes.py b/plugins/configuration/attributes.py index abbe487d..59503a5b 100644 --- a/plugins/configuration/attributes.py +++ b/plugins/configuration/attributes.py @@ -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})