Skip to content

Commit

Permalink
Math - 17804 - Initial updates for fedramp compliance | Updated SDK t…
Browse files Browse the repository at this point in the history
…o the latest version (#2853)
  • Loading branch information
igorski-r7 committed Oct 15, 2024
1 parent 4807969 commit 0245da6
Show file tree
Hide file tree
Showing 22 changed files with 266 additions and 110 deletions.
12 changes: 6 additions & 6 deletions plugins/math/.CHECKSUM
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"spec": "990d9d987b565629ff1bacd185717f6b",
"manifest": "30d28225ce02d2d9698e638a4fc2e656",
"setup": "fc006dbe786e2f5e7636bcc680f077d9",
"spec": "057aaea15b4dac436df277eaf21b1172",
"manifest": "d764412b6d589e5330ece619415a0361",
"setup": "a1e6979da8016ee0b27b09a3440a5305",
"schemas": [
{
"identifier": "calculate/schema.py",
"hash": "32605e5abb79fe7497f124f7e066417d"
"hash": "488209c1d55a6e8ce927398e58582f1c"
},
{
"identifier": "max/schema.py",
"hash": "cb99bd0f0f0fcd232900ba3ecfd7f379"
"hash": "b8bbe6c2e6fe58f103861c67785db4c2"
},
{
"identifier": "connection/schema.py",
"hash": "da5382221ca2a33a2f854e17b068d502"
"hash": "bd524b567f9638ba1c6f7e0c9e45ff2e"
}
]
}
15 changes: 7 additions & 8 deletions plugins/math/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
FROM rapid7/insightconnect-python-3-38-slim-plugin:4
# Add any custom package dependencies here
# NOTE: Add pip packages to requirements.txt
FROM --platform=linux/amd64 rapid7/insightconnect-python-3-slim-plugin:6.1.3

# End package dependencies
LABEL organization=rapid7
LABEL sdk=python

# Add source code
WORKDIR /python/src

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

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

# Install plugin
ADD . /python/src

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

# User to run plugin code. The two supported users are: root, nobody
Expand Down
8 changes: 4 additions & 4 deletions plugins/math/bin/komand_math
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env python
# GENERATED BY KOMAND SDK - DO NOT EDIT
# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT
import os
import json
from sys import argv

Name = "Math"
Vendor = "rapid7"
Version = "1.2.1"
Version = "1.2.2"
Description = "Basic mathematical operations"


Expand Down Expand Up @@ -35,9 +35,9 @@ def main():
connection=connection.Connection()
)
self.add_action(actions.Calculate())

self.add_action(actions.Max())


"""Run plugin"""
cli = insightconnect_plugin_runtime.CLI(ICONMath())
Expand Down
99 changes: 51 additions & 48 deletions plugins/math/help.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,109 +8,111 @@ This plugin allows basic arithmetic functions to be performed.
* Math Division and multiplication, addition and subtraction

# Requirements

*This plugin does not contain any requirements.*

_This plugin does not contain any requirements._
# Supported Product Versions

* 2024-10-09

# Documentation

## Setup

_This plugin does not contain a connection._
*This plugin does not contain a connection.*

## Technical Details

### Actions

#### Max

This action is used to find the largest number from a list of numbers.
#### Calculate

##### Input
This action is used to run a calculation

|Name|Type|Default|Required|Description|Enum|Example|
|----|----|-------|--------|-----------|----|-------|
|numbers|[]number|None|True|Array of numbers to find the highest value from|None|[1, 5.5, 10, 100.5, 100]|
##### Input

|Name|Type|Default|Required|Description|Enum|Example|Placeholder|Tooltip|
| :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- |
|equation|string|None|True|Equation to calculate. Uses Python arithmetic operators (+, -, /, *, **, %)|None|((3**2) * 3) + 3 - 5|None|None|

Example input:

```
{
"numbers": [
1,
5.5,
10,
100.5,
100
]
"equation": "((3**2) * 3) + 3 - 5"
}
```

##### Output

|Name|Type|Required|Description|
|----|----|--------|-----------|
|max|number|True|Highest value number|

|Name|Type|Required|Description|Example|
| :--- | :--- | :--- | :--- | :--- |
|result|number|True|Result of the arithmetic operation|25|
Example output:

```
{
"max": 100.5
"result": 25
}
```

#### Calculate
#### Max

This action is used to run a calculation.
This action is used to find the largest number from a list of numbers

##### Input

|Name|Type|Default|Required|Description|Enum|Example|
|----|----|-------|--------|-----------|----|-------|
|equation|string|None|True|Equation to calculate. Uses Python arithmetic operators (+, -, /, *, **, %)|None|((3**2) * 3) + 3 - 5|

|Name|Type|Default|Required|Description|Enum|Example|Placeholder|Tooltip|
| :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- |
|numbers|[]number|None|True|Array of numbers to find the highest value from|None|[1, 5.5, 10, 100.5, 100]|None|None|
Example input:

```
{
"equation": "((3**2) * 3) + 3 - 5"
"numbers": [
1,
5.5,
10,
100.5,
100
]
}
```

##### Output

|Name|Type|Required|Description|
|----|----|--------|-----------|
|result|number|True|Result of the arithmetic operation|

|Name|Type|Required|Description|Example|
| :--- | :--- | :--- | :--- | :--- |
|max|number|True|Highest value number|100.5|
Example output:

