insightconnect-plugin-runtime 5.5.5__py3-none-any.whl → 5.6.1__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.
@@ -283,7 +283,7 @@ class Endpoints:
283
283
  self.logger.debug("Request input: %s", input_message)
284
284
  Endpoints.validate_action_trigger_task_empty_input(input_message)
285
285
  Endpoints.validate_action_trigger_task_name(input_message, name, "task")
286
- output = self.run_action_trigger_task(input_message, True)
286
+ output = self.run_action_trigger_task(input_message, True, connection_test_type="test_task")
287
287
  return output
288
288
 
289
289
  @v1.route("/api")
@@ -821,13 +821,13 @@ class Endpoints:
821
821
 
822
822
  return input_data
823
823
 
824
- def run_action_trigger_task(self, input_message, test=False):
824
+ def run_action_trigger_task(self, input_message, test=False, connection_test_type="test"):
825
825
  connection = input_message.get("body", {}).get("connection", {})
826
826
  status_code = 200
827
827
  output = None
828
828
  try:
829
829
  output = self.plugin.handle_step(
830
- input_message, is_debug=self.debug, is_test=test
830
+ input_message, is_debug=self.debug, is_test=test, connection_test_type=connection_test_type
831
831
  )
832
832
  except LoggedException as error:
833
833
  wrapped_exception = error.ex
@@ -841,6 +841,8 @@ class Endpoints:
841
841
  and wrapped_exception.preset is PluginException.Preset.BAD_REQUEST
842
842
  ):
843
843
  status_code = 400
844
+ elif isinstance(wrapped_exception, (ConnectionTestException, ClientException)):
845
+ status_code = 400
844
846
  elif isinstance(wrapped_exception, ServerException):
845
847
  # I'm unsure about this
846
848
  status_code = 500
@@ -207,3 +207,9 @@ class PluginException(ConnectionTestException):
207
207
  return "An error occurred during plugin execution!\n\n{cause} {assistance}".format(
208
208
  cause=self.cause, assistance=self.assistance
209
209
  )
