Skip to content

Commit

Permalink
Merge branch 'tkt_87_modify_get_workspace_v2' into 'dev'
Browse files Browse the repository at this point in the history
Resolve "Cambiar get_workspace"

Closes #87

See merge request faradaysec/faraday-cli!79
  • Loading branch information
Diego Nadares committed Feb 26, 2024
2 parents e6f97bb + 98b77fc commit 6269af4
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 61 deletions.
1 change: 1 addition & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ black:
- mkdir -p ~/.faraday/logs
- cp tests/data/server.ini ~/.faraday/config
- python3 ../tests/config/psql_config.py
- pip install 'importlib-metadata<5.0'
- faraday-manage create-tables
- faraday-manage create-superuser --username $FARADAY_USER --password $FARADAY_PASSWORD --email $FARADAY_EMAIL
- faraday-server &
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG/current/87.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[FIX] Fix workspace activation. #87
4 changes: 3 additions & 1 deletion faraday_cli/api_client/faraday_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ def get_workspaces(self, get_inactives=False):
return response.body
else:
return [
workspace for workspace in response.body if workspace["active"]
workspace
for workspace in response.body["rows"]
if workspace["active"]
]

@handle_errors
Expand Down
16 changes: 10 additions & 6 deletions faraday_cli/extras/halo/halo.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,11 @@ def frame(self):
text_frame = self.text_frame()
return "{0} {1}".format(
*[
(text_frame, frame)
if self._placement == "right"
else (frame, text_frame)
(
(text_frame, frame)
if self._placement == "right"
else (frame, text_frame)
)
][0]
)

Expand Down Expand Up @@ -602,9 +604,11 @@ def stop_and_persist(self, symbol=" ", text=None):

output = "{0} {1}\n".format(
*[
(text, symbol)
if self._placement == "right"
else (symbol, text)
(
(text, symbol)
if self._placement == "right"
else (symbol, text)
)
][0]
)

Expand Down
2 changes: 1 addition & 1 deletion faraday_cli/shell/modules/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def run_executor(self, args):
default="",
show_default=False,
)
if type(value) == str and value == "":
if isinstance(value, str) and value == "":
continue
executor_params[parameter] = str(value)
executor_params = json.dumps(executor_params)
Expand Down
6 changes: 3 additions & 3 deletions faraday_cli/shell/modules/executive_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ def list_executive_reports_templates(self, args):
tabulate(
data,
headers="keys",
tablefmt=self._cmd.TABLE_PRETTY_FORMAT
if args.pretty
else "simple",
tablefmt=(
self._cmd.TABLE_PRETTY_FORMAT if args.pretty else "simple"
),
)
)

Expand Down
47 changes: 29 additions & 18 deletions faraday_cli/shell/modules/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,17 @@ def get_data(workspace_name, port_number):
"HOSTNAMES": "\n".join(
x["value"]["hostnames"]
),
"SERVICES": "-"
if len(x["value"]["service_summaries"]) == 0
else len(x["value"]["service_summaries"]),
"VULNS": "-"
if x["value"]["vulns"] == 0
else x["value"]["vulns"],
"SERVICES": (
"-"
if len(x["value"]["service_summaries"])
== 0
else len(x["value"]["service_summaries"])
),
"VULNS": (
"-"
if x["value"]["vulns"] == 0
else x["value"]["vulns"]
),
}
)
for x in hosts["rows"]
Expand Down Expand Up @@ -204,9 +209,11 @@ def get_host_vulns(workspace_name, ip):
tabulate(
host_data,
headers="keys",
tablefmt=self._cmd.TABLE_PRETTY_FORMAT
if args.pretty
else "simple",
tablefmt=(
self._cmd.TABLE_PRETTY_FORMAT
if args.pretty
else "simple"
),
)
)
if host["services"] > 0:
Expand All @@ -221,9 +228,9 @@ def get_host_vulns(workspace_name, ip):
"PORT": x["port"],
"VERSION": x["version"],
"STATUS": x["status"],
"VULNS": "-"
if x["vulns"] == 0
else x["vulns"],
"VULNS": (
"-" if x["vulns"] == 0 else x["vulns"]
),
}
)
for x in services
Expand All @@ -233,9 +240,11 @@ def get_host_vulns(workspace_name, ip):
tabulate(
services_data,
headers="keys",
tablefmt=self._cmd.TABLE_PRETTY_FORMAT
if args.pretty
else "simple",
tablefmt=(
self._cmd.TABLE_PRETTY_FORMAT
if args.pretty
else "simple"
),
)
)
if host["vulns"] > 0:
Expand Down Expand Up @@ -263,9 +272,11 @@ def get_host_vulns(workspace_name, ip):
tabulate(
vulns_data,
headers="keys",
tablefmt=self._cmd.TABLE_PRETTY_FORMAT
if args.pretty
else "simple",
tablefmt=(
self._cmd.TABLE_PRETTY_FORMAT
if args.pretty
else "simple"
),
)
)

