From eb4e5f14a435064db2b042c55fd3f99911b4c602 Mon Sep 17 00:00:00 2001 From: GMartinez1995 Date: Thu, 2 Feb 2023 17:27:12 -0300 Subject: [PATCH 1/5] Add flag and resolve_hostname false --- faraday_cli/config.py | 2 +- faraday_cli/shell/modules/host.py | 10 +++++++++- faraday_cli/shell/modules/tools.py | 7 ++++++- faraday_cli/shell/utils.py | 4 ++-- 4 files changed, 18 insertions(+), 5 deletions(-) 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/modules/host.py b/faraday_cli/shell/modules/host.py index d550c36..e2d0f7b 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: + 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/tools.py b/faraday_cli/shell/modules/tools.py index 2193ff3..cc7e60c 100644 --- a/faraday_cli/shell/modules/tools.py +++ b/faraday_cli/shell/modules/tools.py @@ -55,7 +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 +121,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: From a6f7d50b4e4b6f09e976924acc6c3b1ff661ddba Mon Sep 17 00:00:00 2001 From: GMartinez1995 Date: Thu, 2 Feb 2023 17:29:21 -0300 Subject: [PATCH 2/5] Add changelog --- CHANGELOG/current/79.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 CHANGELOG/current/79.md diff --git a/CHANGELOG/current/79.md b/CHANGELOG/current/79.md new file mode 100644 index 0000000..d32576c --- /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 \ No newline at end of file From b808f2c40a62a7f2ddc8d8b72724576558de5d7d Mon Sep 17 00:00:00 2001 From: GMartinez1995 Date: Thu, 2 Feb 2023 17:35:54 -0300 Subject: [PATCH 3/5] fix black --- faraday_cli/shell/modules/tools.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/faraday_cli/shell/modules/tools.py b/faraday_cli/shell/modules/tools.py index cc7e60c..f3b0716 100644 --- a/faraday_cli/shell/modules/tools.py +++ b/faraday_cli/shell/modules/tools.py @@ -60,6 +60,7 @@ def __init__(self): 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" ) @@ -121,7 +122,7 @@ def process_tool(self, args): getpass.getuser(), args.command, show_output=show_command_output, - force=args.force + force=args.force, ) if not command_json: self._cmd.perror( From 32eb12a3cd32599851ef848e1cd6c5a35e00e4aa Mon Sep 17 00:00:00 2001 From: GMartinez1995 Date: Thu, 2 Feb 2023 17:42:08 -0300 Subject: [PATCH 4/5] fix black --- faraday_cli/shell/main.py | 1 - faraday_cli/shell/modules/service.py | 1 - 2 files changed, 2 deletions(-) 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/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( { From 78e7581da4ae20eb9fc4e8771b33caebe4458246 Mon Sep 17 00:00:00 2001 From: GMartinez1995 Date: Wed, 22 Feb 2023 15:46:14 -0300 Subject: [PATCH 5/5] fix --- CHANGELOG/current/79.md | 2 +- faraday_cli/shell/modules/host.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG/current/79.md b/CHANGELOG/current/79.md index d32576c..c07a9cd 100644 --- a/CHANGELOG/current/79.md +++ b/CHANGELOG/current/79.md @@ -1 +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 \ No newline at end of file +[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/shell/modules/host.py b/faraday_cli/shell/modules/host.py index e2d0f7b..4be494f 100644 --- a/faraday_cli/shell/modules/host.py +++ b/faraday_cli/shell/modules/host.py @@ -355,7 +355,7 @@ def create_hosts(self, args: argparse.Namespace): self._cmd.perror(f"{e}") else: for _host_data in json_data: - if args.resolve: + if args.resolve_hostname: ip, hostname = utils.get_ip_and_hostname(_host_data["ip"]) else: ip, hostname = _host_data["ip"], _host_data["ip"]