Running Plugins
The following describes how to run plugins and continues using the example plugin from Plugin Spec.
insight-plugin Tooling
More documentation for insight-plugin
can be found at Plugin Tooling
About insight-plugin
- The best tooling of the methods
- The
insight-plugin
tool is the primary plugin development tool that should be used to administrate any plugin - Installation instructions for
insight-plugin
is available in the Getting Started document.
Running and Testing Your Plugin
Now that your plugin shell has been built, let's play around with some of the plugin commands that come code-generated with the plugin shell.
Help Command
To see what commands your plugin executable supports, try running:
sh
1$ insight-plugin run --help2usage: insight-plugin run [-h] [-A] [-T] [-J [JQ]] [-R] [-V VOLUMES [VOLUMES ...]] [-d TARGET_DIR] [-v]3[json_target]45positional arguments:6json_target .json files to run78optional arguments:9-h, --help show this help message and exit10-A, --assessment Flag to generate plugin PR template output for contributions11-T, --test Run connection test. Uses first json file passed, or first in tests directory.12-J [JQ], --jq [JQ] JQ Parser. Pass no args to use default (.body.output), or pass one used for all13test/runs.14-R, --rebuild Rebuild the Docker image before running it in a container and entering the shell15-V VOLUMES [VOLUMES ...], --volumes VOLUMES [VOLUMES ...]16Volume to mount from local machine to container, e.g.17/Absolute/src:/Absolute/dest18-d TARGET_DIR, --target-dir TARGET_DIR19Provide plugin directory20-v, --verbose Verbose Mode
Info/View Command
The view command will print plugin metadata.
sh
1❯ insight-plugin view2Name: Base643Vendor: rapid74Version: 1.1.65Description: Encode and decode data using the base64 alphabet67Actions (2):8└── decode (Decode Base64 to data)9└── encode (Encode data to Base64)
Test Command
You can use the test
command to test your connection by running the test()
method in the action/trigger file, unless there is a test method in the connection file.
Note that test()
should be set in the connection and not in the action or trigger. Often it’s used to test network access and validate any user provided credentials.
For this example, we will make the following code changes to insight_plugin_example/actions/test_action/action.py
and then rebuild with make
:
python
1def test_action(self):2self.logger.info('Saying goodbye to %s', 'test')3return { 'message': 'Goodbye test!' }
Test
Run plugin's test method using insight-plugin:
sh
1$ insight-plugin run -T tests/test_action.json2INFO: RunController: Running connection test with /Users/insight-user/insight-connect/example_insight_plugin/tests/test_action.json34INFO: RunContoller: Running command: docker run --rm -i rapid7/example_insight_plugin:1.0.0 test < /Users/insight-user/insight-connect/example_insight_plugin/tests/test_action.json56Connect: Connecting...78rapid7/Example Insight Plugin:1.0.0. Step name: test_action
Run Command
The run
command is used to run your plugin by executing the run()
method in the action/trigger file. When developing, please make sure you run your plugin with the --verbose
flag so that all output is displayed to stdin/stdout
.
Note: --verbose
is special for testing triggers from the command-line and must be used to bypass the URL callback.
For this example, we made the following code changes to icon_example/actions/say_goodbye/action.py
and then rebuild with make
:
python
1def run(self, params={}):2name = params.get(Input.NAME)3self.logger.info(f'Saying goodbye to {name}')45message = f'Goodbye {name}!'6return {'message': message}
Execute All Runs and Tests
To run all actions and triggers instead of choosing a specific file.
1$ insight-plugin run23INFO: RunController: Running /Users/insight-user/insight-connect/example_insight_plugin//tests/test_1.json45INFO: RunController: Running command: docker run --rm -i rapid7/test_insight_plugin:1.0.0 run < /Users/insight-user/insight-connect/example_insight_plugin//tests/test_1.json67Connect: Connecting...89rapid7/Test Insight Plugin:1.0.0. Step name: test_action1011Output is: {'body': {'log': 'Connect: Connecting...\nrapid7/Example Insight Plugin:1.0.0. Step name: test_action\n', 'status': 'ok', 'meta': {}, 'output': {}}, 'version': 'v1', 'type': 'action_event'}1213{"body": {"log": "Connect: Connecting...\nrapid7/Example Insight Plugin:1.0.0. Step name: test_action\n", "status": "ok", "meta": {}, "output": {}}, "version": "v1", "type": "action_event"}1415INFO: RunController: Running /Users/insight-user/insight-connect/example_insight_plugin//tests/test_2.json1617INFO: RunController: Running command: docker run --rm -i rapid7/test_insight_plugin:1.0.0 run < /Users/insight-user/insight-connect/example_insight_plugin/tests/test_2.json1819Connect: Connecting...2021rapid7/Example Insight Plugin:1.0.0. Step name: test_action_22223Output is: {'body': {'log': 'Connect: Connecting...\nrapid7/Example Insight Plugin:1.0.0. Step name: test_action_2\n', 'status': 'ok', 'meta': {}, 'output': {}}, 'version': 'v1', 'type': 'action_event'}2425{"body": {"log": "Connect: Connecting...\nrapid7/Example Insight Plugin:1.0.0. Step name: test_action_2\n", "status": "ok", "meta": {}, "output": {}}, "version": "v1", "type": "action_event"}
Create Assessment
When a branch is ready to be merged into master
on the open-source Github repo, each pull request requires an assessment. This can be generated with insight-plugin using the flag -A
.
Generate an assessment
sh
1$ insight-plugin run -A23INFO: RunController: Running /Users/insight-user/insight-connect/example_insight_plugin/tests/test_1.json45INFO: RunController: Running command: docker run --rm -i rapid7/test_insight_plugin:1.0.0 run < /Users/insight-user/insight-connect/example_insight_plugin/tests/test_1.json67Connect: Connecting...89rapid7/Test Insight Plugin:1.0.0. Step name: test_action1011INFO: RunController: Running /Users/insight-user/insight-connect/example_insight_plugin/tests/test_2.json1213INFO: RunController: Running command: docker run --rm -i rapid7/test_insight_plugin:1.0.0 run < /Users/insight-user/insight-connect/example_insight_plugin/tests/test_2.json1415Connect: Connecting...1617rapid7/Example Insight Plugin:1.0.0. Step name: test_action1819INFO: RunController: Running icon validators2021INFO: RunController:2223## Assessment2425### Run2627<details>2829{30"body": {31"log": "Connect: Connecting...\nrapid7/Example Insight Plugin:1.0.0. Step name: test_action\n",32"status": "ok",33"meta": {},34"output": {}35},36"version": "v1",37"type": "action_event"38}3940<summary>41docker run --rm -i rapid7/test_insight_plugin:1.0.0 run < //Users/insight-user/insight-connect/example_insight_plugin/tests/test_1.json42</summary>43</details>444546<details>474849{50"body": {51"log": "Connect: Connecting...\nrapid7/Example Insight Plugin:1.0.0. Step name: test_action\n",52"status": "ok",53"meta": {},54"output": {}55},56"version": "v1",57"type": "action_event"58}596061<summary>62docker run --rm -i rapid7/example_insight_plugin:1.0.0 run < /Users/insight-user/insight-connect/example_insight_plugin/tests/test_action.json63</summary>64</details>656667### Validation686970<details>7172[*] Validating plugin with all validators at /Users/insight-user/insight-connect/example_insight_plugin737475[*] Running Integration Validators...76[*] Executing validator HelpValidator77[*] Executing validator ChangelogValidator78[*] Executing validator CloudReadyConnectionCredentialTokenValidator79[*] Executing validator RequiredKeysValidator80[*] Executing validator UseCaseValidator81[*] Executing validator SpecPropertiesValidator82[*] Executing validator SpecVersionValidator83[*] Executing validator FilesValidator84[*] Executing validator TagValidator85[*] Executing validator DescriptionValidator86[*] Executing validator TitleValidator87[*] Executing validator VendorValidator88[*] Executing validator DefaultValueValidator89[*] Executing validator IconValidator90[*] Executing validator RequiredValidator91[*] Executing validator VersionValidator92[*] Executing validator DockerfileParentValidator93[*] Executing validator ProfanityValidator94[*] Executing validator AcronymValidator95[*] Executing validator JSONValidator96[*] Executing validator OutputValidator97[*] Executing validator RegenerationValidator98[*] Executing validator HelpInputOutputValidator99100101<summary>102icon-validate --all /Users/insight-user/insight-connect/example_insight_plugin103</summary>104</details>105106107### UI108109Screenshots of the plugin being used in InsightConnect workflows (for validating functionality in the UI) go below this line.110111#### Workflow Builder112113#### Job114115#### Artifact
Rebuild
Optionally, when developing plugins, you also have the ability to rebuild the plugin using the rebuild flag -R
/--rebuild
.
When making code changes to a plugin, to test the code locally a user will need to re-run make as previously mentioned.
The rebuild flag re-runs make image
so a user can test their new changes quicker.
insight-plugin run tests/{test}.json --rebuild
sh
1❯ insight-plugin run tests/encode.json --rebuild2[*] Use ``make menu`` for available targets3[*] Including available Makefiles: ../../tools/Makefiles/Colors.mk ../../tools/Makefiles/Helpers.mk4--5[*] Building plugin image6docker build --pull -t rapid7/base64:1.1.6 .7[+] Building 10.0s (11/11) FINISHED docker:desktop-linux8=> [internal] load build definition from Dockerfile 0.0s9=> => transferring dockerfile: 665B 0.0s10=> [internal] load .dockerignore 0.0s11=> => transferring context: 131B 0.0s12=> [internal] load metadata for docker.io/rapid7/insightconnect-python-3-slim-plugin:5 1.7s13=> [1/6] FROM docker.io/rapid7/insightconnect-python-3-slim-plugin:5@sha256:40767f02134d5009cf44 0.0s14=> [internal] load build context 8.2s15=> => transferring context: 537.06MB 8.2s16=> CACHED [2/6] ADD ./plugin.spec.yaml /plugin.spec.yaml 0.0s17=> CACHED [3/6] ADD . /python/src 0.0s18=> CACHED [4/6] WORKDIR /python/src 0.0s19=> CACHED [5/6] RUN if [ -f requirements.txt ]; then pip install -r requirements.txt; fi 0.0s20=> CACHED [6/6] RUN python setup.py build && python setup.py install 0.0s21=> exporting to image 0.0s22=> => exporting layers 0.0s23=> => writing image sha256:113e3a7c7cb4b66a9112e2d398f97b612f4fb64f0781e6fba76f71e7315a41d4 0.0s24=> => naming to docker.io/rapid7/base64:1.1.6 0.0s2526What's Next?27View summary of image vulnerabilities and recommendations → docker scout quickview28docker tag rapid7/base64:1.1.6 rapid7/base64:latest292023-08-30 08:48:07 [info ] rapid7/Base64:1.1.6. Step name: encode3031{"body": {"log": "", "status": "ok", "meta": {}, "output": {"data": "UmFwaWQ3"}}, "version": "v1", "type": "action_event"}