Skip to content

Commit

Permalink
Merge branch 'synapse-3xx' of https://github.com/vertexproject/synapse
Browse files Browse the repository at this point in the history
…into synapse-3xx
  • Loading branch information
Cisphyx committed Nov 14, 2024
2 parents 1db53aa + 995e241 commit 5ef71a4
Show file tree
Hide file tree
Showing 14 changed files with 197 additions and 73 deletions.
38 changes: 35 additions & 3 deletions synapse/datamodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,10 @@ def reqProp(self, name):

full = f'{self.name}:{name}'
mesg = f'No property named {full}.'

if (prevname := self.modl.propprevnames.get(full)) is not None:
mesg += f' Did you mean {prevname}?'

raise s_exc.NoSuchProp(mesg=mesg, name=full)

def pack(self):
Expand Down Expand Up @@ -477,6 +481,9 @@ def __init__(self, core=None):
self.formabbr = {} # name: [Form(), ... ]
self.modeldefs = []

self.formprevnames = {}
self.propprevnames = {}

self.univs = {}
self.allunivs = collections.defaultdict(list)

Expand Down Expand Up @@ -634,7 +641,11 @@ def reqProp(self, name, extra=None):
if prop is not None:
return prop

exc = s_exc.NoSuchProp.init(name)
mesg = None
if (prevname := self.propprevnames.get(name)) is not None:
mesg = f'No property named {name}. Did you mean {prevname}?'

exc = s_exc.NoSuchProp.init(name, mesg=mesg)
if extra is not None:
raise extra(exc)
raise exc
Expand Down Expand Up @@ -676,7 +687,11 @@ def reqFormsByLook(self, name, extra=None):
if name.endswith('*'):
return self.reqFormsByPrefix(name[:-1], extra=extra)

exc = s_exc.NoSuchForm.init(name)
mesg = None
if (prevname := self.formprevnames.get(name)) is not None:
mesg = f'No form named {name}. Did you mean {prevname}?'

exc = s_exc.NoSuchForm.init(name, mesg=mesg)
if extra is not None:
exc = extra(exc)

Expand All @@ -692,7 +707,11 @@ def reqPropsByLook(self, name, extra=None):
if name.endswith('*'):
return self.reqFormsByPrefix(name[:-1], extra=extra)

exc = s_exc.NoSuchProp.init(name)
mesg = None
if (prevname := self.propprevnames.get(name)) is not None:
mesg = f'No property named {name}. Did you mean {prevname}?'

exc = s_exc.NoSuchProp.init(name, mesg=mesg)
if extra is not None:
exc = extra(exc)

Expand Down Expand Up @@ -920,6 +939,10 @@ def addForm(self, formname, forminfo, propdefs, checks=True):
self.forms[formname] = form
self.props[formname] = form

if (prevnames := forminfo.get('prevnames')) is not None:
for prevname in prevnames:
self.formprevnames[prevname] = formname

if isinstance(form.type, s_types.Array):
self.arraysbytype[form.type.arraytype.name][form.name] = form

Expand Down Expand Up @@ -1075,6 +1098,12 @@ def _addFormProp(self, form, name, tdef, info):
self.arraysbytype[prop.type.arraytype.name][prop.full] = prop

self.props[prop.full] = prop

if (prevnames := info.get('prevnames')) is not None:
for prevname in prevnames:
prevfull = f'{form.name}:{prevname}'
self.propprevnames[prevfull] = prop.full

return prop

def _prepFormIface(self, form, iface):
Expand Down Expand Up @@ -1252,6 +1281,9 @@ def reqForm(self, name):
return form

mesg = f'No form named {name}.'
if (prevname := self.formprevnames.get(name)) is not None:
mesg += f' Did you mean {prevname}?'

raise s_exc.NoSuchForm(mesg=mesg, name=name)

def univ(self, name):
Expand Down
6 changes: 4 additions & 2 deletions synapse/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ def getModelDefs(self):
'doc': 'The type of timeline.'}),
)),

('meta:timeline:type:taxonomy', {}, ()),
('meta:timeline:type:taxonomy', {
'prevnames': ('meta:timeline:taxonomy',)}, ()),

('meta:event', {}, (

Expand All @@ -229,7 +230,8 @@ def getModelDefs(self):
'doc': 'Type of event.'}),
)),

('meta:event:type:taxonomy', {}, ()),
('meta:event:type:taxonomy', {
'prevnames': ('meta:event:taxonomy',)}, ()),

