Skip to content

Commit 6269af4

Browse files
author
Diego Nadares
committed
Merge branch 'tkt_87_modify_get_workspace_v2' into 'dev'
Resolve "Cambiar get_workspace" Closes #87 See merge request faradaysec/faraday-cli!79
2 parents e6f97bb + 98b77fc commit 6269af4

12 files changed

Lines changed: 97 additions & 61 deletions

File tree

.gitlab-ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ black:
8585
- mkdir -p ~/.faraday/logs
8686
- cp tests/data/server.ini ~/.faraday/config
8787
- python3 ../tests/config/psql_config.py
88+
- pip install 'importlib-metadata<5.0'
8889
- faraday-manage create-tables
8990
- faraday-manage create-superuser --username $FARADAY_USER --password $FARADAY_PASSWORD --email $FARADAY_EMAIL
9091
- faraday-server &

CHANGELOG/current/87.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[FIX] Fix workspace activation. #87

faraday_cli/api_client/faraday_api.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,9 @@ def get_workspaces(self, get_inactives=False):
208208
return response.body
209209
else:
210210
return [
211-
workspace for workspace in response.body if workspace["active"]
211+
workspace
212+
for workspace in response.body["rows"]
213+
if workspace["active"]
212214
]
213215

214216
@handle_errors

faraday_cli/extras/halo/halo.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -440,9 +440,11 @@ def frame(self):
440440
text_frame = self.text_frame()
441441
return "{0} {1}".format(
442442
*[
443-
(text_frame, frame)
444-
if self._placement == "right"
445-
else (frame, text_frame)
443+
(
444+
(text_frame, frame)
445+
if self._placement == "right"
446+
else (frame, text_frame)
447+
)
446448
][0]
447449
)
448450

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

603605
output = "{0} {1}\n".format(
604606
*[
605-
(text, symbol)
606-
if self._placement == "right"
607-
else (symbol, text)
607+
(
608+
(text, symbol)
609+
if self._placement == "right"
610+
else (symbol, text)
611+
)
608612
][0]
609613
)
610614

faraday_cli/shell/modules/agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ def run_executor(self, args):
265265
default="",
266266
show_default=False,
267267
)
268-
if type(value) == str and value == "":
268+
if isinstance(value, str) and value == "":
269269
continue
270270
executor_params[parameter] = str(value)
271271
executor_params = json.dumps(executor_params)

faraday_cli/shell/modules/executive_report.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ def list_executive_reports_templates(self, args):
5858
tabulate(
5959
data,
6060
headers="keys",
61-
tablefmt=self._cmd.TABLE_PRETTY_FORMAT
62-
if args.pretty
63-
else "simple",
61+
tablefmt=(
62+
self._cmd.TABLE_PRETTY_FORMAT if args.pretty else "simple"
63+
),
6464
)
6565
)
6666

faraday_cli/shell/modules/host.py

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,17 @@ def get_data(workspace_name, port_number):
9696
"HOSTNAMES": "\n".join(
9797
x["value"]["hostnames"]
9898
),
99-
"SERVICES": "-"
100-
if len(x["value"]["service_summaries"]) == 0
101-
else len(x["value"]["service_summaries"]),
102-
"VULNS": "-"
103-
if x["value"]["vulns"] == 0
104-
else x["value"]["vulns"],
99+
"SERVICES": (
100+
"-"
101+
if len(x["value"]["service_summaries"])
102+
== 0
103+
else len(x["value"]["service_summaries"])
104+
),
105+
"VULNS": (
106+
"-"
107+
if x["value"]["vulns"] == 0
108+
else x["value"]["vulns"]
109+
),
105110
}
106111
)
107112
for x in hosts["rows"]
@@ -204,9 +209,11 @@ def get_host_vulns(workspace_name, ip):
204209
tabulate(
205210
host_data,
206211
headers="keys",
207-
tablefmt=self._cmd.TABLE_PRETTY_FORMAT
208-
if args.pretty
209-
else "simple",
212+
tablefmt=(
213+
self._cmd.TABLE_PRETTY_FORMAT
214+
if args.pretty
215+
else "simple"
216+
),
210217
)
211218
)
212219
if host["services"] > 0:
@@ -221,9 +228,9 @@ def get_host_vulns(workspace_name, ip):
221228
"PORT": x["port"],
222229
"VERSION": x["version"],
223230
"STATUS": x["status"],
224-
"VULNS": "-"
225-
if x["vulns"] == 0
226-
else x["vulns"],
231+
"VULNS": (
232+
"-" if x["vulns"] == 0 else x["vulns"]
233+
),
227234
}
228235
)
229236
for x in services
@@ -233,9 +240,11 @@ def get_host_vulns(workspace_name, ip):
233240
tabulate(
234241
services_data,
235242
headers="keys",
236-
tablefmt=self._cmd.TABLE_PRETTY_FORMAT
237-
if args.pretty
238-
else "simple",
243+
tablefmt=(
244+
self._cmd.TABLE_PRETTY_FORMAT
245+
if args.pretty
246+
else "simple"
247+
),
239248
)
240249
)
241250
if host["vulns"] > 0:
@@ -263,9 +272,11 @@ def get_host_vulns(workspace_name, ip):
263272
tabulate(
264273
vulns_data,
265274
headers="keys",
266-
tablefmt=self._cmd.TABLE_PRETTY_FORMAT
267-
if args.pretty
268-
else "simple",
275+
tablefmt=(
276+
self._cmd.TABLE_PRETTY_FORMAT
277+
if args.pretty
278+
else "simple"
279+
),
269280
)
270281
)
271282

