Skip to content

Commit

Permalink
Surface Command Plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
croberts-r7 committed Dec 19, 2024
1 parent 21e7d03 commit e05e7f8
Show file tree
Hide file tree
Showing 25 changed files with 576 additions and 0 deletions.
15 changes: 15 additions & 0 deletions plugins/rapid7_surface_command/.CHECKSUM
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"spec": "a4b099d042b1b84d6c0239f8784f1f5c",
"manifest": "2d22e59a97bcaaa3e9bd7cbb0810face",
"setup": "6aa89dde78114d142acbe7705a84fbc9",
"schemas": [
{
"identifier": "run_query/schema.py",
"hash": "0f7bd73a9fe89c3311d451d5805e4dd8"
},
{
"identifier": "connection/schema.py",
"hash": "134cb982f22fe0c4969721b954e838ef"
}
]
}
9 changes: 9 additions & 0 deletions plugins/rapid7_surface_command/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
unit_test/**/*
unit_test
examples/**/*
examples
tests
tests/**/*
**/*.json
**/*.tar
**/*.gz
20 changes: 20 additions & 0 deletions plugins/rapid7_surface_command/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM --platform=linux/amd64 rapid7/insightconnect-python-3-plugin:latest

LABEL organization=rapid7
LABEL sdk=python

WORKDIR /python/src

ADD ./plugin.spec.yaml /plugin.spec.yaml
ADD ./requirements.txt /python/src/requirements.txt

RUN if [ -f requirements.txt ]; then pip install -r requirements.txt; fi

ADD . /python/src

RUN python setup.py build && python setup.py install

# User to run plugin code. The two supported users are: root, nobody
USER nobody

ENTRYPOINT ["/usr/local/bin/icon_rapid7_surface_command"]
53 changes: 53 additions & 0 deletions plugins/rapid7_surface_command/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Include other Makefiles for improved functionality
INCLUDE_DIR = ../../tools/Makefiles
MAKEFILES := $(wildcard $(INCLUDE_DIR)/*.mk)
# We can't guarantee customers will have the include files
# - prefix to ignore Makefiles when not present
# https://www.gnu.org/software/make/manual/html_node/Include.html
-include $(MAKEFILES)

ifneq ($(MAKEFILES),)
$(info [$(YELLOW)*$(NORMAL)] Use ``make menu`` for available targets)
$(info [$(YELLOW)*$(NORMAL)] Including available Makefiles: $(MAKEFILES))
$(info --)
else
$(warning Makefile includes directory not present: $(INCLUDE_DIR))
endif

VERSION?=$(shell grep '^version: ' plugin.spec.yaml | sed 's/version: //')
NAME?=$(shell grep '^name: ' plugin.spec.yaml | sed 's/name: //')
VENDOR?=$(shell grep '^vendor: ' plugin.spec.yaml | sed 's/vendor: //')
CWD?=$(shell basename $(PWD))
_NAME?=$(shell echo $(NAME) | awk '{ print toupper(substr($$0,1,1)) tolower(substr($$0,2)) }')
PKG=$(VENDOR)-$(NAME)-$(VERSION).tar.gz

# Set default target explicitly. Make's default behavior is the first target in the Makefile.
# We don't want that behavior due to includes which are read first
.DEFAULT_GOAL := default # Make >= v3.80 (make -version)


default: image tarball

tarball:
$(info [$(YELLOW)*$(NORMAL)] Creating plugin tarball)
rm -rf build
rm -rf $(PKG)
tar -cvzf $(PKG) --exclude=$(PKG) --exclude=tests --exclude=run.sh *

image:
$(info [$(YELLOW)*$(NORMAL)] Building plugin image)
docker build --pull -t $(VENDOR)/$(NAME):$(VERSION) .
docker tag $(VENDOR)/$(NAME):$(VERSION) $(VENDOR)/$(NAME):latest

regenerate:
$(info [$(YELLOW)*$(NORMAL)] Refreshing schema from plugin.spec.yaml)
insight-plugin refresh

export: image
$(info [$(YELLOW)*$(NORMAL)] Exporting docker image)
@printf "\n ---> Exporting Docker image to ./$(VENDOR)_$(NAME)_$(VERSION).tar\n"
@docker save $(VENDOR)/$(NAME):$(VERSION) | gzip > $(VENDOR)_$(NAME)_$(VERSION).tar

# Make will not run a target if a file of the same name exists unless setting phony targets
# https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html
.PHONY: default tarball image regenerate
46 changes: 46 additions & 0 deletions plugins/rapid7_surface_command/bin/icon_rapid7_surface_command
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env python
# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT
import os
import json
from sys import argv

Name = "Rapid7 Surface Command"
Vendor = "rapid7"
Version = "1.0.0"
Description = "Surface Command gives you full visibilty over your assets and identies across multiple technology platforms."


def main():
if 'http' in argv:
if os.environ.get("GUNICORN_CONFIG_FILE"):
with open(os.environ.get("GUNICORN_CONFIG_FILE")) as gf:
gunicorn_cfg = json.load(gf)
if gunicorn_cfg.get("worker_class", "sync") == "gevent":
from gevent import monkey
monkey.patch_all()
elif 'gevent' in argv:
from gevent import monkey
monkey.patch_all()

import insightconnect_plugin_runtime
from icon_rapid7_surface_command import connection, actions, triggers, tasks

class ICONRapid7SurfaceCommand(insightconnect_plugin_runtime.Plugin):
def __init__(self):
super(self.__class__, self).__init__(
name=Name,
vendor=Vendor,
version=Version,
description=Description,
connection=connection.Connection()
)
self.add_action(actions.RunQuery())


"""Run plugin"""
cli = insightconnect_plugin_runtime.CLI(ICONRapid7SurfaceCommand())
cli.run()


if __name__ == "__main__":
main()
98 changes: 98 additions & 0 deletions plugins/rapid7_surface_command/help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Description

Surface Command gives you full visibilty over your assets and identies across multiple technology platforms.

# Key Features

*This plugin does not contain any key features.*

# Requirements

*This plugin does not contain any requirements.*

# Supported Product Versions

* v1.0.790

# Documentation

## Setup

The connection configuration accepts the following parameters:

|Name|Type|Default|Required|Description|Enum|Example|Placeholder|Tooltip|
| :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- |
|api_key|credential_secret_key|None|True|User or Organization Key from the Insight Platform|None|a5zy0a6g-504e-46bz-84xx-1b3f5ci36l99|None|None|
|region|string|United States|True|Region|["United States", "United States 2", "United States 3", "Europe", "Canada", "Australia", "Japan"]|United States|None|None|

Example input:

```
{
"api_key": "a5zy0a6g-504e-46bz-84xx-1b3f5ci36l99",
"region": "United States"
}
```

## Technical Details

### Actions


#### Run Surface Command Query

This action is used to run and execute Surface Command Query

##### Input

|Name|Type|Default|Required|Description|Enum|Example|Placeholder|Tooltip|
| :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- |
|query_id|string|None|True|Query ID (UUID) to run from Surface Command|None|12345678-1234-1234-1234-123456789012|None|None|

Example input:

```
{
"query_id": "12345678-1234-1234-1234-123456789012"
}
```

##### Output

|Name|Type|Required|Description|Example|
| :--- | :--- | :--- | :--- | :--- |
|items|items|False|Array of Items|[]|

Example output:

```
{
"items": []
}
```
### Triggers

*This plugin does not contain any triggers.*
### Tasks

*This plugin does not contain any tasks.*

### Custom Types

*This plugin does not contain any custom output types.*

## Troubleshooting

*This plugin does not contain a troubleshooting.*

# Version History

*This plugin does not contain a version history.*

# Links

*This plugin does not contain any links.*

## References

*This plugin does not contain any references.*
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT

from .run_query.action import RunQuery

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT
from .action import RunQuery
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import insightconnect_plugin_runtime
from .schema import RunQueryInput, RunQueryOutput, Input, Output, Component
# Custom imports below


class RunQuery(insightconnect_plugin_runtime.Action):

def __init__(self):
super(self.__class__, self).__init__(
name="run_query",
description=Component.DESCRIPTION,
input=RunQueryInput(),
output=RunQueryOutput())

def run(self, params={}):
# START INPUT BINDING - DO NOT REMOVE - ANY INPUTS BELOW WILL UPDATE WITH YOUR PLUGIN SPEC AFTER REGENERATION
query_id = params.get(Input.QUERY_ID)
# END INPUT BINDING - DO NOT REMOVE

return {
Output.ITEMS: None,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT
import insightconnect_plugin_runtime
import json


class Component:
DESCRIPTION = "Run and execute Surface Command Query"


class Input:
QUERY_ID = "query_id"


class Output:
ITEMS = "items"


class RunQueryInput(insightconnect_plugin_runtime.Input):
schema = json.loads(r"""
{
"type": "object",
"title": "Variables",
"properties": {
"query_id": {
"type": "string",
"title": "ID of Query to run",
"description": "Query ID (UUID) to run from Surface Command",
"order": 1
}
},
"required": [
"query_id"
],
"definitions": {}
}
""")

def __init__(self):
super(self.__class__, self).__init__(self.schema)


class RunQueryOutput(insightconnect_plugin_runtime.Output):
schema = json.loads(r"""
{
"type": "object",
"title": "Variables",
"properties": {
"items": {
"title": "Items",
"description": "Array of Items",
"order": 1
}
},
"definitions": {}
}
""")

def __init__(self):
super(self.__class__, self).__init__(self.schema)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT
from .connection import Connection
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import insightconnect_plugin_runtime
from .schema import ConnectionSchema, Input
# Custom imports below


class Connection(insightconnect_plugin_runtime.Connection):

def __init__(self):
super(self.__class__, self).__init__(input=ConnectionSchema())

def connect(self, params):
self.logger.info("Connect: Connecting...")
# START INPUT BINDING - DO NOT REMOVE - ANY INPUTS BELOW WILL UPDATE WITH YOUR PLUGIN SPEC AFTER REGENERATION
self.api_key = params.get(Input.API_KEY)
self.region = params.get(Input.REGION)
# END INPUT BINDING - DO NOT REMOVE

def test(self):
# TODO: Implement connection test
pass
Loading

0 comments on commit e05e7f8

Please sign in to comment.