Skip to content

Commit e3f7fb4

Browse files
committed
added example plugin
1 parent 47d3cd3 commit e3f7fb4

File tree

27 files changed

+623
-3
lines changed

27 files changed

+623
-3
lines changed

.github/workflows/pypiPublishProd.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ jobs:
1414
uses: actions/checkout@v3
1515

1616
- name: Set up Python
17-
uses: actions/setup-python@v4
18-
with:
19-
python-version: '3.9'
17+
uses: actions/setup-python@v4
18+
with:
19+
python-version: '3.9'
2020

2121
- name: Install dependencies
2222
run: |

plugins/base64/.CHECKSUM

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"spec": "e50ed0cd4706f4f43f397c6f50426c8b",
3+
"manifest": "d8d14059401870cc978c7210e6cbaa8c",
4+
"setup": "fb701aee1efeb9e7f47a85025f71afad",
5+
"schemas": [
6+
{
7+
"identifier": "decode/schema.py",
8+
"hash": "54af457e2d290878d2aea68d728e4d91"
9+
},
10+
{
11+
"identifier": "encode/schema.py",
12+
"hash": "bed9f4dc2caf31b07fc5452c04d45fbd"
13+
},
14+
{
15+
"identifier": "connection/schema.py",
16+
"hash": "bd524b567f9638ba1c6f7e0c9e45ff2e"
17+
}
18+
]
19+
}

