Skip to content

Commit

Permalink
*: Improvements related to kilo
Browse files Browse the repository at this point in the history
The itemgetter get_allowed_ips() was only used by
Peer.kilo.squat.ai. On top of that it caused issues.
migrate Peer to use get_list_as_list() instead,
and remove get_allowed_ips().

Added a parser-file for Peer.

Improved the info-view for Peer a bit.

Signed-off-by: David Weinehall <[email protected]>
  • Loading branch information
taotriad committed Jan 24, 2025
1 parent 599c5f1 commit 24acfb1
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 42 deletions.
38 changes: 0 additions & 38 deletions clustermanagementtoolkit/itemgetters.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,43 +37,6 @@
from clustermanagementtoolkit.pvtypes import KNOWN_PV_TYPES


# pylint: disable-next=unused-argument
def get_allowed_ips(obj: dict, **kwargs: Any) -> list[dict]:
"""
Get a list of allowed IP-addresses.
Parameters:
obj (dict): The object to get data from
**kwargs (dict[str, Any]): Keyword arguments
Returns:
([dict]): A list of allowed IPs
"""
allowed_ips = []

ip_mask_regex = re.compile(r"^(\d+\.\d+\.\d+\.\d+)\/(\d+)")

for addr in deep_get(obj, DictPath("spec#allowedIPs")):
if "/" in addr:
tmp = ip_mask_regex.match(addr)
if tmp is None:
raise ValueError(f"Could not parse {addr} as an address/address mask")
ip = tmp[1]
mask = tmp[2]
allowed_ips.append({
"lineattrs": WidgetLineAttrs.NORMAL,
"columns": [[ThemeStr(f"{ip}", ThemeAttr("windowwidget", "default")),
ThemeStr("/", ThemeAttr("windowwidget", "dim")),
ThemeStr(f"{mask}", ThemeAttr("windowwidget", "default"))]],
})
else:
allowed_ips.append({
"lineattrs": WidgetLineAttrs.NORMAL,
"columns": [[ThemeStr(f"{addr}", ThemeAttr("windowwidget", "default"))]],
})

return allowed_ips


def get_conditions(obj: dict, **kwargs: Any) -> list[dict]:
"""
Get a list of conditions.
Expand Down Expand Up @@ -1066,7 +1029,6 @@ def get_volume_properties(obj: dict, **kwargs: Any) -> list[tuple[str, str]]:

# Itemgetters acceptable for direct use in view files
itemgetter_allowlist: dict[str, Callable] = {
"get_allowed_ips": get_allowed_ips,
"get_kubernetes_objects": get_kubernetes_objects,
"get_events": get_events,
"get_image_list": get_image_list,
Expand Down
12 changes: 12 additions & 0 deletions parsers/kilo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
- name: "kilo"
show_in_selector: false
matchkeys:
- image_name: "/squat/kilo"
parser_rules:
- name: "json"
- name: "override_severity"
overrides:
- matchtype: "startswith"
matchkey: "Starting Kilo "
loglevel: "notice"
1 change: 0 additions & 1 deletion tests/schemas/views.json
Original file line number Diff line number Diff line change
Expand Up @@ -2239,7 +2239,6 @@
"itemgetter": {
"description": "Function to use to get items",
"enum": [
"get_allowed_ips",
"get_kubernetes_objects",
"get_image_list",
"get_key_value",
Expand Down
22 changes: 19 additions & 3 deletions views/Peer.kilo.squat.ai.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,24 @@ infoview:
infopad:
row_indexes:
Normal:
fields: ["persistent_keepalive", "peer_endpoint", "allowed_ips"]
fields: ["persistent_keepalive", "peer_endpoint", "allowed_ips",
"preshared_key", "public_key"]
rows:
allowed_ips:
header: [["Allowed ", ["main", "infoheader"]],
["I", ["main", "infoheader_shortcut"]],
["Ps:", ["main", "infoheader"]]]
path: "spec#allowedIPs"
default: ["<none>"]
type: "raw"
formatter: "list"
formatter: "address"
peer_endpoint:
header: [["Peer Endpoint:", ["main", "infoheader"]]]
paths:
- path: [["spec#endpoint#dnsOrIP#ip", "spec#endpoint#dnsOrIP#dns"],
["spec#endpoint#port"]]
pathtype: "tuple"
default: ["<unset>"]
# FIXME: The formatter needs to be improved to handle lists
# that contain addresses, etc.
formatter: "list"
Expand All @@ -40,8 +43,19 @@ infoview:
persistent_keepalive:
header: [["Persistent Keepalive:", ["main", "infoheader"]]]
path: "spec#persistentKeepalive"
default: "<unset>"
type: "int"
formatter: "numerical"
preshared_key:
header: [["Pre-shared Key:", ["main", "infoheader"]]]
path: "spec#presharedKey"
default: "<unset>"
type: "str"
public_key:
header: [["Public Key:", ["main", "infoheader"]]]
path: "spec#publicKey"
default: "<unset>"
type: "str"
shortcuts:
"Allowed IPs":
key: "i"
Expand All @@ -50,6 +64,8 @@ infoview:
helptext: "Show list of allowed IPs"
widget: "windowwidget"
title: "Allowed IPs:"
itemgetter: "get_allowed_ips"
itemgetter: "get_list_as_list"
itemgetter_args:
path: "spec#allowedIPs"
# This isn't supported for now
sortcolumn: "key"

0 comments on commit 24acfb1

Please sign in to comment.