synapse 2.191.0__py311-none-any.whl → 2.192.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/axon.py +54 -23
- synapse/cortex.py +2 -2
- synapse/lib/ast.py +6 -2
- synapse/lib/cell.py +48 -0
- synapse/lib/nexus.py +2 -1
- synapse/lib/stormhttp.py +32 -35
- synapse/lib/stormtypes.py +102 -20
- synapse/lib/version.py +2 -2
- synapse/tests/test_axon.py +10 -0
- synapse/tests/test_cortex.py +52 -0
- synapse/tests/test_lib_ast.py +6 -0
- synapse/tests/test_lib_cell.py +35 -0
- synapse/tests/test_lib_httpapi.py +9 -2
- synapse/tests/test_lib_stormhttp.py +57 -12
- synapse/tests/test_servers_univ.py +0 -12
- synapse/tests/test_tools_apikey.py +227 -0
- synapse/tools/apikey.py +93 -0
- {synapse-2.191.0.dist-info → synapse-2.192.0.dist-info}/METADATA +1 -1
- {synapse-2.191.0.dist-info → synapse-2.192.0.dist-info}/RECORD +22 -20
- {synapse-2.191.0.dist-info → synapse-2.192.0.dist-info}/LICENSE +0 -0
- {synapse-2.191.0.dist-info → synapse-2.192.0.dist-info}/WHEEL +0 -0
- {synapse-2.191.0.dist-info → synapse-2.192.0.dist-info}/top_level.txt +0 -0
synapse/axon.py
CHANGED
|
@@ -594,7 +594,7 @@ class AxonApi(s_cell.CellApi, s_share.Share): # type: ignore
|
|
|
594
594
|
return await self.cell.dels(sha256s)
|
|
595
595
|
|
|
596
596
|
async def wget(self, url, params=None, headers=None, json=None, body=None, method='GET',
|
|
597
|
-
ssl=True, timeout=None, proxy=
|
|
597
|
+
ssl=True, timeout=None, proxy=True, ssl_opts=None):
|
|
598
598
|
'''
|
|
599
599
|
Stream a file download directly into the Axon.
|
|
600
600
|
|
|
@@ -607,6 +607,7 @@ class AxonApi(s_cell.CellApi, s_share.Share): # type: ignore
|
|
|
607
607
|
method (str): The HTTP method to use.
|
|
608
608
|
ssl (bool): Perform SSL verification.
|
|
609
609
|
timeout (int): The timeout of the request, in seconds.
|
|
610
|
+
proxy (str|bool): The proxy value.
|
|
610
611
|
ssl_opts (dict): Additional SSL/TLS options.
|
|
611
612
|
|
|
612
613
|
Notes:
|
|
@@ -621,6 +622,13 @@ class AxonApi(s_cell.CellApi, s_share.Share): # type: ignore
|
|
|
621
622
|
'client_key': <str> - PEM encoded key for use in mTLS. Alternatively, can be included in client_cert.
|
|
622
623
|
}
|
|
623
624
|
|
|
625
|
+
The following proxy arguments are supported::
|
|
626
|
+
|
|
627
|
+
None: Deprecated - Use the proxy defined by the http:proxy configuration option if set.
|
|
628
|
+
True: Use the proxy defined by the http:proxy configuration option if set.
|
|
629
|
+
False: Do not use the proxy defined by the http:proxy configuration option if set.
|
|
630
|
+
<str>: A proxy URL string.
|
|
631
|
+
|
|
624
632
|
The dictionary returned by this may contain the following values::
|
|
625
633
|
|
|
626
634
|
{
|
|
@@ -654,13 +662,13 @@ class AxonApi(s_cell.CellApi, s_share.Share): # type: ignore
|
|
|
654
662
|
ssl=ssl, timeout=timeout, proxy=proxy, ssl_opts=ssl_opts)
|
|
655
663
|
|
|
656
664
|
async def postfiles(self, fields, url, params=None, headers=None, method='POST',
|
|
657
|
-
ssl=True, timeout=None, proxy=
|
|
665
|
+
ssl=True, timeout=None, proxy=True, ssl_opts=None):
|
|
658
666
|
await self._reqUserAllowed(('axon', 'wput'))
|
|
659
667
|
return await self.cell.postfiles(fields, url, params=params, headers=headers, method=method,
|
|
660
668
|
ssl=ssl, timeout=timeout, proxy=proxy, ssl_opts=ssl_opts)
|
|
661
669
|
|
|
662
670
|
async def wput(self, sha256, url, params=None, headers=None, method='PUT',
|
|
663
|
-
ssl=True, timeout=None, proxy=
|
|
671
|
+
ssl=True, timeout=None, proxy=True, ssl_opts=None):
|
|
664
672
|
await self._reqUserAllowed(('axon', 'wput'))
|
|
665
673
|
return await self.cell.wput(sha256, url, params=params, headers=headers, method=method,
|
|
666
674
|
ssl=ssl, timeout=timeout, proxy=proxy, ssl_opts=ssl_opts)
|
|
@@ -935,6 +943,24 @@ class Axon(s_cell.Cell):
|
|
|
935
943
|
self.axonhist.add(item, tick=tick)
|
|
936
944
|
self.axonseqn.add(item)
|
|
937
945
|
|
|
946
|
+
async def _resolveProxyUrl(self, valu):
|
|
947
|
+
match valu:
|
|
948
|
+
case None:
|
|
949
|
+
s_common.deprecated('Setting the Axon HTTP proxy argument to None', curv='2.192.0')
|
|
950
|
+
return await self.getConfOpt('http:proxy')
|
|
951
|
+
|
|
952
|
+
case True:
|
|
953
|
+
return await self.getConfOpt('http:proxy')
|
|
954
|
+
|
|
955
|
+
case False:
|
|
956
|
+
return None
|
|
957
|
+
|
|
958
|
+
case str():
|
|
959
|
+
return valu
|
|
960
|
+
|
|
961
|
+
case _:
|
|
962
|
+
raise s_exc.BadArg(mesg='HTTP proxy argument must be a string or bool.')
|
|
963
|
+
|
|
938
964
|
async def _reqHas(self, sha256):
|
|
939
965
|
'''
|
|
940
966
|
Ensure a file exists; and return its size if so.
|
|
@@ -1462,7 +1488,7 @@ class Axon(s_cell.Cell):
|
|
|
1462
1488
|
sha256=sha256) from None
|
|
1463
1489
|
|
|
1464
1490
|
async def postfiles(self, fields, url, params=None, headers=None, method='POST',
|
|
1465
|
-
ssl=True, timeout=None, proxy=
|
|
1491
|
+
ssl=True, timeout=None, proxy=True, ssl_opts=None):
|
|
1466
1492
|
'''
|
|
1467
1493
|
Send files from the axon as fields in a multipart/form-data HTTP request.
|
|
1468
1494
|
|
|
@@ -1474,7 +1500,7 @@ class Axon(s_cell.Cell):
|
|
|
1474
1500
|
method (str): The HTTP method to use.
|
|
1475
1501
|
ssl (bool): Perform SSL verification.
|
|
1476
1502
|
timeout (int): The timeout of the request, in seconds.
|
|
1477
|
-
proxy (
|
|
1503
|
+
proxy (str|bool): The proxy value.
|
|
1478
1504
|
ssl_opts (dict): Additional SSL/TLS options.
|
|
1479
1505
|
|
|
1480
1506
|
Notes:
|
|
@@ -1497,6 +1523,13 @@ class Axon(s_cell.Cell):
|
|
|
1497
1523
|
'client_key': <str> - PEM encoded key for use in mTLS. Alternatively, can be included in client_cert.
|
|
1498
1524
|
}
|
|
1499
1525
|
|
|
1526
|
+
The following proxy arguments are supported::
|
|
1527
|
+
|
|
1528
|
+
None: Deprecated - Use the proxy defined by the http:proxy configuration option if set.
|
|
1529
|
+
True: Use the proxy defined by the http:proxy configuration option if set.
|
|
1530
|
+
False: Do not use the proxy defined by the http:proxy configuration option if set.
|
|
1531
|
+
<str>: A proxy URL string.
|
|
1532
|
+
|
|
1500
1533
|
The dictionary returned by this may contain the following values::
|
|
1501
1534
|
|
|
1502
1535
|
{
|
|
@@ -1512,14 +1545,11 @@ class Axon(s_cell.Cell):
|
|
|
1512
1545
|
Returns:
|
|
1513
1546
|
dict: An information dictionary containing the results of the request.
|
|
1514
1547
|
'''
|
|
1515
|
-
if proxy is None:
|
|
1516
|
-
proxy = self.conf.get('http:proxy')
|
|
1517
|
-
|
|
1518
1548
|
ssl = self.getCachedSslCtx(opts=ssl_opts, verify=ssl)
|
|
1519
1549
|
|
|
1520
1550
|
connector = None
|
|
1521
|
-
if proxy:
|
|
1522
|
-
connector = aiohttp_socks.ProxyConnector.from_url(
|
|
1551
|
+
if proxyurl := await self._resolveProxyUrl(proxy):
|
|
1552
|
+
connector = aiohttp_socks.ProxyConnector.from_url(proxyurl)
|
|
1523
1553
|
|
|
1524
1554
|
atimeout = aiohttp.ClientTimeout(total=timeout)
|
|
1525
1555
|
|
|
@@ -1583,18 +1613,15 @@ class Axon(s_cell.Cell):
|
|
|
1583
1613
|
}
|
|
1584
1614
|
|
|
1585
1615
|
async def wput(self, sha256, url, params=None, headers=None, method='PUT', ssl=True, timeout=None,
|
|
1586
|
-
filename=None, filemime=None, proxy=
|
|
1616
|
+
filename=None, filemime=None, proxy=True, ssl_opts=None):
|
|
1587
1617
|
'''
|
|
1588
1618
|
Stream a blob from the axon as the body of an HTTP request.
|
|
1589
1619
|
'''
|
|
1590
|
-
if proxy is None:
|
|
1591
|
-
proxy = self.conf.get('http:proxy')
|
|
1592
|
-
|
|
1593
1620
|
ssl = self.getCachedSslCtx(opts=ssl_opts, verify=ssl)
|
|
1594
1621
|
|
|
1595
1622
|
connector = None
|
|
1596
|
-
if proxy:
|
|
1597
|
-
connector = aiohttp_socks.ProxyConnector.from_url(
|
|
1623
|
+
if proxyurl := await self._resolveProxyUrl(proxy):
|
|
1624
|
+
connector = aiohttp_socks.ProxyConnector.from_url(proxyurl)
|
|
1598
1625
|
|
|
1599
1626
|
atimeout = aiohttp.ClientTimeout(total=timeout)
|
|
1600
1627
|
|
|
@@ -1654,7 +1681,7 @@ class Axon(s_cell.Cell):
|
|
|
1654
1681
|
return info
|
|
1655
1682
|
|
|
1656
1683
|
async def wget(self, url, params=None, headers=None, json=None, body=None, method='GET',
|
|
1657
|
-
ssl=True, timeout=None, proxy=
|
|
1684
|
+
ssl=True, timeout=None, proxy=True, ssl_opts=None):
|
|
1658
1685
|
'''
|
|
1659
1686
|
Stream a file download directly into the Axon.
|
|
1660
1687
|
|
|
@@ -1667,7 +1694,7 @@ class Axon(s_cell.Cell):
|
|
|
1667
1694
|
method (str): The HTTP method to use.
|
|
1668
1695
|
ssl (bool): Perform SSL verification.
|
|
1669
1696
|
timeout (int): The timeout of the request, in seconds.
|
|
1670
|
-
proxy (
|
|
1697
|
+
proxy (str|bool): The proxy value.
|
|
1671
1698
|
ssl_opts (dict): Additional SSL/TLS options.
|
|
1672
1699
|
|
|
1673
1700
|
Notes:
|
|
@@ -1682,6 +1709,13 @@ class Axon(s_cell.Cell):
|
|
|
1682
1709
|
'client_key': <str> - PEM encoded key for use in mTLS. Alternatively, can be included in client_cert.
|
|
1683
1710
|
}
|
|
1684
1711
|
|
|
1712
|
+
The following proxy arguments are supported::
|
|
1713
|
+
|
|
1714
|
+
None: Deprecated - Use the proxy defined by the http:proxy configuration option if set.
|
|
1715
|
+
True: Use the proxy defined by the http:proxy configuration option if set.
|
|
1716
|
+
False: Do not use the proxy defined by the http:proxy configuration option if set.
|
|
1717
|
+
<str>: A proxy URL string.
|
|
1718
|
+
|
|
1685
1719
|
The dictionary returned by this may contain the following values::
|
|
1686
1720
|
|
|
1687
1721
|
{
|
|
@@ -1712,14 +1746,11 @@ class Axon(s_cell.Cell):
|
|
|
1712
1746
|
'''
|
|
1713
1747
|
logger.debug(f'Wget called for [{url}].', extra=await self.getLogExtra(url=s_urlhelp.sanitizeUrl(url)))
|
|
1714
1748
|
|
|
1715
|
-
if proxy is None:
|
|
1716
|
-
proxy = self.conf.get('http:proxy')
|
|
1717
|
-
|
|
1718
1749
|
ssl = self.getCachedSslCtx(opts=ssl_opts, verify=ssl)
|
|
1719
1750
|
|
|
1720
1751
|
connector = None
|
|
1721
|
-
if proxy:
|
|
1722
|
-
connector = aiohttp_socks.ProxyConnector.from_url(
|
|
1752
|
+
if proxyurl := await self._resolveProxyUrl(proxy):
|
|
1753
|
+
connector = aiohttp_socks.ProxyConnector.from_url(proxyurl)
|
|
1723
1754
|
|
|
1724
1755
|
atimeout = aiohttp.ClientTimeout(total=timeout)
|
|
1725
1756
|
|
synapse/cortex.py
CHANGED
|
@@ -1739,7 +1739,7 @@ class Cortex(s_oauth.OAuthMixin, s_cell.Cell): # type: ignore
|
|
|
1739
1739
|
for filt in gdef.get('filters', ()):
|
|
1740
1740
|
await self.getStormQuery(filt)
|
|
1741
1741
|
|
|
1742
|
-
for pivo in gdef.get('
|
|
1742
|
+
for pivo in gdef.get('pivots', ()):
|
|
1743
1743
|
await self.getStormQuery(pivo)
|
|
1744
1744
|
|
|
1745
1745
|
for form, rule in gdef.get('forms', {}).items():
|
|
@@ -1749,7 +1749,7 @@ class Cortex(s_oauth.OAuthMixin, s_cell.Cell): # type: ignore
|
|
|
1749
1749
|
for filt in rule.get('filters', ()):
|
|
1750
1750
|
await self.getStormQuery(filt)
|
|
1751
1751
|
|
|
1752
|
-
for pivo in rule.get('
|
|
1752
|
+
for pivo in rule.get('pivots', ()):
|
|
1753
1753
|
await self.getStormQuery(pivo)
|
|
1754
1754
|
|
|
1755
1755
|
async def addStormGraph(self, gdef, user=None):
|
synapse/lib/ast.py
CHANGED
|
@@ -59,7 +59,8 @@ class AstNode:
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
def addExcInfo(self, exc):
|
|
62
|
-
|
|
62
|
+
if 'highlight' not in exc.errinfo:
|
|
63
|
+
exc.errinfo['highlight'] = self.getPosInfo()
|
|
63
64
|
return exc
|
|
64
65
|
|
|
65
66
|
def repr(self):
|
|
@@ -3554,7 +3555,10 @@ class VarDeref(Value):
|
|
|
3554
3555
|
|
|
3555
3556
|
valu = s_stormtypes.fromprim(base, path=path)
|
|
3556
3557
|
with s_scope.enter({'runt': runt}):
|
|
3557
|
-
|
|
3558
|
+
try:
|
|
3559
|
+
return await valu.deref(name)
|
|
3560
|
+
except s_exc.SynErr as e:
|
|
3561
|
+
raise self.kids[1].addExcInfo(e)
|
|
3558
3562
|
|
|
3559
3563
|
class FuncCall(Value):
|
|
3560
3564
|
|
synapse/lib/cell.py
CHANGED
|
@@ -459,6 +459,43 @@ class CellApi(s_base.Base):
|
|
|
459
459
|
async def delRole(self, iden):
|
|
460
460
|
return await self.cell.delRole(iden)
|
|
461
461
|
|
|
462
|
+
async def addUserApiKey(self, name, duration=None, useriden=None):
|
|
463
|
+
if useriden is None:
|
|
464
|
+
useriden = self.user.iden
|
|
465
|
+
|
|
466
|
+
if self.user.iden == useriden:
|
|
467
|
+
self.user.confirm(('auth', 'self', 'set', 'apikey'), default=True)
|
|
468
|
+
else:
|
|
469
|
+
self.user.confirm(('auth', 'user', 'set', 'apikey'))
|
|
470
|
+
|
|
471
|
+
return await self.cell.addUserApiKey(useriden, name, duration=duration)
|
|
472
|
+
|
|
473
|
+
async def listUserApiKeys(self, useriden=None):
|
|
474
|
+
if useriden is None:
|
|
475
|
+
useriden = self.user.iden
|
|
476
|
+
|
|
477
|
+
if self.user.iden == useriden:
|
|
478
|
+
self.user.confirm(('auth', 'self', 'set', 'apikey'), default=True)
|
|
479
|
+
else:
|
|
480
|
+
self.user.confirm(('auth', 'user', 'set', 'apikey'))
|
|
481
|
+
|
|
482
|
+
return await self.cell.listUserApiKeys(useriden)
|
|
483
|
+
|
|
484
|
+
async def delUserApiKey(self, iden):
|
|
485
|
+
apikey = await self.cell.getUserApiKey(iden)
|
|
486
|
+
if apikey is None:
|
|
487
|
+
mesg = f'User API key with {iden=} does not exist.'
|
|
488
|
+
raise s_exc.NoSuchIden(mesg=mesg, iden=iden)
|
|
489
|
+
|
|
490
|
+
useriden = apikey.get('user')
|
|
491
|
+
|
|
492
|
+
if self.user.iden == useriden:
|
|
493
|
+
self.user.confirm(('auth', 'self', 'set', 'apikey'), default=True)
|
|
494
|
+
else:
|
|
495
|
+
self.user.confirm(('auth', 'user', 'set', 'apikey'))
|
|
496
|
+
|
|
497
|
+
return await self.cell.delUserApiKey(iden)
|
|
498
|
+
|
|
462
499
|
@adminapi()
|
|
463
500
|
async def dyncall(self, iden, todo, gatekeys=()):
|
|
464
501
|
return await self.cell.dyncall(iden, todo, gatekeys=gatekeys)
|
|
@@ -1095,6 +1132,8 @@ class Cell(s_nexus.Pusher, s_telepath.Aware):
|
|
|
1095
1132
|
}
|
|
1096
1133
|
SYSCTL_CHECK_FREQ = 60.0
|
|
1097
1134
|
|
|
1135
|
+
LOGGED_HTTPAPI_HEADERS = ('User-Agent',)
|
|
1136
|
+
|
|
1098
1137
|
async def __anit__(self, dirn, conf=None, readonly=False, parent=None):
|
|
1099
1138
|
|
|
1100
1139
|
# phase 1
|
|
@@ -3248,6 +3287,15 @@ class Cell(s_nexus.Pusher, s_telepath.Aware):
|
|
|
3248
3287
|
'remoteip': remote_ip,
|
|
3249
3288
|
}
|
|
3250
3289
|
|
|
3290
|
+
headers = {}
|
|
3291
|
+
|
|
3292
|
+
for header in self.LOGGED_HTTPAPI_HEADERS:
|
|
3293
|
+
if (valu := handler.request.headers.get(header)) is not None:
|
|
3294
|
+
headers[header.lower()] = valu
|
|
3295
|
+
|
|
3296
|
+
if headers:
|
|
3297
|
+
enfo['headers'] = headers
|
|
3298
|
+
|
|
3251
3299
|
extra = {'synapse': enfo}
|
|
3252
3300
|
|
|
3253
3301
|
# It is possible that a Cell implementor may register handlers which
|
synapse/lib/nexus.py
CHANGED
|
@@ -505,6 +505,7 @@ class NexsRoot(s_base.Base):
|
|
|
505
505
|
if features.get('dynmirror'):
|
|
506
506
|
await proxy.readyToMirror()
|
|
507
507
|
|
|
508
|
+
synvers = cellinfo['synapse']['version']
|
|
508
509
|
cellvers = cellinfo['cell']['version']
|
|
509
510
|
if cellvers > self.cell.VERSION:
|
|
510
511
|
logger.error('Leader is a higher version than we are. Mirrors must be updated first. Entering read-only mode.')
|
|
@@ -537,7 +538,7 @@ class NexsRoot(s_base.Base):
|
|
|
537
538
|
offs = self.nexslog.index()
|
|
538
539
|
|
|
539
540
|
opts = {}
|
|
540
|
-
if
|
|
541
|
+
if synvers >= (2, 95, 0):
|
|
541
542
|
opts['tellready'] = True
|
|
542
543
|
|
|
543
544
|
genr = proxy.getNexusChanges(offs, **opts)
|
synapse/lib/stormhttp.py
CHANGED
|
@@ -91,12 +91,19 @@ class LibHttp(s_stormtypes.Lib):
|
|
|
91
91
|
|
|
92
92
|
For APIs that accept an ssl_opts argument, the dictionary may contain the following values::
|
|
93
93
|
|
|
94
|
-
{
|
|
94
|
+
({
|
|
95
95
|
'verify': <bool> - Perform SSL/TLS verification. Is overridden by the ssl_verify argument.
|
|
96
96
|
'client_cert': <str> - PEM encoded full chain certificate for use in mTLS.
|
|
97
97
|
'client_key': <str> - PEM encoded key for use in mTLS. Alternatively, can be included in client_cert.
|
|
98
98
|
'ca_cert': <str> - A PEM encoded full chain CA certificate for use when verifying the request.
|
|
99
|
-
}
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
For APIs that accept a proxy argument, the following values are supported::
|
|
102
|
+
|
|
103
|
+
$lib.null: Deprecated - Use the proxy defined by the http:proxy configuration option if set.
|
|
104
|
+
$lib.true: Use the proxy defined by the http:proxy configuration option if set.
|
|
105
|
+
$lib.false: Do not use the proxy defined by the http:proxy configuration option if set.
|
|
106
|
+
<str>: A proxy URL string.
|
|
100
107
|
'''
|
|
101
108
|
_storm_locals = (
|
|
102
109
|
{'name': 'get', 'desc': 'Get the contents of a given URL.',
|
|
@@ -113,8 +120,8 @@ class LibHttp(s_stormtypes.Lib):
|
|
|
113
120
|
'default': 300},
|
|
114
121
|
{'name': 'allow_redirects', 'type': 'bool', 'desc': 'If set to false, do not follow redirects.',
|
|
115
122
|
'default': True},
|
|
116
|
-
{'name': 'proxy', 'type': ['bool', '
|
|
117
|
-
'desc': '
|
|
123
|
+
{'name': 'proxy', 'type': ['bool', 'str'],
|
|
124
|
+
'desc': 'Configure proxy usage. See $lib.inet.http help for additional details.', 'default': True},
|
|
118
125
|
{'name': 'ssl_opts', 'type': 'dict',
|
|
119
126
|
'desc': 'Optional SSL/TLS options. See $lib.inet.http help for additional details.',
|
|
120
127
|
'default': None},
|
|
@@ -145,8 +152,8 @@ class LibHttp(s_stormtypes.Lib):
|
|
|
145
152
|
'and the corresponding file will be uploaded as the value for '
|
|
146
153
|
'the field.',
|
|
147
154
|
'default': None},
|
|
148
|
-
{'name': 'proxy', 'type': ['bool', '
|
|
149
|
-
'desc': '
|
|
155
|
+
{'name': 'proxy', 'type': ['bool', 'str'],
|
|
156
|
+
'desc': 'Configure proxy usage. See $lib.inet.http help for additional details.', 'default': True},
|
|
150
157
|
{'name': 'ssl_opts', 'type': 'dict',
|
|
151
158
|
'desc': 'Optional SSL/TLS options. See $lib.inet.http help for additional details.',
|
|
152
159
|
'default': None},
|
|
@@ -167,8 +174,8 @@ class LibHttp(s_stormtypes.Lib):
|
|
|
167
174
|
'default': 300, },
|
|
168
175
|
{'name': 'allow_redirects', 'type': 'bool', 'desc': 'If set to true, follow redirects.',
|
|
169
176
|
'default': False},
|
|
170
|
-
{'name': 'proxy', 'type': ['bool', '
|
|
171
|
-
'desc': '
|
|
177
|
+
{'name': 'proxy', 'type': ['bool', 'str'],
|
|
178
|
+
'desc': 'Configure proxy usage. See $lib.inet.http help for additional details.', 'default': True},
|
|
172
179
|
{'name': 'ssl_opts', 'type': 'dict',
|
|
173
180
|
'desc': 'Optional SSL/TLS options. See $lib.inet.http help for additional details.',
|
|
174
181
|
'default': None},
|
|
@@ -200,8 +207,8 @@ class LibHttp(s_stormtypes.Lib):
|
|
|
200
207
|
'and the corresponding file will be uploaded as the value for '
|
|
201
208
|
'the field.',
|
|
202
209
|
'default': None},
|
|
203
|
-
{'name': 'proxy', 'type': ['bool', '
|
|
204
|
-
'desc': '
|
|
210
|
+
{'name': 'proxy', 'type': ['bool', 'str'],
|
|
211
|
+
'desc': 'Configure proxy usage. See $lib.inet.http help for additional details.', 'default': True},
|
|
205
212
|
{'name': 'ssl_opts', 'type': 'dict',
|
|
206
213
|
'desc': 'Optional SSL/TLS options. See $lib.inet.http help for additional details.',
|
|
207
214
|
'default': None},
|
|
@@ -221,8 +228,8 @@ class LibHttp(s_stormtypes.Lib):
|
|
|
221
228
|
'default': 300},
|
|
222
229
|
{'name': 'params', 'type': 'dict', 'desc': 'Optional parameters which may be passed to the connection request.',
|
|
223
230
|
'default': None},
|
|
224
|
-
{'name': 'proxy', 'type': ['bool', '
|
|
225
|
-
'desc': '
|
|
231
|
+
{'name': 'proxy', 'type': ['bool', 'str'],
|
|
232
|
+
'desc': 'Configure proxy usage. See $lib.inet.http help for additional details.', 'default': True},
|
|
226
233
|
{'name': 'ssl_opts', 'type': 'dict',
|
|
227
234
|
'desc': 'Optional SSL/TLS options. See $lib.inet.http help for additional details.',
|
|
228
235
|
'default': None},
|
|
@@ -308,23 +315,23 @@ class LibHttp(s_stormtypes.Lib):
|
|
|
308
315
|
return s_common.httpcodereason(code)
|
|
309
316
|
|
|
310
317
|
async def _httpEasyHead(self, url, headers=None, ssl_verify=True, params=None, timeout=300,
|
|
311
|
-
allow_redirects=False, proxy=
|
|
318
|
+
allow_redirects=False, proxy=True, ssl_opts=None):
|
|
312
319
|
return await self._httpRequest('HEAD', url, headers=headers, ssl_verify=ssl_verify, params=params,
|
|
313
320
|
timeout=timeout, allow_redirects=allow_redirects, proxy=proxy, ssl_opts=ssl_opts)
|
|
314
321
|
|
|
315
322
|
async def _httpEasyGet(self, url, headers=None, ssl_verify=True, params=None, timeout=300,
|
|
316
|
-
allow_redirects=True, proxy=
|
|
323
|
+
allow_redirects=True, proxy=True, ssl_opts=None):
|
|
317
324
|
return await self._httpRequest('GET', url, headers=headers, ssl_verify=ssl_verify, params=params,
|
|
318
325
|
timeout=timeout, allow_redirects=allow_redirects, proxy=proxy, ssl_opts=ssl_opts)
|
|
319
326
|
|
|
320
327
|
async def _httpPost(self, url, headers=None, json=None, body=None, ssl_verify=True,
|
|
321
|
-
params=None, timeout=300, allow_redirects=True, fields=None, proxy=
|
|
328
|
+
params=None, timeout=300, allow_redirects=True, fields=None, proxy=True, ssl_opts=None):
|
|
322
329
|
return await self._httpRequest('POST', url, headers=headers, json=json, body=body,
|
|
323
330
|
ssl_verify=ssl_verify, params=params, timeout=timeout,
|
|
324
331
|
allow_redirects=allow_redirects, fields=fields, proxy=proxy, ssl_opts=ssl_opts)
|
|
325
332
|
|
|
326
333
|
async def inetHttpConnect(self, url, headers=None, ssl_verify=True, timeout=300,
|
|
327
|
-
params=None, proxy=
|
|
334
|
+
params=None, proxy=True, ssl_opts=None):
|
|
328
335
|
|
|
329
336
|
url = await s_stormtypes.tostr(url)
|
|
330
337
|
headers = await s_stormtypes.toprim(headers)
|
|
@@ -338,15 +345,9 @@ class LibHttp(s_stormtypes.Lib):
|
|
|
338
345
|
|
|
339
346
|
sock = await WebSocket.anit()
|
|
340
347
|
|
|
341
|
-
if proxy is not None:
|
|
342
|
-
self.runt.confirm(('storm', 'lib', 'inet', 'http', 'proxy'))
|
|
343
|
-
|
|
344
|
-
if proxy is None:
|
|
345
|
-
proxy = await self.runt.snap.core.getConfOpt('http:proxy')
|
|
346
|
-
|
|
347
348
|
connector = None
|
|
348
|
-
if proxy:
|
|
349
|
-
connector = aiohttp_socks.ProxyConnector.from_url(
|
|
349
|
+
if proxyurl := await s_stormtypes.resolveCoreProxyUrl(proxy):
|
|
350
|
+
connector = aiohttp_socks.ProxyConnector.from_url(proxyurl)
|
|
350
351
|
|
|
351
352
|
timeout = aiohttp.ClientTimeout(total=timeout)
|
|
352
353
|
kwargs = {'timeout': timeout}
|
|
@@ -387,7 +388,7 @@ class LibHttp(s_stormtypes.Lib):
|
|
|
387
388
|
|
|
388
389
|
async def _httpRequest(self, meth, url, headers=None, json=None, body=None,
|
|
389
390
|
ssl_verify=True, params=None, timeout=300, allow_redirects=True,
|
|
390
|
-
fields=None, proxy=
|
|
391
|
+
fields=None, proxy=True, ssl_opts=None):
|
|
391
392
|
meth = await s_stormtypes.tostr(meth)
|
|
392
393
|
url = await s_stormtypes.tostr(url)
|
|
393
394
|
json = await s_stormtypes.toprim(json)
|
|
@@ -407,19 +408,18 @@ class LibHttp(s_stormtypes.Lib):
|
|
|
407
408
|
|
|
408
409
|
headers = s_stormtypes.strifyHttpArg(headers)
|
|
409
410
|
|
|
410
|
-
if proxy is not None:
|
|
411
|
-
self.runt.confirm(('storm', 'lib', 'inet', 'http', 'proxy'))
|
|
412
|
-
|
|
413
411
|
if fields:
|
|
414
412
|
if any(['sha256' in field for field in fields]):
|
|
415
413
|
self.runt.confirm(('storm', 'lib', 'axon', 'wput'))
|
|
416
414
|
|
|
417
415
|
kwargs = {}
|
|
418
|
-
|
|
419
|
-
|
|
416
|
+
|
|
417
|
+
ok, proxy = await s_stormtypes.resolveAxonProxyArg(proxy)
|
|
418
|
+
if ok:
|
|
420
419
|
kwargs['proxy'] = proxy
|
|
421
420
|
|
|
422
421
|
if ssl_opts is not None:
|
|
422
|
+
axonvers = self.runt.snap.core.axoninfo['synapse']['version']
|
|
423
423
|
mesg = f'The ssl_opts argument requires an Axon Synapse version {s_stormtypes.AXON_MINVERS_SSLOPTS}, ' \
|
|
424
424
|
f'but the Axon is running {axonvers}'
|
|
425
425
|
s_version.reqVersion(axonvers, s_stormtypes.AXON_MINVERS_SSLOPTS, mesg=mesg)
|
|
@@ -432,12 +432,9 @@ class LibHttp(s_stormtypes.Lib):
|
|
|
432
432
|
|
|
433
433
|
kwargs['ssl'] = self.runt.snap.core.getCachedSslCtx(opts=ssl_opts, verify=ssl_verify)
|
|
434
434
|
|
|
435
|
-
if proxy is None:
|
|
436
|
-
proxy = await self.runt.snap.core.getConfOpt('http:proxy')
|
|
437
|
-
|
|
438
435
|
connector = None
|
|
439
|
-
if proxy:
|
|
440
|
-
connector = aiohttp_socks.ProxyConnector.from_url(
|
|
436
|
+
if proxyurl := await s_stormtypes.resolveCoreProxyUrl(proxy):
|
|
437
|
+
connector = aiohttp_socks.ProxyConnector.from_url(proxyurl)
|
|
441
438
|
|
|
442
439
|
timeout = aiohttp.ClientTimeout(total=timeout)
|
|
443
440
|
|