Skip to content

Commit 6c84f2f

Browse files
author
David Kraus
committed
Merge branch 'tkt_79_set_resolve_hostname_to_false_and_add_force_flag' into 'dev'
Set resolve hostname to false for default and add force flag to tool run Closes #79 See merge request faradaysec/faraday-cli!77
2 parents d85fca6 + 78e7581 commit 6c84f2f

7 files changed

Lines changed: 19 additions & 6 deletions

File tree

CHANGELOG/current/79.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +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

faraday_cli/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def __init__(self):
1616
self.workspace = None
1717
self.custom_plugins_path = None
1818
self.ignore_info_severity = False
19-
self.hostname_resolution = True
19+
self.hostname_resolution = False
2020
self.auto_command_detection = True
2121
self.load()
2222

faraday_cli/shell/main.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66

77
def main(argv=None):
8-
98
parser = argparse.ArgumentParser(description="Commands as arguments")
109
command_help = (
1110
"optional command to run, "

faraday_cli/shell/modules/host.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,11 @@ def delete_host(self, args):
320320
help="Workspace name",
321321
required=False,
322322
)
323+
create_host_parser.add_argument(
324+
"--resolve-hostname",
325+
action="store_true",
326+
help="Doesnt resolve hostname",
327+
)
323328

324329
@cmd2.as_subcommand_to(
325330
"host", "create", create_host_parser, help="create hosts"
@@ -350,7 +355,10 @@ def create_hosts(self, args: argparse.Namespace):
350355
self._cmd.perror(f"{e}")
351356
else:
352357
for _host_data in json_data:
353-
ip, hostname = utils.get_ip_and_hostname(_host_data["ip"])
358+
if args.resolve_hostname:
359+
ip, hostname = utils.get_ip_and_hostname(_host_data["ip"])
360+
else:
361+
ip, hostname = _host_data["ip"], _host_data["ip"]
354362
_host_data["ip"] = ip
355363
if hostname:
356364
if "hostnames" in _host_data:

faraday_cli/shell/modules/service.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ def get_service_host(host_id):
8989
json.dumps(services["services"], indent=4)
9090
)
9191
else:
92-
9392
data = [
9493
OrderedDict(
9594
{

faraday_cli/shell/modules/tools.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ def __init__(self):
5555
action="append",
5656
)
5757
tool_parser.add_argument("command", help="Command of the tool to process")
58+
tool_parser.add_argument(
59+
"--force",
60+
action="store_true",
61+
help="Process the output of the command regardless of the results",
62+
)
5863

5964
@cmd2.as_subcommand_to(
6065
"tool", "run", tool_parser, help="run a tool and process it"
@@ -117,6 +122,7 @@ def process_tool(self, args):
117122
getpass.getuser(),
118123
args.command,
119124
show_output=show_command_output,
125+
force=args.force,
120126
)
121127
if not command_json:
122128
self._cmd.perror(

faraday_cli/shell/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def get_active_workspaces_filter() -> dict:
134134
return query_filter
135135

136136

137-
def run_tool(plugin, user, command, show_output=True):
137+
def run_tool(plugin, user, command, show_output=True, force=False):
138138
current_path = os.path.abspath(os.getcwd())
139139
modified_command = plugin.processCommandString(
140140
getpass.getuser(), current_path, command
@@ -162,7 +162,7 @@ def run_tool(plugin, user, command, show_output=True):
162162
output.writelines(extra_lines)
163163
break
164164
output_value = output.getvalue()
165-
if retcode == 0:
165+
if retcode == 0 or force:
166166
plugin.processOutput(output_value)
167167
return plugin.get_data()
168168
else:

0 commit comments

Comments
 (0)