synapse 2.182.0__py311-none-any.whl → 2.184.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 (37) hide show
  1. synapse/cortex.py +5 -0
  2. synapse/datamodel.py +41 -3
  3. synapse/lib/ast.py +4 -3
  4. synapse/lib/autodoc.py +71 -5
  5. synapse/lib/cell.py +1 -1
  6. synapse/lib/storm.py +23 -0
  7. synapse/lib/stormlib/cortex.py +1 -0
  8. synapse/lib/stormlib/graph.py +17 -0
  9. synapse/lib/stormlib/infosec.py +2 -0
  10. synapse/lib/stormlib/model.py +2 -1
  11. synapse/lib/stormlib/random.py +84 -3
  12. synapse/lib/stormtypes.py +4 -0
  13. synapse/lib/stormwhois.py +3 -0
  14. synapse/lib/version.py +2 -2
  15. synapse/models/infotech.py +3 -15
  16. synapse/models/orgs.py +76 -2
  17. synapse/models/risk.py +22 -0
  18. synapse/tests/files/stormpkg/testpkg.yaml +10 -0
  19. synapse/tests/test_cortex.py +31 -44
  20. synapse/tests/test_lib_ast.py +58 -0
  21. synapse/tests/test_lib_autodoc.py +85 -0
  22. synapse/tests/test_lib_storm.py +18 -0
  23. synapse/tests/test_lib_stormlib_modelext.py +52 -0
  24. synapse/tests/test_lib_stormlib_random.py +93 -0
  25. synapse/tests/test_lib_stormwhois.py +4 -4
  26. synapse/tests/test_model_infotech.py +44 -1
  27. synapse/tests/test_model_orgs.py +37 -0
  28. synapse/tests/test_model_risk.py +3 -0
  29. synapse/tests/test_tools_autodoc.py +6 -0
  30. synapse/tests/utils.py +28 -0
  31. synapse/tools/autodoc.py +2 -1
  32. synapse/tools/changelog.py +53 -10
  33. {synapse-2.182.0.dist-info → synapse-2.184.0.dist-info}/METADATA +1 -1
  34. {synapse-2.182.0.dist-info → synapse-2.184.0.dist-info}/RECORD +37 -37
  35. {synapse-2.182.0.dist-info → synapse-2.184.0.dist-info}/WHEEL +1 -1
  36. {synapse-2.182.0.dist-info → synapse-2.184.0.dist-info}/LICENSE +0 -0
  37. {synapse-2.182.0.dist-info → synapse-2.184.0.dist-info}/top_level.txt +0 -0
synapse/cortex.py CHANGED
@@ -1453,6 +1453,11 @@ class Cortex(s_oauth.OAuthMixin, s_cell.Cell): # type: ignore
1453
1453
  {'perm': ('storm', 'macro', 'edit'), 'gate': 'cortex',
1454
1454
  'desc': 'Controls access to edit a storm macro.'},
1455
1455
 
1456
+ {'perm': ('task', 'get'), 'gate': 'cortex',
1457
+ 'desc': 'Controls access to view other users tasks.'},
1458
+ {'perm': ('task', 'del'), 'gate': 'cortex',
1459
+ 'desc': 'Controls access to terminate other users tasks.'},
1460
+
1456
1461
  {'perm': ('view',), 'gate': 'cortex',
1457
1462
  'desc': 'Controls all view permissions.'},