210
+
211
+
212
+ class APIException(PluginException):
213
+ def __init__(self, cause=None, assistance=None, data=None, preset=None, status_code=None):
214
+ super().__init__(cause, assistance, data, preset)
215
+ self.status_code = status_code
@@ -243,7 +243,8 @@ def response_handler(
243
243
  if hasattr(exception, "data") and data is not None:
244
244
  exception.data = data
245
245
  elif status_code_preset:
246
- exception = PluginException(preset=status_code_preset, data=data)
246
+ exception = PluginException(preset=status_code_preset)
247
+ exception.data = data
247
248
 
248
249
  raise exception
249
250
 
@@ -627,7 +627,7 @@ class Plugin(object):
627
627
  # Check if connection test func available. If so - use it (preferred). Else fallback to action/trigger test
628
628
  if hasattr(step.connection, "test"):
629
629
  if hasattr(step.connection, "test") and connection_test_type == "test_task":
630
- func = step.connection.task_test
630
+ func = step.connection.test_task
631
631
  else:
632
632
  func = step.connection.test
633
633
  else:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: insightconnect-plugin-runtime
3
- Version: 5.5.5
3
+ Version: 5.6.1
4
4
  Summary: InsightConnect Plugin Runtime
5
5
  Home-page: https://github.com/rapid7/komand-plugin-sdk-python
6
6
  Author: Rapid7 Integrations Alliance
@@ -211,6 +211,8 @@ contributed. Black is installed as a test dependency and the hook can be initial
211
211
  after cloning this repository.
212
212
 
213
213
  ## Changelog
214
+ * 5.6.1 - Making sure all paths that can call the task connection test endpoints return a 400 error if the test fails
215
+ * 5.6.0 - Add APIException class for error handling | Fix error in response_handler where data of type Response was not correctly being returned
214
216
  * 5.5.5 - Address bug with typing for type `Dict` in Python 3.8
215
217
  * 5.5.4 - Support pagination parameters within AWS client.
216
218
  * 5.5.3 - Adding in a new endpoint that can be called to run a task connection test
@@ -3,10 +3,10 @@ insightconnect_plugin_runtime/action.py,sha256=8gsOONf7mzY83O3DNjCBIafk7C7acnf7m
3
3
  insightconnect_plugin_runtime/cli.py,sha256=Pb-Janu-XfRlSXxPHh30OIquljWptrhhS51C3clJqh4,8939
4
4
  insightconnect_plugin_runtime/connection.py,sha256=4bHHV2B0UFGsAtvLu1fiYQRwx7fissUakHPUyjLQO0E,2340
5
5
  insightconnect_plugin_runtime/dispatcher.py,sha256=ru7njnyyWE1-oD-VbZJ-Z8tELwvDf69rM7Iezs4rbnw,1774
6
- insightconnect_plugin_runtime/exceptions.py,sha256=7aYNoGgmV6SugHAQqeQYm1zo2LZm0vgXEGqHmYD7NCo,8260
7
- insightconnect_plugin_runtime/helper.py,sha256=XlMGpW2LQYo5KjhJeJtaYRCEDDWjrA9ZW1jP9FDpKpE,31155
6
+ insightconnect_plugin_runtime/exceptions.py,sha256=Pvcdkx81o6qC2qU661x-DzNjuIMP82x52nPMSEqEo4s,8491
7
+ insightconnect_plugin_runtime/helper.py,sha256=kXUt_yq6-9_wMdCIkS1fC3dddE8uwH9tcRITXvrJHIM,31178
8
8
  insightconnect_plugin_runtime/metrics.py,sha256=hf_Aoufip_s4k4o8Gtzz90ymZthkaT2e5sXh5B4LcF0,3186
9
- insightconnect_plugin_runtime/plugin.py,sha256=s2YVyygPcNeXeDi3X_JmaCiLHXZWIqz4mlLJy6p7-UA,24904
9
+ insightconnect_plugin_runtime/plugin.py,sha256=l09-NxNPIfjSyklO4Jnbwf5yHQdobkcs29sjFV6N2ZE,24904
10
10
  insightconnect_plugin_runtime/schema.py,sha256=jTNc6KAMqFpaDVWrAYhkVC6e8I63P3X7uVlJkAr1hiY,583
11
11
  insightconnect_plugin_runtime/server.py,sha256=09fxsbKf2ZZvSqRP2Bv9e9-fspDyEFR8_YgIFeMnXqQ,12578
12
12
  insightconnect_plugin_runtime/step.py,sha256=KdERg-789-s99IEKN61DR08naz-YPxyinPT0C_T81C4,855
@@ -15,7 +15,7 @@ insightconnect_plugin_runtime/trigger.py,sha256=Zq3cy68N3QxAGbNZKCID6CZF05Zi7YD2
15
15
  insightconnect_plugin_runtime/util.py,sha256=qPkZ3LA55nYuNYdansEbnCnBccQkpzIpp9NA1B64Kvw,8444
16
16
  insightconnect_plugin_runtime/variables.py,sha256=7FjJGnU7KUR7m9o-_tRq7Q3KiaB1Pp0Apj1NGgOwrJk,3056
17
17
  insightconnect_plugin_runtime/api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
- insightconnect_plugin_runtime/api/endpoints.py,sha256=rqieWL71Eu0jIKrspizof4xSyp672xCQxbrQUYdpbbA,32560
18
+ insightconnect_plugin_runtime/api/endpoints.py,sha256=xprYehTnO6TSpWcNXZ5iYOAgYk5-5UnxtgM9BDIYuRw,32792
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
21
  insightconnect_plugin_runtime/clients/aws_client.py,sha256=qKldWkyETmVhfoXbMZY58FFaDas6B5Uqc0D1LJROf6M,21658
@@ -67,8 +67,8 @@ tests/unit/test_api.py,sha256=uZ1dWMmgQ-ZePYjmcZfjc-qOTJsjs20Wic0Uf4U12-8,4441
67
67
  tests/unit/test_aws_action.py,sha256=eei4uPDx1Y8WcYgAWhiyqBYv5OOHGiZrCvajXC7RHdM,9597
68
68
  tests/unit/test_custom_encoder.py,sha256=KLYyVOTq9MEkZXyhVHqjm5LVSW6uJS4Davgghsw9DGk,2207
69
69
  tests/unit/test_endpoints.py,sha256=LuXOfLBu47rDjGa5YEsOwTZBEdvQdl_C6-r46oxWZA8,6401
70
- tests/unit/test_exceptions.py,sha256=t8c67n3ZQPpyzzYPN6TZHpNeE8uKlOSfHJPk71QONuU,4668
71
- tests/unit/test_helpers.py,sha256=NaZBnVVsQuRb_0uxPjCyptEd5408Ok_AIPjhetGLPjk,16043
70
+ tests/unit/test_exceptions.py,sha256=Y4F-ij8WkEJkUU3mPvxlEchqE9NCdxDvR8bJzPVVNao,5328
71
+ tests/unit/test_helpers.py,sha256=_1jlU-h-GNY9MLQ8nV_or4zkTI911AmHKtvFyamKjfU,16297
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
@@ -78,7 +78,7 @@ tests/unit/test_server_spec.py,sha256=je97BaktgK0Fiz3AwFPkcmHzYtOJJNqJV_Fw5hrvqX
78
78
  tests/unit/test_trigger.py,sha256=E53mAUoVyponWu_4IQZ0IC1gQ9lakBnTn_9vKN2IZfg,1692
79
79
  tests/unit/test_variables.py,sha256=OUEOqGYZA3Nd5oKk5GVY3hcrWKHpZpxysBJcO_v5gzs,291
80
80
  tests/unit/utils.py,sha256=VooVmfpIgxmglNdtmT32AkEDFxHxyRHLK8RsCWjjYRY,2153
81
- insightconnect_plugin_runtime-5.5.5.dist-info/METADATA,sha256=r5fE44VH3fBDRvvbWrg4XzwK5fA4zz8zCwRLI2DVWU4,13843
82
- insightconnect_plugin_runtime-5.5.5.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
83
- insightconnect_plugin_runtime-5.5.5.dist-info/top_level.txt,sha256=AJtyJOpiFzHxsbHUICTcUKXyrGQ3tZxhrEHsPjJBvEA,36
84
- insightconnect_plugin_runtime-5.5.5.dist-info/RECORD,,
81
+ insightconnect_plugin_runtime-5.6.1.dist-info/METADATA,sha256=Ytd-U6ssnfYqZdQ-KKlMfTjDi6fPOFsPGGHcULACkLg,14106
82
+ insightconnect_plugin_runtime-5.6.1.dist-info/WHEEL,sha256=y4mX-SOX4fYIkonsAGA5N0Oy-8_gI4FXw5HNI1xqvWg,91
83
+ insightconnect_plugin_runtime-5.6.1.dist-info/top_level.txt,sha256=AJtyJOpiFzHxsbHUICTcUKXyrGQ3tZxhrEHsPjJBvEA,36
84
+ insightconnect_plugin_runtime-5.6.1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.43.0)
2
+ Generator: setuptools (70.2.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,4 +1,4 @@
1
- from insightconnect_plugin_runtime.exceptions import PluginException
1
+ from insightconnect_plugin_runtime.exceptions import PluginException, APIException
2
2
  from unittest import TestCase
3
3
 
4
4
 
@@ -85,3 +85,20 @@ class TestExceptions(TestCase):
85
85
  raise (PluginException(preset=test_data.get("preset")))
86
86
  assert context.exception.cause == test_data.get("expected_cause")
87
87
  assert context.exception.assistance == test_data.get("expected_assistance")
88
+
89
+ def test_api_exception(self):
90
+ with self.assertRaises(APIException) as context:
91
+ raise (
92
+ APIException(
93
+ preset=PluginException.Preset.NOT_FOUND,
94
+ status_code=404,
95
+ data="example",
96
+ )
97
+ )
98
+ assert context.exception.cause == "Invalid or unreachable endpoint provided."
99
+ assert (
100
+ context.exception.assistance
101
+ == "Verify the URLs or endpoints in your configuration are correct."
102
+ )
103
+ assert context.exception.data == "example"
104
+ assert context.exception.status_code == 404
@@ -439,7 +439,11 @@ class TestRequestsHelpers(TestCase):
439
439
  ):
440
440
  request = requests.Request(method=method, url=url, json=None)
441
441
  with self.assertRaises(PluginException) as error:
442
- helper.make_request(_request=request, exception_custom_configs=exp_config)
442
+ helper.make_request(
443
+ _request=request,
444
+ exception_custom_configs=exp_config,
445
+ exception_data_location=ResponseExceptionData.RESPONSE,
446
+ )
443
447
  assert (isinstance(error, exception_type), True)
444
448
  if test_name == "custom404":
445
449
  self.assertEqual(
@@ -450,6 +454,8 @@ class TestRequestsHelpers(TestCase):
450
454
  error.exception.assistance,
451
455
  "CustomAssistance",
452
456
  )
457
+ self.assertEqual(error.exception.data.text, "example")
458
+ self.assertEqual(error.exception.data.status_code, 404)
453
459
 
454
460
  @parameterized.expand(
455
461
  [