Skip to content

Commit

Permalink
Merge branch 'tkt_79_set_resolve_hostname_to_false_and_add_force_flag…
Browse files Browse the repository at this point in the history
…' 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
  • Loading branch information
David Kraus committed Feb 23, 2023
2 parents d85fca6 + 78e7581 commit 6c84f2f
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG/current/79.md
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion faraday_cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
1 change: 0 additions & 1 deletion faraday_cli/shell/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


def main(argv=None):

parser = argparse.ArgumentParser(description="Commands as arguments")
command_help = (
"optional command to run, "
Expand Down
10 changes: 9 additions & 1 deletion faraday_cli/shell/modules/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion faraday_cli/shell/modules/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ def get_service_host(host_id):
json.dumps(services["services"], indent=4)
)
else:

data = [
OrderedDict(
{
Expand Down
6 changes: 6 additions & 0 deletions faraday_cli/shell/modules/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions faraday_cli/shell/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 6c84f2f

Please sign in to comment.