Expand Down
6 changes: 3 additions & 3 deletions faraday_cli/shell/modules/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ def gather_vulns_stats(vulns):
counters[host_identifier] += 1
data = list(map(lambda x: [x], counters.values()))
termgraph_data = termgraph.TERMGRAPH_DATA_TEMPLATE.copy()
termgraph_data[
"title"
] = f"Vulnerability stats [{workspace_name}]"
termgraph_data["title"] = (
f"Vulnerability stats [{workspace_name}]"
)
termgraph_data["data"] = data
termgraph_data["labels"] = [x for x in counters.keys()]
termgraph_data["categories"] = ["vulns"]
Expand Down
50 changes: 31 additions & 19 deletions faraday_cli/shell/modules/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,24 +101,32 @@ def get_workspace(workspace_name):
"ACTIVE": workspace["active"],
"PUBLIC": workspace["public"],
"READONLY": workspace["readonly"],
"HOSTS": "-"
if workspace["stats"]["hosts"] == 0
else workspace["stats"]["hosts"],
"SERVICES": "-"
if workspace["stats"]["services"] == 0
else workspace["stats"]["services"],
"VULNS": "-"
if workspace["stats"]["total_vulns"] == 0
else workspace["stats"]["total_vulns"],
"HOSTS": (
"-"
if workspace["stats"]["hosts"] == 0
else workspace["stats"]["hosts"]
),
"SERVICES": (
"-"
if workspace["stats"]["services"] == 0
else workspace["stats"]["services"]
),
"VULNS": (
"-"
if workspace["stats"]["total_vulns"] == 0
else workspace["stats"]["total_vulns"]
),
}
]
self._cmd.print_output(
tabulate(
data,
headers="keys",
tablefmt=self._cmd.TABLE_PRETTY_FORMAT
if args.pretty
else "simple",
tablefmt=(
self._cmd.TABLE_PRETTY_FORMAT
if args.pretty
else "simple"
),
)
)

Expand Down Expand Up @@ -236,9 +244,11 @@ def get_workspaces():
"NAME": x["name"],
"HOSTS": x["stats"]["hosts"],
"SERVICES": x["stats"]["services"],
"VULNS": "-"
if x["stats"]["total_vulns"] == 0
else x["stats"]["total_vulns"],
"VULNS": (
"-"
if x["stats"]["total_vulns"] == 0
else x["stats"]["total_vulns"]
),
"ACTIVE": x["active"],
"PUBLIC": x["public"],
"READONLY": x["readonly"],
Expand All @@ -250,9 +260,11 @@ def get_workspaces():
tabulate(
data,
headers="keys",
tablefmt=self._cmd.TABLE_PRETTY_FORMAT
if args.pretty
else "simple",
tablefmt=(
self._cmd.TABLE_PRETTY_FORMAT
if args.pretty
else "simple"
),
)
)

Expand Down Expand Up @@ -400,7 +412,7 @@ def activities_vulns_parser(activity_data):
)
data.append(
[
"\n".join(item) if type(item) == list else item
"\n".join(item) if isinstance(item, list) else item
for item in workspace_data.values()
]
)
Expand Down
18 changes: 10 additions & 8 deletions faraday_cli/shell/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,11 +403,13 @@ def do_status(self, args):
"USER": user if user else "-",
"VALID TOKEN": "\U00002714" if valid_token else "\U0000274c",
"WORKSPACE": active_config.workspace,
"CLI VERSION": __version__
if not self.update_available
else style(
f"{__version__} (latest: {self.latest_version})",
fg=COLORS.RED,
"CLI VERSION": (
__version__
if not self.update_available
else style(
f"{__version__} (latest: {self.latest_version})",
fg=COLORS.RED,
)
),
}
]
Expand All @@ -416,9 +418,9 @@ def do_status(self, args):
tabulate(
data,
headers="keys",
tablefmt=self.TABLE_PRETTY_FORMAT
if args.pretty
else "simple",
tablefmt=(
self.TABLE_PRETTY_FORMAT if args.pretty else "simple"
),
),
fg=COLORS.GREEN,
)
Expand Down
5 changes: 4 additions & 1 deletion faraday_cli/shell/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@


def validate_url(value):
valid_url = url(value)
if sys.version_info < (3, 8):
valid_url = url(value)
else:
valid_url = url(value, simple_host=True)
if valid_url:
return value
else:
Expand Down
2 changes: 1 addition & 1 deletion hooks/hook-faraday_plugins.plugins.repo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from PyInstaller.utils.hooks import collect_all, collect_submodules
from PyInstaller.utils.hooks import collect_all

datas, binaries, hiddenimports = collect_all(
"faraday_plugins", include_py_files=True
Expand Down

0 comments on commit 6269af4

Please sign in to comment.