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)
|
||||
return obj
|
||||
|
||||
def _output(self, obj):
|
||||
if self.output_format == 'json':
|
||||
return json.dumps(self._safer_obj(obj), indent=2)
|
||||
elif self.output_format == 'yaml':
|
||||
return dump(obj, Dumper=Dumper)
|
||||
def _output(self, obj, unsafe=False):
|
||||
if unsafe:
|
||||
out_obj = obj
|
||||
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'''
|
||||
self._log.debug(
|
||||
self._output(obj)
|
||||
self._output(obj, unsafe=unsafe)
|
||||
)
|
||||
|
||||
def warning(self, obj):
|
||||
def warning(self, obj, unsafe=False):
|
||||
'''Show warning information'''
|
||||
self._log.warning(
|
||||
self._output(obj)
|
||||
self._output(obj, unsafe=unsafe)
|
||||
)
|
||||
|
||||
def info(self, obj):
|
||||
def info(self, obj, unsafe=False):
|
||||
'''Show information'''
|
||||
self._log.info(
|
||||
self._output(obj)
|
||||
self._output(obj, unsafe=unsafe)
|
||||
)
|
||||
|
||||
def error(self, obj):
|
||||
def error(self, obj, unsafe=False):
|
||||
'''Show error information'''
|
||||
try:
|
||||
self._log.error(
|
||||
self._output(obj)
|
||||
self._output(obj, unsafe=unsafe)
|
||||
)
|
||||
except TypeError as error:
|
||||
self._log.error(
|
||||
|
@ -1061,48 +1075,51 @@ class NcPasswordClient:
|
|||
item = self._safer_obj(item, fields=fields)
|
||||
return obj
|
||||
|
||||
def _output(self, obj):
|
||||
if self.output_format == 'json':
|
||||
return json.dumps(self._safer_obj(obj), indent=2)
|
||||
elif self.output_format == 'yaml':
|
||||
return dump(obj, Dumper=Dumper)
|
||||
def _output(self, obj, unsafe=False):
|
||||
if unsafe:
|
||||
out_obj = obj
|
||||
else:
|
||||
output = ''
|
||||
if isinstance(obj, list):
|
||||
output += '-' * os.get_terminal_size(0)[0]
|
||||
for item in obj:
|
||||
output += f"{self._output(item)}\n"
|
||||
elif isinstance(obj, dict):
|
||||
output += '-' * os.get_terminal_size(0)[0]
|
||||
for key in obj.keys():
|
||||
output += f"{key} = {self._output(obj[key])}\n"
|
||||
else:
|
||||
output += f"{obj}\n"
|
||||
return output.strip('\n')
|
||||
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'''
|
||||
self._log.debug(
|
||||
self._output(obj)
|
||||
self._output(obj, unsafe=unsafe)
|
||||
)
|
||||
|
||||
def warning(self, obj):
|
||||
def warning(self, obj, unsafe=False):
|
||||
'''Show warning information'''
|
||||
self._log.warning(
|
||||
self._output(obj)
|
||||
self._output(obj, unsafe=unsafe)
|
||||
)
|
||||
|
||||
def info(self, obj):
|
||||
def info(self, obj, unsafe=False):
|
||||
'''Show information'''
|
||||
self._log.info(
|
||||
self._output(obj)
|
||||
self._output(obj, unsafe=unsafe)
|
||||
)
|
||||
|
||||
def error(self, obj):
|
||||
def error(self, obj, unsafe=False):
|
||||
'''Show error information'''
|
||||
try:
|
||||
self._log.error(
|
||||
self._output(obj)
|
||||
self._output(obj, unsafe=unsafe)
|
||||
)
|
||||
except TypeError as error:
|
||||
self._log.error(
|
||||
|
@ -1308,24 +1325,27 @@ class NcPasswordClient:
|
|||
for key in password.keys():
|
||||
match = re.search(
|
||||
pattern,
|
||||
password[key],
|
||||
flags=re.IGNORECASE | re.MULTILINE
|
||||
f"{password[key]}",
|
||||
re.IGNORECASE | re.MULTILINE
|
||||
)
|
||||
if match:
|
||||
self.info(
|
||||
password
|
||||
password,
|
||||
unsafe=True
|
||||
)
|
||||
count += 1
|
||||
if limit != -1 and count >= limit:
|
||||
return True
|
||||
self.info(
|
||||
{
|
||||
"action": "search",
|
||||
"message": "No passwords found with the given pattern",
|
||||
"patter": pattern,
|
||||
"total_passwords": len(passwords)
|
||||
}
|
||||
)
|
||||
if limit != -1 and count >= limit:
|
||||
return True
|
||||
break
|
||||
if count == 0:
|
||||
self.info(
|
||||
{
|
||||
"action": "search",
|
||||
"message": "No passwords found with the given pattern",
|
||||
"patter": pattern,
|
||||
"total_passwords": len(passwords)
|
||||
}
|
||||
)
|
||||
return False
|
||||
|
||||
def _init_log(self):
|
||||
|
|
Loading…
Reference in a new issue