Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor tweaks #69

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class TestTheme:
""" Expected theme values for the tests """
panel_title_main = "bold yellow"
panel_title = "bold yellow"
heading_h1 = "bold bright_green on dark_green"
heading_h2 = "bold yellow"
table_field = "bold bright_magenta"
Expand Down
7 changes: 5 additions & 2 deletions tests/test_ui_domain_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def test_domain_panel(self, view01, theme, display_timestamp):
domain = view01.domain_panel()
assert type(domain) is Panel
assert domain.title == Text("gist.github.com")
assert domain.title.style == theme.panel_title_main
assert domain.title.style == theme.panel_title

#
# VT section
Expand Down Expand Up @@ -1552,7 +1552,10 @@ def test_domain_panel_urlhaus(self, view14, theme):
assert table.columns[1]._cells == [
Text(
"1+ online (3248 total)",
spans=[Span(9, 22, theme.table_value)],
spans=[
Span(0, 9, theme.error),
Span(9, 22, theme.table_value),
],
),
Text(
"abused_legit_malware in spamhaus\nlisted in surbl",
Expand Down
3 changes: 2 additions & 1 deletion tests/test_ui_ip_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def test_ip_panel(self, view01, theme, display_timestamp):
ip = view01.ip_panel()
assert type(ip) is Panel
assert ip.title == Text("1.1.1.1")
assert ip.title.style == theme.panel_title_main
assert ip.title.style == theme.panel_title

# Sections
vt_section = ip.renderable.renderables[0]
Expand Down Expand Up @@ -264,6 +264,7 @@ def test_ip_panel(self, view01, theme, display_timestamp):
Text(
"10 online (10 total)",
spans=[
Span(0, 9, theme.error),
Span(9, 20, theme.table_value),
]
),
Expand Down
36 changes: 17 additions & 19 deletions wtfis/ui/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def _gen_heading_text(self, heading: str, hyperlink: Optional[str] = None, type:
elif type == "h2":
text = Text(justify="center")
return text.append(heading, style=f"{self.theme.heading_h2}{link_style}")
else:
else: # pragma: no cover
raise Exception(f"Invalid heading type \"{type}\"")

def _gen_linked_field_name(self, name: str, hyperlink: str) -> Text:
Expand Down Expand Up @@ -111,14 +111,9 @@ def _gen_panel(
self,
renderable: RenderableType,
title: Optional[str] = None,
main_panel: bool = False
) -> Panel:
if title is not None:
if main_panel is True:
title_style = self.theme.panel_title_main
else: # Note to future self: we might not need two panel title styles anymore
title_style = self.theme.panel_title_default
panel_title = Text(title, style=title_style)
panel_title = Text(title, style=self.theme.panel_title)
return Panel(renderable, title=panel_title, expand=False)
return Panel(renderable, expand=False)

Expand Down Expand Up @@ -261,12 +256,14 @@ def _gen_asn_text(
asn: Optional[str],
org: Optional[RenderableType],
) -> Optional[RenderableType]:
if not asn:
if asn == "0" or not asn:
return None

text = Text(f"{asn.replace('AS', '')} (")
text.append(str(org), style=self.theme.asn_org)
text.append(")")
text = Text()
(text
.append(f"{asn.replace('AS', '')} (")
.append(str(org), style=self.theme.asn_org)
.append(")"))
return text

def _get_ip_enrichment(self, ip: str) -> Optional[Union[IpWhois, ShodanIp]]:
Expand Down Expand Up @@ -385,7 +382,7 @@ def bl_text(blocklist: str, status: str) -> Text:
text.append(status, self.theme.urlhaus_bl_med)
elif status.endswith("_domain") or status == "listed":
text.append(status, self.theme.urlhaus_bl_high)
else:
else: # pragma: no cover
raise Exception(f"Invalid URLhaus BL status: {status}")
text.append(" in ").append(blocklist, style=self.theme.urlhaus_bl_name)
return text
Expand All @@ -400,17 +397,18 @@ def bl_text(blocklist: str, status: str) -> Text:
hyperlink=enrich.urlhaus_reference,
) if enrich.urlhaus_reference else "Malware URLs:"

malware_urls_value = Text(
malware_urls_value = Text()
(malware_urls_value
.append(
(str(enrich.online_url_count)
if enrich.url_count and enrich.url_count <= 100
else f"{enrich.online_url_count}+") + " online",
if enrich.url_count and enrich.url_count <= 100
else f"{enrich.online_url_count}+") + " online",
style=self.theme.error if enrich.online_url_count > 0 else self.theme.warn,
)

malware_urls_value.append(
)
.append(
f" ({enrich.url_count} total)",
style=self.theme.table_value,
)
))

tags = smart_join(*enrich.tags, style=self.theme.tags) if enrich.tags else None

Expand Down
3 changes: 1 addition & 2 deletions wtfis/ui/theme.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
class Theme:
panel_title_default = "default"
panel_title_main = "bold yellow"
panel_title = "bold yellow"
heading_h1 = "bold bright_green on dark_green"
heading_h2 = "bold yellow"
table_field = "bold bright_magenta"
Expand Down
4 changes: 2 additions & 2 deletions wtfis/ui/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def domain_panel(self) -> Panel:
content.append("")
content.append(section)

return self._gen_panel(self._gen_group(content), self.entity.data.id_, main_panel=True)
return self._gen_panel(self._gen_group(content), self.entity.data.id_)

def resolutions_panel(self) -> Optional[Panel]:
# Skip if no resolutions data
Expand Down Expand Up @@ -198,7 +198,7 @@ def ip_panel(self) -> Panel:
content.append("")
content.append(section)

return self._gen_panel(self._gen_group(content), self.entity.data.id_, main_panel=True)
return self._gen_panel(self._gen_group(content), self.entity.data.id_)

def print(self, one_column: bool = False) -> None:
renderables = [i for i in (
Expand Down
Loading