Skip to content

Commit

Permalink
Support rpki-client JSON format
Browse files Browse the repository at this point in the history
  • Loading branch information
quantum5 committed Nov 1, 2024
1 parent 6e1d2e9 commit 1b303e4
Show file tree
Hide file tree
Showing 4 changed files with 1,043 additions and 13 deletions.
21 changes: 15 additions & 6 deletions aspa/data.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import json
import re
from dataclasses import dataclass
from typing import Optional
from typing import Optional, Union

reasn = re.compile(r"^AS(\d+)$")


def parse_asn(text: str) -> Optional[int]:
match = reasn.match(text)
def parse_asn(value: Union[str, int]) -> Optional[int]:
if isinstance(value, int):
return value

match = reasn.match(value)
if match:
return int(match.group(1))

Expand All @@ -16,14 +19,20 @@ def parse_asn(text: str) -> Optional[int]:
class ASPA:
customer: int
providers: list[int]
ta: str
ta: Optional[str]

@classmethod
def from_dict(cls, d):
try:
customer = parse_asn(d['customer'])
if 'customer' in d:
customer = parse_asn(d['customer'])
elif 'customer_asid' in d:
customer = parse_asn(d['customer_asid'])
else:
return None

providers = list(map(parse_asn, d['providers']))
return cls(customer, providers, d['ta'])
return cls(customer, providers, d.get('ta'))
except (KeyError, TypeError):
return None

Expand Down
105 changes: 101 additions & 4 deletions aspa/example.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
{
"metadata": {
"generated": 1730172244,
"generatedTime": "2024-10-29T03:24:04Z"
"generated": 1730500980,
"generatedTime": "2024-11-01T22:43:00Z"
},
"aspas": [
{
"customer": "AS970",
"providers": [
"AS54874"
],
"ta": "arin"
},
{
"customer": "AS11358",
"providers": [
Expand Down Expand Up @@ -43,6 +50,13 @@
],
"ta": "arin"
},
{
"customer": "AS21957",
"providers": [
"AS970"
],
"ta": "arin"
},
{
"customer": "AS28584",
"providers": [
Expand Down Expand Up @@ -213,6 +227,13 @@
],
"ta": "ripe"
},
{
"customer": "AS50555",
"providers": [
"AS970"
],
"ta": "ripe"
},
{
"customer": "AS51019",
"providers": [
Expand Down Expand Up @@ -438,6 +459,31 @@
],
"ta": "ripe"
},
{
"customer": "AS200160",
"providers": [
"AS945",
"AS6939",
"AS15353",
"AS21738",
"AS29632",
"AS34465",
"AS34549",
"AS34927",
"AS36369",
"AS48605",
"AS140731",
"AS150249",
"AS199762",
"AS203686",
"AS203913",
"AS210152",
"AS210475",
"AS400304",
"AS400818"
],
"ta": "ripe"
},
{
"customer": "AS200242",
"providers": [
Expand Down Expand Up @@ -615,6 +661,32 @@
],
"ta": "ripe"
},
{
"customer": "AS209025",
"providers": [
"AS945",
"AS6939",
"AS15353",
"AS21738",
"AS29632",
"AS34465",
"AS34549",
"AS34927",
"AS36369",
"AS48605",
"AS140731",
"AS150249",
"AS199762",
"AS200160",
"AS203686",
"AS203913",
"AS210152",
"AS210475",
"AS400304",
"AS400818"
],
"ta": "ripe"
},
{
"customer": "AS210561",
"providers": [
Expand Down Expand Up @@ -656,6 +728,33 @@
],
"ta": "ripe"
},
{
"customer": "AS213086",
"providers": [
"AS945",
"AS6939",
"AS15353",
"AS21738",
"AS29632",
"AS34465",
"AS34549",
"AS34927",
"AS36369",
"AS48605",
"AS140731",
"AS150249",
"AS199762",
"AS200160",
"AS203686",
"AS203913",
"AS207656",
"AS210152",
"AS210475",
"AS400304",
"AS400818"
],
"ta": "ripe"
},
{
"customer": "AS215028",
"providers": [
Expand Down Expand Up @@ -707,7 +806,6 @@
{
"customer": "AS215778",
"providers": [
"AS34465",
"AS39249",
"AS41051",
"AS207656",
Expand Down Expand Up @@ -813,7 +911,6 @@
"customer": "AS401111",
"providers": [
"AS945",
"AS6939",
"AS17676"
],
"ta": "arin"
Expand Down
Loading

0 comments on commit 1b303e4

Please sign in to comment.