synapse 2.178.0__py311-none-any.whl → 2.179.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.

Files changed (44) hide show
  1. synapse/cortex.py +162 -27
  2. synapse/datamodel.py +47 -1
  3. synapse/exc.py +1 -0
  4. synapse/lib/aha.py +2 -1
  5. synapse/lib/ast.py +26 -22
  6. synapse/lib/base.py +12 -3
  7. synapse/lib/cell.py +150 -11
  8. synapse/lib/coro.py +14 -0
  9. synapse/lib/drive.py +551 -0
  10. synapse/lib/schemas.py +39 -0
  11. synapse/lib/snap.py +17 -7
  12. synapse/lib/storm.py +3 -1
  13. synapse/lib/stormhttp.py +1 -0
  14. synapse/lib/stormlib/modelext.py +29 -3
  15. synapse/lib/stormlib/stix.py +40 -17
  16. synapse/lib/stormlib/vault.py +2 -2
  17. synapse/lib/stormtypes.py +1 -1
  18. synapse/lib/types.py +9 -0
  19. synapse/lib/version.py +2 -2
  20. synapse/lookup/pe.py +303 -38
  21. synapse/models/dns.py +24 -1
  22. synapse/models/geospace.py +4 -1
  23. synapse/models/infotech.py +26 -1
  24. synapse/tests/test_cortex.py +45 -1
  25. synapse/tests/test_lib_aha.py +17 -0
  26. synapse/tests/test_lib_cell.py +224 -0
  27. synapse/tests/test_lib_coro.py +12 -0
  28. synapse/tests/test_lib_stormhttp.py +40 -0
  29. synapse/tests/test_lib_stormlib_modelext.py +55 -3
  30. synapse/tests/test_lib_stormlib_stix.py +15 -0
  31. synapse/tests/test_lib_stormlib_vault.py +11 -1
  32. synapse/tests/test_lib_stormtypes.py +5 -0
  33. synapse/tests/test_lib_types.py +9 -0
  34. synapse/tests/test_model_dns.py +8 -0
  35. synapse/tests/test_model_geospace.py +3 -1
  36. synapse/tests/test_model_infotech.py +47 -0
  37. synapse/tests/test_model_syn.py +11 -0
  38. synapse/tests/test_utils_stormcov.py +1 -1
  39. synapse/tools/changelog.py +28 -0
  40. {synapse-2.178.0.dist-info → synapse-2.179.0.dist-info}/METADATA +1 -1
  41. {synapse-2.178.0.dist-info → synapse-2.179.0.dist-info}/RECORD +44 -43
  42. {synapse-2.178.0.dist-info → synapse-2.179.0.dist-info}/WHEEL +1 -1
  43. {synapse-2.178.0.dist-info → synapse-2.179.0.dist-info}/LICENSE +0 -0
  44. {synapse-2.178.0.dist-info → synapse-2.179.0.dist-info}/top_level.txt +0 -0
synapse/lib/cell.py CHANGED
@@ -37,6 +37,7 @@ import synapse.lib.hive as s_hive
37
37
  import synapse.lib.link as s_link
38
38
  import synapse.lib.cache as s_cache
39
39
  import synapse.lib.const as s_const
40
+ import synapse.lib.drive as s_drive
40
41
  import synapse.lib.nexus as s_nexus
41
42
  import synapse.lib.queue as s_queue
42
43
  import synapse.lib.scope as s_scope
@@ -1285,7 +1286,9 @@ class Cell(s_nexus.Pusher, s_telepath.Aware):
1285
1286
  await self._initAhaRegistry()
1286
1287
 
1287
1288
  # phase 2 - service storage
1289
+ await self.initCellStorage()
1288
1290
  await self.initServiceStorage()
1291
+
1289
1292
  # phase 3 - nexus subsystem
1290
1293
  await self.initNexusSubsystem()
1291
1294
 
@@ -1741,6 +1744,129 @@ class Cell(s_nexus.Pusher, s_telepath.Aware):
1741
1744
  async def initServiceEarly(self):
1742
1745
  pass
1743
1746
 
