synapse 2.155.0__py311-none-any.whl → 2.156.0__py311-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of synapse might be problematic. Click here for more details.
- synapse/cmds/cortex.py +2 -14
- synapse/common.py +1 -28
- synapse/cortex.py +10 -510
- synapse/lib/ast.py +60 -1
- synapse/lib/cell.py +33 -8
- synapse/lib/certdir.py +11 -0
- synapse/lib/cmdr.py +0 -5
- synapse/lib/gis.py +2 -2
- synapse/lib/httpapi.py +1 -43
- synapse/lib/layer.py +64 -201
- synapse/lib/lmdbslab.py +11 -0
- synapse/lib/node.py +1 -3
- synapse/lib/parser.py +10 -0
- synapse/lib/snap.py +121 -21
- synapse/lib/storm.lark +23 -6
- synapse/lib/storm.py +15 -338
- synapse/lib/storm_format.py +5 -0
- synapse/lib/stormlib/gen.py +1 -2
- synapse/lib/stormlib/gis.py +41 -0
- synapse/lib/stormlib/stats.py +21 -2
- synapse/lib/stormlib/storm.py +16 -1
- synapse/lib/stormtypes.py +225 -12
- synapse/lib/version.py +2 -2
- synapse/lib/view.py +96 -21
- synapse/models/inet.py +60 -30
- synapse/models/infotech.py +56 -1
- synapse/models/orgs.py +3 -0
- synapse/models/risk.py +15 -0
- synapse/models/syn.py +0 -38
- synapse/tests/test_cmds_cortex.py +1 -1
- synapse/tests/test_cortex.py +32 -336
- synapse/tests/test_lib_agenda.py +19 -54
- synapse/tests/test_lib_aha.py +97 -0
- synapse/tests/test_lib_ast.py +402 -0
- synapse/tests/test_lib_grammar.py +30 -10
- synapse/tests/test_lib_httpapi.py +0 -46
- synapse/tests/test_lib_layer.py +19 -234
- synapse/tests/test_lib_lmdbslab.py +22 -0
- synapse/tests/test_lib_snap.py +9 -0
- synapse/tests/test_lib_storm.py +16 -309
- synapse/tests/test_lib_stormlib_gis.py +21 -0
- synapse/tests/test_lib_stormlib_stats.py +107 -20
- synapse/tests/test_lib_stormlib_storm.py +25 -0
- synapse/tests/test_lib_stormtypes.py +231 -8
- synapse/tests/test_lib_view.py +6 -13
- synapse/tests/test_model_base.py +1 -1
- synapse/tests/test_model_inet.py +15 -0
- synapse/tests/test_model_infotech.py +60 -0
- synapse/tests/test_model_orgs.py +10 -0
- synapse/tests/test_model_person.py +0 -3
- synapse/tests/test_model_risk.py +20 -0
- synapse/tests/test_model_syn.py +20 -34
- synapse/tests/test_tools_csvtool.py +2 -1
- synapse/tests/test_tools_feed.py +4 -30
- synapse/tools/csvtool.py +2 -1
- {synapse-2.155.0.dist-info → synapse-2.156.0.dist-info}/METADATA +3 -3
- {synapse-2.155.0.dist-info → synapse-2.156.0.dist-info}/RECORD +60 -62
- {synapse-2.155.0.dist-info → synapse-2.156.0.dist-info}/WHEEL +1 -1
- synapse/cmds/cron.py +0 -726
- synapse/cmds/trigger.py +0 -319
- synapse/tests/test_cmds_cron.py +0 -453
- synapse/tests/test_cmds_trigger.py +0 -176
- {synapse-2.155.0.dist-info → synapse-2.156.0.dist-info}/LICENSE +0 -0
- {synapse-2.155.0.dist-info → synapse-2.156.0.dist-info}/top_level.txt +0 -0
synapse/lib/stormtypes.py
CHANGED
|
@@ -6317,6 +6317,29 @@ class Layer(Prim):
|
|
|
6317
6317
|
{'name': 'propname', 'type': 'str', 'desc': 'The property or form name to look up.', },
|
|
6318
6318
|
{'name': 'maxsize', 'type': 'int', 'desc': 'The maximum number of rows to look up.',
|
|
6319
6319
|
'default': None, },
|
|
6320
|
+
{'name': 'valu', 'type': 'any', 'default': '$lib.undef',
|
|
6321
|
+
'desc': 'A specific value of the property to look up.', },
|
|
6322
|
+
),
|
|
6323
|
+
'returns': {'type': 'int', 'desc': 'The count of rows.', }}},
|
|
6324
|
+
{'name': 'getPropArrayCount',
|
|
6325
|
+
'desc': 'Get the number of individual value rows in the layer for the given array property name.',
|
|
6326
|
+
'type': {'type': 'function', '_funcname': '_methGetPropArrayCount',
|
|
6327
|
+
'args': (
|
|
6328
|
+
{'name': 'propname', 'type': 'str', 'desc': 'The property name to look up.', },
|
|
6329
|
+
{'name': 'valu', 'type': 'any', 'default': '$lib.undef',
|
|
6330
|
+
'desc': 'A specific value in the array property to look up.', },
|
|
6331
|
+
),
|
|
6332
|
+
'returns': {'type': 'int', 'desc': 'The count of rows.', }}},
|
|
6333
|
+
{'name': 'getTagPropCount',
|
|
6334
|
+
'desc': 'Get the number of rows in the layer for the given tag property.',
|
|
6335
|
+
'type': {'type': 'function', '_funcname': '_methGetTagPropCount',
|
|
6336
|
+
'args': (
|
|
6337
|
+
{'name': 'tag', 'type': 'str', 'desc': 'The tag to look up.', },
|
|
6338
|
+
{'name': 'propname', 'type': 'str', 'desc': 'The property name to look up.', },
|
|
6339
|
+
{'name': 'form', 'type': 'str', 'default': None,
|
|
6340
|
+
'desc': 'The optional form to look up.', },
|
|
6341
|
+
{'name': 'valu', 'type': 'any', 'default': '$lib.undef',
|
|
6342
|
+
'desc': 'A specific value of the property to look up.', },
|
|
6320
6343
|
),
|
|
6321
6344
|
'returns': {'type': 'int', 'desc': 'The count of rows.', }}},
|
|
6322
6345
|
{'name': 'getFormCounts', 'desc': '''
|
|
@@ -6514,6 +6537,8 @@ class Layer(Prim):
|
|
|
6514
6537
|
'liftByProp': self.liftByProp,
|
|
6515
6538
|
'getTagCount': self._methGetTagCount,
|
|
6516
6539
|
'getPropCount': self._methGetPropCount,
|
|
6540
|
+
'getTagPropCount': self._methGetTagPropCount,
|
|
6541
|
+
'getPropArrayCount': self._methGetPropArrayCount,
|
|
6517
6542
|
'getFormCounts': self._methGetFormcount,
|
|
6518
6543
|
'getStorNode': self.getStorNode,
|
|
6519
6544
|
'getStorNodes': self.getStorNodes,
|
|
@@ -6678,7 +6703,7 @@ class Layer(Prim):
|
|
|
6678
6703
|
return await layr.getTagCount(tagname, formname=formname)
|
|
6679
6704
|
|
|
6680
6705
|
@stormfunc(readonly=True)
|
|
6681
|
-
async def _methGetPropCount(self, propname, maxsize=None):
|
|
6706
|
+
async def _methGetPropCount(self, propname, maxsize=None, valu=undef):
|
|
6682
6707
|
propname = await tostr(propname)
|
|
6683
6708
|
maxsize = await toint(maxsize, noneok=True)
|
|
6684
6709
|
|
|
@@ -6691,13 +6716,86 @@ class Layer(Prim):
|
|
|
6691
6716
|
await self.runt.reqUserCanReadLayer(layriden)
|
|
6692
6717
|
layr = self.runt.snap.core.getLayer(layriden)
|
|
6693
6718
|
|
|
6719
|
+
if valu is undef:
|
|
6720
|
+
if prop.isform:
|
|
6721
|
+
return await layr.getPropCount(prop.name, None, maxsize=maxsize)
|
|
6722
|
+
|
|
6723
|
+
if prop.isuniv:
|
|
6724
|
+
return await layr.getPropCount(None, prop.name, maxsize=maxsize)
|
|
6725
|
+
|
|
6726
|
+
return await layr.getPropCount(prop.form.name, prop.name, maxsize=maxsize)
|
|
6727
|
+
|
|
6728
|
+
valu = await toprim(valu)
|
|
6729
|
+
norm, info = prop.type.norm(valu)
|
|
6730
|
+
|
|
6731
|
+
if prop.isform:
|
|
6732
|
+
return layr.getPropValuCount(prop.name, None, prop.type.stortype, norm)
|
|
6733
|
+
|
|
6734
|
+
if prop.isuniv:
|
|
6735
|
+
return layr.getPropValuCount(None, prop.name, prop.type.stortype, norm)
|
|
6736
|
+
|
|
6737
|
+
return layr.getPropValuCount(prop.form.name, prop.name, prop.type.stortype, norm)
|
|
6738
|
+
|
|
6739
|
+
@stormfunc(readonly=True)
|
|
6740
|
+
async def _methGetPropArrayCount(self, propname, valu=undef):
|
|
6741
|
+
propname = await tostr(propname)
|
|
6742
|
+
|
|
6743
|
+
prop = self.runt.snap.core.model.prop(propname)
|
|
6744
|
+
if prop is None:
|
|
6745
|
+
mesg = f'No property named {propname}'
|
|
6746
|
+
raise s_exc.NoSuchProp(mesg=mesg)
|
|
6747
|
+
|
|
6748
|
+
if not prop.type.isarray:
|
|
6749
|
+
mesg = f'Property is not an array type: {prop.type.name}.'
|
|
6750
|
+
raise s_exc.BadTypeValu(mesg=mesg)
|
|
6751
|
+
|
|
6752
|
+
layriden = self.valu.get('iden')
|
|
6753
|
+
await self.runt.reqUserCanReadLayer(layriden)
|
|
6754
|
+
layr = self.runt.snap.core.getLayer(layriden)
|
|
6755
|
+
|
|
6756
|
+
if valu is undef:
|
|
6757
|
+
if prop.isform:
|
|
6758
|
+
return await layr.getPropArrayCount(prop.name, None)
|
|
6759
|
+
|
|
6760
|
+
if prop.isuniv:
|
|
6761
|
+
return await layr.getPropArrayCount(None, prop.name)
|
|
6762
|
+
|
|
6763
|
+
return await layr.getPropArrayCount(prop.form.name, prop.name)
|
|
6764
|
+
|
|
6765
|
+
valu = await toprim(valu)
|
|
6766
|
+
atyp = prop.type.arraytype
|
|
6767
|
+
norm, info = atyp.norm(valu)
|
|
6768
|
+
|
|
6694
6769
|
if prop.isform:
|
|
6695
|
-
return
|
|
6770
|
+
return layr.getPropArrayValuCount(prop.name, None, atyp.stortype, norm)
|
|
6696
6771
|
|
|
6697
6772
|
if prop.isuniv:
|
|
6698
|
-
return
|
|
6773
|
+
return layr.getPropArrayValuCount(None, prop.name, atyp.stortype, norm)
|
|
6774
|
+
|
|
6775
|
+
return layr.getPropArrayValuCount(prop.form.name, prop.name, atyp.stortype, norm)
|
|
6776
|
+
|
|
6777
|
+
@stormfunc(readonly=True)
|
|
6778
|
+
async def _methGetTagPropCount(self, tag, propname, form=None, valu=undef):
|
|
6779
|
+
tag = await tostr(tag)
|
|
6780
|
+
propname = await tostr(propname)
|
|
6781
|
+
form = await tostr(form, noneok=True)
|
|
6782
|
+
|
|
6783
|
+
prop = self.runt.snap.core.model.getTagProp(propname)
|
|
6784
|
+
if prop is None:
|
|
6785
|
+
mesg = f'No tag property named {propname}'
|
|
6786
|
+
raise s_exc.NoSuchTagProp(name=propname, mesg=mesg)
|
|
6699
6787
|
|
|
6700
|
-
|
|
6788
|
+
layriden = self.valu.get('iden')
|
|
6789
|
+
await self.runt.reqUserCanReadLayer(layriden)
|
|
6790
|
+
layr = self.runt.snap.core.getLayer(layriden)
|
|
6791
|
+
|
|
6792
|
+
if valu is undef:
|
|
6793
|
+
return await layr.getTagPropCount(form, tag, prop.name)
|
|
6794
|
+
|
|
6795
|
+
valu = await toprim(valu)
|
|
6796
|
+
norm, info = prop.type.norm(valu)
|
|
6797
|
+
|
|
6798
|
+
return layr.getTagPropValuCount(form, tag, prop.name, prop.type.stortype, norm)
|
|
6701
6799
|
|
|
6702
6800
|
@stormfunc(readonly=True)
|
|
6703
6801
|
async def _methLayerEdits(self, offs=0, wait=True, size=None):
|
|
@@ -7022,6 +7120,63 @@ class View(Prim):
|
|
|
7022
7120
|
{'type': 'dict',
|
|
7023
7121
|
'desc': "Dictionary containing form names and the count of the nodes in the View's Layers.", }}},
|
|
7024
7122
|
|
|
7123
|
+
{'name': 'getPropCount',
|
|
7124
|
+
'desc': '''
|
|
7125
|
+
Get the number of nodes in the View with a specific property and optional value.
|
|
7126
|
+
|
|
7127
|
+
Notes:
|
|
7128
|
+
This is a fast approximate count calculated by summing the number of
|
|
7129
|
+
nodes with the property value in each layer of the view. Property values
|
|
7130
|
+
which are overwritten by different values in higher layers will still
|
|
7131
|
+
be included in the count.
|
|
7132
|
+
''',
|
|
7133
|
+
'type': {'type': 'function', '_funcname': '_methGetPropCount',
|
|
7134
|
+
'args': (
|
|
7135
|
+
{'name': 'propname', 'type': 'str', 'desc': 'The property name to look up.', },
|
|
7136
|
+
{'name': 'valu', 'type': 'any', 'default': '$lib.undef',
|
|
7137
|
+
'desc': 'The value of the property to look up.', },
|
|
7138
|
+
),
|
|
7139
|
+
'returns': {'type': 'int', 'desc': 'The count of nodes.', }}},
|
|
7140
|
+
|
|
7141
|
+
{'name': 'getPropArrayCount',
|
|
7142
|
+
'desc': '''
|
|
7143
|
+
Get the number of invidivual array property values in the View for the given array property name.
|
|
7144
|
+
|
|
7145
|
+
Notes:
|
|
7146
|
+
This is a fast approximate count calculated by summing the number of
|
|
7147
|
+
array property values in each layer of the view. Property values
|
|
7148
|
+
which are overwritten by different values in higher layers will
|
|
7149
|
+
still be included in the count.
|
|
7150
|
+
''',
|
|
7151
|
+
'type': {'type': 'function', '_funcname': '_methGetPropArrayCount',
|
|
7152
|
+
'args': (
|
|
7153
|
+
{'name': 'propname', 'type': 'str', 'desc': 'The property name to look up.', },
|
|
7154
|
+
{'name': 'valu', 'type': 'any', 'default': '$lib.undef',
|
|
7155
|
+
'desc': 'The value in the array property to look up.', },
|
|
7156
|
+
),
|
|
7157
|
+
'returns': {'type': 'int', 'desc': 'The count of nodes.', }}},
|
|
7158
|
+
|
|
7159
|
+
{'name': 'getTagPropCount',
|
|
7160
|
+
'desc': '''
|
|
7161
|
+
Get the number of nodes in the View with the given tag property and optional value.
|
|
7162
|
+
|
|
7163
|
+
Notes:
|
|
7164
|
+
This is a fast approximate count calculated by summing the number of
|
|
7165
|
+
nodes with the tag property value in each layer of the view.
|
|
7166
|
+
Values which are overwritten by different values in higher layers
|
|
7167
|
+
will still be included in the count.
|
|
7168
|
+
''',
|
|
7169
|
+
'type': {'type': 'function', '_funcname': '_methGetTagPropCount',
|
|
7170
|
+
'args': (
|
|
7171
|
+
{'name': 'tag', 'type': 'str', 'desc': 'The tag to look up.', },
|
|
7172
|
+
{'name': 'propname', 'type': 'str', 'desc': 'The property name to look up.', },
|
|
7173
|
+
{'name': 'form', 'type': 'str', 'default': None,
|
|
7174
|
+
'desc': 'The optional form to look up.', },
|
|
7175
|
+
{'name': 'valu', 'type': 'any', 'default': '$lib.undef',
|
|
7176
|
+
'desc': 'The value of the property to look up.', },
|
|
7177
|
+
),
|
|
7178
|
+
'returns': {'type': 'int', 'desc': 'The count of nodes.', }}},
|
|
7179
|
+
|
|
7025
7180
|
{'name': 'detach', 'desc': 'Detach the view from its parent. WARNING: This cannot be reversed.',
|
|
7026
7181
|
'type': {'type': 'function', '_funcname': 'detach',
|
|
7027
7182
|
'args': (),
|
|
@@ -7059,6 +7214,9 @@ class View(Prim):
|
|
|
7059
7214
|
'addNodeEdits': self._methAddNodeEdits,
|
|
7060
7215
|
'getEdgeVerbs': self._methGetEdgeVerbs,
|
|
7061
7216
|
'getFormCounts': self._methGetFormcount,
|
|
7217
|
+
'getPropCount': self._methGetPropCount,
|
|
7218
|
+
'getTagPropCount': self._methGetTagPropCount,
|
|
7219
|
+
'getPropArrayCount': self._methGetPropArrayCount,
|
|
7062
7220
|
}
|
|
7063
7221
|
|
|
7064
7222
|
async def addNode(self, form, valu, props=None):
|
|
@@ -7112,6 +7270,53 @@ class View(Prim):
|
|
|
7112
7270
|
todo = s_common.todo('getFormCounts')
|
|
7113
7271
|
return await self.viewDynCall(todo, ('view', 'read'))
|
|
7114
7272
|
|
|
7273
|
+
@stormfunc(readonly=True)
|
|
7274
|
+
async def _methGetPropCount(self, propname, valu=undef):
|
|
7275
|
+
propname = await tostr(propname)
|
|
7276
|
+
|
|
7277
|
+
if valu is undef:
|
|
7278
|
+
valu = s_common.novalu
|
|
7279
|
+
else:
|
|
7280
|
+
valu = await toprim(valu)
|
|
7281
|
+
|
|
7282
|
+
viewiden = self.valu.get('iden')
|
|
7283
|
+
self.runt.confirm(('view', 'read'), gateiden=viewiden)
|
|
7284
|
+
view = self.runt.snap.core.getView(viewiden)
|
|
7285
|
+
|
|
7286
|
+
return await view.getPropCount(propname, valu=valu)
|
|
7287
|
+
|
|
7288
|
+
@stormfunc(readonly=True)
|
|
7289
|
+
async def _methGetTagPropCount(self, tag, propname, form=None, valu=undef):
|
|
7290
|
+
tag = await tostr(tag)
|
|
7291
|
+
propname = await tostr(propname)
|
|
7292
|
+
form = await tostr(form, noneok=True)
|
|
7293
|
+
|
|
7294
|
+
if valu is undef:
|
|
7295
|
+
valu = s_common.novalu
|
|
7296
|
+
else:
|
|
7297
|
+
valu = await toprim(valu)
|
|
7298
|
+
|
|
7299
|
+
viewiden = self.valu.get('iden')
|
|
7300
|
+
self.runt.confirm(('view', 'read'), gateiden=viewiden)
|
|
7301
|
+
view = self.runt.snap.core.getView(viewiden)
|
|
7302
|
+
|
|
7303
|
+
return await view.getTagPropCount(form, tag, propname, valu=valu)
|
|
7304
|
+
|
|
7305
|
+
@stormfunc(readonly=True)
|
|
7306
|
+
async def _methGetPropArrayCount(self, propname, valu=undef):
|
|
7307
|
+
propname = await tostr(propname)
|
|
7308
|
+
|
|
7309
|
+
if valu is undef:
|
|
7310
|
+
valu = s_common.novalu
|
|
7311
|
+
else:
|
|
7312
|
+
valu = await toprim(valu)
|
|
7313
|
+
|
|
7314
|
+
viewiden = self.valu.get('iden')
|
|
7315
|
+
self.runt.confirm(('view', 'read'), gateiden=viewiden)
|
|
7316
|
+
view = self.runt.snap.core.getView(viewiden)
|
|
7317
|
+
|
|
7318
|
+
return await view.getPropArrayCount(propname, valu=valu)
|
|
7319
|
+
|
|
7115
7320
|
@stormfunc(readonly=True)
|
|
7116
7321
|
async def _methGetEdges(self, verb=None):
|
|
7117
7322
|
verb = await toprim(verb)
|
|
@@ -7155,8 +7360,14 @@ class View(Prim):
|
|
|
7155
7360
|
else:
|
|
7156
7361
|
valu = await tostr(await toprim(valu), noneok=True)
|
|
7157
7362
|
|
|
7363
|
+
if name == 'parent' and valu is not None:
|
|
7364
|
+
self.runt.snap.core.reqView(valu, mesg='The parent view must already exist.')
|
|
7365
|
+
self.runt.confirm(('view', 'read'), gateiden=valu)
|
|
7366
|
+
self.runt.confirm(('view', 'fork'), gateiden=valu)
|
|
7367
|
+
|
|
7158
7368
|
elif name == 'nomerge':
|
|
7159
7369
|
valu = await tobool(valu)
|
|
7370
|
+
|
|
7160
7371
|
elif name == 'layers':
|
|
7161
7372
|
|
|
7162
7373
|
view = self._reqView()
|
|
@@ -7185,8 +7396,11 @@ class View(Prim):
|
|
|
7185
7396
|
mesg = f'View does not support setting: {name}'
|
|
7186
7397
|
raise s_exc.BadOptValu(mesg=mesg)
|
|
7187
7398
|
|
|
7188
|
-
|
|
7189
|
-
|
|
7399
|
+
view = self.runt.snap.core.reqView(self.valu.get('iden'))
|
|
7400
|
+
|
|
7401
|
+
self.runt.confirm(('view', 'set', name), gateiden=view.iden)
|
|
7402
|
+
await view.setViewInfo(name, valu)
|
|
7403
|
+
|
|
7190
7404
|
self.valu[name] = valu
|
|
7191
7405
|
|
|
7192
7406
|
@stormfunc(readonly=True)
|
|
@@ -7217,10 +7431,9 @@ class View(Prim):
|
|
|
7217
7431
|
useriden = self.runt.user.iden
|
|
7218
7432
|
viewiden = self.valu.get('iden')
|
|
7219
7433
|
|
|
7220
|
-
|
|
7221
|
-
|
|
7222
|
-
|
|
7223
|
-
)
|
|
7434
|
+
self.runt.confirm(('view', 'add'))
|
|
7435
|
+
self.runt.confirm(('view', 'read'), gateiden=viewiden)
|
|
7436
|
+
self.runt.confirm(('view', 'fork'), gateiden=viewiden)
|
|
7224
7437
|
|
|
7225
7438
|
ldef = {'creator': self.runt.user.iden}
|
|
7226
7439
|
vdef = {'creator': self.runt.user.iden}
|
|
@@ -7228,9 +7441,9 @@ class View(Prim):
|
|
|
7228
7441
|
if name is not None:
|
|
7229
7442
|
vdef['name'] = name
|
|
7230
7443
|
|
|
7231
|
-
|
|
7444
|
+
view = self.runt.snap.core.reqView(viewiden)
|
|
7232
7445
|
|
|
7233
|
-
newv = await
|
|
7446
|
+
newv = await view.fork(ldef=ldef, vdef=vdef)
|
|
7234
7447
|
|
|
7235
7448
|
return View(self.runt, newv, path=self.path)
|
|
7236
7449
|
|
synapse/lib/version.py
CHANGED
|
@@ -223,6 +223,6 @@ def reqVersion(valu, reqver,
|
|
|
223
223
|
##############################################################################
|
|
224
224
|
# The following are touched during the release process by bumpversion.
|
|
225
225
|
# Do not modify these directly.
|
|
226
|
-
version = (2,
|
|
226
|
+
version = (2, 156, 0)
|
|
227
227
|
verstring = '.'.join([str(x) for x in version])
|
|
228
|
-
commit = '
|
|
228
|
+
commit = '918a46d769574c99d1510654c1c2aaa13c3fda2c'
|
synapse/lib/view.py
CHANGED
|
@@ -398,6 +398,95 @@ class View(s_nexus.Pusher): # type: ignore
|
|
|
398
398
|
counts[name] += valu
|
|
399
399
|
return counts
|
|
400
400
|
|
|
401
|
+
async def getPropCount(self, propname, valu=s_common.novalu):
|
|
402
|
+
prop = self.core.model.prop(propname)
|
|
403
|
+
if prop is None:
|
|
404
|
+
mesg = f'No property named {propname}'
|
|
405
|
+
raise s_exc.NoSuchProp(mesg=mesg)
|
|
406
|
+
|
|
407
|
+
count = 0
|
|
408
|
+
formname = None
|
|
409
|
+
propname = None
|
|
410
|
+
|
|
411
|
+
if prop.isform:
|
|
412
|
+
formname = prop.name
|
|
413
|
+
else:
|
|
414
|
+
propname = prop.name
|
|
415
|
+
if not prop.isuniv:
|
|
416
|
+
formname = prop.form.name
|
|
417
|
+
|
|
418
|
+
if valu is s_common.novalu:
|
|
419
|
+
for layr in self.layers:
|
|
420
|
+
await asyncio.sleep(0)
|
|
421
|
+
count += await layr.getPropCount(formname, propname)
|
|
422
|
+
return count
|
|
423
|
+
|
|
424
|
+
norm, info = prop.type.norm(valu)
|
|
425
|
+
|
|
426
|
+
for layr in self.layers:
|
|
427
|
+
await asyncio.sleep(0)
|
|
428
|
+
count += layr.getPropValuCount(formname, propname, prop.type.stortype, norm)
|
|
429
|
+
|
|
430
|
+
return count
|
|
431
|
+
|
|
432
|
+
async def getTagPropCount(self, form, tag, propname, valu=s_common.novalu):
|
|
433
|
+
prop = self.core.model.getTagProp(propname)
|
|
434
|
+
if prop is None:
|
|
435
|
+
mesg = f'No tag property named {propname}'
|
|
436
|
+
raise s_exc.NoSuchTagProp(name=propname, mesg=mesg)
|
|
437
|
+
|
|
438
|
+
count = 0
|
|
439
|
+
|
|
440
|
+
if valu is s_common.novalu:
|
|
441
|
+
for layr in self.layers:
|
|
442
|
+
await asyncio.sleep(0)
|
|
443
|
+
count += await layr.getTagPropCount(form, tag, prop.name)
|
|
444
|
+
return count
|
|
445
|
+
|
|
446
|
+
norm, info = prop.type.norm(valu)
|
|
447
|
+
|
|
448
|
+
for layr in self.layers:
|
|
449
|
+
await asyncio.sleep(0)
|
|
450
|
+
count += layr.getTagPropValuCount(form, tag, prop.name, prop.type.stortype, norm)
|
|
451
|
+
|
|
452
|
+
return count
|
|
453
|
+
|
|
454
|
+
async def getPropArrayCount(self, propname, valu=s_common.novalu):
|
|
455
|
+
prop = self.core.model.prop(propname)
|
|
456
|
+
if prop is None:
|
|
457
|
+
mesg = f'No property named {propname}'
|
|
458
|
+
raise s_exc.NoSuchProp(mesg=mesg)
|
|
459
|
+
|
|
460
|
+
if not prop.type.isarray:
|
|
461
|
+
mesg = f'Property is not an array type: {prop.type.name}.'
|
|
462
|
+
raise s_exc.BadTypeValu(mesg=mesg)
|
|
463
|
+
|
|
464
|
+
count = 0
|
|
465
|
+
formname = None
|
|
466
|
+
propname = None
|
|
467
|
+
|
|
468
|
+
if prop.isform:
|
|
469
|
+
formname = prop.name
|
|
470
|
+
else:
|
|
471
|
+
propname = prop.name
|
|
472
|
+
if not prop.isuniv:
|
|
473
|
+
formname = prop.form.name
|
|
474
|
+
|
|
475
|
+
if valu is s_common.novalu:
|
|
476
|
+
for layr in self.layers:
|
|
477
|
+
await asyncio.sleep(0)
|
|
478
|
+
count += await layr.getPropArrayCount(formname, propname)
|
|
479
|
+
return count
|
|
480
|
+
|
|
481
|
+
atyp = prop.type.arraytype
|
|
482
|
+
norm, info = atyp.norm(valu)
|
|
483
|
+
|
|
484
|
+
for layr in self.layers:
|
|
485
|
+
await asyncio.sleep(0)
|
|
486
|
+
count += layr.getPropArrayValuCount(formname, propname, atyp.stortype, norm)
|
|
487
|
+
|
|
488
|
+
return count
|
|
489
|
+
|
|
401
490
|
async def getEdgeVerbs(self):
|
|
402
491
|
|
|
403
492
|
async with await s_spooled.Set.anit(dirn=self.core.dirn, cell=self.core) as vset:
|
|
@@ -531,11 +620,8 @@ class View(s_nexus.Pusher): # type: ignore
|
|
|
531
620
|
|
|
532
621
|
mode = opts.get('mode', 'storm')
|
|
533
622
|
editformat = opts.get('editformat', 'nodeedits')
|
|
534
|
-
if editformat not in ('nodeedits', '
|
|
535
|
-
raise s_exc.BadConfValu(mesg='editformat')
|
|
536
|
-
|
|
537
|
-
if editformat == 'splices':
|
|
538
|
-
s_common.deprdate('storm option editformat=splices', s_common._splicedepr)
|
|
623
|
+
if editformat not in ('nodeedits', 'count', 'none'):
|
|
624
|
+
raise s_exc.BadConfValu(mesg=f'invalid edit format, got {editformat}', name='editformat', valu=editformat)
|
|
539
625
|
|
|
540
626
|
texthash = hashlib.md5(text.encode(errors='surrogatepass'), usedforsecurity=False).hexdigest()
|
|
541
627
|
|
|
@@ -629,18 +715,11 @@ class View(s_nexus.Pusher): # type: ignore
|
|
|
629
715
|
if editformat == 'none':
|
|
630
716
|
continue
|
|
631
717
|
|
|
632
|
-
|
|
633
|
-
count = sum(len(edit[2]) for edit in mesg[1].get('edits', ()))
|
|
634
|
-
mesg = ('node:edits:count', {'count': count})
|
|
635
|
-
yield mesg
|
|
636
|
-
continue
|
|
637
|
-
|
|
638
|
-
assert editformat == 'splices'
|
|
718
|
+
assert editformat == 'count'
|
|
639
719
|
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
yield splice
|
|
720
|
+
count = sum(len(edit[2]) for edit in mesg[1].get('edits', ()))
|
|
721
|
+
mesg = ('node:edits:count', {'count': count})
|
|
722
|
+
yield mesg
|
|
644
723
|
continue
|
|
645
724
|
|
|
646
725
|
if kind == 'fini':
|
|
@@ -690,11 +769,7 @@ class View(s_nexus.Pusher): # type: ignore
|
|
|
690
769
|
|
|
691
770
|
if name == 'parent':
|
|
692
771
|
|
|
693
|
-
parent = self.core.
|
|
694
|
-
if parent is None:
|
|
695
|
-
mesg = 'The parent view must already exist.'
|
|
696
|
-
raise s_exc.NoSuchView(mesg=mesg)
|
|
697
|
-
|
|
772
|
+
parent = self.core.reqView(valu, mesg='The parent view must already exist.')
|
|
698
773
|
if parent.iden == self.iden:
|
|
699
774
|
mesg = 'A view may not have parent set to itself.'
|
|
700
775
|
raise s_exc.BadArg(mesg=mesg)
|
synapse/models/inet.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import socket
|
|
2
|
+
import asyncio
|
|
2
3
|
import hashlib
|
|
3
4
|
import logging
|
|
4
5
|
import ipaddress
|
|
@@ -7,6 +8,7 @@ import urllib.parse
|
|
|
7
8
|
|
|
8
9
|
import idna
|
|
9
10
|
import regex
|
|
11
|
+
import collections
|
|
10
12
|
import unicodedata
|
|
11
13
|
|
|
12
14
|
import synapse.exc as s_exc
|
|
@@ -479,10 +481,20 @@ class IPv4(s_types.Type):
|
|
|
479
481
|
return minv, maxv
|
|
480
482
|
|
|
481
483
|
def getCidrRange(self, text):
|
|
482
|
-
addr,
|
|
484
|
+
addr, mask_str = text.split('/', 1)
|
|
483
485
|
norm, info = self.norm(addr)
|
|
484
486
|
|
|
485
|
-
|
|
487
|
+
try:
|
|
488
|
+
mask_int = int(mask_str)
|
|
489
|
+
except ValueError:
|
|
490
|
+
raise s_exc.BadTypeValu(valu=text, name=self.name,
|
|
491
|
+
mesg=f'Invalid CIDR Mask "{text}"')
|
|
492
|
+
|
|
493
|
+
if mask_int > 32 or mask_int < 0:
|
|
494
|
+
raise s_exc.BadTypeValu(valu=text, name=self.name,
|
|
495
|
+
mesg=f'Invalid CIDR Mask "{text}"')
|
|
496
|
+
|
|
497
|
+
mask = cidrmasks[mask_int]
|
|
486
498
|
|
|
487
499
|
minv = norm & mask[0]
|
|
488
500
|
return minv, minv + mask[1]
|
|
@@ -1008,39 +1020,50 @@ class InetModule(s_module.CoreModule):
|
|
|
1008
1020
|
fqdn = node.ndef[1]
|
|
1009
1021
|
domain = node.get('domain')
|
|
1010
1022
|
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1023
|
+
async with node.snap.getEditor() as editor:
|
|
1024
|
+
protonode = editor.loadNode(node)
|
|
1025
|
+
if domain is None:
|
|
1026
|
+
await protonode.set('iszone', False)
|
|
1027
|
+
await protonode.set('issuffix', True)
|
|
1028
|
+
return
|
|
1015
1029
|
|
|
1016
|
-
|
|
1017
|
-
|
|
1030
|
+
if protonode.get('issuffix') is None:
|
|
1031
|
+
await protonode.set('issuffix', False)
|
|
1018
1032
|
|
|
1019
|
-
|
|
1020
|
-
|
|
1033
|
+
parent = await node.snap.getNodeByNdef(('inet:fqdn', domain))
|
|
1034
|
+
if parent is None:
|
|
1035
|
+
parent = await editor.addNode('inet:fqdn', domain)
|
|
1021
1036
|
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1037
|
+
if parent.get('issuffix'):
|
|
1038
|
+
await protonode.set('iszone', True)
|
|
1039
|
+
await protonode.set('zone', fqdn)
|
|
1040
|
+
return
|
|
1026
1041
|
|
|
1027
|
-
|
|
1042
|
+
await protonode.set('iszone', False)
|
|
1028
1043
|
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1044
|
+
if parent.get('iszone'):
|
|
1045
|
+
await protonode.set('zone', domain)
|
|
1046
|
+
return
|
|
1032
1047
|
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1048
|
+
zone = parent.get('zone')
|
|
1049
|
+
if zone is not None:
|
|
1050
|
+
await protonode.set('zone', zone)
|
|
1036
1051
|
|
|
1037
1052
|
async def _onSetFqdnIsSuffix(self, node, oldv):
|
|
1038
1053
|
|
|
1039
1054
|
fqdn = node.ndef[1]
|
|
1040
1055
|
|
|
1041
1056
|
issuffix = node.get('issuffix')
|
|
1042
|
-
|
|
1043
|
-
|
|
1057
|
+
|
|
1058
|
+
async with node.snap.getEditor() as editor:
|
|
1059
|
+
async for child in node.snap.nodesByPropValu('inet:fqdn:domain', '=', fqdn):
|
|
1060
|
+
await asyncio.sleep(0)
|
|
1061
|
+
|
|
1062
|
+
if child.get('iszone') == issuffix:
|
|
1063
|
+
continue
|
|
1064
|
+
|
|
1065
|
+
protonode = editor.loadNode(child)
|
|
1066
|
+
await protonode.set('iszone', issuffix)
|
|
1044
1067
|
|
|
1045
1068
|
async def _onSetFqdnIsZone(self, node, oldv):
|
|
1046
1069
|
|
|
@@ -1069,17 +1092,24 @@ class InetModule(s_module.CoreModule):
|
|
|
1069
1092
|
|
|
1070
1093
|
async def _onSetFqdnZone(self, node, oldv):
|
|
1071
1094
|
|
|
1072
|
-
|
|
1095
|
+
todo = collections.deque([node.ndef[1]])
|
|
1073
1096
|
zone = node.get('zone')
|
|
1074
1097
|
|
|
1075
|
-
async
|
|
1098
|
+
async with node.snap.getEditor() as editor:
|
|
1099
|
+
while todo:
|
|
1100
|
+
fqdn = todo.pop()
|
|
1101
|
+
async for child in node.snap.nodesByPropValu('inet:fqdn:domain', '=', fqdn):
|
|
1102
|
+
await asyncio.sleep(0)
|
|
1103
|
+
|
|
1104
|
+
# if they are their own zone level, skip
|
|
1105
|
+
if child.get('iszone') or child.get('zone') == zone:
|
|
1106
|
+
continue
|
|
1076
1107
|
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1108
|
+
# the have the same zone we do
|
|
1109
|
+
protonode = editor.loadNode(child)
|
|
1110
|
+
await protonode.set('zone', zone)
|
|
1080
1111
|
|
|
1081
|
-
|
|
1082
|
-
await child.set('zone', zone)
|
|
1112
|
+
todo.append(child.ndef[1])
|
|
1083
1113
|
|
|
1084
1114
|
def getModelDefs(self):
|
|
1085
1115
|
return (
|