```
{
"result": 25.0
"max": 100.5
}
```

### Triggers

_This plugin does not contain any triggers._


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

*This plugin does not contain any tasks.*

_This plugin does not contain any tasks._

### Custom Output Types

_This plugin does not contain any custom output types._
### Custom Types

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

## Troubleshooting

_This plugin does not contain any troubleshooting information._
*This plugin does not contain a troubleshooting.*

# Version History

* 1.2.2 - Initial updates for fedramp compliance | Updated SDK to the latest version
* 1.2.1 - Update to v4 Python plugin runtime
* 1.2.0 - New action Max
* 1.1.3 - Change docker image from `komand/python-pypy3-plugin:2` to `komand/python-3-37-slim-plugin:3` to reduce plugin image size | Changed `Exception` to `PluginException` | Use input and output constants | Remove not secure eval for simple_eval
Expand All @@ -122,7 +124,8 @@ _This plugin does not contain any troubleshooting information._

# Links

## References

* [Arithmetic](https://en.wikipedia.org/wiki/Arithmetic)

## References

* [Arithmetic](https://en.wikipedia.org/wiki/Arithmetic)
5 changes: 4 additions & 1 deletion plugins/math/komand_math/actions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# GENERATED BY KOMAND SDK - DO NOT EDIT
# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT

from .calculate.action import Calculate

from .max.action import Max

2 changes: 1 addition & 1 deletion plugins/math/komand_math/actions/calculate/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# GENERATED BY KOMAND SDK - DO NOT EDIT
# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT
from .action import Calculate
29 changes: 21 additions & 8 deletions plugins/math/komand_math/actions/calculate/action.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from typing import Union

import insightconnect_plugin_runtime
from .schema import CalculateInput, CalculateOutput, Input, Output, Component
from insightconnect_plugin_runtime.exceptions import PluginException
from simpleeval import simple_eval

from .schema import CalculateInput, CalculateOutput, Component, Input, Output


class Calculate(insightconnect_plugin_runtime.Action):
_result = None
Expand All @@ -16,19 +19,29 @@ def __init__(self):
)

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

try:
result = Calculate.execute_equation(equation)
except Exception as error:
raise PluginException(preset=PluginException.Preset.UNKNOWN, data=error)
if result is None:
raise PluginException(
cause="Calculation error",
assistance="Error occurred while calculating the equation. Check to make sure it is valid and try "
"again. ",
"again.",
)

return {Output.RESULT: result}

@staticmethod
def execute_equation(eq):
eq = str().join([c for c in eq if (c.isdecimal() or c in ["+", "-", "*", "/", "**", "%", "(", ")", "."])])
return simple_eval(eq)
def execute_equation(equation) -> Union[int, float]:
equation = str().join(
[
character
for character in equation
if (character.isdecimal() or character in ["+", "-", "*", "/", "**", "%", "(", ")", "."])
]
)
return simple_eval(equation)
16 changes: 9 additions & 7 deletions plugins/math/komand_math/actions/calculate/schema.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# GENERATED BY KOMAND SDK - DO NOT EDIT
# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT
import insightconnect_plugin_runtime
import json

Expand All @@ -9,14 +9,14 @@ class Component:

class Input:
EQUATION = "equation"


class Output:
RESULT = "result"


class CalculateInput(insightconnect_plugin_runtime.Input):
schema = json.loads("""
schema = json.loads(r"""
{
"type": "object",
"title": "Variables",
Expand All @@ -30,7 +30,8 @@ class CalculateInput(insightconnect_plugin_runtime.Input):
},
"required": [
"equation"
]
],
"definitions": {}
}
""")

Expand All @@ -39,7 +40,7 @@ def __init__(self):


class CalculateOutput(insightconnect_plugin_runtime.Output):
schema = json.loads("""
schema = json.loads(r"""
{
"type": "object",
"title": "Variables",
Expand All @@ -53,7 +54,8 @@ class CalculateOutput(insightconnect_plugin_runtime.Output):
},
"required": [
"result"
]
],
"definitions": {}
}
""")

Expand Down
2 changes: 1 addition & 1 deletion plugins/math/komand_math/actions/max/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# GENERATED BY KOMAND SDK - DO NOT EDIT
# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT
from .action import Max
14 changes: 11 additions & 3 deletions plugins/math/komand_math/actions/max/action.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import insightconnect_plugin_runtime
from .schema import MaxInput, MaxOutput, Input, Output, Component
from insightconnect_plugin_runtime.exceptions import PluginException

from .schema import Component, Input, MaxInput, MaxOutput, Output

# Custom imports below

Expand All @@ -11,5 +13,11 @@ def __init__(self):
)

def run(self, params={}):
numbers = params.get(Input.NUMBERS)
return {"max": max(numbers)}
# START INPUT BINDING - DO NOT REMOVE - ANY INPUTS BELOW WILL UPDATE WITH YOUR PLUGIN SPEC AFTER REGENERATION
numbers = params.get(Input.NUMBERS, [])
# END INPUT BINDING - DO NOT REMOVE

try:
return {Output.MAX: max(numbers)}
except Exception as error:
raise PluginException(preset=PluginException.Preset.UNKNOWN, data=error)
Loading

0 comments on commit 0245da6

Please sign in to comment.