diff --git a/CHANGELOG/current/79.md b/CHANGELOG/current/79.md new file mode 100644 index 0000000..c07a9cd --- /dev/null +++ b/CHANGELOG/current/79.md @@ -0,0 +1 @@ +[MOD] Change resolve_hostname to false for default, add the --resolve-hostname flag for host create and add --force flag to tool run to process the output of the command regardless of the return code. #79 diff --git a/faraday_cli/config.py b/faraday_cli/config.py index a1c8e7a..9044a2f 100644 --- a/faraday_cli/config.py +++ b/faraday_cli/config.py @@ -16,7 +16,7 @@ def __init__(self): self.workspace = None self.custom_plugins_path = None self.ignore_info_severity = False - self.hostname_resolution = True + self.hostname_resolution = False self.auto_command_detection = True self.load() diff --git a/faraday_cli/shell/main.py b/faraday_cli/shell/main.py index f9946a9..a0e3497 100644 --- a/faraday_cli/shell/main.py +++ b/faraday_cli/shell/main.py @@ -5,7 +5,6 @@ def main(argv=None): - parser = argparse.ArgumentParser(description="Commands as arguments") command_help = ( "optional command to run, " diff --git a/faraday_cli/shell/modules/host.py b/faraday_cli/shell/modules/host.py index d550c36..4be494f 100644 --- a/faraday_cli/shell/modules/host.py +++ b/faraday_cli/shell/modules/host.py @@ -320,6 +320,11 @@ def delete_host(self, args): help="Workspace name", required=False, ) + create_host_parser.add_argument( + "--resolve-hostname", + action="store_true", + help="Doesnt resolve hostname", + ) @cmd2.as_subcommand_to( "host", "create", create_host_parser, help="create hosts" @@ -350,7 +355,10 @@ def create_hosts(self, args: argparse.Namespace): self._cmd.perror(f"{e}") else: for _host_data in json_data: - ip, hostname = utils.get_ip_and_hostname(_host_data["ip"]) + if args.resolve_hostname: + ip, hostname = utils.get_ip_and_hostname(_host_data["ip"]) + else: + ip, hostname = _host_data["ip"], _host_data["ip"] _host_data["ip"] = ip if hostname: if "hostnames" in _host_data: diff --git a/faraday_cli/shell/modules/service.py b/faraday_cli/shell/modules/service.py index d6108ae..74ca52f 100644 --- a/faraday_cli/shell/modules/service.py +++ b/faraday_cli/shell/modules/service.py @@ -89,7 +89,6 @@ def get_service_host(host_id): json.dumps(services["services"], indent=4) ) else: - data = [ OrderedDict( { diff --git a/faraday_cli/shell/modules/tools.py b/faraday_cli/shell/modules/tools.py index 2193ff3..f3b0716 100644 --- a/faraday_cli/shell/modules/tools.py +++ b/faraday_cli/shell/modules/tools.py @@ -55,6 +55,11 @@ def __init__(self): action="append", ) tool_parser.add_argument("command", help="Command of the tool to process") + tool_parser.add_argument( + "--force", + action="store_true", + help="Process the output of the command regardless of the results", + ) @cmd2.as_subcommand_to( "tool", "run", tool_parser, help="run a tool and process it" @@ -117,6 +122,7 @@ def process_tool(self, args): getpass.getuser(), args.command, show_output=show_command_output, + force=args.force, ) if not command_json: self._cmd.perror( diff --git a/faraday_cli/shell/utils.py b/faraday_cli/shell/utils.py index 45335d2..8eef02e 100644 --- a/faraday_cli/shell/utils.py +++ b/faraday_cli/shell/utils.py @@ -134,7 +134,7 @@ def get_active_workspaces_filter() -> dict: return query_filter -def run_tool(plugin, user, command, show_output=True): +def run_tool(plugin, user, command, show_output=True, force=False): current_path = os.path.abspath(os.getcwd()) modified_command = plugin.processCommandString( getpass.getuser(), current_path, command @@ -162,7 +162,7 @@ def run_tool(plugin, user, command, show_output=True): output.writelines(extra_lines) break output_value = output.getvalue() - if retcode == 0: + if retcode == 0 or force: plugin.processOutput(output_value) return plugin.get_data() else: