From ec89d8b2f71d8ebb8eb1f92e0ba7b5831fe474d5 Mon Sep 17 00:00:00 2001 From: igorski-r7 <99184344+igorski-r7@users.noreply.github.com> Date: Mon, 9 Sep 2024 09:06:12 +0200 Subject: [PATCH] String - 16974 - Initial updates for fedramp compliance | Updated SDK to the latest version (#2768) --- plugins/string/.CHECKSUM | 24 +- plugins/string/Dockerfile | 23 +- plugins/string/bin/komand_string | 30 +- plugins/string/help.md | 310 +++++++++--------- .../string/komand_string/actions/__init__.py | 19 +- .../komand_string/actions/length/__init__.py | 2 +- .../komand_string/actions/length/action.py | 12 +- .../komand_string/actions/length/schema.py | 16 +- .../komand_string/actions/lower/__init__.py | 2 +- .../komand_string/actions/lower/action.py | 14 +- .../komand_string/actions/lower/schema.py | 16 +- .../komand_string/actions/replace/__init__.py | 2 +- .../komand_string/actions/replace/action.py | 15 +- .../komand_string/actions/replace/schema.py | 16 +- .../actions/set_encoding/__init__.py | 2 +- .../actions/set_encoding/action.py | 17 +- .../actions/set_encoding/schema.py | 18 +- .../actions/split_to_list/__init__.py | 2 +- .../actions/split_to_list/action.py | 20 +- .../actions/split_to_list/schema.py | 16 +- .../actions/split_to_object/__init__.py | 2 +- .../actions/split_to_object/action.py | 66 ++-- .../actions/split_to_object/schema.py | 16 +- .../komand_string/actions/trim/__init__.py | 2 +- .../komand_string/actions/trim/action.py | 10 +- .../komand_string/actions/trim/schema.py | 16 +- .../komand_string/actions/upper/__init__.py | 2 +- .../komand_string/actions/upper/action.py | 15 +- .../komand_string/actions/upper/schema.py | 16 +- .../komand_string/connection/__init__.py | 2 +- .../string/komand_string/connection/schema.py | 5 +- .../string/komand_string/tasks/__init__.py | 2 + .../string/komand_string/triggers/__init__.py | 3 +- plugins/string/plugin.spec.yaml | 53 ++- plugins/string/requirements.txt | 3 +- plugins/string/setup.py | 4 +- plugins/string/unit_test/__init__.py | 4 + plugins/string/unit_test/test_length.py | 40 +++ plugins/string/unit_test/test_lower.py | 42 +++ plugins/string/unit_test/test_replace.py | 8 +- plugins/string/unit_test/test_set_encoding.py | 51 +++ .../string/unit_test/test_split_to_list.py | 56 ++++ .../string/unit_test/test_split_to_object.py | 62 ++++ plugins/string/unit_test/test_trim.py | 1 + plugins/string/unit_test/test_upper.py | 43 +++ 45 files changed, 753 insertions(+), 347 deletions(-) create mode 100644 plugins/string/komand_string/tasks/__init__.py create mode 100644 plugins/string/unit_test/test_length.py create mode 100644 plugins/string/unit_test/test_lower.py create mode 100644 plugins/string/unit_test/test_set_encoding.py create mode 100644 plugins/string/unit_test/test_split_to_list.py create mode 100644 plugins/string/unit_test/test_split_to_object.py create mode 100644 plugins/string/unit_test/test_upper.py diff --git a/plugins/string/.CHECKSUM b/plugins/string/.CHECKSUM index e61ce34f2a..f482dcb19d 100644 --- a/plugins/string/.CHECKSUM +++ b/plugins/string/.CHECKSUM @@ -1,43 +1,43 @@ { - "spec": "67b1aec16d3984c4cfe263d856f22561", - "manifest": "828f222889a88dd9686e97b8327a6d0f", - "setup": "a84d0255a4806c28f6d62d612e0f3cc0", + "spec": "2d872dd50b19daa898791255146106af", + "manifest": "922ea555f44944378c4f1b096747bd0c", + "setup": "c44b119f9f8f9981c367bc04a6dc9234", "schemas": [ { "identifier": "length/schema.py", - "hash": "0de363a97e185c91b95b3d4e01fbb075" + "hash": "3e1148fc9cc7384ff04e76f77b57434d" }, { "identifier": "lower/schema.py", - "hash": "84b256cc45c2bfe5fc9a8be4d1bfd85e" + "hash": "4b202dd01733d13bf70235e901acef6a" }, { "identifier": "replace/schema.py", - "hash": "00cb6cb4d33ef74048856c84537ef1d2" + "hash": "0354be994d37d1129247095f398deff5" }, { "identifier": "set_encoding/schema.py", - "hash": "ae4eb9807851a18300e147253f3ad913" + "hash": "6f954cf5a4c9274affebb8d9c6102949" }, { "identifier": "split_to_list/schema.py", - "hash": "58448f50d317761aa3dd5cb7ec30a622" + "hash": "31618e2e31399771514d12a8f191f7dd" }, { "identifier": "split_to_object/schema.py", - "hash": "95314b1484fe6cfb1cbc307d19afede4" + "hash": "d39a4841d4f5601bc93f5a28ae286eeb" }, { "identifier": "trim/schema.py", - "hash": "658fcd5acc1e51653618a0b97b0e4850" + "hash": "fcef89843d1448a481f7cc6b96a6d11d" }, { "identifier": "upper/schema.py", - "hash": "5b01e824ada701bcfbe19ce2557af1de" + "hash": "75c74ad6056ac287d31024cdaa36ff32" }, { "identifier": "connection/schema.py", - "hash": "da5382221ca2a33a2f854e17b068d502" + "hash": "bd524b567f9638ba1c6f7e0c9e45ff2e" } ] } \ No newline at end of file diff --git a/plugins/string/Dockerfile b/plugins/string/Dockerfile index 1fa760608a..a9094f6b81 100755 --- a/plugins/string/Dockerfile +++ b/plugins/string/Dockerfile @@ -1,27 +1,20 @@ -FROM rapid7/insightconnect-python-3-38-plugin:4 -# The three supported python parent images are: -# - komand/python-2-plugin -# - komand/python-3-plugin -# - komand/python-pypy3-plugin -# -LABEL organization=komand +FROM --platform=linux/amd64 rapid7/insightconnect-python-3-slim-plugin:6.1.0 -# Add any custom package dependencies here -# NOTE: Add pip packages to requirements.txt +LABEL organization=rapid7 +LABEL sdk=python -# End package dependencies - -# 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 USER nobody ENTRYPOINT ["/usr/local/bin/komand_string"] diff --git a/plugins/string/bin/komand_string b/plugins/string/bin/komand_string index 19632fac99..b9f0777c7a 100755 --- a/plugins/string/bin/komand_string +++ b/plugins/string/bin/komand_string @@ -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 = "String Operations" Vendor = "rapid7" -Version = "1.4.0" +Version = "1.4.1" Description = "The String plugin provides common programmatic string operations" @@ -23,7 +23,7 @@ def main(): monkey.patch_all() import insightconnect_plugin_runtime - from komand_string import connection, actions, triggers + from komand_string import connection, actions, triggers, tasks class ICONString(insightconnect_plugin_runtime.Plugin): def __init__(self): @@ -34,22 +34,22 @@ def main(): description=Description, connection=connection.Connection() ) - self.add_action(actions.Length()) - - self.add_action(actions.Lower()) - - self.add_action(actions.Replace()) - self.add_action(actions.SetEncoding()) - + self.add_action(actions.SplitToList()) - + self.add_action(actions.SplitToObject()) - - self.add_action(actions.Trim()) - + self.add_action(actions.Upper()) - + + self.add_action(actions.Lower()) + + self.add_action(actions.Trim()) + + self.add_action(actions.Length()) + + self.add_action(actions.Replace()) + """Run plugin""" cli = insightconnect_plugin_runtime.CLI(ICONString()) diff --git a/plugins/string/help.md b/plugins/string/help.md index 2f13e67ba3..0488b090b0 100644 --- a/plugins/string/help.md +++ b/plugins/string/help.md @@ -12,84 +12,157 @@ This plugin utilizes the Python 3 String library [set of methods](https://docs.p * Replace parts of a string # Requirements + +*This plugin does not contain any requirements.* -_This plugin does not contain any requirements._ +# Supported Product Versions + +* 2024-09-06 # Documentation ## Setup - -_This plugin does not contain a connection._ + +*This plugin does not contain a connection.* ## Technical Details ### Actions -#### Replace -This action is used to replace parts of a string. +#### Length -##### Input +This action is used to return the length of a string -|Name|Type|Default|Required|Description|Enum|Example| -|----|----|-------|--------|-----------|----|-------| -|in_string|string|None|True|The string to replace parts of|None|this is a string| -|replacement_value|string|None|False|The string that will replace the parts that are found. If left blank the characters to find will be deleted|None|replacement| -|string_part_to_find|string|None|True|The string part to look for. All instances of this string will be replaced|None|string| +##### Input +|Name|Type|Default|Required|Description|Enum|Example|Placeholder|Tooltip| +| :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | +|string|string|None|True|String to return length of|None|return the number of characters in this string|None|None| + Example input: ``` { - "in_string": "the cow jumped over the moon", - "replacement_value": "cat", - "string_part_to_find": "cow" + "string": "return the number of characters in this string" } ``` ##### Output -|Name|Type|Required|Description| -|----|----|--------|-----------| -|result_string|string|True|The string after replacement| - +|Name|Type|Required|Description|Example| +| :--- | :--- | :--- | :--- | :--- | +|length|integer|True|Length of string|46| + Example output: ``` { - "result_string": "the cat jumped over the moon" + "length": 46 } ``` -#### Length +#### Lower -This action is used to return the length of a string. +This action is used to converts uppercase letters to lowercase ##### Input -|Name|Type|Default|Required|Description|Enum|Example| -|----|----|-------|--------|-----------|----|-------| -|string|string|None|True|String to return length of|None|return the number of characters in this string| +|Name|Type|Default|Required|Description|Enum|Example|Placeholder|Tooltip| +| :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | +|string|string|None|True|String to convert e.g. USER=bob|None|LOWERCASE THIS STRING|None|None| + +Example input: + +``` +{ + "string": "LOWERCASE THIS STRING" +} +``` +##### Output + +|Name|Type|Required|Description|Example| +| :--- | :--- | :--- | :--- | :--- | +|lower|string|False|Lowercase string|lowercase this string| + +Example output: + +``` +{ + "lower": "lowercase this string" +} +``` + +#### Replace + +This action is used to replace parts of a string + +##### Input + +|Name|Type|Default|Required|Description|Enum|Example|Placeholder|Tooltip| +| :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | +|in_string|string|None|True|The string to replace parts of|None|this is a string|None|None| +|replacement_value|string|None|False|The string that will replace the parts that are found. If left blank the characters to find will be deleted|None|replacement|None|None| +|string_part_to_find|string|None|True|The string part to look for. All instances of this string will be replaced|None|string|None|None| + Example input: ``` { - "string": "return the number of characters in this string" + "in_string": "this is a string", + "replacement_value": "replacement", + "string_part_to_find": "string" } ``` ##### Output -|Name|Type|Required|Description| -|----|----|--------|-----------| -|length|integer|True|Length of string| +|Name|Type|Required|Description|Example| +| :--- | :--- | :--- | :--- | :--- | +|result_string|string|True|The string after replacement|this is a replacement| + +Example output: +``` +{ + "result_string": "this is a replacement" +} +``` + +#### Set Encoding + +This action is used to encode a string + +##### Input + +|Name|Type|Default|Required|Description|Enum|Example|Placeholder|Tooltip| +| :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | +|encoding|string|None|True|Encoding to use|["UTF-8", "ASCII"]|ASCII|None|None| +|error_handling|string|None|True|Error handler to use for encoding and decoding|["strict", "replace", "ignore"]|ignore|None|None| +|string|string|None|True|String to encode|None|hello|None|None| + +Example input: + +``` +{ + "encoding": "ASCII", + "error_handling": "ignore", + "string": "hello" +} +``` + +##### Output + +|Name|Type|Required|Description|Example| +| :--- | :--- | :--- | :--- | :--- | +|encoded|string|True|Encoded string|hello| + Example output: ``` { - "length": 46 + "encoded": "hello" } ``` @@ -99,11 +172,11 @@ This action is used to convert a string to a list of strings. ##### Input -|Name|Type|Default|Required|Description|Enum|Example| -|----|----|-------|--------|-----------|----|-------| -|delimiter|string|None|False|The character used to split the string into slices for the list. The default is a newline, if not provided by the user|None|,| -|string|string|None|True|String to break into an array|None|This,is,a,sentence| - +|Name|Type|Default|Required|Description|Enum|Example|Placeholder|Tooltip| +| :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | +|delimiter|string|None|False|The character used to split the string into slices for the list. The default is a newline, if not provided by the user|None|,|None|None| +|string|string|None|True|String to break into an array|None|This,is,a,sentence|None|None| + Example input: ``` @@ -115,10 +188,10 @@ Example input: ##### Output -|Name|Type|Required|Description| -|----|----|--------|-----------| -|list|[]string|False|List of string components| - +|Name|Type|Required|Description|Example| +| :--- | :--- | :--- | :--- | :--- | +|list|[]string|False|List of string components|["This", "is", "a", "sentence"]| + Example output: ``` @@ -146,16 +219,17 @@ It allows users the ability to use the green selector and choose a specific vari ##### Input -|Name|Type|Default|Required|Description|Enum|Example| -|----|----|-------|--------|-----------|----|-------| -|block_delimiter|string|None|False|The character delimiter for the initial string split, applied before the string delimiter input. This parameter is optional but allows for more complex handling|None|[| -|string|string|None|True|String to convert e.g. USER=Bob|None|User=Bob| -|string_delimiter|string|None|False|The character used to split the string into slices for the list. The default is a space, if not provided by the user|None|=| - +|Name|Type|Default|Required|Description|Enum|Example|Placeholder|Tooltip| +| :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | +|block_delimiter|string|None|False|The character delimiter for the initial string split, applied before the string delimiter input. This parameter is optional but allows for more complex handling|None|[|None|None| +|string|string|None|True|String to convert e.g. USER=Bob|None|User=Bob|None|None| +|string_delimiter|string|None|False|The character used to split the string into slices for the list. The default is a space, if not provided by the user|None|=|None|None| + Example input: ``` { + "block_delimiter": "[", "string": "User=Bob", "string_delimiter": "=" } @@ -163,12 +237,10 @@ Example input: ##### Output -|Name|Type|Required|Description| -|----|----|--------|-----------| -|object|object|False|Object from string split| - -Given an input string of `User=Bob`, setting `string_delimiter` to `=` would return the information presented in the example below. - +|Name|Type|Required|Description|Example| +| :--- | :--- | :--- | :--- | :--- | +|object|object|False|Object from string split|{"User":"Bob"}| + Example output: ``` @@ -200,153 +272,87 @@ Example output: } ``` -#### Upper - -This action is used to convert lowercase letters to uppercase. - -##### Input - -|Name|Type|Default|Required|Description|Enum|Example| -|----|----|-------|--------|-----------|----|-------| -|string|string|None|True|String to uppercase|None|uppercase this string| - -Example input: - -``` -{ - "string": "uppercase this string" -} -``` - -##### Output - -|Name|Type|Required|Description| -|----|----|--------|-----------| -|upper|string|False|Uppercase string| - -Example output: - -``` -{ - "upper": "UPPERCASE THIS STRING" -} -``` - -#### Lower - -This action is used to convert uppercase letters to lowercase. - -##### Input - -|Name|Type|Default|Required|Description|Enum|Example| -|----|----|-------|--------|-----------|----|-------| -|string|string|None|True|String to convert e.g. USER=bob|None|LOWERCASE THIS STRING| - -Example input: - -``` -{ - "string": "LOWERCASE THIS STRING" -} -``` - -##### Output - -|Name|Type|Required|Description| -|----|----|--------|-----------| -|lower|string|False|Lowercase string| - -Example output: - -``` -{ - "lower": "lowercase this string" -} -``` - -#### Set Encoding +#### Trim -This action is used to encode a string. +This action is used to trim a string of leading and trailing whitespace ##### Input -|Name|Type|Default|Required|Description|Enum|Example| -|----|----|-------|--------|-----------|----|-------| -|encoding|string|None|True|Encoding to use|['UTF-8', 'ASCII']|ASCII| -|error_handling|string|None|True|Error handler to use for encoding and decoding|['strict', 'replace', 'ignore']|ignore| -|string|string|None|True|String to encode|None|hello| - +|Name|Type|Default|Required|Description|Enum|Example|Placeholder|Tooltip| +| :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | +|string|string|None|True|String to trim|None|Extra spaces at the end of this string |None|None| + Example input: ``` { - "encoding": "ASCII", - "error_handling": "ignore", - "string": "hello" + "string": "Extra spaces at the end of this string " } ``` ##### Output -|Name|Type|Required|Description| -|----|----|--------|-----------| -|encoded|string|True|Encoded string| - +|Name|Type|Required|Description|Example| +| :--- | :--- | :--- | :--- | :--- | +|trimmed|string|True|Trimmed string|Extra spaces at the end of this string| + Example output: ``` { - "encoded": "hello" + "trimmed": "Extra spaces at the end of this string" } ``` -#### Trim +#### Upper -This action is used to trim a string of leading and trailing whitespace. +This action is used to converts lowercase letters to uppercase ##### Input -|Name|Type|Default|Required|Description|Enum|Example| -|----|----|-------|--------|-----------|----|-------| -|string|string|None|True|String to trim|None|Extra spaces at the end of this string | - +|Name|Type|Default|Required|Description|Enum|Example|Placeholder|Tooltip| +| :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | +|string|string|None|True|String to uppercase|None|uppercase this string|None|None| + Example input: ``` { - "string": "Extra spaces at the end of this string " + "string": "uppercase this string" } ``` ##### Output -|Name|Type|Required|Description| -|----|----|--------|-----------| -|trimmed|string|True|Trimmed string| - +|Name|Type|Required|Description|Example| +| :--- | :--- | :--- | :--- | :--- | +|upper|string|False|Uppercase string|UPPERCASE THIS STRING| + Example output: ``` { - "trimmed": "Extra spaces at the end of this string" + "upper": "UPPERCASE THIS STRING" } ``` - ### Triggers + +*This plugin does not contain any triggers.* +### Tasks + +*This plugin does not contain any tasks.* -_This plugin does not contain any triggers._ - -### Custom Output Types - -_This plugin does not contain any custom output types._ +### Custom Types + +*This plugin does not contain any custom output types.* ## Troubleshooting -There may be complex string manipulation needs that are likely outside the scope of this plugin. -If this is the case, consider using the Python 3 Script plugin instead. +There may be complex string manipulation needs that are likely outside the scope of this plugin. If this is the case, consider using the Python 3 Script plugin instead. # Version History +* 1.4.1 - Initial updates for fedramp compliance | Updated SDK to the latest version * 1.4.0 - New action Replace * 1.3.1 - Update to v4 Python plugin runtime * 1.3.0 - New action Length | Add example inputs @@ -358,6 +364,8 @@ If this is the case, consider using the Python 3 Script plugin instead. # Links +* [Python 3 String Methods](https://docs.python.org/3/library/stdtypes.html#string-methods) + ## References -* [Python 3 String Methods](https://docs.python.org/3/library/stdtypes.html#string-methods) +* [Python 3 String Methods](https://docs.python.org/3/library/stdtypes.html#string-methods) \ No newline at end of file diff --git a/plugins/string/komand_string/actions/__init__.py b/plugins/string/komand_string/actions/__init__.py index 642c01dca0..7901d69c61 100755 --- a/plugins/string/komand_string/actions/__init__.py +++ b/plugins/string/komand_string/actions/__init__.py @@ -1,9 +1,18 @@ -# GENERATED BY KOMAND SDK - DO NOT EDIT -from .length.action import Length -from .lower.action import Lower -from .replace.action import Replace +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT + from .set_encoding.action import SetEncoding + from .split_to_list.action import SplitToList + from .split_to_object.action import SplitToObject -from .trim.action import Trim + from .upper.action import Upper + +from .lower.action import Lower + +from .trim.action import Trim + +from .length.action import Length + +from .replace.action import Replace + diff --git a/plugins/string/komand_string/actions/length/__init__.py b/plugins/string/komand_string/actions/length/__init__.py index a393c54c57..2a45543fff 100755 --- a/plugins/string/komand_string/actions/length/__init__.py +++ b/plugins/string/komand_string/actions/length/__init__.py @@ -1,2 +1,2 @@ -# GENERATED BY KOMAND SDK - DO NOT EDIT +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT from .action import Length diff --git a/plugins/string/komand_string/actions/length/action.py b/plugins/string/komand_string/actions/length/action.py index 32022b5ab9..c2da4e8b35 100755 --- a/plugins/string/komand_string/actions/length/action.py +++ b/plugins/string/komand_string/actions/length/action.py @@ -2,6 +2,7 @@ from .schema import LengthInput, LengthOutput, Input, Output, Component # Custom imports below +from insightconnect_plugin_runtime.exceptions import PluginException class Length(insightconnect_plugin_runtime.Action): @@ -14,6 +15,11 @@ def __init__(self): ) def run(self, params={}): - _str = params.get("string") - length = len(_str) - return {"length": length} + # START INPUT BINDING - DO NOT REMOVE - ANY INPUTS BELOW WILL UPDATE WITH YOUR PLUGIN SPEC AFTER REGENERATION + input_string = params.get(Input.STRING) + # END INPUT BINDING - DO NOT REMOVE + + try: + return {Output.LENGTH: len(input_string)} + except Exception as error: + raise PluginException(preset=PluginException.Preset.UNKNOWN, data=error) diff --git a/plugins/string/komand_string/actions/length/schema.py b/plugins/string/komand_string/actions/length/schema.py index b4f3726463..43124197c0 100755 --- a/plugins/string/komand_string/actions/length/schema.py +++ b/plugins/string/komand_string/actions/length/schema.py @@ -1,4 +1,4 @@ -# GENERATED BY KOMAND SDK - DO NOT EDIT +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT import insightconnect_plugin_runtime import json @@ -9,14 +9,14 @@ class Component: class Input: STRING = "string" - + class Output: LENGTH = "length" - + class LengthInput(insightconnect_plugin_runtime.Input): - schema = json.loads(""" + schema = json.loads(r""" { "type": "object", "title": "Variables", @@ -30,7 +30,8 @@ class LengthInput(insightconnect_plugin_runtime.Input): }, "required": [ "string" - ] + ], + "definitions": {} } """) @@ -39,7 +40,7 @@ def __init__(self): class LengthOutput(insightconnect_plugin_runtime.Output): - schema = json.loads(""" + schema = json.loads(r""" { "type": "object", "title": "Variables", @@ -53,7 +54,8 @@ class LengthOutput(insightconnect_plugin_runtime.Output): }, "required": [ "length" - ] + ], + "definitions": {} } """) diff --git a/plugins/string/komand_string/actions/lower/__init__.py b/plugins/string/komand_string/actions/lower/__init__.py index 2036344f94..8a8f036954 100755 --- a/plugins/string/komand_string/actions/lower/__init__.py +++ b/plugins/string/komand_string/actions/lower/__init__.py @@ -1,2 +1,2 @@ -# GENERATED BY KOMAND SDK - DO NOT EDIT +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT from .action import Lower diff --git a/plugins/string/komand_string/actions/lower/action.py b/plugins/string/komand_string/actions/lower/action.py index 7b2c3d507b..39391422bf 100755 --- a/plugins/string/komand_string/actions/lower/action.py +++ b/plugins/string/komand_string/actions/lower/action.py @@ -1,5 +1,5 @@ import insightconnect_plugin_runtime -from .schema import LowerInput, LowerOutput +from .schema import LowerInput, LowerOutput, Input, Output # Custom imports below from insightconnect_plugin_runtime.exceptions import PluginException @@ -15,11 +15,17 @@ def __init__(self): ) def run(self, params={}): - string = params.get("string") - if not string: + # START INPUT BINDING - DO NOT REMOVE - ANY INPUTS BELOW WILL UPDATE WITH YOUR PLUGIN SPEC AFTER REGENERATION + input_string = params.get(Input.STRING) + # END INPUT BINDING - DO NOT REMOVE + + if not input_string: raise PluginException( cause="Action failed! Missing required user input.", assistance="Please provide the input string.", ) - return {"lower": string.lower()} + try: + return {Output.LOWER: input_string.lower()} + except Exception as error: + raise PluginException(preset=PluginException.Preset.UNKNOWN, data=error) diff --git a/plugins/string/komand_string/actions/lower/schema.py b/plugins/string/komand_string/actions/lower/schema.py index 510a345671..5db008f235 100755 --- a/plugins/string/komand_string/actions/lower/schema.py +++ b/plugins/string/komand_string/actions/lower/schema.py @@ -1,4 +1,4 @@ -# GENERATED BY KOMAND SDK - DO NOT EDIT +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT import insightconnect_plugin_runtime import json @@ -9,14 +9,14 @@ class Component: class Input: STRING = "string" - + class Output: LOWER = "lower" - + class LowerInput(insightconnect_plugin_runtime.Input): - schema = json.loads(""" + schema = json.loads(r""" { "type": "object", "title": "Variables", @@ -30,7 +30,8 @@ class LowerInput(insightconnect_plugin_runtime.Input): }, "required": [ "string" - ] + ], + "definitions": {} } """) @@ -39,7 +40,7 @@ def __init__(self): class LowerOutput(insightconnect_plugin_runtime.Output): - schema = json.loads(""" + schema = json.loads(r""" { "type": "object", "title": "Variables", @@ -50,7 +51,8 @@ class LowerOutput(insightconnect_plugin_runtime.Output): "description": "Lowercase string", "order": 1 } - } + }, + "definitions": {} } """) diff --git a/plugins/string/komand_string/actions/replace/__init__.py b/plugins/string/komand_string/actions/replace/__init__.py index d7220fcbb2..d77fa16475 100755 --- a/plugins/string/komand_string/actions/replace/__init__.py +++ b/plugins/string/komand_string/actions/replace/__init__.py @@ -1,2 +1,2 @@ -# GENERATED BY KOMAND SDK - DO NOT EDIT +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT from .action import Replace diff --git a/plugins/string/komand_string/actions/replace/action.py b/plugins/string/komand_string/actions/replace/action.py index 8494d97cb7..c094aa612b 100755 --- a/plugins/string/komand_string/actions/replace/action.py +++ b/plugins/string/komand_string/actions/replace/action.py @@ -2,7 +2,7 @@ from .schema import ReplaceInput, ReplaceOutput, Input, Output, Component # Custom imports below -import string +from insightconnect_plugin_runtime.exceptions import PluginException class Replace(insightconnect_plugin_runtime.Action): @@ -12,14 +12,17 @@ def __init__(self): ) def run(self, params={}): - in_string = params.get(Input.IN_STRING) + # START INPUT BINDING - DO NOT REMOVE - ANY INPUTS BELOW WILL UPDATE WITH YOUR PLUGIN SPEC AFTER REGENERATION + input_string = params.get(Input.IN_STRING) find_string = params.get(Input.STRING_PART_TO_FIND) replace_string = params.get(Input.REPLACEMENT_VALUE, "") + # END INPUT BINDING - DO NOT REMOVE - self.logger.info(f"in_string: {in_string}") + self.logger.info(f"in_string: {input_string}") self.logger.info(f"find_string: {find_string}") self.logger.info(f"replace_string: {replace_string}") - out_string = in_string.replace(find_string, replace_string) - - return {Output.RESULT_STRING: out_string} + try: + return {Output.RESULT_STRING: input_string.replace(find_string, replace_string)} + except Exception as error: + raise PluginException(preset=PluginException.Preset.UNKNOWN, data=error) diff --git a/plugins/string/komand_string/actions/replace/schema.py b/plugins/string/komand_string/actions/replace/schema.py index 9f62487252..6a2b62e290 100755 --- a/plugins/string/komand_string/actions/replace/schema.py +++ b/plugins/string/komand_string/actions/replace/schema.py @@ -1,4 +1,4 @@ -# GENERATED BY KOMAND SDK - DO NOT EDIT +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT import insightconnect_plugin_runtime import json @@ -11,14 +11,14 @@ class Input: IN_STRING = "in_string" REPLACEMENT_VALUE = "replacement_value" STRING_PART_TO_FIND = "string_part_to_find" - + class Output: RESULT_STRING = "result_string" - + class ReplaceInput(insightconnect_plugin_runtime.Input): - schema = json.loads(""" + schema = json.loads(r""" { "type": "object", "title": "Variables", @@ -45,7 +45,8 @@ class ReplaceInput(insightconnect_plugin_runtime.Input): "required": [ "in_string", "string_part_to_find" - ] + ], + "definitions": {} } """) @@ -54,7 +55,7 @@ def __init__(self): class ReplaceOutput(insightconnect_plugin_runtime.Output): - schema = json.loads(""" + schema = json.loads(r""" { "type": "object", "title": "Variables", @@ -68,7 +69,8 @@ class ReplaceOutput(insightconnect_plugin_runtime.Output): }, "required": [ "result_string" - ] + ], + "definitions": {} } """) diff --git a/plugins/string/komand_string/actions/set_encoding/__init__.py b/plugins/string/komand_string/actions/set_encoding/__init__.py index 5545a13030..8960c88f02 100755 --- a/plugins/string/komand_string/actions/set_encoding/__init__.py +++ b/plugins/string/komand_string/actions/set_encoding/__init__.py @@ -1,2 +1,2 @@ -# GENERATED BY KOMAND SDK - DO NOT EDIT +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT from .action import SetEncoding diff --git a/plugins/string/komand_string/actions/set_encoding/action.py b/plugins/string/komand_string/actions/set_encoding/action.py index 9379b12d28..fa7f87f2a6 100755 --- a/plugins/string/komand_string/actions/set_encoding/action.py +++ b/plugins/string/komand_string/actions/set_encoding/action.py @@ -15,15 +15,14 @@ def __init__(self): ) def run(self, params={}): - string = params.get(Input.STRING) - encoding_val = params.get(Input.ENCODING).lower() + # START INPUT BINDING - DO NOT REMOVE - ANY INPUTS BELOW WILL UPDATE WITH YOUR PLUGIN SPEC AFTER REGENERATION + input_string = params.get(Input.STRING) + encoding_val = params.get(Input.ENCODING, "").lower() error_handler = params.get(Input.ERROR_HANDLING) + # END INPUT BINDING - DO NOT REMOVE try: - output = string.encode(encoding_val, error_handler) - except UnicodeError: - raise PluginException(cause="Encoding failed.", assistance="Could not encode given string.") - - output = output.decode(encoding_val, error_handler) - - return {Output.ENCODED: output} + output = input_string.encode(encoding_val, error_handler) + return {Output.ENCODED: output.decode(encoding_val, error_handler)} + except Exception as error: + raise PluginException(cause="Encoding failed.", assistance="Could not encode given string.", data=error) diff --git a/plugins/string/komand_string/actions/set_encoding/schema.py b/plugins/string/komand_string/actions/set_encoding/schema.py index 0c3487f022..9da83b7a1c 100755 --- a/plugins/string/komand_string/actions/set_encoding/schema.py +++ b/plugins/string/komand_string/actions/set_encoding/schema.py @@ -1,4 +1,4 @@ -# GENERATED BY KOMAND SDK - DO NOT EDIT +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT import insightconnect_plugin_runtime import json @@ -11,21 +11,20 @@ class Input: ENCODING = "encoding" ERROR_HANDLING = "error_handling" STRING = "string" - + class Output: ENCODED = "encoded" - + class SetEncodingInput(insightconnect_plugin_runtime.Input): - schema = json.loads(""" + schema = json.loads(r""" { "type": "object", "title": "Variables", "properties": { "encoding": { "type": "string", - "title": "Encoding", "description": "Encoding to use", "enum": [ "UTF-8", @@ -35,7 +34,6 @@ class SetEncodingInput(insightconnect_plugin_runtime.Input): }, "error_handling": { "type": "string", - "title": "Error Handling", "description": "Error handler to use for encoding and decoding", "enum": [ "strict", @@ -55,7 +53,8 @@ class SetEncodingInput(insightconnect_plugin_runtime.Input): "encoding", "error_handling", "string" - ] + ], + "definitions": {} } """) @@ -64,7 +63,7 @@ def __init__(self): class SetEncodingOutput(insightconnect_plugin_runtime.Output): - schema = json.loads(""" + schema = json.loads(r""" { "type": "object", "title": "Variables", @@ -78,7 +77,8 @@ class SetEncodingOutput(insightconnect_plugin_runtime.Output): }, "required": [ "encoded" - ] + ], + "definitions": {} } """) diff --git a/plugins/string/komand_string/actions/split_to_list/__init__.py b/plugins/string/komand_string/actions/split_to_list/__init__.py index f04c15dfb3..bb7ad3c4e7 100755 --- a/plugins/string/komand_string/actions/split_to_list/__init__.py +++ b/plugins/string/komand_string/actions/split_to_list/__init__.py @@ -1,2 +1,2 @@ -# GENERATED BY KOMAND SDK - DO NOT EDIT +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT from .action import SplitToList diff --git a/plugins/string/komand_string/actions/split_to_list/action.py b/plugins/string/komand_string/actions/split_to_list/action.py index 0df31eb83b..b3cac49983 100755 --- a/plugins/string/komand_string/actions/split_to_list/action.py +++ b/plugins/string/komand_string/actions/split_to_list/action.py @@ -1,5 +1,5 @@ import insightconnect_plugin_runtime -from .schema import SplitToListInput, SplitToListOutput +from .schema import SplitToListInput, SplitToListOutput, Input, Output # Custom imports below from insightconnect_plugin_runtime.exceptions import PluginException @@ -15,16 +15,22 @@ def __init__(self): ) def run(self, params={}): - string = params.get("string") - if not string: + # START INPUT BINDING - DO NOT REMOVE - ANY INPUTS BELOW WILL UPDATE WITH YOUR PLUGIN SPEC AFTER REGENERATION + input_string = params.get(Input.STRING) + delimiter = params.get(Input.DELIMITER) + # END INPUT BINDING - DO NOT REMOVE + + if not input_string: raise PluginException( cause="Action failed! Missing required user input.", assistance="Please provide the input string.", ) - delimiter = params.get("delimiter") - if delimiter == "": - self.logger.info("User did not supply a string delimiter. " "Defaulting to a newline character.") + if not delimiter: + self.logger.info("User did not supply a string delimiter. Defaulting to a newline character.") delimiter = "\n" - return {"list": string.split(delimiter)} + try: + return {Output.LIST: input_string.split(delimiter)} + except Exception as error: + raise PluginException(preset=PluginException.Preset.UNKNOWN, data=error) diff --git a/plugins/string/komand_string/actions/split_to_list/schema.py b/plugins/string/komand_string/actions/split_to_list/schema.py index 0fe2fedb3d..9a064d0ad7 100755 --- a/plugins/string/komand_string/actions/split_to_list/schema.py +++ b/plugins/string/komand_string/actions/split_to_list/schema.py @@ -1,4 +1,4 @@ -# GENERATED BY KOMAND SDK - DO NOT EDIT +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT import insightconnect_plugin_runtime import json @@ -10,14 +10,14 @@ class Component: class Input: DELIMITER = "delimiter" STRING = "string" - + class Output: LIST = "list" - + class SplitToListInput(insightconnect_plugin_runtime.Input): - schema = json.loads(""" + schema = json.loads(r""" { "type": "object", "title": "Variables", @@ -37,7 +37,8 @@ class SplitToListInput(insightconnect_plugin_runtime.Input): }, "required": [ "string" - ] + ], + "definitions": {} } """) @@ -46,7 +47,7 @@ def __init__(self): class SplitToListOutput(insightconnect_plugin_runtime.Output): - schema = json.loads(""" + schema = json.loads(r""" { "type": "object", "title": "Variables", @@ -60,7 +61,8 @@ class SplitToListOutput(insightconnect_plugin_runtime.Output): }, "order": 1 } - } + }, + "definitions": {} } """) diff --git a/plugins/string/komand_string/actions/split_to_object/__init__.py b/plugins/string/komand_string/actions/split_to_object/__init__.py index 27deafc1ab..48d3f9c9d9 100755 --- a/plugins/string/komand_string/actions/split_to_object/__init__.py +++ b/plugins/string/komand_string/actions/split_to_object/__init__.py @@ -1,2 +1,2 @@ -# GENERATED BY KOMAND SDK - DO NOT EDIT +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT from .action import SplitToObject diff --git a/plugins/string/komand_string/actions/split_to_object/action.py b/plugins/string/komand_string/actions/split_to_object/action.py index c377f93593..ce92fb1319 100755 --- a/plugins/string/komand_string/actions/split_to_object/action.py +++ b/plugins/string/komand_string/actions/split_to_object/action.py @@ -1,8 +1,9 @@ import insightconnect_plugin_runtime -from .schema import SplitToObjectInput, SplitToObjectOutput +from .schema import SplitToObjectInput, SplitToObjectOutput, Input, Output # Custom imports below from insightconnect_plugin_runtime.exceptions import PluginException +from typing import Dict, Any class SplitToObject(insightconnect_plugin_runtime.Action): @@ -15,49 +16,52 @@ def __init__(self): ) def run(self, params={}): - block_split = False - string = params.get("string") - sd = params.get("string_delimiter") - bd = params.get("block_delimiter") + # START INPUT BINDING - DO NOT REMOVE - ANY INPUTS BELOW WILL UPDATE WITH YOUR PLUGIN SPEC AFTER REGENERATION + input_string = params.get(Input.STRING) + string_delimiter = params.get(Input.STRING_DELIMITER) + block_delimiter = params.get(Input.BLOCK_DELIMITER) + # END INPUT BINDING - DO NOT REMOVE - if not sd: - self.logger.info("User did not supply a string delimiter. " "Defaulting to a space character.") - sd = " " - - if not string: + if not input_string: raise PluginException( cause="Action failed! Missing required user input.", assistance="Please provide the input string.", ) - if bd: - block_split = True - self.logger.info("Block delimiter received, performing block split first") - - d = {} + if not string_delimiter: + self.logger.info("User did not supply a string delimiter. Defaulting to a space character.") + string_delimiter = " " - if block_split: + dict_ = {} + if block_delimiter: # Split a block of text before applying user's string split delimiter - for line in string.split(bd): - pair = line.split(sd) - c = len(pair) - if c == 2: - # Assign 1st element as key, 2nd as value to dict - d[pair[0].strip('"')] = pair[1].strip('"') - else: - self.logger.info("Skipping {count} element split: {pair}".format(count=c, pair=pair)) - return {"object": d} + try: + for line in input_string.split(block_delimiter): + pair = line.split(string_delimiter) + length_pair = len(pair) + if length_pair == 2: + # Assign 1st element as key, 2nd as value to dict + dict_[pair[0].strip('"')] = pair[1].strip('"') + else: + self.logger.info(f"Skipping {length_pair} element split: {pair}") + return {Output.OBJECT: dict_} + except Exception as error: + raise PluginException( + cause="Action failed! Unable to split string cleanly.", + assistance="Please try specifying the block delimiter for more multi-key:value input.", + data=error, + ) # Single key:value pair split e.g. USER=bob try: - list_ = string.split(sd) - self.logger.info("User input to split: %s -> %s", string, list_) - d[list_[0]] = list_[1] - except (ValueError, IndexError): + list_ = input_string.split(string_delimiter) + self.logger.info(f"User input to split: {input_string} -> {list_}") + dict_[list_[0]] = list_[1] + return {Output.OBJECT: dict_} + except Exception as error: self.logger.error("It looks like the input contained more than a single key:value split.") raise PluginException( cause="Action failed! Unable to split string cleanly.", assistance="Please try specifying the block delimiter for more multi-key:value input.", + data=error, ) - - return {"object": d} diff --git a/plugins/string/komand_string/actions/split_to_object/schema.py b/plugins/string/komand_string/actions/split_to_object/schema.py index 0ce131345c..76a8da5298 100755 --- a/plugins/string/komand_string/actions/split_to_object/schema.py +++ b/plugins/string/komand_string/actions/split_to_object/schema.py @@ -1,4 +1,4 @@ -# GENERATED BY KOMAND SDK - DO NOT EDIT +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT import insightconnect_plugin_runtime import json @@ -11,14 +11,14 @@ class Input: BLOCK_DELIMITER = "block_delimiter" STRING = "string" STRING_DELIMITER = "string_delimiter" - + class Output: OBJECT = "object" - + class SplitToObjectInput(insightconnect_plugin_runtime.Input): - schema = json.loads(""" + schema = json.loads(r""" { "type": "object", "title": "Variables", @@ -44,7 +44,8 @@ class SplitToObjectInput(insightconnect_plugin_runtime.Input): }, "required": [ "string" - ] + ], + "definitions": {} } """) @@ -53,7 +54,7 @@ def __init__(self): class SplitToObjectOutput(insightconnect_plugin_runtime.Output): - schema = json.loads(""" + schema = json.loads(r""" { "type": "object", "title": "Variables", @@ -64,7 +65,8 @@ class SplitToObjectOutput(insightconnect_plugin_runtime.Output): "description": "Object from string split", "order": 1 } - } + }, + "definitions": {} } """) diff --git a/plugins/string/komand_string/actions/trim/__init__.py b/plugins/string/komand_string/actions/trim/__init__.py index 63d838134e..5d909232ad 100755 --- a/plugins/string/komand_string/actions/trim/__init__.py +++ b/plugins/string/komand_string/actions/trim/__init__.py @@ -1,2 +1,2 @@ -# GENERATED BY KOMAND SDK - DO NOT EDIT +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT from .action import Trim diff --git a/plugins/string/komand_string/actions/trim/action.py b/plugins/string/komand_string/actions/trim/action.py index 3292abcb18..9e7ebef3c1 100755 --- a/plugins/string/komand_string/actions/trim/action.py +++ b/plugins/string/komand_string/actions/trim/action.py @@ -12,5 +12,11 @@ def __init__(self): ) def run(self, params={}): - string = params.get(Input.STRING) - return {Output.TRIMMED: string.strip()} + # START INPUT BINDING - DO NOT REMOVE - ANY INPUTS BELOW WILL UPDATE WITH YOUR PLUGIN SPEC AFTER REGENERATION + input_string = params.get(Input.STRING) + # END INPUT BINDING - DO NOT REMOVE + + try: + return {Output.TRIMMED: input_string.strip()} + except Exception as error: + raise PluginException(preset=PluginException.Preset.UNKNOWN, data=error) diff --git a/plugins/string/komand_string/actions/trim/schema.py b/plugins/string/komand_string/actions/trim/schema.py index 497a7af7b3..c3884cd8ff 100755 --- a/plugins/string/komand_string/actions/trim/schema.py +++ b/plugins/string/komand_string/actions/trim/schema.py @@ -1,4 +1,4 @@ -# GENERATED BY KOMAND SDK - DO NOT EDIT +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT import insightconnect_plugin_runtime import json @@ -9,14 +9,14 @@ class Component: class Input: STRING = "string" - + class Output: TRIMMED = "trimmed" - + class TrimInput(insightconnect_plugin_runtime.Input): - schema = json.loads(""" + schema = json.loads(r""" { "type": "object", "title": "Variables", @@ -30,7 +30,8 @@ class TrimInput(insightconnect_plugin_runtime.Input): }, "required": [ "string" - ] + ], + "definitions": {} } """) @@ -39,7 +40,7 @@ def __init__(self): class TrimOutput(insightconnect_plugin_runtime.Output): - schema = json.loads(""" + schema = json.loads(r""" { "type": "object", "title": "Variables", @@ -53,7 +54,8 @@ class TrimOutput(insightconnect_plugin_runtime.Output): }, "required": [ "trimmed" - ] + ], + "definitions": {} } """) diff --git a/plugins/string/komand_string/actions/upper/__init__.py b/plugins/string/komand_string/actions/upper/__init__.py index bbb51831ef..d67e38f954 100755 --- a/plugins/string/komand_string/actions/upper/__init__.py +++ b/plugins/string/komand_string/actions/upper/__init__.py @@ -1,2 +1,2 @@ -# GENERATED BY KOMAND SDK - DO NOT EDIT +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT from .action import Upper diff --git a/plugins/string/komand_string/actions/upper/action.py b/plugins/string/komand_string/actions/upper/action.py index 55ed2c910a..b9662a278c 100755 --- a/plugins/string/komand_string/actions/upper/action.py +++ b/plugins/string/komand_string/actions/upper/action.py @@ -1,5 +1,5 @@ import insightconnect_plugin_runtime -from .schema import UpperInput, UpperOutput +from .schema import UpperInput, UpperOutput, Input, Output # Custom imports below from insightconnect_plugin_runtime.exceptions import PluginException @@ -15,10 +15,17 @@ def __init__(self): ) def run(self, params={}): - string = params.get("string") - if not string: + # START INPUT BINDING - DO NOT REMOVE - ANY INPUTS BELOW WILL UPDATE WITH YOUR PLUGIN SPEC AFTER REGENERATION + input_string = params.get(Input.STRING) + # END INPUT BINDING - DO NOT REMOVE + + if not input_string: raise PluginException( cause="Action failed! Missing required user input.", assistance="Please provide the input string.", ) - return {"upper": string.upper()} + + try: + return {Output.UPPER: input_string.upper()} + except Exception as error: + raise PluginException(preset=PluginException.Preset.UNKNOWN, data=error) diff --git a/plugins/string/komand_string/actions/upper/schema.py b/plugins/string/komand_string/actions/upper/schema.py index 112506d188..8abe6c98ad 100755 --- a/plugins/string/komand_string/actions/upper/schema.py +++ b/plugins/string/komand_string/actions/upper/schema.py @@ -1,4 +1,4 @@ -# GENERATED BY KOMAND SDK - DO NOT EDIT +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT import insightconnect_plugin_runtime import json @@ -9,14 +9,14 @@ class Component: class Input: STRING = "string" - + class Output: UPPER = "upper" - + class UpperInput(insightconnect_plugin_runtime.Input): - schema = json.loads(""" + schema = json.loads(r""" { "type": "object", "title": "Variables", @@ -30,7 +30,8 @@ class UpperInput(insightconnect_plugin_runtime.Input): }, "required": [ "string" - ] + ], + "definitions": {} } """) @@ -39,7 +40,7 @@ def __init__(self): class UpperOutput(insightconnect_plugin_runtime.Output): - schema = json.loads(""" + schema = json.loads(r""" { "type": "object", "title": "Variables", @@ -50,7 +51,8 @@ class UpperOutput(insightconnect_plugin_runtime.Output): "description": "Uppercase string", "order": 1 } - } + }, + "definitions": {} } """) diff --git a/plugins/string/komand_string/connection/__init__.py b/plugins/string/komand_string/connection/__init__.py index a515dcf6b0..c78d3356be 100755 --- a/plugins/string/komand_string/connection/__init__.py +++ b/plugins/string/komand_string/connection/__init__.py @@ -1,2 +1,2 @@ -# GENERATED BY KOMAND SDK - DO NOT EDIT +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT from .connection import Connection diff --git a/plugins/string/komand_string/connection/schema.py b/plugins/string/komand_string/connection/schema.py index b93c5a7c44..10cc2e684f 100755 --- a/plugins/string/komand_string/connection/schema.py +++ b/plugins/string/komand_string/connection/schema.py @@ -1,4 +1,4 @@ -# GENERATED BY KOMAND SDK - DO NOT EDIT +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT import insightconnect_plugin_runtime import json @@ -6,8 +6,9 @@ class Input: pass + class ConnectionSchema(insightconnect_plugin_runtime.Input): - schema = json.loads(""" + schema = json.loads(r""" {} """) diff --git a/plugins/string/komand_string/tasks/__init__.py b/plugins/string/komand_string/tasks/__init__.py new file mode 100644 index 0000000000..7020c9a4ad --- /dev/null +++ b/plugins/string/komand_string/tasks/__init__.py @@ -0,0 +1,2 @@ +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT + diff --git a/plugins/string/komand_string/triggers/__init__.py b/plugins/string/komand_string/triggers/__init__.py index bace8db897..7020c9a4ad 100755 --- a/plugins/string/komand_string/triggers/__init__.py +++ b/plugins/string/komand_string/triggers/__init__.py @@ -1 +1,2 @@ -# GENERATED BY KOMAND SDK - DO NOT EDIT +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT + diff --git a/plugins/string/plugin.spec.yaml b/plugins/string/plugin.spec.yaml index cb542b94e1..1961ae7140 100644 --- a/plugins/string/plugin.spec.yaml +++ b/plugins/string/plugin.spec.yaml @@ -4,22 +4,49 @@ products: [insightconnect] name: string title: String Operations description: The String plugin provides common programmatic string operations -version: 1.4.0 +version: 1.4.1 +connection_version: 1 vendor: rapid7 support: community status: [] +supported_versions: ["2024-09-06"] cloud_ready: true +fedramp_ready: true resources: source_url: https://github.com/rapid7/insightconnect-plugins/tree/master/plugins/string license_url: https://github.com/rapid7/insightconnect-plugins/blob/master/LICENSE tags: -- utilities -- string -- split + - utilities + - string + - split hub_tags: use_cases: [data_utility] keywords: [string, cloud_enabled] features: [] +sdk: + type: slim + version: 6.1.0 + user: nobody +key_features: + - "Split a string to a list of elements" + - "Split a string to an object" + - "Upper case, lower case, and trim a string" + - "Replace parts of a string" +version_history: + - "1.4.1 - Initial updates for fedramp compliance | Updated SDK to the latest version" + - "1.4.0 - New action Replace" + - "1.3.1 - Update to v4 Python plugin runtime" + - "1.3.0 - New action Length | Add example inputs" + - "1.2.1 - New spec and help.md format for the Extension Library" + - "1.2.0 - New action Trim" + - "1.1.0 - New action Set Encoding" + - "1.0.1 - Update plugin tag from `util` to `utilities` for Marketplace searchability" + - "1.0.0 - Initial plugin" +troubleshooting: "There may be complex string manipulation needs that are likely outside the scope of this plugin. If this is the case, consider using the Python 3 Script plugin instead." +links: + - "[Python 3 String Methods](https://docs.python.org/3/library/stdtypes.html#string-methods)" +references: + - "[Python 3 String Methods](https://docs.python.org/3/library/stdtypes.html#string-methods)" actions: set_encoding: title: Set Encoding @@ -35,17 +62,17 @@ actions: type: string description: Encoding to use enum: - - "UTF-8" - - "ASCII" + - "UTF-8" + - "ASCII" required: true example: ASCII error_handling: type: string description: Error handler to use for encoding and decoding enum: - - "strict" - - "replace" - - "ignore" + - "strict" + - "replace" + - "ignore" required: true example: ignore output: @@ -54,6 +81,7 @@ actions: title: Encoded String description: Encoded string required: true + example: hello split_to_list: title: Split String to List description: Converts a string to a list of strings @@ -77,6 +105,7 @@ actions: title: List description: List of string components required: false + example: '["This", "is", "a", "sentence"]' split_to_object: title: Split String to Object description: Converts a string to an object containing key:value strings @@ -108,6 +137,7 @@ actions: title: Object description: Object from string split required: false + example: '{"User":"Bob"}' upper: title: Upper description: Converts lowercase letters to uppercase @@ -124,6 +154,7 @@ actions: title: Uppercase description: Uppercase string required: false + example: UPPERCASE THIS STRING lower: title: Lower description: Converts uppercase letters to lowercase @@ -140,6 +171,7 @@ actions: title: Lowercase description: Lowercase string required: false + example: lowercase this string trim: title: Trim description: Trim a string of leading and trailing whitespace @@ -156,6 +188,7 @@ actions: title: Trimmed description: Trimmed string required: true + example: Extra spaces at the end of this string length: title: Length description: Return the length of a string @@ -172,6 +205,7 @@ actions: title: Length description: Length of string required: true + example: 46 replace: title: Replace description: Replace parts of a string @@ -200,3 +234,4 @@ actions: description: The string after replacement type: string required: true + example: this is a replacement diff --git a/plugins/string/requirements.txt b/plugins/string/requirements.txt index d0674c75e2..d2f13c4d7e 100755 --- a/plugins/string/requirements.txt +++ b/plugins/string/requirements.txt @@ -1,3 +1,4 @@ # List third-party dependencies here, separated by newlines. # All dependencies must be version-pinned, eg. requests==1.2.0 -# See: https://pip.pypa.io/en/stable/user_guide/#requirements-files \ No newline at end of file +# See: https://pip.pypa.io/en/stable/user_guide/#requirements-files +parameterized==0.8.1 diff --git a/plugins/string/setup.py b/plugins/string/setup.py index 5ed8b75c94..b38c31c243 100755 --- a/plugins/string/setup.py +++ b/plugins/string/setup.py @@ -1,9 +1,9 @@ -# GENERATED BY KOMAND SDK - DO NOT EDIT +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT from setuptools import setup, find_packages setup(name="string-rapid7-plugin", - version="1.4.0", + version="1.4.1", description="The String plugin provides common programmatic string operations", author="rapid7", author_email="", diff --git a/plugins/string/unit_test/__init__.py b/plugins/string/unit_test/__init__.py index e69de29bb2..d9ae09fc16 100644 --- a/plugins/string/unit_test/__init__.py +++ b/plugins/string/unit_test/__init__.py @@ -0,0 +1,4 @@ +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT +import sys + +sys.path.append("../") \ No newline at end of file diff --git a/plugins/string/unit_test/test_length.py b/plugins/string/unit_test/test_length.py new file mode 100644 index 0000000000..1c0197b47a --- /dev/null +++ b/plugins/string/unit_test/test_length.py @@ -0,0 +1,40 @@ +import os +import sys + +from insightconnect_plugin_runtime.exceptions import PluginException + +sys.path.append(os.path.abspath("../")) + +from typing import Any, Dict +from unittest import TestCase + +from jsonschema import validate +from komand_string.actions.length import Length +from komand_string.actions.length.schema import Input, Output +from parameterized import parameterized + + +class TestLength(TestCase): + def setUp(self) -> None: + self.action = Length() + + @parameterized.expand([({Input.STRING: ""}, {Output.LENGTH: 0}), ({Input.STRING: "MyTest"}, {Output.LENGTH: 6})]) + def test_length(self, input_data: Dict[str, Any], expected: Dict[str, Any]) -> None: + response = self.action.run(input_data) + validate(response, self.action.output.schema) + self.assertEqual(response, expected) + + @parameterized.expand( + [ + ( + {Input.STRING: 2}, + PluginException.causes[PluginException.Preset.UNKNOWN], + PluginException.assistances[PluginException.Preset.UNKNOWN], + ) + ] + ) + def test_length_error(self, input_data: Dict[str, Any], cause: str, assistance: str) -> None: + with self.assertRaises(PluginException) as context: + self.action.run(input_data) + self.assertEqual(context.exception.cause, cause) + self.assertEqual(context.exception.assistance, assistance) diff --git a/plugins/string/unit_test/test_lower.py b/plugins/string/unit_test/test_lower.py new file mode 100644 index 0000000000..ba6d9af912 --- /dev/null +++ b/plugins/string/unit_test/test_lower.py @@ -0,0 +1,42 @@ +import os +import sys + +sys.path.append(os.path.abspath("../")) + +from typing import Any, Dict +from unittest import TestCase + +from insightconnect_plugin_runtime.exceptions import PluginException +from jsonschema import validate +from komand_string.actions.lower import Lower +from komand_string.actions.lower.schema import Input, Output +from parameterized import parameterized + + +class TestLower(TestCase): + def setUp(self) -> None: + self.action = Lower() + + @parameterized.expand( + [({Input.STRING: "MyTest"}, {Output.LOWER: "mytest"}), ({Input.STRING: "test"}, {Output.LOWER: "test"})] + ) + def test_lower(self, input_data: Dict[str, Any], expected: Dict[str, Any]) -> None: + response = self.action.run(input_data) + validate(response, self.action.output.schema) + self.assertEqual(response, expected) + + @parameterized.expand( + [ + ( + {Input.STRING: 2}, + PluginException.causes[PluginException.Preset.UNKNOWN], + PluginException.assistances[PluginException.Preset.UNKNOWN], + ), + ({Input.STRING: ""}, "Action failed! Missing required user input.", "Please provide the input string."), + ] + ) + def test_lower_error(self, input_data: Dict[str, Any], cause: str, assistance: str) -> None: + with self.assertRaises(PluginException) as context: + self.action.run(input_data) + self.assertEqual(context.exception.cause, cause) + self.assertEqual(context.exception.assistance, assistance) diff --git a/plugins/string/unit_test/test_replace.py b/plugins/string/unit_test/test_replace.py index 0a5a575b19..cc1ef82bf4 100644 --- a/plugins/string/unit_test/test_replace.py +++ b/plugins/string/unit_test/test_replace.py @@ -1,6 +1,12 @@ +import os +import sys + +sys.path.append(os.path.abspath("../")) + +import logging from unittest import TestCase + from komand_string.actions.replace import Replace -import logging class TestReplace(TestCase): diff --git a/plugins/string/unit_test/test_set_encoding.py b/plugins/string/unit_test/test_set_encoding.py new file mode 100644 index 0000000000..3447a453fc --- /dev/null +++ b/plugins/string/unit_test/test_set_encoding.py @@ -0,0 +1,51 @@ +import os +import sys + +sys.path.append(os.path.abspath("../")) + +from typing import Any, Dict +from unittest import TestCase + +from insightconnect_plugin_runtime.exceptions import PluginException +from jsonschema import validate +from komand_string.actions.set_encoding import SetEncoding +from komand_string.actions.set_encoding.schema import Input, Output +from parameterized import parameterized + + +class TestSetEncoding(TestCase): + def setUp(self) -> None: + self.action = SetEncoding() + + @parameterized.expand( + [ + ( + {Input.STRING: "MyTest", Input.ENCODING: "UTF-8", Input.ERROR_HANDLING: "ignore"}, + {Output.ENCODED: "MyTest"}, + ) + ] + ) + def test_set_encoding(self, input_data: Dict[str, Any], expected: Dict[str, Any]) -> None: + response = self.action.run(input_data) + validate(response, self.action.output.schema) + self.assertEqual(response, expected) + + @parameterized.expand( + [ + ( + {Input.STRING: 2, Input.ENCODING: "UTF-8", Input.ERROR_HANDLING: "ignore"}, + "Encoding failed.", + "Could not encode given string.", + ), + ( + {Input.STRING: ["test"], Input.ENCODING: "UTF-8", Input.ERROR_HANDLING: "ignore"}, + "Encoding failed.", + "Could not encode given string.", + ), + ] + ) + def test_set_encoding_error(self, input_data: Dict[str, Any], cause: str, assistance: str) -> None: + with self.assertRaises(PluginException) as context: + self.action.run(input_data) + self.assertEqual(context.exception.cause, cause) + self.assertEqual(context.exception.assistance, assistance) diff --git a/plugins/string/unit_test/test_split_to_list.py b/plugins/string/unit_test/test_split_to_list.py new file mode 100644 index 0000000000..4f771fe255 --- /dev/null +++ b/plugins/string/unit_test/test_split_to_list.py @@ -0,0 +1,56 @@ +import os +import sys + +sys.path.append(os.path.abspath("../")) + +from typing import Any, Dict +from unittest import TestCase + +from insightconnect_plugin_runtime.exceptions import PluginException +from jsonschema import validate +from komand_string.actions.split_to_list import SplitToList +from komand_string.actions.split_to_list.schema import Input, Output +from parameterized import parameterized + + +class TestSplitToList(TestCase): + def setUp(self) -> None: + self.action = SplitToList() + + @parameterized.expand( + [ + ( + {Input.STRING: "MyTest Example", Input.DELIMITER: " "}, + {Output.LIST: ["MyTest", "Example"]}, + ) + ] + ) + def test_split_to_list(self, input_data: Dict[str, Any], expected: Dict[str, Any]) -> None: + response = self.action.run(input_data) + validate(response, self.action.output.schema) + self.assertEqual(response, expected) + + @parameterized.expand( + [ + ( + {Input.STRING: 2}, + PluginException.causes[PluginException.Preset.UNKNOWN], + PluginException.assistances[PluginException.Preset.UNKNOWN], + ), + ( + {Input.STRING: ["test"]}, + PluginException.causes[PluginException.Preset.UNKNOWN], + PluginException.assistances[PluginException.Preset.UNKNOWN], + ), + ( + {Input.STRING: "", Input.DELIMITER: ""}, + "Action failed! Missing required user input.", + "Please provide the input string.", + ), + ] + ) + def test_split_to_list_error(self, input_data: Dict[str, Any], cause: str, assistance: str) -> None: + with self.assertRaises(PluginException) as context: + self.action.run(input_data) + self.assertEqual(context.exception.cause, cause) + self.assertEqual(context.exception.assistance, assistance) diff --git a/plugins/string/unit_test/test_split_to_object.py b/plugins/string/unit_test/test_split_to_object.py new file mode 100644 index 0000000000..6d24ea12c9 --- /dev/null +++ b/plugins/string/unit_test/test_split_to_object.py @@ -0,0 +1,62 @@ +import os +import sys + +sys.path.append(os.path.abspath("../")) + + +from typing import Any, Dict +from unittest import TestCase + +from insightconnect_plugin_runtime.exceptions import PluginException +from jsonschema import validate +from komand_string.actions.split_to_object import SplitToObject +from komand_string.actions.split_to_object.schema import Input, Output +from parameterized import parameterized + + +class TestSplitToObject(TestCase): + def setUp(self) -> None: + self.action = SplitToObject() + + @parameterized.expand( + [ + ( + {Input.STRING: "MyTest Example", Input.STRING_DELIMITER: " ", Input.BLOCK_DELIMITER: ""}, + {Output.OBJECT: {"MyTest": "Example"}}, + ) + ] + ) + def test_split_to_object(self, input_data: Dict[str, Any], expected: Dict[str, Any]) -> None: + response = self.action.run(input_data) + validate(response, self.action.output.schema) + self.assertEqual(response, expected) + + @parameterized.expand( + [ + ( + {Input.STRING: 2}, + "Action failed! Unable to split string cleanly.", + "Please try specifying the block delimiter for more multi-key:value input.", + ), + ( + {Input.STRING: ["test"], Input.STRING_DELIMITER: ""}, + "Action failed! Unable to split string cleanly.", + "Please try specifying the block delimiter for more multi-key:value input.", + ), + ( + {Input.STRING: ["test"], Input.STRING_DELIMITER: "", Input.BLOCK_DELIMITER: "["}, + "Action failed! Unable to split string cleanly.", + "Please try specifying the block delimiter for more multi-key:value input.", + ), + ( + {Input.STRING: "", Input.STRING_DELIMITER: ""}, + "Action failed! Missing required user input.", + "Please provide the input string.", + ), + ] + ) + def test_split_to_object_error(self, input_data: Dict[str, Any], cause: str, assistance: str) -> None: + with self.assertRaises(PluginException) as context: + self.action.run(input_data) + self.assertEqual(context.exception.cause, cause) + self.assertEqual(context.exception.assistance, assistance) diff --git a/plugins/string/unit_test/test_trim.py b/plugins/string/unit_test/test_trim.py index f92ea1792d..a0e5458db8 100644 --- a/plugins/string/unit_test/test_trim.py +++ b/plugins/string/unit_test/test_trim.py @@ -1,4 +1,5 @@ from unittest import TestCase + from komand_string.actions.trim import Trim diff --git a/plugins/string/unit_test/test_upper.py b/plugins/string/unit_test/test_upper.py new file mode 100644 index 0000000000..ad8150a834 --- /dev/null +++ b/plugins/string/unit_test/test_upper.py @@ -0,0 +1,43 @@ +import os +import sys + +sys.path.append(os.path.abspath("../")) + + +from typing import Any, Dict +from unittest import TestCase + +from insightconnect_plugin_runtime.exceptions import PluginException +from jsonschema import validate +from komand_string.actions.upper import Upper +from komand_string.actions.upper.schema import Input, Output +from parameterized import parameterized + + +class TestUpper(TestCase): + def setUp(self) -> None: + self.action = Upper() + + @parameterized.expand( + [({Input.STRING: "MyTest"}, {Output.UPPER: "MYTEST"}), ({Input.STRING: "TEST"}, {Output.UPPER: "TEST"})] + ) + def test_upper(self, input_data: Dict[str, Any], expected: Dict[str, Any]) -> None: + response = self.action.run(input_data) + validate(response, self.action.output.schema) + self.assertEqual(response, expected) + + @parameterized.expand( + [ + ( + {Input.STRING: 2}, + PluginException.causes[PluginException.Preset.UNKNOWN], + PluginException.assistances[PluginException.Preset.UNKNOWN], + ), + ({Input.STRING: ""}, "Action failed! Missing required user input.", "Please provide the input string."), + ] + ) + def test_upper_error(self, input_data: Dict[str, Any], cause: str, assistance: str) -> None: + with self.assertRaises(PluginException) as context: + self.action.run(input_data) + self.assertEqual(context.exception.cause, cause) + self.assertEqual(context.exception.assistance, assistance)