('meta:ruleset', {}, (
('name', ('str', {'lower': True, 'onespace': True}), {
Expand Down
14 changes: 10 additions & 4 deletions synapse/models/biz.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,17 @@ def getModelDefs(self):
}),
),
'forms': (
('biz:deal:type:taxonomy', {}, ()),
('biz:product:type:taxonomy', {}, ()),
('biz:deal:type:taxonomy', {
'prevnames': ('biz:dealtype',)}, ()),

('biz:product:type:taxonomy', {
'prevnames': ('biz:prodtype',)}, ()),

('biz:deal:status:taxonomy', {
'prevnames': ('biz:dealstatus',)}, ()),

('biz:service:type:taxonomy', {}, ()),
('biz:deal:type:taxonomy', {}, ()),
('biz:deal:status:taxonomy', {}, ()),

('biz:rfp', {}, (
('ext:id', ('str', {}), {
'doc': 'An externally specified identifier for the RFP.',
Expand Down
2 changes: 1 addition & 1 deletion synapse/models/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ def getModelDefs(self):

('identities:ips', ('array', {'type': 'inet:ip', 'uniq': True, 'sorted': True}), {
'doc': 'The fused list of IP addresses identified by the cert CN and SANs.',
}),
'prevnames': ('identities:ipv4s', 'identities:ipv6s')}),

('identities:urls', ('array', {'type': 'inet:url', 'uniq': True, 'sorted': True}), {
'doc': 'The fused list of URLs identified by the cert CN and SANs.',
Expand Down
28 changes: 19 additions & 9 deletions synapse/models/dns.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,21 @@ def getModelDefs(self):
('fqdn', ('inet:fqdn', {}), {'ro': True,
'doc': 'The domain queried for its DNS A record.'}),
('ip', ('inet:ip', {}), {'ro': True,
'doc': 'The IPv4 address returned in the A record.'}),
'doc': 'The IPv4 address returned in the A record.',
'prevnames': ('ipv4',)}),
)),
('inet:dns:aaaa', {}, (
('fqdn', ('inet:fqdn', {}), {'ro': True,
'doc': 'The domain queried for its DNS AAAA record.'}),
'doc': 'The domain queried for its DNS AAAA record.'}),
('ip', ('inet:ip', {}), {'ro': True,
'doc': 'The IPv6 address returned in the AAAA record.'}),
'doc': 'The IPv6 address returned in the AAAA record.',
'prevnames': ('ipv6',)}),
)),
('inet:dns:rev', {}, (
('inet:dns:rev', {'prevnames': ('inet:dns:rev6',)}, (
('ip', ('inet:ip', {}), {'ro': True,
'doc': 'The IP address queried for its DNS PTR record.'}),
'doc': 'The IP address queried for its DNS PTR record.',
'prevnames': ('ipv4', 'ipv6')}),

('fqdn', ('inet:fqdn', {}), {'ro': True,
'doc': 'The domain returned in the PTR record.'}),
)),
Expand Down Expand Up @@ -217,7 +221,9 @@ def getModelDefs(self):
('inet:dns:query', {}, (
('client', ('inet:client', {}), {'ro': True, }),
('name', ('inet:dns:name', {}), {'ro': True, }),
('name:ip', ('inet:ip', {}), {}),
('name:ip', ('inet:ip', {}), {
'prevnames': ('name:ipv4', 'name:ipv6')}),

('name:fqdn', ('inet:fqdn', {}), {}),
('type', ('int', {}), {'ro': True, }),
)),
Expand All @@ -228,7 +234,9 @@ def getModelDefs(self):

('query', ('inet:dns:query', {}), {}),
('query:name', ('inet:dns:name', {}), {}),
('query:name:ip', ('inet:ip', {}), {}),
('query:name:ip', ('inet:ip', {}), {
'prevnames': ('query:name:ipv4', 'query:name:ipv6')}),

('query:name:fqdn', ('inet:fqdn', {}), {}),
('query:type', ('int', {}), {}),

Expand Down Expand Up @@ -291,14 +299,16 @@ def getModelDefs(self):
('fqdn', ('inet:fqdn', {}), {'ro': True,
'doc': 'The domain containing a wild card record.'}),
('ip', ('inet:ip', {}), {'ro': True,
'doc': 'The IPv4 address returned by wild card resolutions.'}),
'doc': 'The IPv4 address returned by wild card resolutions.',
'prevnames': ('ipv4',)}),
)),

('inet:dns:wild:aaaa', {}, (
('fqdn', ('inet:fqdn', {}), {'ro': True,
'doc': 'The domain containing a wild card record.'}),
('ip', ('inet:ip', {}), {'ro': True,
'doc': 'The IPv6 address returned by wild card resolutions.'}),
'doc': 'The IPv6 address returned by wild card resolutions.',
'prevnames': ('ipv6',)}),
)),

('inet:dns:dynreg', {}, (
Expand Down
4 changes: 3 additions & 1 deletion synapse/models/geospace.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,9 @@ def getModelDefs(self):
'doc': 'The node that was observed at the associated time and place.'}),
)),

('geo:place:type:taxonomy', {}, ()),
('geo:place:type:taxonomy', {
'prevnames': ('geo:place:taxonomy',)}, ()),

('geo:place', {}, (

('name', ('geo:name', {}), {
Expand Down
68 changes: 42 additions & 26 deletions synapse/models/inet.py
Original file line number Diff line number Diff line change
Expand Up @@ -1739,7 +1739,8 @@ def getModelDefs(self):
'doc': 'An array of email headers from the message.'}),

('received:from:ip', ('inet:ip', {}), {
'doc': 'The sending SMTP server IP, potentially from the Received: header.'}),
'doc': 'The sending SMTP server IP, potentially from the Received: header.',
'prevnames': ('received:from:ipv4', 'received:from:ipv6')}),