1747
+ async def initCellStorage(self):
1748
+ self.drive = await s_drive.Drive.anit(self.slab, 'celldrive')
1749
+ self.onfini(self.drive.fini)
1750
+
1751
+ async def addDriveItem(self, info, path=None, reldir=s_drive.rootdir):
1752
+
1753
+ iden = info.get('iden')
1754
+ if iden is None:
1755
+ info['iden'] = s_common.guid()
1756
+
1757
+ info.setdefault('created', s_common.now())
1758
+ info.setdefault('creator', self.auth.rootuser.iden)
1759
+
1760
+ return await self._push('drive:add', info, path=path, reldir=reldir)
1761
+
1762
+ @s_nexus.Pusher.onPush('drive:add')
1763
+ async def _addDriveItem(self, info, path=None, reldir=s_drive.rootdir):
1764
+
1765
+ # replay safety...
1766
+ iden = info.get('iden')
1767
+ if self.drive.hasItemInfo(iden): # pragma: no cover
1768
+ return await self.drive.getItemPath(iden)
1769
+
1770
+ return await self.drive.addItemInfo(info, path=path, reldir=reldir)
1771
+
1772
+ async def getDriveInfo(self, iden):
1773
+ return self.drive.getItemInfo(iden)
1774
+
1775
+ async def getDrivePath(self, path, reldir=s_drive.rootdir):
1776
+ '''
1777
+ Return a list of drive info elements for each step in path.
1778
+
1779
+ This may be used as a sort of "open" which returns all the
1780
+ path info entries. You may then operate directly on drive iden
1781
+ entries and/or check easyperm entries on them before you do...
1782
+ '''
1783
+ return await self.drive.getPathInfo(path, reldir=reldir)
1784
+
1785
+ async def addDrivePath(self, path, perm=None, reldir=s_drive.rootdir):
1786
+ '''
1787
+ Create the given path using the specified permissions.
1788
+
1789
+ The specified permissions are only used when creating new directories.
1790
+
1791
+ NOTE: We must do this outside the Drive class to allow us to generate
1792
+ iden and tick but remain nexus compatible.
1793
+ '''
1794
+ tick = s_common.now()
1795
+ user = self.auth.rootuser.iden
1796
+ path = self.drive.getPathNorm(path)
1797
+
1798
+ if perm is None:
1799
+ perm = {'users': {}, 'roles': {}}
1800
+
1801
+ for name in path:
1802
+
1803
+ info = self.drive.getStepInfo(reldir, name)
1804
+ await asyncio.sleep(0)
1805
+
1806
+ if info is not None:
1807
+ reldir = info.get('iden')
1808
+ continue
1809
+
1810
+ info = {
1811
+ 'name': name,
1812
+ 'perm': perm,
1813
+ 'iden': s_common.guid(),
1814
+ 'created': tick,
1815
+ 'creator': user,
1816
+ }
1817
+ pathinfo = await self.addDriveItem(info, reldir=reldir)
1818
+ reldir = pathinfo[-1].get('iden')
1819
+
1820
+ return await self.drive.getItemPath(reldir)
1821
+
1822
+ async def getDriveData(self, iden, vers=None):
1823
+ '''
1824
+ Return the data associated with the drive item by iden.
1825
+ If vers is specified, return that specific version.
1826
+ '''
1827
+ return self.drive.getItemData(iden, vers=vers)
1828
+
1829
+ async def getDriveDataVersions(self, iden):
1830
+ async for item in self.drive.getItemDataVersions(iden):
1831
+ yield item
1832
+
1833
+ @s_nexus.Pusher.onPushAuto('drive:del')
1834
+ async def delDriveInfo(self, iden):
1835
+ if self.drive.getItemInfo(iden) is not None:
1836
+ await self.drive.delItemInfo(iden)
1837
+
1838
+ @s_nexus.Pusher.onPushAuto('drive:set:perm')
1839
+ async def setDriveInfoPerm(self, iden, perm):
1840
+ return self.drive.setItemPerm(iden, perm)
1841
+
1842
+ @s_nexus.Pusher.onPushAuto('drive:set:path')
1843
+ async def setDriveInfoPath(self, iden, path):
1844
+
1845
+ path = self.drive.getPathNorm(path)
1846
+ pathinfo = await self.drive.getItemPath(iden)
1847
+ if path == [p.get('name') for p in pathinfo]:
1848
+ return pathinfo
1849
+
1850
+ return await self.drive.setItemPath(iden, path)
1851
+
1852
+ @s_nexus.Pusher.onPushAuto('drive:data:set')
1853
+ async def setDriveData(self, iden, versinfo, data):
1854
+ return self.drive.setItemData(iden, versinfo, data)
1855
+
1856
+ async def delDriveData(self, iden, vers=None):
1857
+ if vers is None:
1858
+ info = self.drive.reqItemInfo(iden)
1859
+ vers = info.get('version')
1860
+ return await self._push('drive:data:del', iden, vers)
1861
+
1862
+ @s_nexus.Pusher.onPush('drive:data:del')
1863
+ async def _delDriveData(self, iden, vers):
1864
+ return self.drive.delItemData(iden, vers)
1865
+
1866
+ async def getDriveKids(self, iden):
1867
+ async for info in self.drive.getItemKids(iden):
1868
+ yield info
1869
+
1744
1870
  async def initServiceStorage(self):
