Ejemplo n.º 1
0
 def has_asset(cls, as_set):
     """
     Returns true if as-set has members in cache
     :param as_set:
     :return:
     """
     if is_asn(as_set[2:]):
         return True
     db = get_db()
     collection = db.noc.whois.asset.members
     return bool(collection.find_one({"_id": as_set}, {"_id": 1}))
Ejemplo n.º 2
0
 def resolve_as_set(cls, as_set, seen=None, collection=None):
     members = set()
     if seen is None:
         seen = set()
     if collection is None:
         db = get_db()
         collection = db.noc.whois.asset.members
     for a in as_set.split():
         a = a.upper()
         seen.add(a)
         if is_asn(a[2:]):
             # ASN Given
             members.update([a.upper()])
         else:
             o = collection.find_one({"_id": a}, {"members": 1})
             if o:
                 for m in [x for x in o["members"] if x not in seen]:
                     members.update(cls.resolve_as_set(m, seen, collection))
     return members
Ejemplo n.º 3
0
def test_is_asn(raw, expected):
    assert is_asn(raw) is expected