synapse 2.215.0__py311-none-any.whl → 2.217.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/cortex.py +16 -1
- synapse/lib/cell.py +12 -0
- synapse/lib/cmd.py +6 -2
- synapse/lib/layer.py +10 -5
- synapse/lib/schemas.py +9 -2
- synapse/lib/snap.py +15 -5
- synapse/lib/storm.py +1 -1
- synapse/lib/stormtypes.py +6 -0
- synapse/lib/types.py +3 -0
- synapse/lib/version.py +2 -2
- synapse/lib/view.py +16 -7
- synapse/models/inet.py +24 -4
- synapse/models/orgs.py +4 -2
- synapse/models/risk.py +2 -0
- synapse/tests/test_cortex.py +262 -0
- synapse/tests/test_lib_auth.py +2 -0
- synapse/tests/test_lib_storm.py +52 -1
- synapse/tests/test_lib_stormsvc.py +2 -2
- synapse/tests/test_lib_types.py +6 -0
- synapse/tests/test_model_inet.py +23 -0
- synapse/tests/test_tools_cryo_cat.py +3 -8
- synapse/tests/test_tools_storm.py +3 -2
- synapse/tests/utils.py +2 -0
- synapse/tools/aha/clone.py +3 -13
- synapse/tools/aha/easycert.py +5 -18
- synapse/tools/aha/enroll.py +3 -12
- synapse/tools/aha/list.py +2 -15
- synapse/tools/aha/mirror.py +3 -14
- synapse/tools/aha/provision/service.py +3 -13
- synapse/tools/aha/provision/user.py +3 -12
- synapse/tools/apikey.py +3 -13
- synapse/tools/autodoc.py +7 -19
- synapse/tools/axon2axon.py +1 -9
- synapse/tools/cellauth.py +5 -14
- synapse/tools/changelog.py +12 -16
- synapse/tools/cmdr.py +2 -6
- synapse/tools/cryo/cat.py +5 -15
- synapse/tools/cryo/list.py +3 -10
- synapse/tools/csvtool.py +40 -49
- synapse/tools/demote.py +1 -6
- synapse/tools/docker/validate.py +0 -1
- synapse/tools/easycert.py +3 -8
- synapse/tools/feed.py +7 -18
- synapse/tools/genpkg.py +3 -12
- synapse/tools/guid.py +4 -6
- synapse/tools/healthcheck.py +4 -11
- synapse/tools/json2mpk.py +1 -5
- synapse/tools/livebackup.py +3 -13
- synapse/tools/modrole.py +3 -12
- synapse/tools/moduser.py +3 -12
- synapse/tools/pkgs/gendocs.py +1 -1
- synapse/tools/promote.py +3 -13
- synapse/tools/pullfile.py +6 -18
- synapse/tools/pushfile.py +6 -18
- synapse/tools/reload.py +5 -14
- synapse/tools/rstorm.py +4 -12
- synapse/tools/shutdown.py +1 -2
- synapse/tools/snapshot.py +3 -14
- synapse/tools/storm.py +4 -12
- {synapse-2.215.0.dist-info → synapse-2.217.0.dist-info}/METADATA +1 -1
- {synapse-2.215.0.dist-info → synapse-2.217.0.dist-info}/RECORD +64 -64
- {synapse-2.215.0.dist-info → synapse-2.217.0.dist-info}/WHEEL +0 -0
- {synapse-2.215.0.dist-info → synapse-2.217.0.dist-info}/licenses/LICENSE +0 -0
- {synapse-2.215.0.dist-info → synapse-2.217.0.dist-info}/top_level.txt +0 -0
synapse/tests/test_cortex.py
CHANGED
|
@@ -8776,6 +8776,268 @@ class CortexBasicTest(s_t_utils.SynTest):
|
|
|
8776
8776
|
self.eq(core._test_pre_nexus_index, offs)
|
|
8777
8777
|
self.ge(core._test_post_nexus_index, core._test_pre_nexus_index)
|
|
8778
8778
|
|
|
8779
|
+
async def test_cortex_safemode(self):
|
|
8780
|
+
safemode = {'safemode': True}
|
|
8781
|
+
nosafe = {'safemode': False}
|
|
8782
|
+
|
|
8783
|
+
# Cortex safemode disables the following functionality:
|
|
8784
|
+
# - crons
|
|
8785
|
+
# - triggers
|
|
8786
|
+
# - dmons
|
|
8787
|
+
# - storm package onloads
|
|
8788
|
+
# - merge tasks (e.g. for quorum)
|
|
8789
|
+
# - storm pools
|
|
8790
|
+
|
|
8791
|
+
# Make sure we're logging the message
|
|
8792
|
+
with self.getStructuredAsyncLoggerStream('synapse.lib.cell', 'Booting cortex in safe-mode.') as stream:
|
|
8793
|
+
async with self.getTestCore(conf=safemode) as core:
|
|
8794
|
+
self.true(core.safemode)
|
|
8795
|
+
self.true(await stream.wait(10))
|
|
8796
|
+
msgs = stream.jsonlines()
|
|
8797
|
+
self.len(1, msgs)
|
|
8798
|
+
self.eq(msgs[0].get('message'), 'Booting cortex in safe-mode. Some functionality may be disabled.')
|
|
8799
|
+
self.eq(msgs[0].get('level'), 'WARNING')
|
|
8800
|
+
|
|
8801
|
+
# Check crons, triggers, dmons in this section
|
|
8802
|
+
with self.getTestDir() as dirn:
|
|
8803
|
+
|
|
8804
|
+
# Setup the cortex
|
|
8805
|
+
async with self.getTestCore(dirn=dirn) as core:
|
|
8806
|
+
await core.addCoreQueue('queue:safemode:done', {})
|
|
8807
|
+
# Add a cron job and immediately disable it
|
|
8808
|
+
q = '''
|
|
8809
|
+
cron.add --minute +1 {
|
|
8810
|
+
$now = $lib.cast(time, now)
|
|
8811
|
+
$lib.log.warning(`SAFEMODE CRON: {$now}`)
|
|
8812
|
+
[ test:str=CRON :tick=$now ]
|
|
8813
|
+
} |
|
|
8814
|
+
$job = $lib.cron.list().0
|
|
8815
|
+
cron.disable $job.iden
|
|
8816
|
+
'''
|
|
8817
|
+
await core.callStorm(q)
|
|
8818
|
+
jobs = await core.listCronJobs()
|
|
8819
|
+
self.len(1, jobs)
|
|
8820
|
+
self.eq(jobs[0].get('enabled'), False)
|
|
8821
|
+
|
|
8822
|
+
# Add a regular trigger
|
|
8823
|
+
q = '''
|
|
8824
|
+
$lib.log.warning(`SAFEMODE TRIGGER: {$node}`)
|
|
8825
|
+
$tick = :tick
|
|
8826
|
+
$str = { [( test:str=TRIGGER :hehe=$tick )] }
|
|
8827
|
+
$queue = $lib.queue.gen(queue:safemode)
|
|
8828
|
+
$queue.put($tick)
|
|
8829
|
+
'''
|
|
8830
|
+
opts = {'vars': {'query': q}}
|
|
8831
|
+
await core.callStorm(f'trigger.add prop:set --prop test:str:tick --query {{{q}}}')
|
|
8832
|
+
|
|
8833
|
+
# Add an async trigger
|
|
8834
|
+
q = '''
|
|
8835
|
+
$lib.log.warning(`SAFEMODE ATRIGGER: {$node}`)
|
|
8836
|
+
$tick = :tick
|
|
8837
|
+
$str = { [( test:str=ATRIGGER :hehe=$tick )] }
|
|
8838
|
+
$queue = $lib.queue.gen(queue:safemode)
|
|
8839
|
+
$queue.put($tick)
|
|
8840
|
+
'''
|
|
8841
|
+
opts = {'vars': {'query': q}}
|
|
8842
|
+
await core.callStorm(f'trigger.add prop:set --prop test:str:tick --async --query {{{q}}}')
|
|
8843
|
+
|
|
8844
|
+
# Add a dmon
|
|
8845
|
+
q = '''
|
|
8846
|
+
$queue = $lib.queue.gen(queue:safemode)
|
|
8847
|
+
$queue2 = $lib.queue.gen(queue:safemode:done)
|
|
8848
|
+
while (true) {
|
|
8849
|
+
($offs, $item) = $queue.get()
|
|
8850
|
+
$lib.log.warning(`SAFEMODE DMON: {$item}`)
|
|
8851
|
+
[ test:str=DMON :hehe=$item ]
|
|
8852
|
+
$queue2.put($item)
|
|
8853
|
+
}
|
|
8854
|
+
'''
|
|
8855
|
+
await core.callStorm(f'$iden = $lib.dmon.add(${{{q}}}) $lib.dmon.start($iden)')
|
|
8856
|
+
|
|
8857
|
+
nodes = await core.nodes('test:str')
|
|
8858
|
+
self.len(0, nodes)
|
|
8859
|
+
|
|
8860
|
+
# Run in safemode and verify cron, trigger, and dmons don't execute
|
|
8861
|
+
with self.getLoggerStream('synapse.storm') as stream:
|
|
8862
|
+
async with self.getTestCore(dirn=dirn, conf=safemode) as core:
|
|
8863
|
+
await core.callStorm('cron.enable $lib.cron.list().0.iden')
|
|
8864
|
+
# Increment the cron tick to get it to fire
|
|
8865
|
+
core.agenda._addTickOff(60)
|
|
8866
|
+
|
|
8867
|
+
# Add a test:str:tick to get the trigger to fire
|
|
8868
|
+
await core.callStorm('[ test:str=newp :tick=1234 ]')
|
|
8869
|
+
|
|
8870
|
+
# Check for test:strs
|
|
8871
|
+
nodes = await core.nodes('test:str')
|
|
8872
|
+
self.len(1, nodes)
|
|
8873
|
+
self.eq(nodes[0].repr(), 'newp')
|
|
8874
|
+
|
|
8875
|
+
with self.raises(TimeoutError):
|
|
8876
|
+
await s_common.wait_for(core.coreQueueGet('queue:safemode:done', wait=True), timeout=2)
|
|
8877
|
+
|
|
8878
|
+
# Add a dmon to make sure it doesn't start
|
|
8879
|
+
await core.addCoreQueue('queue:safemode:started', {})
|
|
8880
|
+
q = '''
|
|
8881
|
+
$queue = $lib.queue.gen(queue:safemode)
|
|
8882
|
+
$queue2 = $lib.queue.get(queue:safemode:started)
|
|
8883
|
+
while (true) {
|
|
8884
|
+
$queue2.put(foo)
|
|
8885
|
+
$lib.log.warning(`SAFEMODE DMON START`)
|
|
8886
|
+
($offs, $item) = $queue.get()
|
|
8887
|
+
}
|
|
8888
|
+
'''
|
|
8889
|
+
await core.callStorm(f'$iden = $lib.dmon.add(${{{q}}}) $lib.dmon.start($iden)')
|
|
8890
|
+
|
|
8891
|
+
with self.raises(TimeoutError):
|
|
8892
|
+
await s_common.wait_for(core.coreQueueGet('queue:safemode:started', wait=True), timeout=2)
|
|
8893
|
+
|
|
8894
|
+
stream.seek(0)
|
|
8895
|
+
data = stream.read()
|
|
8896
|
+
self.notin('SAFEMODE CRON', data)
|
|
8897
|
+
self.notin('SAFEMODE TRIGGER', data)
|
|
8898
|
+
self.notin('SAFEMODE ATRIGGER', data)
|
|
8899
|
+
self.notin('SAFEMODE DMON', data)
|
|
8900
|
+
|
|
8901
|
+
with self.getLoggerStream('synapse.storm') as stream:
|
|
8902
|
+
async with self.getTestCore(dirn=dirn) as core:
|
|
8903
|
+
core.agenda._addTickOff(60)
|
|
8904
|
+
|
|
8905
|
+
item = await s_common.wait_for(core.coreQueueGet('queue:safemode:done', wait=True), timeout=5)
|
|
8906
|
+
self.len(2, item)
|
|
8907
|
+
|
|
8908
|
+
nodes = await core.nodes('test:str')
|
|
8909
|
+
self.len(5, nodes)
|
|
8910
|
+
self.sorteq(
|
|
8911
|
+
['newp', 'CRON', 'TRIGGER', 'DMON', 'ATRIGGER'],
|
|
8912
|
+
[k.repr() for k in nodes]
|
|
8913
|
+
)
|
|
8914
|
+
|
|
8915
|
+
stream.seek(0)
|
|
8916
|
+
data = stream.read()
|
|
8917
|
+
self.isin('SAFEMODE CRON', data)
|
|
8918
|
+
self.isin('SAFEMODE TRIGGER', data)
|
|
8919
|
+
self.isin('SAFEMODE ATRIGGER', data)
|
|
8920
|
+
self.isin('SAFEMODE DMON', data)
|
|
8921
|
+
|
|
8922
|
+
# Check storm package onload handlers are not executed
|
|
8923
|
+
with self.getTestDir() as dirn:
|
|
8924
|
+
async with self.getTestCore(dirn=dirn, conf=safemode) as core:
|
|
8925
|
+
pkgdef = {
|
|
8926
|
+
'name': 'foopkg',
|
|
8927
|
+
'version': (0, 0, 1),
|
|
8928
|
+
'onload': '$lib.import(foo.setup).onload()',
|
|
8929
|
+
'modules': (
|
|
8930
|
+
{
|
|
8931
|
+
'name': 'foo.setup',
|
|
8932
|
+
'storm': '''
|
|
8933
|
+
function onload() {
|
|
8934
|
+
$lib.warn('foopkg onload')
|
|
8935
|
+
}
|
|
8936
|
+
''',
|
|
8937
|
+
},
|
|
8938
|
+
)
|
|
8939
|
+
}
|
|
8940
|
+
|
|
8941
|
+
waiter = core.waiter(1, 'core:pkg:onload:skipped')
|
|
8942
|
+
await core.addStormPkg(pkgdef)
|
|
8943
|
+
events = await waiter.wait(timeout=10)
|
|
8944
|
+
self.nn(events)
|
|
8945
|
+
self.len(1, events)
|
|
8946
|
+
self.eq(events, (('core:pkg:onload:skipped', {'pkg': 'foopkg', 'reason': 'safemode'}),))
|
|
8947
|
+
|
|
8948
|
+
with self.getAsyncLoggerStream('synapse.cortex', 'foopkg onload output: foopkg onload') as stream:
|
|
8949
|
+
async with self.getTestCore(dirn=dirn, conf=nosafe) as core:
|
|
8950
|
+
self.false(core.safemode)
|
|
8951
|
+
await stream.wait(timeout=10)
|
|
8952
|
+
|
|
8953
|
+
# Check merge tasks are not executed
|
|
8954
|
+
with self.getTestDir() as dirn:
|
|
8955
|
+
async with self.getTestCore(dirn=dirn, conf=safemode) as core:
|
|
8956
|
+
alliden = core.auth.allrole.iden
|
|
8957
|
+
|
|
8958
|
+
blackout = await core.auth.addUser('blackout')
|
|
8959
|
+
await blackout.allow(('view', 'read'))
|
|
8960
|
+
|
|
8961
|
+
await core.auth.rootuser.grant(alliden)
|
|
8962
|
+
|
|
8963
|
+
view = core.getView()
|
|
8964
|
+
qnfo = {
|
|
8965
|
+
'count': 1,
|
|
8966
|
+
'roles': [alliden],
|
|
8967
|
+
}
|
|
8968
|
+
await view.setViewInfo('quorum', qnfo)
|
|
8969
|
+
|
|
8970
|
+
forkiden = (await view.fork()).get('iden')
|
|
8971
|
+
|
|
8972
|
+
opts = {'view': forkiden}
|
|
8973
|
+
|
|
8974
|
+
nodes = await core.nodes('[ test:str=fork ]', opts=opts)
|
|
8975
|
+
self.len(1, nodes)
|
|
8976
|
+
|
|
8977
|
+
await core.callStorm('$lib.view.get().setMergeRequest()', opts=opts)
|
|
8978
|
+
await core.callStorm('$lib.view.get().setMergeVote()', opts=opts | {'user': blackout.iden})
|
|
8979
|
+
|
|
8980
|
+
fork = core.getView(forkiden)
|
|
8981
|
+
|
|
8982
|
+
self.true(await fork.isMergeReady())
|
|
8983
|
+
self.none(fork.mergetask)
|
|
8984
|
+
|
|
8985
|
+
self.len(0, await core.nodes('test:str'))
|
|
8986
|
+
|
|
8987
|
+
async with self.getTestCore(dirn=dirn, conf=nosafe) as core:
|
|
8988
|
+
nodes = await core.nodes('test:str')
|
|
8989
|
+
self.len(1, nodes)
|
|
8990
|
+
self.eq(nodes[0].repr(), 'fork')
|
|
8991
|
+
|
|
8992
|
+
# Check storm pools are not enabled
|
|
8993
|
+
async with self.getTestAha() as aha:
|
|
8994
|
+
|
|
8995
|
+
ahanet = aha.conf.req('aha:network')
|
|
8996
|
+
|
|
8997
|
+
async with await s_base.Base.anit() as base:
|
|
8998
|
+
|
|
8999
|
+
with self.getTestDir() as dirn:
|
|
9000
|
+
|
|
9001
|
+
dirn00 = s_common.genpath(dirn, 'cell00')
|
|
9002
|
+
dirn01 = s_common.genpath(dirn, 'cell01')
|
|
9003
|
+
|
|
9004
|
+
core00 = await base.enter_context(self.addSvcToAha(aha, '00.core', s_cortex.Cortex, dirn=dirn00,
|
|
9005
|
+
conf=safemode))
|
|
9006
|
+
provinfo = {'mirror': 'core'}
|
|
9007
|
+
core01 = await base.enter_context(self.addSvcToAha(aha, '01.core', s_cortex.Cortex, dirn=dirn01,
|
|
9008
|
+
provinfo=provinfo))
|
|
9009
|
+
|
|
9010
|
+
msgs = await core01.stormlist('aha.pool.add pool00...')
|
|
9011
|
+
self.stormHasNoWarnErr(msgs)
|
|
9012
|
+
self.stormIsInPrint('Created AHA service pool: pool00.synapse', msgs)
|
|
9013
|
+
|
|
9014
|
+
msgs = await core01.stormlist('aha.pool.svc.add pool00... 01.core...')
|
|
9015
|
+
self.stormHasNoWarnErr(msgs)
|
|
9016
|
+
self.stormIsInPrint('AHA service (01.core...) added to service pool (pool00.synapse)', msgs)
|
|
9017
|
+
|
|
9018
|
+
msgs = await core00.stormlist('cortex.storm.pool.set --connection-timeout 1 --sync-timeout 1 aha://pool00...')
|
|
9019
|
+
self.stormHasNoWarnErr(msgs)
|
|
9020
|
+
self.stormIsInPrint('Storm pool configuration set.', msgs)
|
|
9021
|
+
|
|
9022
|
+
# Make sure queries still work
|
|
9023
|
+
nodes = await core00.nodes('[ it:dev:str="stormpools!" ]', opts={'mirror': True})
|
|
9024
|
+
self.len(1, nodes)
|
|
9025
|
+
|
|
9026
|
+
self.none(core00.stormpool)
|
|
9027
|
+
|
|
9028
|
+
await core00.fini()
|
|
9029
|
+
|
|
9030
|
+
# Now disable safemode and check that the stormpool is enabled
|
|
9031
|
+
core00 = await base.enter_context(self.getTestCore(dirn=dirn00, conf=nosafe))
|
|
9032
|
+
|
|
9033
|
+
nodes = await core00.nodes('it:dev:str', opts={'mirror': True})
|
|
9034
|
+
self.len(1, nodes)
|
|
9035
|
+
|
|
9036
|
+
self.nn(core00.stormpool)
|
|
9037
|
+
|
|
9038
|
+
await core00.fini()
|
|
9039
|
+
await core01.fini()
|
|
9040
|
+
|
|
8779
9041
|
async def test_cortex_queue_mirror_authgates(self):
|
|
8780
9042
|
async with self.getRegrCore('2.213.0-queue-authgates') as core:
|
|
8781
9043
|
self.nn(await core.getAuthGate('queue:stillhere'))
|
synapse/tests/test_lib_auth.py
CHANGED
|
@@ -431,6 +431,8 @@ class AuthTest(s_test.SynTest):
|
|
|
431
431
|
await core.auth.allrole.setRules([(True, ('hehe', 'haha'), 'newp')])
|
|
432
432
|
with self.raises(s_exc.SchemaViolation):
|
|
433
433
|
await core.auth.allrole.setRules([(True, )])
|
|
434
|
+
with self.raises(s_exc.SchemaViolation):
|
|
435
|
+
await core.auth.allrole.setRules([(True, '')])
|
|
434
436
|
|
|
435
437
|
async def test_auth_archived_locked_interaction(self):
|
|
436
438
|
|
synapse/tests/test_lib_storm.py
CHANGED
|
@@ -101,7 +101,8 @@ class StormTest(s_t_utils.SynTest):
|
|
|
101
101
|
with self.raises(s_exc.BadTypeValu):
|
|
102
102
|
await core.nodes('[ ou:org=({}) ]')
|
|
103
103
|
|
|
104
|
-
self.
|
|
104
|
+
with self.raises(s_exc.BadTypeValu):
|
|
105
|
+
await core.nodes('[ ou:org=() ]')
|
|
105
106
|
|
|
106
107
|
with self.raises(s_exc.BadTypeValu):
|
|
107
108
|
await core.nodes('[ ou:org=({}) ]')
|
|
@@ -293,6 +294,56 @@ class StormTest(s_t_utils.SynTest):
|
|
|
293
294
|
|
|
294
295
|
self.len(0, await core.nodes('inet:service:platform:name=barplat'))
|
|
295
296
|
|
|
297
|
+
# Gutors work for props
|
|
298
|
+
nodes = await core.nodes('''[
|
|
299
|
+
test:str=guidprop
|
|
300
|
+
:gprop=({'name': 'someprop', '$props': {'size': 5}})
|
|
301
|
+
]''')
|
|
302
|
+
self.len(1, nodes)
|
|
303
|
+
node = nodes[0]
|
|
304
|
+
self.eq(node.ndef, ('test:str', 'guidprop'))
|
|
305
|
+
self.nn(node.get('gprop'))
|
|
306
|
+
|
|
307
|
+
nodes = await core.nodes('test:str=guidprop -> test:guid')
|
|
308
|
+
self.len(1, nodes)
|
|
309
|
+
node = nodes[0]
|
|
310
|
+
self.eq(node.get('name'), 'someprop')
|
|
311
|
+
self.eq(node.get('size'), 5)
|
|
312
|
+
|
|
313
|
+
with self.raises(s_exc.BadTypeValu) as cm:
|
|
314
|
+
nodes = await core.nodes('''[
|
|
315
|
+
test:str=newpprop
|
|
316
|
+
:gprop=({'size': 'newp'})
|
|
317
|
+
]''')
|
|
318
|
+
|
|
319
|
+
self.eq(cm.exception.get('form'), 'test:guid')
|
|
320
|
+
self.eq(cm.exception.get('prop'), 'size')
|
|
321
|
+
self.true(cm.exception.get('mesg').startswith('Bad value for prop test:guid:size: invalid literal'))
|
|
322
|
+
|
|
323
|
+
nodes = await core.nodes('''[
|
|
324
|
+
test:str=newpprop
|
|
325
|
+
:gprop?=({'size': 'newp'})
|
|
326
|
+
]''')
|
|
327
|
+
self.len(1, nodes)
|
|
328
|
+
node = nodes[0]
|
|
329
|
+
self.eq(node.ndef, ('test:str', 'newpprop'))
|
|
330
|
+
self.none(node.get('gprop'))
|
|
331
|
+
|
|
332
|
+
nodes = await core.nodes('''
|
|
333
|
+
[ test:str=methset ]
|
|
334
|
+
$node.props.gprop = ({'name': 'someprop'})
|
|
335
|
+
''')
|
|
336
|
+
self.len(1, nodes)
|
|
337
|
+
node = nodes[0]
|
|
338
|
+
self.eq(node.ndef, ('test:str', 'methset'))
|
|
339
|
+
self.nn(node.get('gprop'))
|
|
340
|
+
|
|
341
|
+
nodes = await core.nodes('test:str=methset -> test:guid')
|
|
342
|
+
self.len(1, nodes)
|
|
343
|
+
node = nodes[0]
|
|
344
|
+
self.eq(node.get('name'), 'someprop')
|
|
345
|
+
self.eq(node.get('size'), 5)
|
|
346
|
+
|
|
296
347
|
async def test_lib_storm_jsonexpr(self):
|
|
297
348
|
async with self.getTestCore() as core:
|
|
298
349
|
|
|
@@ -780,7 +780,7 @@ class StormSvcTest(s_test.SynTest):
|
|
|
780
780
|
}
|
|
781
781
|
with patchcore(core, 'setStormSvcEvents', badSetStormSvcEvents):
|
|
782
782
|
svci = await core.addStormSvc(sdef)
|
|
783
|
-
self.true(await core.waitStormSvc('dead', timeout=
|
|
783
|
+
self.true(await core.waitStormSvc('dead', timeout=12))
|
|
784
784
|
await core.delStormSvc(svci.get('iden'))
|
|
785
785
|
|
|
786
786
|
self.len(1, badiden)
|
|
@@ -792,7 +792,7 @@ class StormSvcTest(s_test.SynTest):
|
|
|
792
792
|
|
|
793
793
|
with patchcore(core, '_runStormSvcAdd', badRunStormSvcAdd):
|
|
794
794
|
svci = await core.addStormSvc(sdef)
|
|
795
|
-
self.true(await core.waitStormSvc('dead', timeout=
|
|
795
|
+
self.true(await core.waitStormSvc('dead', timeout=12))
|
|
796
796
|
await core.delStormSvc(svci.get('iden'))
|
|
797
797
|
self.len(1, badiden)
|
|
798
798
|
self.eq(svci.get('iden'), badiden[0])
|
synapse/tests/test_lib_types.py
CHANGED
|
@@ -316,6 +316,12 @@ class TypesTest(s_t_utils.SynTest):
|
|
|
316
316
|
self.true(s_common.isguid(lnorm))
|
|
317
317
|
self.eq(lnorm, tnorm)
|
|
318
318
|
|
|
319
|
+
with self.raises(s_exc.BadTypeValu) as exc:
|
|
320
|
+
model.type('guid').norm(())
|
|
321
|
+
self.eq(exc.exception.get('name'), 'guid')
|
|
322
|
+
self.eq(exc.exception.get('valu'), ())
|
|
323
|
+
self.eq(exc.exception.get('mesg'), 'Guid list values cannot be empty.')
|
|
324
|
+
|
|
319
325
|
async def test_hex(self):
|
|
320
326
|
|
|
321
327
|
async with self.getTestCore() as core:
|
synapse/tests/test_model_inet.py
CHANGED
|
@@ -1363,6 +1363,27 @@ class InetModelTest(s_t_utils.SynTest):
|
|
|
1363
1363
|
for p, v in props.items():
|
|
1364
1364
|
self.eq(node.get(p), v)
|
|
1365
1365
|
|
|
1366
|
+
nodes = await core.nodes('[ inet:server=gre://::1 ]')
|
|
1367
|
+
self.eq(nodes[0].get('proto'), 'gre')
|
|
1368
|
+
|
|
1369
|
+
nodes = await core.nodes('[ inet:server=gre://1.2.3.4 ]')
|
|
1370
|
+
self.eq(nodes[0].get('proto'), 'gre')
|
|
1371
|
+
|
|
1372
|
+
with self.raises(s_exc.BadTypeValu) as ctx:
|
|
1373
|
+
await core.nodes('[ inet:server=gre://1.2.3.4:99 ]')
|
|
1374
|
+
|
|
1375
|
+
self.eq(ctx.exception.get('mesg'), 'Protocol gre does not allow specifying ports.')
|
|
1376
|
+
|
|
1377
|
+
with self.raises(s_exc.BadTypeValu) as ctx:
|
|
1378
|
+
await core.nodes('[ inet:server="gre://[::1]:99" ]')
|
|
1379
|
+
|
|
1380
|
+
self.eq(ctx.exception.get('mesg'), 'Protocol gre does not allow specifying ports.')
|
|
1381
|
+
|
|
1382
|
+
with self.raises(s_exc.BadTypeValu) as ctx:
|
|
1383
|
+
await core.nodes('[ inet:server=newp://1.2.3.4:99 ]')
|
|
1384
|
+
|
|
1385
|
+
self.eq(ctx.exception.get('mesg'), 'inet:addr protocol must be one of: tcp,udp,icmp,host,gre')
|
|
1386
|
+
|
|
1366
1387
|
async def test_servfile(self):
|
|
1367
1388
|
async with self.getTestCore() as core:
|
|
1368
1389
|
valu = ('tcp://127.0.0.1:4040', 64 * 'f')
|
|
@@ -3017,6 +3038,8 @@ class InetModelTest(s_t_utils.SynTest):
|
|
|
3017
3038
|
platinst = nodes[0]
|
|
3018
3039
|
app00 = nodes[0].get('app')
|
|
3019
3040
|
|
|
3041
|
+
self.len(1, await core.nodes('inet:service:instance:id=T2XK1223Y -> inet:service:app [ :provider=* :provider:name=vertex ] :provider -> ou:org'))
|
|
3042
|
+
|
|
3020
3043
|
q = '''
|
|
3021
3044
|
[
|
|
3022
3045
|
(inet:service:account=(blackout, account, vertex, slack)
|
|
@@ -93,14 +93,9 @@ class CryoCatTest(s_t_utils.SynTest):
|
|
|
93
93
|
stdout.buffer = io.BytesIO()
|
|
94
94
|
|
|
95
95
|
with mock.patch('sys.stdout', stdout):
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
self.eq(0, retn)
|
|
100
|
-
|
|
101
|
-
stream.seek(0)
|
|
102
|
-
mesgs = stream.read()
|
|
103
|
-
self.isin(f'connecting to: {cryourl}', mesgs)
|
|
96
|
+
argv = ['--msgpack', '--size', '20', cryourl]
|
|
97
|
+
retn, _ = await self.execToolMain(s_cryocat.main, argv)
|
|
98
|
+
self.eq(0, retn)
|
|
104
99
|
|
|
105
100
|
stdout.buffer.seek(0)
|
|
106
101
|
outdata = list(msgpack.Unpacker(stdout.buffer, raw=False, use_list=False))
|
|
@@ -62,7 +62,8 @@ class StormCliTest(s_test.SynTest):
|
|
|
62
62
|
|
|
63
63
|
await core.addTagProp('foo', ('int', {}), {})
|
|
64
64
|
|
|
65
|
-
|
|
65
|
+
outp = self.getTestOutp()
|
|
66
|
+
pars = s_t_storm.getArgParser(outp)
|
|
66
67
|
opts = pars.parse_args(('woot',))
|
|
67
68
|
self.eq('woot', opts.cortex)
|
|
68
69
|
self.none(opts.view)
|
|
@@ -263,7 +264,7 @@ class StormCliTest(s_test.SynTest):
|
|
|
263
264
|
|
|
264
265
|
url = core.getLocalUrl()
|
|
265
266
|
|
|
266
|
-
pars = s_t_storm.getArgParser()
|
|
267
|
+
pars = s_t_storm.getArgParser(self.getTestOutp())
|
|
267
268
|
opts = pars.parse_args(('woot', '--view', '246e7d5dab883eb28d345a33abcdb577'))
|
|
268
269
|
self.eq(opts.view, '246e7d5dab883eb28d345a33abcdb577')
|
|
269
270
|
|
synapse/tests/utils.py
CHANGED
|
@@ -439,6 +439,7 @@ testmodel = {
|
|
|
439
439
|
|
|
440
440
|
('test:guid', {}, (
|
|
441
441
|
('size', ('test:int', {}), {}),
|
|
442
|
+
('name', ('test:str', {}), {}),
|
|
442
443
|
('tick', ('test:time', {}), {}),
|
|
443
444
|
('posneg', ('test:sub', {}), {}),
|
|
444
445
|
('posneg:isbig', ('bool', {}), {}),
|
|
@@ -459,6 +460,7 @@ testmodel = {
|
|
|
459
460
|
('hehe', ('str', {}), {}),
|
|
460
461
|
('ndefs', ('array', {'type': 'ndef'}), {}),
|
|
461
462
|
('somestr', ('test:str', {}), {}),
|
|
463
|
+
('gprop', ('test:guid', {}), {}),
|
|
462
464
|
)),
|
|
463
465
|
('test:strregex', {}, ()),
|
|
464
466
|
|
synapse/tools/aha/clone.py
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import sys
|
|
2
|
-
import asyncio
|
|
3
|
-
import argparse
|
|
4
|
-
|
|
5
1
|
import synapse.exc as s_exc
|
|
6
2
|
import synapse.telepath as s_telepath
|
|
7
3
|
|
|
8
|
-
import synapse.lib.
|
|
4
|
+
import synapse.lib.cmd as s_cmd
|
|
9
5
|
import synapse.lib.output as s_output
|
|
10
6
|
|
|
11
7
|
descr = '''
|
|
@@ -19,8 +15,7 @@ Examples:
|
|
|
19
15
|
|
|
20
16
|
async def main(argv, outp=s_output.stdout):
|
|
21
17
|
|
|
22
|
-
pars =
|
|
23
|
-
formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
18
|
+
pars = s_cmd.Parser(prog='synapse.tools.aha.clone', outp=outp, description=descr)
|
|
24
19
|
|
|
25
20
|
pars.add_argument('dnsname', help='The DNS name of the new AHA server.')
|
|
26
21
|
pars.add_argument('--port', type=int, default=27492, help='The port that the new AHA server should listen on.')
|
|
@@ -49,10 +44,5 @@ async def main(argv, outp=s_output.stdout):
|
|
|
49
44
|
outp.printf(f'ERROR: {mesg}')
|
|
50
45
|
return 1
|
|
51
46
|
|
|
52
|
-
async def _main(argv, outp=s_output.stdout): # pragma: no cover
|
|
53
|
-
ret = await main(argv, outp=outp)
|
|
54
|
-
await asyncio.wait_for(s_coro.await_bg_tasks(), timeout=60)
|
|
55
|
-
return ret
|
|
56
|
-
|
|
57
47
|
if __name__ == '__main__': # pragma: no cover
|
|
58
|
-
|
|
48
|
+
s_cmd.exitmain(main)
|
synapse/tools/aha/easycert.py
CHANGED
|
@@ -1,22 +1,15 @@
|
|
|
1
|
-
import sys
|
|
2
|
-
import asyncio
|
|
3
|
-
import logging
|
|
4
|
-
import argparse
|
|
5
|
-
|
|
6
1
|
import cryptography.x509 as c_x509
|
|
7
2
|
|
|
8
3
|
import synapse.common as s_common
|
|
9
4
|
import synapse.telepath as s_telepath
|
|
10
5
|
|
|
11
|
-
import synapse.lib.
|
|
6
|
+
import synapse.lib.cmd as s_cmd
|
|
12
7
|
import synapse.lib.output as s_output
|
|
13
8
|
import synapse.lib.certdir as s_certdir
|
|
14
9
|
|
|
15
10
|
|
|
16
|
-
logger = logging.getLogger(__name__)
|
|
17
|
-
|
|
18
11
|
async def main(argv, outp=s_output.stdout):
|
|
19
|
-
pars = getArgParser()
|
|
12
|
+
pars = getArgParser(outp)
|
|
20
13
|
opts = pars.parse_args(argv)
|
|
21
14
|
|
|
22
15
|
if opts.network:
|
|
@@ -56,9 +49,9 @@ async def main(argv, outp=s_output.stdout):
|
|
|
56
49
|
cdir.delUserCsr(name, outp=outp)
|
|
57
50
|
return 0
|
|
58
51
|
|
|
59
|
-
def getArgParser():
|
|
52
|
+
def getArgParser(outp):
|
|
60
53
|
desc = 'CLI tool to generate simple x509 certificates from an Aha server.'
|
|
61
|
-
pars =
|
|
54
|
+
pars = s_cmd.Parser(prog='synapse.tools.aha.easycert', outp=outp, description=desc)
|
|
62
55
|
|
|
63
56
|
pars.add_argument('-a', '--aha', required=True, # type=str,
|
|
64
57
|
help='Aha server to connect too.')
|
|
@@ -77,11 +70,5 @@ def getArgParser():
|
|
|
77
70
|
|
|
78
71
|
return pars
|
|
79
72
|
|
|
80
|
-
async def _main(argv, outp=s_output.stdout): # pragma: no cover
|
|
81
|
-
s_common.setlogging(logger, 'WARNING')
|
|
82
|
-
ret = await main(argv, outp=outp)
|
|
83
|
-
await asyncio.wait_for(s_coro.await_bg_tasks(), timeout=60)
|
|
84
|
-
return ret
|
|
85
|
-
|
|
86
73
|
if __name__ == '__main__': # pragma: no cover
|
|
87
|
-
|
|
74
|
+
s_cmd.exitmain(main)
|
synapse/tools/aha/enroll.py
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import os
|
|
2
|
-
import sys
|
|
3
|
-
import asyncio
|
|
4
|
-
import argparse
|
|
5
2
|
|
|
6
3
|
import synapse.common as s_common
|
|
7
4
|
import synapse.telepath as s_telepath
|
|
8
5
|
|
|
9
|
-
import synapse.lib.
|
|
6
|
+
import synapse.lib.cmd as s_cmd
|
|
10
7
|
import synapse.lib.output as s_output
|
|
11
8
|
import synapse.lib.certdir as s_certdir
|
|
12
9
|
import synapse.lib.msgpack as s_msgpack
|
|
@@ -22,9 +19,7 @@ Examples:
|
|
|
22
19
|
|
|
23
20
|
async def main(argv, outp=s_output.stdout):
|
|
24
21
|
|
|
25
|
-
pars =
|
|
26
|
-
formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
27
|
-
|
|
22
|
+
pars = s_cmd.Parser(prog='synapse.tools.aha.enroll', outp=outp, description=descr)
|
|
28
23
|
pars.add_argument('onceurl', help='The one-time use AHA user enrollment URL.')
|
|
29
24
|
opts = pars.parse_args(argv)
|
|
30
25
|
|
|
@@ -103,10 +98,6 @@ async def main(argv, outp=s_output.stdout):
|
|
|
103
98
|
|
|
104
99
|
return 0
|
|
105
100
|
|
|
106
|
-
async def _main(argv, outp=s_output.stdout): # pragma: no cover
|
|
107
|
-
ret = await main(argv, outp=outp)
|
|
108
|
-
await asyncio.wait_for(s_coro.await_bg_tasks(), timeout=60)
|
|
109
|
-
return ret
|
|
110
101
|
|
|
111
102
|
if __name__ == '__main__': # pragma: no cover
|
|
112
|
-
|
|
103
|
+
s_cmd.exitmain(main)
|
synapse/tools/aha/list.py
CHANGED
|
@@ -1,17 +1,10 @@
|
|
|
1
|
-
import sys
|
|
2
|
-
import asyncio
|
|
3
|
-
import logging
|
|
4
|
-
|
|
5
1
|
import synapse.exc as s_exc
|
|
6
|
-
import synapse.common as s_common
|
|
7
2
|
import synapse.telepath as s_telepath
|
|
8
3
|
|
|
9
|
-
import synapse.lib.
|
|
4
|
+
import synapse.lib.cmd as s_cmd
|
|
10
5
|
import synapse.lib.output as s_output
|
|
11
6
|
import synapse.lib.version as s_version
|
|
12
7
|
|
|
13
|
-
logger = logging.getLogger(__name__)
|
|
14
|
-
|
|
15
8
|
reqver = '>=2.11.0,<3.0.0'
|
|
16
9
|
|
|
17
10
|
async def main(argv, outp=s_output.stdout):
|
|
@@ -74,11 +67,5 @@ async def main(argv, outp=s_output.stdout):
|
|
|
74
67
|
outp.printf(mesg)
|
|
75
68
|
return 0
|
|
76
69
|
|
|
77
|
-
async def _main(argv, outp=s_output.stdout): # pragma: no cover
|
|
78
|
-
s_common.setlogging(logger, 'WARNING')
|
|
79
|
-
ret = await main(argv, outp=outp)
|
|
80
|
-
await asyncio.wait_for(s_coro.await_bg_tasks(), timeout=60)
|
|
81
|
-
return ret
|
|
82
|
-
|
|
83
70
|
if __name__ == '__main__': # pragma: no cover
|
|
84
|
-
|
|
71
|
+
s_cmd.exitmain(main)
|
synapse/tools/aha/mirror.py
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
import sys
|
|
2
|
-
import asyncio
|
|
3
|
-
import argparse
|
|
4
|
-
|
|
5
1
|
import synapse.exc as s_exc
|
|
6
2
|
import synapse.common as s_common
|
|
7
3
|
import synapse.telepath as s_telepath
|
|
8
4
|
|
|
9
|
-
import synapse.lib.
|
|
5
|
+
import synapse.lib.cmd as s_cmd
|
|
10
6
|
import synapse.lib.output as s_output
|
|
11
|
-
import synapse.lib.version as s_version
|
|
12
7
|
|
|
13
8
|
descr = '''
|
|
14
9
|
Query the Aha server for the service cluster status of mirrors.
|
|
@@ -87,8 +82,7 @@ def timeout_type(valu):
|
|
|
87
82
|
|
|
88
83
|
async def main(argv, outp=s_output.stdout):
|
|
89
84
|
|
|
90
|
-
pars =
|
|
91
|
-
formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
85
|
+
pars = s_cmd.Parser(prog='synapse.tools.aha.mirror', outp=outp, description=descr)
|
|
92
86
|
|
|
93
87
|
pars.add_argument('--url', default='cell:///vertex/storage', help='The telepath URL to connect to the AHA service.')
|
|
94
88
|
pars.add_argument('--timeout', type=timeout_type, default=10, help='The timeout in seconds for individual service API calls')
|
|
@@ -192,10 +186,5 @@ async def main(argv, outp=s_output.stdout):
|
|
|
192
186
|
outp.printf(f'ERROR: {mesg}')
|
|
193
187
|
return 1
|
|
194
188
|
|
|
195
|
-
async def _main(argv, outp=s_output.stdout): # pragma: no cover
|
|
196
|
-
ret = await main(argv, outp=outp)
|
|
197
|
-
await asyncio.wait_for(s_coro.await_bg_tasks(), timeout=60)
|
|
198
|
-
return ret
|
|
199
|
-
|
|
200
189
|
if __name__ == '__main__': # pragma: no cover
|
|
201
|
-
|
|
190
|
+
s_cmd.exitmain(main)
|