mirror of
https://git.dn42.dev/dn42/registry.git
synced 2025-05-09 22:25:23 +08:00
update rpsl whois
This commit is contained in:
parent
0ddf8af686
commit
92a54621f0
4 changed files with 31 additions and 13 deletions
|
@ -262,4 +262,6 @@ def index_files(path: str,
|
||||||
for f in files:
|
for f in files:
|
||||||
dom = FileDOM.from_file(os.path.join(root, f))
|
dom = FileDOM.from_file(os.path.join(root, f))
|
||||||
dom.namespace = namespace
|
dom.namespace = namespace
|
||||||
|
if dom.schema in primary_keys:
|
||||||
|
dom.primary_key = primary_keys[dom.schema]
|
||||||
yield dom
|
yield dom
|
||||||
|
|
|
@ -19,7 +19,8 @@ class RPSL:
|
||||||
self._config = config
|
self._config = config
|
||||||
self._files = {} # type: Dict[Tuple[str, str], str]
|
self._files = {} # type: Dict[Tuple[str, str], str]
|
||||||
self._lookup = {} # type: Dict[str, List[Tuple[str, str]]]
|
self._lookup = {} # type: Dict[str, List[Tuple[str, str]]]
|
||||||
self._links = {} # type: Dict[Tuple[str, str], List[Tuple[str, str]]]
|
self._links = {} \
|
||||||
|
# type: Dict[Tuple[str, str], List[Tuple[str, str, str]]]
|
||||||
self._nettree = None # type: NetTree
|
self._nettree = None # type: NetTree
|
||||||
self._schema = {} # type: Dict[str, SchemaDOM]
|
self._schema = {} # type: Dict[str, SchemaDOM]
|
||||||
self._load_index()
|
self._load_index()
|
||||||
|
@ -36,8 +37,9 @@ class RPSL:
|
||||||
for line in fd.readlines():
|
for line in fd.readlines():
|
||||||
sp = line.strip().split(sep="|")
|
sp = line.strip().split(sep="|")
|
||||||
key = (sp[0], sp[1])
|
key = (sp[0], sp[1])
|
||||||
self._links[key] = self._lookup.get(key, [])
|
arr = self._links.get(key, [])
|
||||||
self._links[key].append((sp[2], sp[3]))
|
arr.append((sp[2], sp[3], sp[4]))
|
||||||
|
self._links[key] = arr
|
||||||
|
|
||||||
self._nettree = NetTree.read_csv(self._config.nettree_file)
|
self._nettree = NetTree.read_csv(self._config.nettree_file)
|
||||||
|
|
||||||
|
@ -71,9 +73,16 @@ class RPSL:
|
||||||
if schema is None:
|
if schema is None:
|
||||||
keys = self._lookup.get(text, [])
|
keys = self._lookup.get(text, [])
|
||||||
|
|
||||||
|
related = set()
|
||||||
|
|
||||||
for i in keys:
|
for i in keys:
|
||||||
yield self.load_file(self._files[i])
|
yield self.load_file(self._files[i])
|
||||||
print(self.links(i))
|
for link in self.links(i):
|
||||||
|
key = (link[1], link[2])
|
||||||
|
related.add(key)
|
||||||
|
|
||||||
|
for i in related:
|
||||||
|
yield self.load_file(self._files[i])
|
||||||
|
|
||||||
def load_file(self, fn: str) -> FileDOM:
|
def load_file(self, fn: str) -> FileDOM:
|
||||||
"load file"
|
"load file"
|
||||||
|
|
|
@ -9,6 +9,7 @@ import log
|
||||||
from .filedom import FileDOM, Row
|
from .filedom import FileDOM, Row
|
||||||
|
|
||||||
DOM = TypeVar("DOM", bound="FileDOM")
|
DOM = TypeVar("DOM", bound="FileDOM")
|
||||||
|
STATE = TypeVar("STATE", bound="State")
|
||||||
|
|
||||||
|
|
||||||
class Level(Enum):
|
class Level(Enum):
|
||||||
|
@ -34,6 +35,11 @@ class State:
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return "PASS" if self.state else "FAIL"
|
return "PASS" if self.state else "FAIL"
|
||||||
|
|
||||||
|
def extend(self, state: STATE):
|
||||||
|
"apply state to state"
|
||||||
|
self.msgs.extend(state.msgs)
|
||||||
|
self.state = state.state
|
||||||
|
|
||||||
def print_msgs(self):
|
def print_msgs(self):
|
||||||
"""print out state info"""
|
"""print out state info"""
|
||||||
for (level, row, msg) in self.msgs:
|
for (level, row, msg) in self.msgs:
|
||||||
|
@ -156,16 +162,18 @@ class SchemaDOM:
|
||||||
if state is None:
|
if state is None:
|
||||||
state = State()
|
state = State()
|
||||||
|
|
||||||
|
file_state = State()
|
||||||
if not f.valid:
|
if not f.valid:
|
||||||
state.error(Row("", "", 0, f.src), "file does not parse")
|
file_state.error(Row("", "", 0, f.src), "file does not parse")
|
||||||
|
|
||||||
state = self._check_file_structure(state, f)
|
file_state = self._check_file_structure(file_state, f)
|
||||||
state = self._check_file_values(state, f, lookups)
|
file_state = self._check_file_values(file_state, f, lookups)
|
||||||
state = inetnum_check(state, f)
|
file_state = inetnum_check(file_state, f)
|
||||||
|
|
||||||
print("CHECK\t%-10s\t%-44s\t%s\tMNTNERS: %s" %
|
print("CHECK\t%-10s\t%-44s\t%s\tMNTNERS: %s" %
|
||||||
(f.schema, f.src.split("/")[-1], state, ','.join(f.mntner)))
|
(f.schema, f.src.split("/")[-1], file_state, ','.join(f.mntner)))
|
||||||
|
|
||||||
|
state.extend(file_state)
|
||||||
return state
|
return state
|
||||||
|
|
||||||
def _check_file_structure(self, state: State, f: FileDOM) -> State:
|
def _check_file_structure(self, state: State, f: FileDOM) -> State:
|
||||||
|
|
|
@ -27,9 +27,8 @@ def run(args: List[str], env: Dict[str, str]) -> int:
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
config = Config.from_path(path)
|
config = Config.from_path(path)
|
||||||
if not os.path.exists(config.index_file) or \
|
if not os.path.exists(config.config_file):
|
||||||
not os.path.exists(config.schema_file):
|
print("RPSL config files not found. do `rpsl init`?", file=sys.stderr)
|
||||||
print("RPSL index files not found. do `rpsl index`?", file=sys.stderr)
|
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
if not os.path.isdir(config.schema_dir):
|
if not os.path.isdir(config.schema_dir):
|
||||||
|
@ -150,7 +149,7 @@ def generate_links(
|
||||||
for (link, refs) in links.items():
|
for (link, refs) in links.items():
|
||||||
d = dom.get(link)
|
d = dom.get(link)
|
||||||
if d is None:
|
if d is None:
|
||||||
return
|
continue
|
||||||
|
|
||||||
found = False
|
found = False
|
||||||
for ref in refs:
|
for ref in refs:
|
||||||
|
|
Loading…
Add table
Reference in a new issue