Add unsafe output
This commit is contained in:
parent
29f0a2f37b
commit
70731a7011
1 changed files with 72 additions and 52 deletions
|
@ -311,37 +311,51 @@ class NextcloudHandler:
|
||||||
item = self._safer_obj(item, fields=fields)
|
item = self._safer_obj(item, fields=fields)
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
def _output(self, obj):
|
def _output(self, obj, unsafe=False):
|
||||||
if self.output_format == 'json':
|
if unsafe:
|
||||||
return json.dumps(self._safer_obj(obj), indent=2)
|
out_obj = obj
|
||||||
elif self.output_format == 'yaml':
|
|
||||||
return dump(obj, Dumper=Dumper)
|
|
||||||
else:
|
else:
|
||||||
return f"{obj}"
|
out_obj = self._safer_obj(obj)
|
||||||
|
if self.output_format == 'json':
|
||||||
|
return json.dumps(out_obj, indent=2)
|
||||||
|
if self.output_format == 'yaml':
|
||||||
|
return dump(out_obj, Dumper=Dumper)
|
||||||
|
output = ''
|
||||||
|
if isinstance(out_obj, list):
|
||||||
|
output += '-' * os.get_terminal_size(0)[0]
|
||||||
|
for item in obj:
|
||||||
|
output += f"{self._output(item)}\n"
|
||||||
|
elif isinstance(out_obj, dict):
|
||||||
|
output += '-' * os.get_terminal_size(0)[0]
|
||||||
|
for key in out_obj.keys():
|
||||||
|
output += f"{key} = {self._output(out_obj[key])}\n"
|
||||||
|
else:
|
||||||
|
output += f"{out_obj}\n"
|
||||||
|
return output.strip('\n')
|
||||||
|
|
||||||
def debug(self, obj):
|
def debug(self, obj, unsafe=False):
|
||||||
'''Show debug information'''
|
'''Show debug information'''
|
||||||
self._log.debug(
|
self._log.debug(
|
||||||
self._output(obj)
|
self._output(obj, unsafe=unsafe)
|
||||||
)
|
)
|
||||||
|
|
||||||
def warning(self, obj):
|
def warning(self, obj, unsafe=False):
|
||||||
'''Show warning information'''
|
'''Show warning information'''
|
||||||
self._log.warning(
|
self._log.warning(
|
||||||
self._output(obj)
|
self._output(obj, unsafe=unsafe)
|
||||||
)
|
)
|
||||||
|
|
||||||
def info(self, obj):
|
def info(self, obj, unsafe=False):
|
||||||
'''Show information'''
|
'''Show information'''
|
||||||
self._log.info(
|
self._log.info(
|
||||||
self._output(obj)
|
self._output(obj, unsafe=unsafe)
|
||||||
)
|
)
|
||||||
|
|
||||||
def error(self, obj):
|
def error(self, obj, unsafe=False):
|
||||||
'''Show error information'''
|
'''Show error information'''
|
||||||
try:
|
try:
|
||||||
self._log.error(
|
self._log.error(
|
||||||
self._output(obj)
|
self._output(obj, unsafe=unsafe)
|
||||||
)
|
)
|
||||||
except TypeError as error:
|
except TypeError as error:
|
||||||
self._log.error(
|
self._log.error(
|
||||||
|
@ -1061,48 +1075,51 @@ class NcPasswordClient:
|
||||||
item = self._safer_obj(item, fields=fields)
|
item = self._safer_obj(item, fields=fields)
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
def _output(self, obj):
|
def _output(self, obj, unsafe=False):
|
||||||
if self.output_format == 'json':
|
if unsafe:
|
||||||
return json.dumps(self._safer_obj(obj), indent=2)
|
out_obj = obj
|
||||||
elif self.output_format == 'yaml':
|
|
||||||
return dump(obj, Dumper=Dumper)
|
|
||||||
else:
|
else:
|
||||||
|
out_obj = self._safer_obj(obj)
|
||||||
|
if self.output_format == 'json':
|
||||||
|
return json.dumps(out_obj, indent=2)
|
||||||
|
if self.output_format == 'yaml':
|
||||||
|
return dump(out_obj, Dumper=Dumper)
|
||||||
output = ''
|
output = ''
|
||||||
if isinstance(obj, list):
|
if isinstance(out_obj, list):
|
||||||
output += '-' * os.get_terminal_size(0)[0]
|
output += '-' * os.get_terminal_size(0)[0]
|
||||||
for item in obj:
|
for item in obj:
|
||||||
output += f"{self._output(item)}\n"
|
output += f"{self._output(item)}\n"
|
||||||
elif isinstance(obj, dict):
|
elif isinstance(out_obj, dict):
|
||||||
output += '-' * os.get_terminal_size(0)[0]
|
output += '-' * os.get_terminal_size(0)[0]
|
||||||
for key in obj.keys():
|
for key in out_obj.keys():
|
||||||
output += f"{key} = {self._output(obj[key])}\n"
|
output += f"{key} = {self._output(out_obj[key])}\n"
|
||||||
else:
|
else:
|
||||||
output += f"{obj}\n"
|
output += f"{out_obj}\n"
|
||||||
return output.strip('\n')
|
return output.strip('\n')
|
||||||
|
|
||||||
def debug(self, obj):
|
def debug(self, obj, unsafe=False):
|
||||||
'''Show debug information'''
|
'''Show debug information'''
|
||||||
self._log.debug(
|
self._log.debug(
|
||||||
self._output(obj)
|
self._output(obj, unsafe=unsafe)
|
||||||
)
|
)
|
||||||
|
|
||||||
def warning(self, obj):
|
def warning(self, obj, unsafe=False):
|
||||||
'''Show warning information'''
|
'''Show warning information'''
|
||||||
self._log.warning(
|
self._log.warning(
|
||||||
self._output(obj)
|
self._output(obj, unsafe=unsafe)
|
||||||
)
|
)
|
||||||
|
|
||||||
def info(self, obj):
|
def info(self, obj, unsafe=False):
|
||||||
'''Show information'''
|
'''Show information'''
|
||||||
self._log.info(
|
self._log.info(
|
||||||
self._output(obj)
|
self._output(obj, unsafe=unsafe)
|
||||||
)
|
)
|
||||||
|
|
||||||
def error(self, obj):
|
def error(self, obj, unsafe=False):
|
||||||
'''Show error information'''
|
'''Show error information'''
|
||||||
try:
|
try:
|
||||||
self._log.error(
|
self._log.error(
|
||||||
self._output(obj)
|
self._output(obj, unsafe=unsafe)
|
||||||
)
|
)
|
||||||
except TypeError as error:
|
except TypeError as error:
|
||||||
self._log.error(
|
self._log.error(
|
||||||
|
@ -1308,16 +1325,19 @@ class NcPasswordClient:
|
||||||
for key in password.keys():
|
for key in password.keys():
|
||||||
match = re.search(
|
match = re.search(
|
||||||
pattern,
|
pattern,
|
||||||
password[key],
|
f"{password[key]}",
|
||||||
flags=re.IGNORECASE | re.MULTILINE
|
re.IGNORECASE | re.MULTILINE
|
||||||
)
|
)
|
||||||
if match:
|
if match:
|
||||||
self.info(
|
self.info(
|
||||||
password
|
password,
|
||||||
|
unsafe=True
|
||||||
)
|
)
|
||||||
count += 1
|
count += 1
|
||||||
if limit != -1 and count >= limit:
|
if limit != -1 and count >= limit:
|
||||||
return True
|
return True
|
||||||
|
break
|
||||||
|
if count == 0:
|
||||||
self.info(
|
self.info(
|
||||||
{
|
{
|
||||||
"action": "search",
|
"action": "search",
|
||||||
|
|
Loading…
Reference in a new issue