1745
1871
  pass
1746
1872
 
@@ -3214,10 +3340,13 @@ class Cell(s_nexus.Pusher, s_telepath.Aware):
3214
3340
 
3215
3341
  return hive
3216
3342
 
3217
- async def _initSlabFile(self, path, readonly=False):
3343
+ async def _initSlabFile(self, path, readonly=False, ephemeral=False):
3218
3344
  slab = await s_lmdbslab.Slab.anit(path, map_size=SLAB_MAP_SIZE, readonly=readonly)
3219
3345
  slab.addResizeCallback(self.checkFreeSpace)
3220
- self.onfini(slab)
3346
+ fini = slab.fini
3347
+ if ephemeral:
3348
+ fini = slab
3349
+ self.onfini(fini)
3221
3350
  return slab
3222
3351
 
3223
3352
  async def _initCellSlab(self, readonly=False):
@@ -4741,18 +4870,28 @@ class Cell(s_nexus.Pusher, s_telepath.Aware):
4741
4870
  sslctx.check_hostname = False
4742
4871
  sslctx.verify_mode = ssl.CERT_NONE
4743
4872
 
4744
- if not opts['client_cert']:
4745
- return sslctx
4873
+ # crypto functions require reading certs/keys from disk so make a temp dir
4874
+ # to save any certs/keys to disk so they can be read.
4875
+ with self.getTempDir() as tmpdir:
4876
+ if opts.get('ca_cert'):
4877
+ ca_cert = opts.get('ca_cert').encode()
4878
+ with tempfile.NamedTemporaryFile(dir=tmpdir, mode='wb', delete=False) as fh:
4879
+ fh.write(ca_cert)
4880
+ try:
4881
+ sslctx.load_verify_locations(cafile=fh.name)
4882
+ except Exception as e: # pragma: no cover
4883
+ raise s_exc.BadArg(mesg=f'Error loading CA cert: {str(e)}') from None
4746
4884
 
4747
- client_cert = opts['client_cert'].encode()
4885
+ if not opts['client_cert']:
4886
+ return sslctx
4748
4887
 
4749
- if opts['client_key']:
4750
- client_key = opts['client_key'].encode()
4751
- else:
4752
- client_key = None
4753
- client_key_path = None
4888
+ client_cert = opts['client_cert'].encode()
4754
4889
 
4755
- with self.getTempDir() as tmpdir:
4890
+ if opts['client_key']:
4891
+ client_key = opts['client_key'].encode()
4892
+ else:
4893
+ client_key = None
4894
+ client_key_path = None
4756
4895
 
4757
4896
  with tempfile.NamedTemporaryFile(dir=tmpdir, mode='wb', delete=False) as fh:
4758
4897
  fh.write(client_cert)
synapse/lib/coro.py CHANGED
@@ -39,6 +39,20 @@ async def agen(item):
39
39
  for x in item:
40
40
  yield x
41
41
 
42
+ async def chunks(genr, size=100):
43
+
44
+ retn = []
45
+ async for item in genr:
46
+
47
+ retn.append(item)
48
+
49
+ if len(retn) == size:
50
+ yield retn
51
+ retn = []
52
+
53
+ if retn:
54
+ yield retn
55
+
42
56
  async def pause(genr, iterations=10):
43
57
  idx = 0
44
58