('received:from:fqdn', ('inet:fqdn', {}), {
'doc': 'The sending server FQDN, potentially from the Received: header.'}),
Expand Down Expand Up @@ -1787,26 +1788,32 @@ def getModelDefs(self):
}),
)),

('inet:asnet', {}, (
('inet:asnet', {
'prevnames': ('inet:asnet4', 'inet:asnet6')}, (

('asn', ('inet:asn', {}), {
'ro': True,
'doc': 'The Autonomous System Number (ASN) of the netblock.'
}),
('net', ('inet:net', {}), {
'ro': True,
'doc': 'The IP address range assigned to the ASN.'
}),
'doc': 'The IP address range assigned to the ASN.',
'prevnames': ('net4', 'net6')}),

('net:min', ('inet:ip', {}), {
'ro': True,
'doc': 'The first IP in the range assigned to the ASN.'
}),
'doc': 'The first IP in the range assigned to the ASN.',
'prevnames': ('net4:min', 'net6:min')}),

('net:max', ('inet:ip', {}), {
'ro': True,
'doc': 'The last IP in the range assigned to the ASN.'
}),
'doc': 'The last IP in the range assigned to the ASN.',
'prevnames': ('net4:max', 'net6:max')}),
)),

('inet:cidr', {}, (
('inet:cidr', {
'prevnames': ('inet:cidr4', 'inet:cidr6')}, (

('broadcast', ('inet:ip', {}), {
'ro': True,
'doc': 'The broadcast IP address from the CIDR notation.'
Expand All @@ -1828,8 +1835,9 @@ def getModelDefs(self):
}),
('ip', ('inet:ip', {}), {
'ro': True,
'doc': 'The IP of the client.'
}),
'doc': 'The IP of the client.',
'prevnames': ('ipv4', 'ipv6')}),

('host', ('it:host', {}), {
'ro': True,
'doc': 'The it:host node for the client.'
Expand Down Expand Up @@ -2129,8 +2137,9 @@ def getModelDefs(self):
'doc': 'The ethernet (MAC) address of the interface.'
}),
('ip', ('inet:ip', {}), {
'doc': 'The IP address of the interface.'
}),
'doc': 'The IP address of the interface.',
'prevnames': ('ipv4', 'ipv6')}),

('phone', ('tel:phone', {}), {
'doc': 'The telephone number of the interface.'
}),
Expand All @@ -2151,7 +2160,8 @@ def getModelDefs(self):
}),
)),

('inet:ip', {}, (
('inet:ip', {
'prevnames': ('inet:ipv4', 'inet:ipv6')}, (

('asn', ('inet:asn', {}), {
'doc': 'The ASN to which the IP address is currently assigned.'}),
Expand Down Expand Up @@ -2218,8 +2228,9 @@ def getModelDefs(self):
}),
('ip', ('inet:ip', {}), {
'ro': True,
'doc': 'The IP of the server.'
}),
'doc': 'The IP of the server.',
'prevnames': ('ipv4', 'ipv6')}),

('host', ('it:host', {}), {
'ro': True,
'doc': 'The it:host node for the server.'
Expand Down Expand Up @@ -2273,8 +2284,9 @@ def getModelDefs(self):
}),
('ip', ('inet:ip', {}), {
'ro': True,
'doc': 'The IP address used in the URL (e.g., http://1.2.3.4/page.html).'
}),
'doc': 'The IP address used in the URL (e.g., http://1.2.3.4/page.html).',
'prevnames': ('ipv4', 'ipv6')}),

('passwd', ('inet:passwd', {}), {
'ro': True,
'doc': 'The optional password used to access the URL.'
Expand Down Expand Up @@ -3035,8 +3047,9 @@ def getModelDefs(self):
'doc': 'The FQDN of the host server when using the legacy WHOIS Protocol.'
}),
('ip', ('inet:ip', {}), {
'doc': 'The IP address queried.'
}),
'doc': 'The IP address queried.',
'prevnames': ('ipv4', 'ipv6')}),

('success', ('bool', {}), {
'doc': 'Whether the host returned a valid response for the query.'
}),
Expand All @@ -3047,14 +3060,17 @@ def getModelDefs(self):

('inet:whois:iprec', {}, (
('net', ('inet:net', {}), {
'doc': 'The IP address range assigned.'
}),
'doc': 'The IP address range assigned.',
'prevnames': ('net4', 'net6')}),

('net:min', ('inet:ip', {}), {
'doc': 'The first IP in the range assigned.'
}),
'doc': 'The first IP in the range assigned.',
'prevnames': ('net4:min', 'net6:min')}),

('net:max', ('inet:ip', {}), {
'doc': 'The last IP in the range assigned.'
}),
'doc': 'The last IP in the range assigned.',
'prevnames': ('net4:max', 'net6:max')}),

('asof', ('time', {}), {
'doc': 'The date of the record.'
}),
Expand Down
Loading

0 comments on commit 5ef71a4

Please sign in to comment.