faraday_cli/shell/modules/stats.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ def gather_vulns_stats(vulns):
7070
counters[host_identifier] += 1
7171
data = list(map(lambda x: [x], counters.values()))
7272
termgraph_data = termgraph.TERMGRAPH_DATA_TEMPLATE.copy()
73-
termgraph_data[
74-
"title"
75-
] = f"Vulnerability stats [{workspace_name}]"
73+
termgraph_data["title"] = (
74+
f"Vulnerability stats [{workspace_name}]"
75+
)
7676
termgraph_data["data"] = data
7777
termgraph_data["labels"] = [x for x in counters.keys()]
7878
termgraph_data["categories"] = ["vulns"]

faraday_cli/shell/modules/workspace.py

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -101,24 +101,32 @@ def get_workspace(workspace_name):
101101
"ACTIVE": workspace["active"],
102102
"PUBLIC": workspace["public"],
103103
"READONLY": workspace["readonly"],
104-
"HOSTS": "-"
105-
if workspace["stats"]["hosts"] == 0
106-
else workspace["stats"]["hosts"],
107-
"SERVICES": "-"
108-
if workspace["stats"]["services"] == 0
109-
else workspace["stats"]["services"],
110-
"VULNS": "-"
111-
if workspace["stats"]["total_vulns"] == 0
112-
else workspace["stats"]["total_vulns"],
104+
"HOSTS": (
105+
"-"
106+
if workspace["stats"]["hosts"] == 0
107+
else workspace["stats"]["hosts"]
108+
),
109+
"SERVICES": (
110+
"-"
111+
if workspace["stats"]["services"] == 0
112+
else workspace["stats"]["services"]
113+
),
114+
"VULNS": (
115+
"-"
116+
if workspace["stats"]["total_vulns"] == 0
117+
else workspace["stats"]["total_vulns"]
118+
),
113119
}
114120
]
115121
self._cmd.print_output(
116122
tabulate(
117123
data,
118124
headers="keys",
119-
tablefmt=self._cmd.TABLE_PRETTY_FORMAT
120-
if args.pretty
121-
else "simple",
125+
tablefmt=(
126+
self._cmd.TABLE_PRETTY_FORMAT
127+
if args.pretty
128+
else "simple"
129+
),
122130
)
123131
)
124132

@@ -236,9 +244,11 @@ def get_workspaces():
236244
"NAME": x["name"],
237245
"HOSTS": x["stats"]["hosts"],
238246
"SERVICES": x["stats"]["services"],
239-
"VULNS": "-"
240-
if x["stats"]["total_vulns"] == 0
241-
else x["stats"]["total_vulns"],
247+
"VULNS": (
248+
"-"
249+
if x["stats"]["total_vulns"] == 0
250+
else x["stats"]["total_vulns"]
251+
),
242252
"ACTIVE": x["active"],
243253
"PUBLIC": x["public"],
244254
"READONLY": x["readonly"],
@@ -250,9 +260,11 @@ def get_workspaces():
250260
tabulate(
251261
data,
252262
headers="keys",
253-
tablefmt=self._cmd.TABLE_PRETTY_FORMAT
254-
if args.pretty
255-
else "simple",
263+
tablefmt=(
264+
self._cmd.TABLE_PRETTY_FORMAT
265+
if args.pretty
266+
else "simple"
267+
),
256268
)
257269
)
258270

@@ -400,7 +412,7 @@ def activities_vulns_parser(activity_data):
400412
)
401413
data.append(
402414
[
403-
"\n".join(item) if type(item) == list else item
415+
"\n".join(item) if isinstance(item, list) else item
404416
for item in workspace_data.values()
405417
]
406418
)

faraday_cli/shell/shell.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -403,11 +403,13 @@ def do_status(self, args):
403403
"USER": user if user else "-",
404404
"VALID TOKEN": "\U00002714" if valid_token else "\U0000274c",
405405
"WORKSPACE": active_config.workspace,
406-
"CLI VERSION": __version__
407-
if not self.update_available
408-
else style(
409-
f"{__version__} (latest: {self.latest_version})",
410-
fg=COLORS.RED,
406+
"CLI VERSION": (
407+
__version__
408+
if not self.update_available
409+
else style(
410+
f"{__version__} (latest: {self.latest_version})",
411+
fg=COLORS.RED,
412+
)
411413
),
412414
}
413415
]
@@ -416,9 +418,9 @@ def do_status(self, args):
416418
tabulate(
417419
data,
418420
headers="keys",
419-
tablefmt=self.TABLE_PRETTY_FORMAT
420-
if args.pretty
421-
else "simple",
421+
tablefmt=(
422+
self.TABLE_PRETTY_FORMAT if args.pretty else "simple"
423+
),
422424
),
423425
fg=COLORS.GREEN,
424426
)

0 commit comments

Comments
 (0)