1458
1463
  {'perm': ('view', 'add'), 'gate': 'cortex',
synapse/datamodel.py CHANGED
@@ -987,7 +987,17 @@ class Model:
987
987
  if form is None:
988
988
  return
989
989
 
990
- formprops = [p for p in form.props.values() if p.univ is None]
990
+ ifaceprops = set()
991
+ for iface in form.ifaces.values():
992
+ for prop in iface.get('props', ()):
993
+ ifaceprops.add(prop[0])
994
+
995
+ formprops = []
996
+ for propname, prop in form.props.items():
997
+ if prop.univ is not None or propname in ifaceprops:
998
+ continue
999
+ formprops.append(prop)
1000
+
991
1001
  if formprops:
992
1002
  propnames = ', '.join(prop.name for prop in formprops)
993
1003
  mesg = f'Form has extended properties: {propnames}'
@@ -996,8 +1006,8 @@ class Model:
996
1006
  if isinstance(form.type, s_types.Array):
997
1007
  self.arraysbytype[form.type.arraytype.name].pop(form.name, None)
998
1008
 
999
- for ifname in form.ifaces.keys():
1000
- self.formsbyiface[ifname].remove(formname)
1009
+ for ifname in form.type.info.get('interfaces', ()):
1010
+ self._delFormIface(form, ifname)
1001
1011
 
1002
1012
  self.forms.pop(formname, None)
1003
1013
  self.props.pop(formname, None)
@@ -1108,6 +1118,34 @@ class Model:
1108
1118
  for ifname in ifaces:
1109
1119
  self._addFormIface(form, ifname, subifaces=subifaces)
1110
1120
 
1121
+ def _delFormIface(self, form, name, subifaces=None):
1122
+
1123
+ if (iface := self.ifaces.get(name)) is None:
1124
+ return
1125
+
1126
+ for propname, typedef, propinfo in iface.get('props', ()):
1127
+ fullprop = f'{form.name}:{propname}'
1128
+ self.delFormProp(form.name, propname)
1129
+ self.ifaceprops[f'{name}:{propname}'].remove(fullprop)
1130
+
1131
+ if subifaces is not None:
1132
+ for subi in subifaces:
1133
+ self.ifaceprops[f'{subi}:{propname}'].remove(fullprop)
1134
+
1135
+ form.ifaces.pop(name, None)
1136
+ self.formsbyiface[name].remove(form.name)
1137
+
1138
+ if (ifaces := iface.get('interfaces')) is not None:
1139
+ if subifaces is None:
1140
+ subifaces = []
1141
+ else:
1142
+ subifaces = list(subifaces)
1143
+
1144
+ subifaces.append(name)
1145
+
1146
+ for ifname in ifaces:
1147
+ self._delFormIface(form, ifname, subifaces=subifaces)
1148
+
1111
1149
  def delTagProp(self, name):
1112
1150
  return self.tagprops.pop(name)
1113
1151
 
synapse/lib/ast.py CHANGED
@@ -1302,8 +1302,9 @@ class VarListSetOper(Oper):
1302
1302
  names = self.kids[0].value()
1303
1303
  vkid = self.kids[1]
1304
1304
 
1305
+ anynodes = False
1305
1306
  async for node, path in genr:
1306
-
1307
+ anynodes = True
1307
1308
  item = await vkid.compute(runt, path)
1308
1309
  item = [i async for i in s_stormtypes.toiter(item)]
1309
1310
 
@@ -1318,7 +1319,7 @@ class VarListSetOper(Oper):
1318
1319
 
1319
1320
  yield node, path
1320
1321
 
1321
- if vkid.isRuntSafe(runt):
1322
+ if not anynodes and vkid.isRuntSafe(runt):
1322
1323
 
1323
1324
  item = await vkid.compute(runt, None)
1324
1325
  item = [i async for i in s_stormtypes.toiter(item)]
@@ -4517,7 +4518,7 @@ class EditTagAdd(Edit):
4517
4518
  else:
4518
4519
  oper_offset = 0
4519
4520
 
4520
- excignore = (s_exc.BadTypeValu,) if oper_offset == 1 else ()
4521
+ excignore = (s_exc.BadTypeValu, s_exc.BadTag) if oper_offset == 1 else ()
4521
4522
 
4522
4523
  hasval = len(self.kids) > 2 + oper_offset
4523
4524
 
synapse/lib/autodoc.py CHANGED
@@ -28,6 +28,7 @@ stormtype_doc_schema = {
28
28
  'description': 'For a function argument, the name of the argument.'},
29
29
  'desc': {'type': 'string',
30
30
  'description': 'For a function argument or return value, the description of the value.'},
31
+ 'deprecated': {'$ref': '#/definitions/deprecatedItem'},
31
32
  'type': {'$ref': '#/definitions/stormType'},
32
33
  'args': {
33
34
  'type': 'array',
@@ -46,7 +47,28 @@ stormtype_doc_schema = {
46
47
  'documentation for.',
47
48
  'additionalProperties': False,
48
49
  },
49
-
50
+ 'deprecatedItem': {
51
+ 'type': 'object',
52
+ 'properties': {
53
+ 'eolvers': {'type': 'string', 'minLength': 1,
54
+ 'description': "The version which will not longer support the item."},
55
+ 'eoldate': {'type': 'string', 'minLength': 1,
56
+ 'description': 'Optional string indicating Synapse releases after this date may no longer support the item.'},
57
+ 'mesg': {'type': ['string', 'null'], 'default': None,
58
+ 'description': 'Optional message to include in the warning text.'}
59
+ },
60
+ 'oneOf': [
61
+ {
62
+ 'required': ['eolvers'],
63
+ 'not': {'required': ['eoldate']}
64
+ },
65
+ {
66
+ 'required': ['eoldate'],
67
+ 'not': {'required': ['eolvers']}
68
+ }
69
+ ],
70
+ 'additionalProperties': False,
71
+ },
50
72
  'stormtypeDoc': {
51
73
  'type': 'object',
52
74
  'properties': {
@@ -54,6 +76,7 @@ stormtype_doc_schema = {
54
76
  'description': 'The name of the object.'},
55
77
  'desc': {'type': 'string',
56
78
  'description': 'The docstring of the object.'},
79
+ 'deprecated': {'$ref': '#/definitions/deprecatedItem'},
57
80
  'type': {'$ref': '#/definitions/stormType'}
58
81
  },
59
82
  'additionalProperties': False,
@@ -186,6 +209,34 @@ def getArgLines(rtype):
186
209
 
187
210
  return lines
188
211
 
212
+ def genDeprecationWarning(name, depr, runt=False):
213
+ assert name is not None
214
+ assert depr is not None
215
+ lines = []
216
+ if runt:
217
+ lines.append('.. warning::')
218
+ else:
219
+ lines.append('Warning:')
220
+
221
+ mesg = depr.get('mesg')
222
+ date = depr.get('eoldate')
223
+ vers = depr.get('eolvers')
224
+
225
+ ws = ''
226
+ if runt:
227
+ ws = ' '
228
+
229
+ if date:
230
+ lines.append(f'{ws}``{name}`` has been deprecated and will be removed on or after {date}.')
231
+ else:
232
+ lines.append(f'{ws}``{name}`` has been deprecated and will be removed in version {vers}.')
233
+ if mesg:
234
+ lines.append(f'{ws}{mesg}')
235
+
236
+ lines.append('\n')
237
+
238
+ return lines
239
+
189
240
  def runtimeGetArgLines(rtype):
190
241
  lines = []
191
242
  args = rtype.get('args', ())
@@ -413,6 +464,7 @@ def docStormTypes(page, docinfo, linkprefix, islib=False, lvl=1,
413
464
 
414
465
  locls = info.get('locals', ())
415
466
  locls = sorted(locls, key=lambda x: x.get('name'))
467
+ libdepr = info.get('deprecated')
416
468
 
417
469
  for locl in locls:
418
470
 
@@ -424,6 +476,11 @@ def docStormTypes(page, docinfo, linkprefix, islib=False, lvl=1,
424
476
  assert rtype is not None
425
477
 
426
478
  link = f'.. _{linkprefix}-{loclname.replace(":", ".").replace(".", "-")}:'
479
+ lines = []
480
+ if depr := locl.get('deprecated'):
481
+ lines.extend(genDeprecationWarning(f'${loclname}', depr, True))
482
+ elif libdepr is not None:
483
+ lines.extend(genDeprecationWarning(f'${loclname}', libdepr, True))
427
484
 
428
485
  if isinstance(rtype, dict):
429
486
  rname = rtype.get('type')
@@ -445,7 +502,7 @@ def docStormTypes(page, docinfo, linkprefix, islib=False, lvl=1,
445
502
  if rname == 'stor' or 'stor' in rname:
446
503
  isstor = True
447
504
 
448
- lines = prepareRstLines(desc)
505
+ lines.extend(prepareRstLines(desc))
449
506
  arglines = getArgLines(rtype)
450
507
  lines.extend(arglines)
451
508
 
@@ -461,7 +518,7 @@ def docStormTypes(page, docinfo, linkprefix, islib=False, lvl=1,
461
518
 
462
519
  else:
463
520
  header = name
464
- lines = prepareRstLines(desc)
521
+ lines.extend(prepareRstLines(desc))
465
522
 
466
523
  retlines = getReturnLines(rtype, known_types=known_types, types_prefix=types_prefix,
467
524
  suffix=types_suffix)
@@ -472,6 +529,7 @@ def docStormTypes(page, docinfo, linkprefix, islib=False, lvl=1,
472
529
  header = f'${header}'
473
530
 
474
531
  page.addHead(header, lvl=lvl + 1, link=link)
532
+
475
533
  page.addLines(*lines)
476
534
 
477
535
  def runtimeDocStormTypes(page, docinfo, islib=False, lvl=1,
@@ -521,6 +579,7 @@ def runtimeDocStormTypes(page, docinfo, islib=False, lvl=1,
521
579
 
522
580
  page.addLines(*preamble)
523
581
 
582
+ libdepr = info.get('deprecated')
524
583
  locls = info.get('locals', ())
525
584
  locls = sorted(locls, key=lambda x: x.get('name'))
526
585
 
@@ -568,13 +627,20 @@ def runtimeDocStormTypes(page, docinfo, islib=False, lvl=1,
568
627
  assert desc is not None
569
628
  assert rtype is not None
570
629
 
630
+ lines = []
631
+ if not oneline:
632
+ if (depr := locl.get('deprecated')):
633
+ lines.extend(genDeprecationWarning(f'${loclname}', depr))
634
+ elif libdepr is not None:
635
+ lines.extend(genDeprecationWarning(f'${loclname}', libdepr))
636
+
571
637
  if isinstance(rtype, dict):
572
638
  rname = rtype.get('type')
573
639
 
574
640
  if isinstance(rname, dict):
575
641
  raise AssertionError(f'rname as dict not supported loclname={loclname} rname={rname}')
576
642
 
577
- lines = prepareRstLines(desc)
643
+ lines.extend(prepareRstLines(desc))
578
644
  arglines = runtimeGetArgLines(rtype)
579
645
  lines.extend(arglines)
580
646
 
@@ -588,7 +654,7 @@ def runtimeDocStormTypes(page, docinfo, islib=False, lvl=1,
588
654
 
589
655
  else:
590
656
  header = name
591
- lines = prepareRstLines(desc)
657
+ lines.extend(prepareRstLines(desc))
592
658
 
593
659
  retlines = runtimeGetReturnLines(rtype)
594
660
  lines.extend(retlines)
synapse/lib/cell.py CHANGED
@@ -3560,7 +3560,7 @@ class Cell(s_nexus.Pusher, s_telepath.Aware):
3560
3560
  item.setdefault('permissions', {})
3561
3561
  item['permissions'].setdefault('users', {})
3562
3562
  item['permissions'].setdefault('roles', {})
3563
- item['permissions']['default'] = default
3563
+ item['permissions'].setdefault('default', default)
3564
3564
 
3565
3565
  async def getTeleApi(self, link, mesg, path):
3566
3566
 
synapse/lib/storm.py CHANGED
@@ -342,6 +342,7 @@ reqValidPkgdef = s_config.getJsValidator({
342
342
  'properties': {
343
343
  'name': {'type': 'string'},
344
344
  'desc': {'type': 'string'},
345
+ 'deprecated': {'$ref': '#/definitions/deprecatedItem'},
345
346
  'type': {
346
347
  'type': 'object',
347
348
  'properties': {
@@ -395,6 +396,28 @@ reqValidPkgdef = s_config.getJsValidator({
395
396
  'additionalProperties': False,
396
397
  'required': ['name', 'desc', 'type']
397
398
  },
399
+ 'deprecatedItem': {
400
+ 'type': 'object',
401
+ 'properties': {
402
+ 'eolvers': {'type': 'string', 'minLength': 1,
403
+ 'description': "The version which will not longer support the item."},
404
+ 'eoldate': {'type': 'string', 'minLength': 1,
405
+ 'description': 'Optional string indicating Synapse releases after this date may no longer support the item.'},
406
+ 'mesg': {'type': ['string', 'null'], 'default': None,
407
+ 'description': 'Optional message to include in the warning text.'}
408
+ },
409
+ 'oneOf': [
410
+ {
411
+ 'required': ['eolvers'],
412
+ 'not': {'required': ['eoldate']}
413
+ },
414
+ {
415
+ 'required': ['eoldate'],
416
+ 'not': {'required': ['eolvers']}
417
+ }
418
+ ],
419
+ 'additionalProperties': False,
420
+ },
398
421
  'apitype': {
399
422
  'type': 'string',
400
423
  },
@@ -715,6 +715,7 @@ class HttpPermsList(s_stormtypes.List):
715
715
  ),
716
716
  'returns': {'type': 'any', 'desc': 'The permission present in the list at the index position.', }}},
717
717
  {'name': 'length', 'desc': 'Get the length of the list. This is deprecated; please use ``.size()`` instead.',
718
+ 'deprecated': {'eolvers': 'v3.0.0'},
718
719
  'type': {'type': 'function', '_funcname': '_methListLength',
719
720
  'returns': {'type': 'int', 'desc': 'The size of the list.', }}},
720
721
  {'name': 'append', 'desc': 'Append a permission to the list.',
@@ -157,6 +157,15 @@ class GraphLib(s_stormtypes.Lib):
157
157
  ),
158
158
  'returns': {'type': 'null', }}},
159
159
 
160
+ {'name': 'revoke', 'desc': 'Revoke permissions granted to users/roles on a graph projection.',
161
+ 'type': {'type': 'function', '_funcname': '_methGraphRevoke',
162
+ 'args': (
163
+ {'name': 'gden', 'type': 'str', 'desc': 'Iden of the graph projection to modify.'},
164
+ {'name': 'scope', 'type': 'str', 'desc': 'The scope, either "users" or "roles".'},
165
+ {'name': 'iden', 'type': 'str', 'desc': 'The user/role iden depending on scope.'},
166
+ ),
167
+ 'returns': {'type': 'null'}}},
168
+
160
169
  {'name': 'activate', 'desc': 'Set the graph projection to use for the top level Storm Runtime.',
161
170
  'type': {'type': 'function', '_funcname': '_methGraphActivate',
162
171
  'args': (
@@ -174,6 +183,7 @@ class GraphLib(s_stormtypes.Lib):
174
183
  'mod': self._methGraphMod,
175
184
  'list': self._methGraphList,
176
185
  'grant': self._methGraphGrant,
186
+ 'revoke': self._methGraphRevoke,
177
187
  'activate': self._methGraphActivate,
178
188
  }
179
189
 
@@ -219,6 +229,13 @@ class GraphLib(s_stormtypes.Lib):
219
229
 
220
230
  await self.runt.snap.core.setStormGraphPerm(gden, scope, iden, level, user=self.runt.user)
221
231
 
232
+ async def _methGraphRevoke(self, gden, scope, iden):
233
+ gden = await s_stormtypes.tostr(gden)
234
+ scope = await s_stormtypes.tostr(scope)
235
+ iden = await s_stormtypes.tostr(iden)
236
+
237
+ await self.runt.snap.core.setStormGraphPerm(gden, scope, iden, None, user=self.runt.user)
238
+
222
239
  async def _methGraphActivate(self, iden):
223
240
  gdef = await self._methGraphGet(iden)
224
241
  self.runt.setGraph(gdef)
@@ -537,6 +537,7 @@ class CvssLib(s_stormtypes.Lib):
537
537
  'returns': {'type': 'dict', 'desc': 'A dictionary containing the computed score and subscores.', }
538
538
  }},
539
539
  {'name': 'vectToProps', 'desc': 'Parse a CVSS v3.1 vector and return a dictionary of risk:vuln props.',
540
+ 'deprecated': {'eolvers': 'v3.0.0'},
540
541
  'type': {'type': 'function', '_funcname': 'vectToProps',
541
542
  'args': (
542
543
  {'name': 'text', 'type': 'str', 'desc': 'A CVSS vector string.'},
@@ -544,6 +545,7 @@ class CvssLib(s_stormtypes.Lib):
544
545
  'returns': {'type': 'dict', 'desc': 'A dictionary of risk:vuln secondary props.', }
545
546
  }},
546
547
  {'name': 'saveVectToNode', 'desc': 'Parse a CVSS v3.1 vector and record properties on a risk:vuln node.',
548
+ 'deprecated': {'eolvers': 'v3.0.0'},
547
549
  'type': {'type': 'function', '_funcname': 'saveVectToNode',
548
550
  'args': (
549
551
  {'name': 'node', 'type': 'node',
@@ -543,7 +543,7 @@ class ModelType(s_stormtypes.Prim):
543
543
  @s_stormtypes.registry.registerLib
544
544
  class LibModelEdge(s_stormtypes.Lib):
545
545
  '''
546
- A Storm Library for interacting with light edges and manipulating their key-value attributes.
546
+ A Storm Library for interacting with light edges and manipulating their key-value attributes. This Library is deprecated.
547
547
  '''
548
548
  _storm_locals = (
549
549
  {'name': 'get', 'desc': 'Get the key-value data for a given Edge verb.',
@@ -588,6 +588,7 @@ class LibModelEdge(s_stormtypes.Lib):
588
588
  hivepath = ('cortex', 'model', 'edges')
589
589
 
590
590
  _storm_lib_path = ('model', 'edge')
591
+ _storm_lib_deprecation = {'eolvers': 'v3.0.0'}
591
592
 
592
593
  def __init__(self, runt, name=()):
593
594
  s_stormtypes.Lib.__init__(self, runt, name)
@@ -1,10 +1,77 @@
1
1
  import random
2
2
 
3
3
  import synapse.exc as s_exc
4
+ import synapse.common as s_common
5
+
4
6
  import synapse.lib.stormtypes as s_stormtypes
5
7
 
8
+ from typing import Optional
9
+
6
10
  randinst = random.SystemRandom()
7
11
 
12
+
13
+ @s_stormtypes.registry.registerType
14
+ class Random(s_stormtypes.StormType):
15
+ '''
16
+ A random number generator.
17
+ '''
18
+ _storm_typename = 'random'
19
+ _storm_locals = (
20
+ {'name': 'int', 'desc': 'Generate a random integer.',
21
+ 'type': {'type': 'function', '_funcname': '_methInt',
22
+ 'args': (
23
+ {'name': 'maxval', 'type': 'int', 'desc': 'The maximum random value.'},
24
+ {'name': 'minval', 'type': 'int', 'desc': 'The minimum random value.', 'default': 0},
25
+ ),
26
+ 'returns': {'type': 'int', 'desc': 'A random integer in the range min-max inclusive.'}}},
27
+ {'name': 'seed', 'desc': 'The seed used for the generator. Setting this value resets the generator state.',
28
+ 'type': {'type': ['gtor', 'stor'], '_storfunc': '_storSeed', '_gtorfunc': '_gtorSeed',
29
+ 'returns': {'type': ['str', 'null']}}},
30
+ )
31
+ _ismutable = False
32
+
33
+ def __init__(self, runt, seed: Optional[str] =None):
34
+ s_stormtypes.StormType.__init__(self)
35
+ self.runt = runt
36
+ self._seed = seed
37
+ self.robj = random.Random()
38
+ if seed is not None:
39
+ self.robj.seed(self._seed, version=2)
40
+ self.locls.update(self.getObjLocals())
41
+ self.gtors.update({
42
+ 'seed': self._gtorSeed,
43
+ })
44
+ self.stors.update({
45
+ 'seed': self._storSeed,
46
+ })
47
+
48
+ async def stormrepr(self):
49
+ ret = f'{self._storm_typename}'
50
+ if self._seed is not None:
51
+ ret = f'{ret} seed={s_common.trimText(self._seed, n=40)}'
52
+ return ret
53
+
54
+ def getObjLocals(self):
55
+ return {
56
+ 'int': self._methInt,
57
+ }
58
+
59
+ async def _gtorSeed(self):
60
+ return self._seed
61
+
62
+ async def _storSeed(self, seed):
63
+ self._seed = await s_stormtypes.tostr(seed, noneok=True)
64
+ self.robj.seed(self._seed)
65
+
66
+ @s_stormtypes.stormfunc(readonly=True)
67
+ async def _methInt(self, maxval, minval=0):
68
+ maxval = await s_stormtypes.toint(maxval)
69
+ minval = await s_stormtypes.toint(minval)
70
+ if minval > maxval:
71
+ raise s_exc.BadArg(mesg=f'Minval must be less than or equal to maxval, minval={minval}, maxval={maxval}',
72
+ minval=minval, maxval=maxval)
73
+ return self.robj.randint(minval, maxval)
74
+
8
75
  @s_stormtypes.registry.registerLib
9
76
  class LibRandom(s_stormtypes.Lib):
10
77
  '''
@@ -12,22 +79,36 @@ class LibRandom(s_stormtypes.Lib):
12
79
  '''
13
80
  _storm_locals = (
14
81
  {'name': 'int', 'desc': 'Generate a random integer.',
15
- 'type': {'type': 'function', '_funcname': '_int',
82
+ 'type': {'type': 'function', '_funcname': '_methInt',
16
83
  'args': (
17
84
  {'name': 'maxval', 'type': 'int', 'desc': 'The maximum random value.'},
18
85
  {'name': 'minval', 'type': 'int', 'desc': 'The minimum random value.', 'default': 0},
19
86
  ),
20
87
  'returns': {'type': 'int', 'desc': 'A random integer in the range min-max inclusive.'}}},
88
+ {'name': 'generator', 'desc': 'Make a random generator with a given seed.',
89
+ 'type': {'type': 'function', '_funcname': '_methGenerator',
90
+ 'args': (
91
+ {'name': 'seed', 'type': 'str', 'default': None,
92
+ 'desc': 'The seed value used for the random generator.'},
93
+ ),
94
+ 'returns': {'type': 'random', 'desc': 'The random generator object.'}}
95
+ }
21
96
  )
22
97
  _storm_lib_path = ('random',)
23
98
 
24
99
  def getObjLocals(self):
25
100
  return {
26
- 'int': self._int,
101
+ 'int': self._methInt,
102
+ 'generator': self._methGenerator,
27
103
  }
28
104
 
29
105
  @s_stormtypes.stormfunc(readonly=True)
30
- async def _int(self, maxval, minval=0):
106
+ async def _methGenerator(self, seed=None):
107
+ seed = await s_stormtypes.tostr(seed, noneok=True)
108
+ return Random(self.runt, seed=seed)
109
+
110
+ @s_stormtypes.stormfunc(readonly=True)
111
+ async def _methInt(self, maxval, minval=0):
31
112
  maxval = await s_stormtypes.toint(maxval)
32
113
  minval = await s_stormtypes.toint(minval)
33
114
  if minval > maxval:
synapse/lib/stormtypes.py CHANGED
@@ -277,6 +277,7 @@ class StormTypesRegistry:
277
277
  'desc': getDoc(slib, sname),
278
278
  'locals': locs,
279
279
  'path': ('lib',) + slib._storm_lib_path,
280
+ 'deprecated': slib._storm_lib_deprecation,
280
281
  }
281
282
  for info in sorted(slib._storm_locals, key=lambda x: x.get('name')):
282
283
  info = s_msgpack.deepcopy(info)
@@ -509,6 +510,7 @@ class Lib(StormType):
509
510
  _storm_query = None
510
511
  _storm_typename = 'lib'
511
512
  _storm_lib_perms = ()
513
+ _storm_lib_deprecation = None
512
514
 
513
515
  def __init__(self, runt, name=()):
514
516
  StormType.__init__(self)
@@ -2659,6 +2661,7 @@ class LibBytes(Lib):
2659
2661
  'returns': {'type': 'list', 'desc': 'A tuple of the file size and sha256 value.', }}},
2660
2662
  )
2661
2663
  _storm_lib_path = ('bytes',)
2664
+ _storm_lib_deprecation = {'eolvers': 'v3.0.0', 'mesg': 'Use the corresponding ``$lib.axon`` function.'}
2662
2665
 
2663
2666
  def getObjLocals(self):
2664
2667
  return {
@@ -5005,6 +5008,7 @@ class List(Prim):
5005
5008
  ),
5006
5009
  'returns': {'type': 'any', 'desc': 'The item present in the list at the index position.', }}},
5007
5010
  {'name': 'length', 'desc': 'Get the length of the list. This is deprecated; please use ``.size()`` instead.',
5011
+ 'deprecated': {'eolvers': 'v3.0.0'},
5008
5012
  'type': {'type': 'function', '_funcname': '_methListLength',
5009
5013
  'returns': {'type': 'int', 'desc': 'The size of the list.', }}},
5010
5014
  {'name': 'append', 'desc': 'Append a value to the list.',
synapse/lib/stormwhois.py CHANGED
@@ -16,6 +16,7 @@ class LibWhois(s_stormtypes.Lib):
16
16
 
17
17
  Raises:
18
18
  StormRuntimeError: If form is not supported in this method.''',
19
+ 'deprecated': {'eolvers': 'v3.0.0', 'mesg': 'Please use the GUID constructor syntax.'},
19
20
  'type': {'type': 'function', '_funcname': '_whoisGuid',
20
21
  'args': (
21
22
  {'name': 'props', 'type': 'dict', 'desc': 'Dictionary of properties used to create the form.', },
@@ -31,6 +32,8 @@ class LibWhois(s_stormtypes.Lib):
31
32
  }
32
33
 
33
34
  async def _whoisGuid(self, props, form):
35
+ s_common.deprecated('$lib.inet.whois.guid()', curv='2.183.0')
36
+ await self.runt.snap.warnonce('$lib.inet.whois.guid() is deprecated. Use the GUID constructor syntax.')
34
37
  form = await s_stormtypes.tostr(form)
35
38
  props = await s_stormtypes.toprim(props)
36
39
  if form == 'iprec':
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, 182, 0)
226
+ version = (2, 184, 0)
227
227
  verstring = '.'.join([str(x) for x in version])
228
- commit = '72e535c8c22073fd1b7428121849de4b9fb034ae'
228
+ commit = '05940dce070d26f83bb7e4070f1d44d051804e3b'