plugins/base64/.dockerignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
unit_test/**/*
2+
unit_test
3+
examples/**/*
4+
examples
5+
tests
6+
tests/**/*
7+
**/*.json
8+
**/*.tar
9+
**/*.gz

plugins/base64/Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM rapid7/insightconnect-python-3-38-plugin:4
2+
3+
LABEL organization=rapid7
4+
LABEL sdk=python
5+
6+
WORKDIR /python/src
7+
8+
ADD ./plugin.spec.yaml /plugin.spec.yaml
9+
ADD ./requirements.txt /python/src/requirements.txt
10+
11+
RUN if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
12+
13+
ADD . /python/src
14+
15+
RUN python setup.py build && python setup.py install
16+
17+
# User to run plugin code. The two supported users are: root, nobody
18+
USER nobody
19+
20+
ENTRYPOINT ["/usr/local/bin/komand_base64"]

plugins/base64/Makefile

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Include other Makefiles for improved functionality
2+
INCLUDE_DIR = ../../tools/Makefiles
3+
MAKEFILES := $(wildcard $(INCLUDE_DIR)/*.mk)
4+
# We can't guarantee customers will have the include files
5+
# - prefix to ignore Makefiles when not present
6+
# https://www.gnu.org/software/make/manual/html_node/Include.html
7+
-include $(MAKEFILES)
8+
9+
ifneq ($(MAKEFILES),)
10+
$(info [$(YELLOW)*$(NORMAL)] Use ``make menu`` for available targets)
11+
$(info [$(YELLOW)*$(NORMAL)] Including available Makefiles: $(MAKEFILES))
12+
$(info --)
13+
else
14+
$(warning Makefile includes directory not present: $(INCLUDE_DIR))
15+
endif
16+
17+
VERSION?=$(shell grep '^version: ' plugin.spec.yaml | sed 's/version: //')
18+
NAME?=$(shell grep '^name: ' plugin.spec.yaml | sed 's/name: //')
19+
VENDOR?=$(shell grep '^vendor: ' plugin.spec.yaml | sed 's/vendor: //')
20+
CWD?=$(shell basename $(PWD))
21+
_NAME?=$(shell echo $(NAME) | awk '{ print toupper(substr($$0,1,1)) tolower(substr($$0,2)) }')
22+
PKG=$(VENDOR)-$(NAME)-$(VERSION).tar.gz
23+
24+
# Set default target explicitly. Make's default behavior is the first target in the Makefile.
25+
# We don't want that behavior due to includes which are read first
26+
.DEFAULT_GOAL := default # Make >= v3.80 (make -version)
27+
28+
29+
default: image tarball
30+
31+
tarball:
32+
$(info [$(YELLOW)*$(NORMAL)] Creating plugin tarball)
33+
rm -rf build
34+
rm -rf $(PKG)
35+
tar -cvzf $(PKG) --exclude=$(PKG) --exclude=tests --exclude=run.sh *
36+
37+
image:
38+
$(info [$(YELLOW)*$(NORMAL)] Building plugin image)
39+
docker build --pull -t $(VENDOR)/$(NAME):$(VERSION) .
40+
docker tag $(VENDOR)/$(NAME):$(VERSION) $(VENDOR)/$(NAME):latest
41+
42+
regenerate:
43+
$(info [$(YELLOW)*$(NORMAL)] Refreshing schema from plugin.spec.yaml)
44+
insight-plugin refresh
45+
46+
export: image
47+
$(info [$(YELLOW)*$(NORMAL)] Exporting docker image)
48+
@printf "\n ---> Exporting Docker image to ./$(VENDOR)_$(NAME)_$(VERSION).tar\n"
49+
@docker save $(VENDOR)/$(NAME):$(VERSION) | gzip > $(VENDOR)_$(NAME)_$(VERSION).tar
50+
51+
# Make will not run a target if a file of the same name exists unless setting phony targets
52+
# https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html
53+
.PHONY: default tarball image regenerate

plugins/base64/bin/komand_base64

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env python
2+
# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT
3+
import os
4+
import json
5+
from sys import argv
6+
7+
Name = "Base64"
8+
Vendor = "rapid7"
9+
Version = "1.1.6"
10+
Description = "Encode and decode data using the base64 alphabet"
11+
12+
13+
def main():
14+
if 'http' in argv:
15+
if os.environ.get("GUNICORN_CONFIG_FILE"):
16+
with open(os.environ.get("GUNICORN_CONFIG_FILE")) as gf:
17+
gunicorn_cfg = json.load(gf)
18+
if gunicorn_cfg.get("worker_class", "sync") == "gevent":
19+
from gevent import monkey
20+
monkey.patch_all()
21+
elif 'gevent' in argv:
22+
from gevent import monkey
23+
monkey.patch_all()
24+
25+
import insightconnect_plugin_runtime
26+
from komand_base64 import connection, actions, triggers, tasks
27+
28+
class ICONBase64(insightconnect_plugin_runtime.Plugin):
29+
def __init__(self):
30+
super(self.__class__, self).__init__(
31+
name=Name,
32+
vendor=Vendor,
33+
version=Version,
34+
description=Description,
35+
connection=connection.Connection()
36+
)
37+
self.add_action(actions.Encode())
38+
39+
self.add_action(actions.Decode())
40+
41+
42+
"""Run plugin"""
43+
cli = insightconnect_plugin_runtime.CLI(ICONBase64())
44+
cli.run()
45+
46+
47+
if __name__ == "__main__":
48+
main()

plugins/base64/help.md

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# Description
2+
3+
Encode and decode data using the base64 alphabet
4+
5+
# Key Features
6+
7+
*This plugin does not contain any key features.*
8+
9+
# Requirements
10+
11+
*This plugin does not contain any requirements.*
12+
13+
# Supported Product Versions
14+
15+
*This plugin does not contain any supported product versions.*
16+
17+
# Documentation
18+
19+
## Setup
20+
21+
*This plugin does not contain a connection.*
22+
23+
## Technical Details
24+
25+
### Actions
26+
27+
28+
#### Decoder
29+
30+
Decode Base64 to data
31+
32+
##### Input
33+
34+
|Name|Type|Default|Required|Description|Enum|Example|
35+
| :--- | :--- | :--- | :--- | :--- | :--- | :--- |
36+
|base64|bytes|None|True|Data to decode|None|UmFwaWQ3IEluc2lnaHRDb25uZWN0Cgo=|
37+
|errors|string|nothing|False|How errors should be handled when decoding Base64|['replace', 'ignore', 'nothing']|ignore|
38+
39+
Example input:
40+
41+
```
42+
{
43+
"base64": "UmFwaWQ3IEluc2lnaHRDb25uZWN0Cgo=",
44+
"errors": "nothing"
45+
}
46+
```
47+
48+
##### Output
49+
50+
|Name|Type|Required|Description|Example|
51+
| :--- | :--- | :--- | :--- | :--- |
52+
|data|string|True|Decoded data result|None|
53+
54+
Example output:
55+
56+
```
57+
{
58+
"data": ""
59+
}
60+
```
61+
62+
#### Encoder
63+
64+
Encode data to Base64
65+
66+
##### Input
67+
68+
|Name|Type|Default|Required|Description|Enum|Example|
69+
| :--- | :--- | :--- | :--- | :--- | :--- | :--- |
70+
|content|string|None|True|Data to encode|None|Rapid7 InsightConnect|
71+
72+
Example input:
73+
74+
```
75+
{
76+
"content": "Rapid7 InsightConnect"
77+
}
78+
```
79+
80+
##### Output
81+
82+
|Name|Type|Required|Description|Example|
83+
| :--- | :--- | :--- | :--- | :--- |
84+
|data|bytes|True|Encoded data result|None|
85+
86+
Example output:
87+
88+
```
89+
{
90+
"data": ""
91+
}
92+
```
93+
### Triggers
94+
95+
*This plugin does not contain any triggers.*
96+
### Tasks
97+
98+
*This plugin does not contain any tasks.*
99+
100+
### Custom Types
101+
102+
*This plugin does not contain any custom output types.*
103+
104+
## Troubleshooting
105+
106+
*There is no troubleshooting for this plugin.*
107+
108+
# Version History
109+
110+
*This plugin does not contain a version history.*
111+
112+
# Links
113+
114+
115+
## References
116+
117+
*This plugin does not contain any references.*
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT
2+
3+
from .encode.action import Encode
4+
5+
from .decode.action import Decode
6+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT
2+
from .action import Decode

0 commit comments

Comments
 (0)