1
mirror of https://git.dn42.dev/dn42/registry.git synced 2024-11-19 21:26:48 +01:00

update rpsl whois

This commit is contained in:
Jonathan Lundy 2020-06-26 17:03:39 -06:00
parent 0ddf8af686
commit 92a54621f0
No known key found for this signature in database
GPG Key ID: C63E6D61F3035024
4 changed files with 31 additions and 13 deletions

View File

@ -262,4 +262,6 @@ def index_files(path: str,
for f in files:
dom = FileDOM.from_file(os.path.join(root, f))
dom.namespace = namespace
if dom.schema in primary_keys:
dom.primary_key = primary_keys[dom.schema]
yield dom

View File

@ -19,7 +19,8 @@ class RPSL:
self._config = config
self._files = {} # type: Dict[Tuple[str, 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._schema = {} # type: Dict[str, SchemaDOM]
self._load_index()
@ -36,8 +37,9 @@ class RPSL:
for line in fd.readlines():
sp = line.strip().split(sep="|")
key = (sp[0], sp[1])
self._links[key] = self._lookup.get(key, [])
self._links[key].append((sp[2], sp[3]))
arr = self._links.get(key, [])
arr.append((sp[2], sp[3], sp[4]))
self._links[key] = arr
self._nettree = NetTree.read_csv(self._config.nettree_file)
@ -71,9 +73,16 @@ class RPSL:
if schema is None:
keys = self._lookup.get(text, [])
related = set()
for i in keys:
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:
"load file"

View File

@ -9,6 +9,7 @@ import log
from .filedom import FileDOM, Row
DOM = TypeVar("DOM", bound="FileDOM")
STATE = TypeVar("STATE", bound="State")
class Level(Enum):
@ -34,6 +35,11 @@ class State:
def __str__(self) -> str:
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):
"""print out state info"""
for (level, row, msg) in self.msgs:
@ -156,16 +162,18 @@ class SchemaDOM:
if state is None:
state = State()
file_state = State()
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)
state = self._check_file_values(state, f, lookups)
state = inetnum_check(state, f)
file_state = self._check_file_structure(file_state, f)
file_state = self._check_file_values(file_state, f, lookups)
file_state = inetnum_check(file_state, f)
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
def _check_file_structure(self, state: State, f: FileDOM) -> State:

View File

@ -27,9 +27,8 @@ def run(args: List[str], env: Dict[str, str]) -> int:
return 1
config = Config.from_path(path)
if not os.path.exists(config.index_file) or \
not os.path.exists(config.schema_file):
print("RPSL index files not found. do `rpsl index`?", file=sys.stderr)
if not os.path.exists(config.config_file):
print("RPSL config files not found. do `rpsl init`?", file=sys.stderr)
return 1
if not os.path.isdir(config.schema_dir):
@ -150,7 +149,7 @@ def generate_links(
for (link, refs) in links.items():
d = dom.get(link)
if d is None:
return
continue
found = False
for ref in refs: