insightconnect-plugin-runtime 6.2.3__py3-none-any.whl → 6.2.5__py3-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.
@@ -599,7 +599,7 @@ class AWSAction(Action):
599
599
  auth_params: Dict[str, str],
600
600
  ):
601
601
  session_name = str(uuid.uuid1())
602
- sts_client = boto3.client("sts", **auth_params)
602
+ sts_client = boto3.client("sts", **auth_params, region_name=assume_role_params.get(REGION))
603
603
  try:
604
604
  assumed_role_object = sts_client.assume_role(
605
605
  **clean(
@@ -21,6 +21,7 @@ from insightconnect_plugin_runtime.exceptions import (
21
21
  PluginException,
22
22
  HTTPStatusCodes,
23
23
  ResponseExceptionData,
24
+ APIException
24
25
  )
25
26
 
26
27
  CAMEL_CASE_REGEX = r"\b[a-z0-9]+([A-Z][a-z]+[0-9]*)*\b"
@@ -111,6 +112,7 @@ def make_request(
111
112
  exception_custom_configs: Dict[int, Exception] = {},
112
113
  exception_data_location: str = None,
113
114
  allowed_status_codes: List[str] = [],
115
+ max_response_size: int = None,
114
116
  ) -> Tuple[requests.Response, Dict]:
115
117
  """
116
118
  Makes a HTTP request while checking for RequestErrors and JSONDecodeErrors
@@ -133,6 +135,8 @@ def make_request(
133
135
  :type str:
134
136
  :param allowed_status_codes: Status codes that will not raise an exception.
135
137
  :type List[str]:
138
+ :param max_response_size: Raise an error if the stream content is bigger than this specified size
139
+ :type int:
136
140
 
137
141
  :return: The request response and the response JSON.
138
142
  :rtype: Tuple[Response, Dict]
@@ -148,6 +152,19 @@ def make_request(
148
152
  cert=cert,
149
153
  stream=stream,
150
154
  )
155
+
156
+ # Before we close this session check and download all content, check if the returned content is too large.
157
+ # This may not be supported on all APIs as they need to support streaming and return the content-length
158
+ # header but adding this extra check will be beneficial for memory usage to those that do support it.
159
+ if stream and max_response_size:
160
+ resp_size = response.headers.get("content-length", "0")
161
+ if int(resp_size) > max_response_size:
162
+ raise APIException(
163
+ status_code=400,
164
+ cause=f"API response is exceeding allowed limit of {max_response_size} bytes.",
165
+ assistance="Please update the parameters to reduce the size of the data being returned.",
166
+ data=f"Content length returned was {resp_size} and max allowed is {max_response_size}",
167
+ )
151
168
  except requests.exceptions.Timeout as exception:
152
169
  raise PluginException(
153
170
  preset=PluginException.Preset.TIMEOUT, data=str(exception)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: insightconnect-plugin-runtime
3
- Version: 6.2.3
3
+ Version: 6.2.5
4
4
  Summary: InsightConnect Plugin Runtime
5
5
  Home-page: https://github.com/rapid7/komand-plugin-sdk-python
6
6
  Author: Rapid7 Integrations Alliance
@@ -219,6 +219,8 @@ contributed. Black is installed as a test dependency and the hook can be initial
219
219
  after cloning this repository.
220
220
 
221
221
  ## Changelog
222
+ * 6.2.5 - Fixed bug related to failure to set default region to assume role method in `aws_client` for newer versions of boto3 | Updated alpine image packages on build
223
+ * 6.2.4 - Update `make_request` helper to support extra parameter of `max_response_size` to cap the response
222
224
  * 6.2.3 - Updated dockerfiles for both `slim` and `full` SDK types to use Python 3.11.11 | Updated dependencies | Removed `pkg_resources` usage due to deprecation
223
225
  * 6.2.2 - Fix instances where logging errors would lead to duplicate entries being output | Add option to hash only on provided keys for `hash_sha1` function
224
226
  * 6.2.1 - Fix instances where logging would lead to duplicate entries being output
@@ -4,7 +4,7 @@ insightconnect_plugin_runtime/cli.py,sha256=Pb-Janu-XfRlSXxPHh30OIquljWptrhhS51C
4
4
  insightconnect_plugin_runtime/connection.py,sha256=4bHHV2B0UFGsAtvLu1fiYQRwx7fissUakHPUyjLQO0E,2340
5
5
  insightconnect_plugin_runtime/dispatcher.py,sha256=ru7njnyyWE1-oD-VbZJ-Z8tELwvDf69rM7Iezs4rbnw,1774
6
6
  insightconnect_plugin_runtime/exceptions.py,sha256=Pvcdkx81o6qC2qU661x-DzNjuIMP82x52nPMSEqEo4s,8491
7
- insightconnect_plugin_runtime/helper.py,sha256=WiCFu4S33BL8wugBmyFH-06inkcXPmdC5cv0UGlSHfA,32646
7
+ insightconnect_plugin_runtime/helper.py,sha256=B0XqAXmn8CT1KQ6i5IoWLQrQ_HVOvuKrIKFuj_npQ-g,33770
8
8
  insightconnect_plugin_runtime/metrics.py,sha256=hf_Aoufip_s4k4o8Gtzz90ymZthkaT2e5sXh5B4LcF0,3186
9
9
  insightconnect_plugin_runtime/plugin.py,sha256=Yf4LNczykDVc31F9G8uuJ9gxEsgmxmAr0n4pcZzichM,26393
10
10
  insightconnect_plugin_runtime/schema.py,sha256=6MVw5hqGATU1VLgwfOWfPsP3hy1OnsugCTsgX8sknes,521
@@ -18,7 +18,7 @@ insightconnect_plugin_runtime/api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeR
18
18
  insightconnect_plugin_runtime/api/endpoints.py,sha256=8QQrxzW8jmQIkalud8fqYwB05uUw8sTiDNgO5ZekOCA,33353
19
19
  insightconnect_plugin_runtime/api/schemas.py,sha256=jRmDrwLJTBl-iQOnyZkSwyJlCWg4eNjAnKfD9Eko4z0,2754
20
20
  insightconnect_plugin_runtime/clients/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
21
- insightconnect_plugin_runtime/clients/aws_client.py,sha256=bgSK3Txr1YonDiUN5JFEZ5cAyCXFM14JjfMus6lRV8o,23017
21
+ insightconnect_plugin_runtime/clients/aws_client.py,sha256=ViJF3klbD1YM5GVxme3BFYfpuADUlVGP8sdbX2Z6_Cw,23061
22
22
  insightconnect_plugin_runtime/clients/oauth.py,sha256=bWtAGRMwdK4dw9vMPcw9usklyIHBDtZh55kMZ7sWROc,2453
23
23
  insightconnect_plugin_runtime/data/input_message_schema.json,sha256=7_BcHi6UOBiVWGrrJHHn5IoddteXjL7GOKETdO9T2DE,1770
24
24
  insightconnect_plugin_runtime/data/output_message_schema.json,sha256=Qya6U-NR5MfOlw4V98VpQzGBVq75eGMUQhI-j3yxOHI,1137
@@ -68,7 +68,7 @@ tests/unit/test_aws_action.py,sha256=pBE23Qn4aXKJqPmwiHMcEU5zPdyvbKO-eK-6jUlrsQw
68
68
  tests/unit/test_custom_encoder.py,sha256=KLYyVOTq9MEkZXyhVHqjm5LVSW6uJS4Davgghsw9DGk,2207
69
69
  tests/unit/test_endpoints.py,sha256=LuXOfLBu47rDjGa5YEsOwTZBEdvQdl_C6-r46oxWZA8,6401
70
70
  tests/unit/test_exceptions.py,sha256=Y4F-ij8WkEJkUU3mPvxlEchqE9NCdxDvR8bJzPVVNao,5328
71
- tests/unit/test_helpers.py,sha256=9Y5N5cUBtesfr289oOZFekMJb84VYuFjucqQ9VEk3WQ,17431
71
+ tests/unit/test_helpers.py,sha256=ym1tFi1VSKmdPaHEAlMEl1S7Ibu9-LrqZ2oqJv7bfbE,18685
72
72
  tests/unit/test_metrics.py,sha256=PjjTrB9w7uQ2Q5UN-893-SsH3EGJuBseOMHSD1I004s,7979
73
73
  tests/unit/test_oauth.py,sha256=nbFG0JH1x04ExXqSe-b5BGdt_hJs7DP17eUa6bQzcYI,2093
74
74
  tests/unit/test_plugin.py,sha256=ZTNAZWwZhDIAbxkVuWhnz9FzmojbijgMmsLWM2mXQI0,4160
@@ -77,8 +77,8 @@ tests/unit/test_server_cloud_plugins.py,sha256=PuMDHTz3af6lR9QK1BtPScr7_cRbWheto
77
77
  tests/unit/test_server_spec.py,sha256=je97BaktgK0Fiz3AwFPkcmHzYtOJJNqJV_Fw5hrvqX4,644
78
78
  tests/unit/test_trigger.py,sha256=E53mAUoVyponWu_4IQZ0IC1gQ9lakBnTn_9vKN2IZfg,1692
79
79
  tests/unit/test_variables.py,sha256=OUEOqGYZA3Nd5oKk5GVY3hcrWKHpZpxysBJcO_v5gzs,291
80
- tests/unit/utils.py,sha256=VooVmfpIgxmglNdtmT32AkEDFxHxyRHLK8RsCWjjYRY,2153
81
- insightconnect_plugin_runtime-6.2.3.dist-info/METADATA,sha256=m0fZClkhAwEVwvC34tDdEfursS7-CuHs5bhYZJNJab8,15610
82
- insightconnect_plugin_runtime-6.2.3.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
83
- insightconnect_plugin_runtime-6.2.3.dist-info/top_level.txt,sha256=AJtyJOpiFzHxsbHUICTcUKXyrGQ3tZxhrEHsPjJBvEA,36
84
- insightconnect_plugin_runtime-6.2.3.dist-info/RECORD,,
80
+ tests/unit/utils.py,sha256=hcY0A2H_DMgCDXUTvDtCXMdMvRjLQgTaGcTpATb8YG0,2236
81
+ insightconnect_plugin_runtime-6.2.5.dist-info/METADATA,sha256=n08BX1O96S4-Nd6kDOiKrXF5jWec4b2Qq4g3DLBJLIs,15887
82
+ insightconnect_plugin_runtime-6.2.5.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
83
+ insightconnect_plugin_runtime-6.2.5.dist-info/top_level.txt,sha256=AJtyJOpiFzHxsbHUICTcUKXyrGQ3tZxhrEHsPjJBvEA,36
84
+ insightconnect_plugin_runtime-6.2.5.dist-info/RECORD,,
@@ -4,6 +4,7 @@ from insightconnect_plugin_runtime.exceptions import (
4
4
  HTTPStatusCodes,
5
5
  ResponseExceptionData,
6
6
  PluginException,
7
+ APIException
7
8
  )
8
9
  import requests
9
10
  import os
@@ -378,16 +379,39 @@ class TestRequestsHelpers(TestCase):
378
379
  json={"sample": "value"},
379
380
  headers={"Content-Type": "application/json"},
380
381
  )
381
- response = helper.make_request(_request=request)
382
+ response = helper.make_request(_request=request, stream=True, max_response_size=100)
382
383
  expected = {
383
384
  "json": {"example": "sample"},
384
385
  "status_code": 200,
385
386
  "content": b"example",
386
387
  "url": "https://example.com/success",
388
+ "content-length": "1",
387
389
  }
388
390
  self.assertEqual(response.content, expected.get("content"))
389
391
  self.assertEqual(response.status_code, expected.get("status_code"))
390
392
  self.assertEqual(response.url, expected.get("url"))
393
+ self.assertEqual(response.headers.get("content-length"), expected.get("content-length"))
394
+
395
+ @patch("requests.Session.send")
396
+ def test_make_request_enforces_max_response_size(self, mocked_request):
397
+ returned_max_size, test_max_size = "5000", 1527
398
+
399
+ response = requests.Response()
400
+ response.headers = {"content-length": returned_max_size, "content-type": "application/json"}
401
+ mocked_request.return_value = response
402
+
403
+ test_request = requests.Request(method="GET", url="https://event_source.com/api/v1/logs")
404
+
405
+ with self.assertRaises(APIException) as api_err:
406
+ helper.make_request(_request=test_request, stream=True, max_response_size=test_max_size)
407
+
408
+ self.assertEqual(400, api_err.exception.status_code)
409
+ exp_err_cause = f"API response is exceeding allowed limit of {test_max_size} bytes."
410
+ exp_err_data = f"Content length returned was {returned_max_size} and max allowed is {test_max_size}"
411
+ self.assertEqual(400, api_err.exception.status_code)
412
+ self.assertEqual(exp_err_cause, api_err.exception.cause)
413
+ self.assertEqual(exp_err_data, api_err.exception.data)
414
+
391
415
 
392
416
  @parameterized.expand(
393
417
  [
tests/unit/utils.py CHANGED
@@ -34,6 +34,7 @@ def get_mock_response(
34
34
  response._content = bytes_string
35
35
  response.url = url
36
36
  response.reason = reason
37
+ response.headers = {"content-length": "1", "content-type": "application/json"}
37
38
 
38
39
  def return_json():
39
40
  return data