Skip to content

Commit

Permalink
Nail internetnl (almost)
Browse files Browse the repository at this point in the history
  • Loading branch information
originalsouth committed Jan 15, 2025
1 parent 2ca65dd commit ff021ea
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
6 changes: 2 additions & 4 deletions octopoes/nibbles/internetnl/nibble.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from octopoes.models import Reference
from octopoes.models.ooi.dns.zone import Hostname, Network
from octopoes.models.ooi.findings import Finding
from octopoes.models.ooi.web import Website

finding_types = [
"KAT-WEBSERVER-NO-IPV6",
Expand Down Expand Up @@ -95,9 +94,8 @@ def pull(statements: list[str]) -> str:
NIBBLE = NibbleDefinition(
id="internet_nl",
signature=[
NibbleParameter(object_type=Hostname, parser="[*][?object_type == 'IPPort'][]"),
NibbleParameter(object_type=list[Website], parser="[[*][?object_type == 'Website'][]]", additional={Website}),
NibbleParameter(object_type=list[Finding], parser="[[*][?object_type == 'Findings'][]]", additional={Finding}),
NibbleParameter(object_type=Hostname, parser="[*][?object_type == 'Hostname'][]"),
NibbleParameter(object_type=list[Finding], parser="[[*][?object_type == 'Finding'][]]", additional={Finding}),
],
query=query,
)
4 changes: 3 additions & 1 deletion octopoes/octopoes/repositories/ooi_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ def parse_as(cls, type_: type | list[type], obj: dict | list | set | Any) -> tup
# list --> tuple
if isinstance(type_, list):
return tuple(cls.parse_as(type_t, o) for o, type_t in zip(obj, type_))
elif hasattr(type_, "__origin__") and hasattr(type_, "__args__") and type_.__origin__ is list:
t = [type_.__args__[0]] * len(obj)
return tuple(cls.parse_as(t, o) for o, t in zip(obj, t))
else:
return tuple(cls.parse_as(type_, o) for o in obj)
else:
Expand Down Expand Up @@ -926,7 +929,6 @@ def nibble_query(
else:
arguments = [None for _ in nibble.signature]
query = nibble.query if isinstance(nibble.query, str) else nibble.query(arguments)
breakpoint()
data = self.session.client.query(query, valid_time)
objects = [
{self.parse_as(element.object_type, obj) for obj in search(element.parser, data)}
Expand Down
4 changes: 4 additions & 0 deletions octopoes/tests/test_ooi_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,7 @@ def pull(ooi: OOI):
[network, url, network]
)
assert self.repository.parse_as(Network, [pull(network), pull(url), pull(url)]) == tuple([network, url, url])

assert self.repository.parse_as(list[Network], [pull(network), pull(network), pull(network)]) == tuple(
[network, network, network]
)
4 changes: 2 additions & 2 deletions octopoes/tools/xtdb-cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ def query(
client: XTDBClient = ctx.obj["client"]

if edn:
click.echo(client.query(edn, valid_time, tx_time, tx_id))
click.echo(json.dumps(client.query(edn, valid_time, tx_time, tx_id)))
else:
click.echo(client.query(valid_time=valid_time, tx_time=tx_time, tx_id=tx_id))
click.echo(json.dumps(client.query(valid_time=valid_time, tx_time=tx_time, tx_id=tx_id)))


@cli.command(help="List all keys in node")
Expand Down
3 changes: 1 addition & 2 deletions octopoes/tools/xtdb_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def query(
valid_time: datetime.datetime | None = None,
tx_time: datetime.datetime | None = None,
tx_id: int | None = None,
) -> str:
) -> JsonValue:
params = {}
if valid_time is not None:
params["valid-time"] = valid_time.isoformat()
Expand All @@ -52,7 +52,6 @@ def query(

res = self._client.post("/query", params=params, content=query, headers={"Content-Type": "application/edn"})

return res.text
return res.json()

def entity(
Expand Down

0 comments on commit ff021ea

Please sign in to comment.