Skip to content

Commit

Permalink
Merge pull request #97 from rapid7/new_input
Browse files Browse the repository at this point in the history
Update HelpInputOutputValidator to validate on new Example inputs
  • Loading branch information
mhofert-r7 authored Apr 2, 2020
2 parents 270369b + c09f71d commit aa6210c
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 46 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ to simulate the `--all` flag.

## Changelog

* 2.21.1 - Update HelpInputOutputValidator to validate on new Example inputs
* 2.21.0 - Add new runtime validator to align with 4.0.0 release of InsightConnect Python Plugin Runtime
* 2.20.0 - Add plugin utilization workflow validator | Fix issue where numbers in screenshot titles would cause validation to fail
* 2.19.0 - Add new `example` input to whitelist in SpecPropertiesValidator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ def get_spec_input(input_content: dict) -> list:
required = input_content.get(k).get("required")
description = input_content.get(k).get("description")
enum = input_content.get(k).get("enum", None)
action_input.append(f"|{name_}|{type_}|{default_}|{required}|{description}|{enum}|")
example = input_content.get(k).get("example", None)
action_input.append(f"|{name_}|{type_}|{default_}|{required}|{description}|{enum}|{example}|")
return action_input

@staticmethod
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
long_description = fh.read()

setup(name="insightconnect_integrations_validators",

version="2.21.0",
version="2.21.1",
description="Validator tooling for InsightConnect integrations",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down
46 changes: 33 additions & 13 deletions unit_test/plugin_examples/good_plugin/help.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,38 +21,58 @@ _This plugin does not contain a connection._

### Actions

#### Encoder
#### Decoder

This action is used to Base64 encode a `string` using the standard Base64 alphabet.
This action is used to decode Base64 to data.

##### Input

|Name|Type|Default|Required|Description|Enum|
|----|----|-------|--------|-----------|----|
|content|string|None|True|String to Encode|None|
|Name|Type|Default|Required|Description||Enum|Example|
|----|----|-------|--------|-----------|-----|-------|
|base64|bytes|None|True|Data to decode|None|None|
|errors|string|nothing|False|How errors should be handled when decoding Base64|['replace', 'ignore', 'nothing']|replace|

Example input:

```
```

##### Output

|Name|Type|Required|Description|
|----|----|--------|-----------|
|data|bytes|False|None|
|data|string|True|Decoded data result|

#### Decoder
Example output:

```
```

This action is used to decode a Base64 `string` or file of type `bytes` using the standard Base64 alphabet.
#### Encoder

This action is used to encode data to Base64.

##### Input

|Name|Type|Default|Required|Description|Enum|
|----|----|-------|--------|-----------|----|
|base64|bytes|None|True|Data to decode|None|
|errors|string|None|False|How errors should be handled when decoding Base64 e.g replace or ignore|None|
|Name|Type|Default|Required|Description|Enum|Example|
|----|----|-------|--------|-----------|----|-------|
|content|string|None|True|Data to encode|None|This is a string|

Example input:

```
```

##### Output

|Name|Type|Required|Description|
|----|----|--------|-----------|
|data|string|False|None|
|data|bytes|True|Encoded data result|

Example output:

```
```

### Triggers

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import komand
from .schema import DecodeInput, DecodeOutput
from .schema import DecodeInput, DecodeOutput, Input, Output, Component
from komand.exceptions import PluginException
import base64


Expand All @@ -8,26 +9,21 @@ class Decode(komand.Action):
def __init__(self):
super(self.__class__, self).__init__(
name='decode',
description='Decode Base64 to data',
description=Component.DESCRIPTION,
input=DecodeInput(),
output=DecodeOutput())

def run(self, params={}):
try:
data = params.get('base64')
errors = params.get('errors')
data = params.get(Input.BASE64)
errors = params.get(Input.ERRORS)
result = base64.standard_b64decode(data)
if errors in ["replace", "ignore"]:
return {'data': result.decode('utf-8', errors=errors)}
return {Output.DATA: result.decode('utf-8', errors=errors)}
else:
return {'data': result.decode('utf-8')}
return {Output.DATA: result.decode('utf-8')}
except Exception as e:
self.logger.error("An error has occurred while decoding ", e)
raise

def test(self):
b64 = 'YmFzZTY0'
result = base64.standard_b64decode(b64).decode('utf-8')
if result == 'base64':
return {'data': result}
raise Exception('Base64 decode failed: %s') % result
raise PluginException(cause="Internal error",
assistance='An error has occurred while decoding ',
data=e)
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
import komand
from .schema import EncodeInput, EncodeOutput
from .schema import EncodeInput, EncodeOutput, Input, Output, Component
import base64


class Encode(komand.Action):

def __init__(self):
super(self.__class__, self).__init__(
name='encode',
description='Encode data to Base64',
input=EncodeInput(),
output=EncodeOutput())
name='encode',
description=Component.DESCRIPTION,
input=EncodeInput(),
output=EncodeOutput())

def run(self, params={}):
string = params['content'].encode('utf-8')
string = params[Input.CONTENT].encode('utf-8')
result = base64.standard_b64encode(string)
return { 'data': result.decode('utf-8') }

def test(self):
string = 'base64'.encode('utf-8')
result = base64.standard_b64encode(string).decode('utf-8')
if result == 'YmFzZTY0':
return { 'data': result }
raise Exception('Base64 encode failed: %s') % result
return {Output.DATA: result.decode('utf-8')}
2 changes: 2 additions & 0 deletions unit_test/plugin_examples/good_plugin/plugin.spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ actions:
content:
type: string
description: Data to encode
example: This is a string
required: true
output:
data:
Expand All @@ -47,6 +48,7 @@ actions:
type: string
description: How errors should be handled when decoding Base64
default: nothing
example: replace
enum:
- replace
- ignore
Expand Down
4 changes: 2 additions & 2 deletions unit_test/test_validate_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class TestPluginValidate(unittest.TestCase):

def test_plugin_validate(self):
# example workflow in plugin_examples directory. Run tests with these files
directory_to_test = "plugin_examples/good_test"
directory_to_test = "plugin_examples/good_plugin"
file_to_test = "plugin.spec.yaml"
result = validate(directory_to_test, file_to_test, False, True)
result = validate(directory_to_test, file_to_test, False, False)
self.assertFalse(result)

def test_title_validator(self):
Expand Down

0 comments on commit aa6210c

Please sign in to comment.