diff --git a/plugins/redis/.CHECKSUM b/plugins/redis/.CHECKSUM index 9b438440c2..bfc99cdc7b 100644 --- a/plugins/redis/.CHECKSUM +++ b/plugins/redis/.CHECKSUM @@ -1,55 +1,55 @@ { - "spec": "d0b30bfb265d667698015fcfe69b3cae", - "manifest": "bbc79cf009aa939c5b68b8451bc78cff", - "setup": "ff76a01958969fcc28eee17ba2c723c4", + "spec": "d87af4a73af23e65eb280f06b17501b0", + "manifest": "bcbee882883b3bbc53d23c28bd6b860d", + "setup": "c8ba0398d017459776ab5d8547c2cec8", "schemas": [ { "identifier": "delete/schema.py", - "hash": "cc53755684e4fafc9ed1fe174c785ffb" + "hash": "386fe4ffdd554d1fb0a496a236ccda92" }, { "identifier": "get/schema.py", - "hash": "5f1665805e95c97039a3b5fad822d780" + "hash": "2418731519a2321c938a28e583e704af" }, { "identifier": "hash_get/schema.py", - "hash": "b5f4fdbc34ae38777e2845e3dc8fc64f" + "hash": "bdc6637e32a37012a11202971b603724" }, { "identifier": "hash_set/schema.py", - "hash": "e1a4b84e6de13a1ac9ddd9ed796a49d7" + "hash": "18f12299445dfd8f3f44112c740cfcfb" }, { "identifier": "hincrby/schema.py", - "hash": "5a4bc414be3bc4a85e498e8448ddf4c0" + "hash": "850449363335a16515b2688d9175ae44" }, { "identifier": "hmget/schema.py", - "hash": "b04fd826b25f37609b74b0dfdb26eb26" + "hash": "cfd9e10b14abf01aee7ba9b51decc806" }, { "identifier": "hmset/schema.py", - "hash": "7b6f4e269aaa39359d5d6e8250068cef" + "hash": "5a6329f4e908f56dda0945dd5d5f5b86" }, { "identifier": "keys/schema.py", - "hash": "926ec56a7a223dd425ed8ebdea29277f" + "hash": "8d7d2d83a6ca32146513410db60a2ffe" }, { "identifier": "list_get/schema.py", - "hash": "c8e12e4c4a39041a9314ec2983debf55" + "hash": "9f58960109892b890a5a13901f5a37ea" }, { "identifier": "list_push/schema.py", - "hash": "18d8d51e7b8587da3378a9d46c5a6340" + "hash": "0bec3c41dc71e64bafdc6b08b8cfa478" }, { "identifier": "set/schema.py", - "hash": "0ff0feb90ffa83aeba47a5dfb263b77c" + "hash": "f66301278673270476bc92beb2e90fe3" }, { "identifier": "connection/schema.py", - "hash": "979eba6adfe726ecd022022e917e5d6d" + "hash": "9eaaa3df08bbb42bb41cddb928260b07" } ] } \ No newline at end of file diff --git a/plugins/redis/Dockerfile b/plugins/redis/Dockerfile index b1364c7862..62e01d4b61 100644 --- a/plugins/redis/Dockerfile +++ b/plugins/redis/Dockerfile @@ -1,25 +1,20 @@ -FROM komand/python-3-plugin:2 -# The three supported python parent images are: -# - komand/python-2-plugin -# - komand/python-3-plugin -# - komand/python-pypy3-plugin -# -# Update the tag to a full semver version +FROM --platform=linux/amd64 rapid7/insightconnect-python-3-slim-plugin:6.2.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_redis"] diff --git a/plugins/redis/bin/komand_redis b/plugins/redis/bin/komand_redis index 6f50db2719..8ea52d5522 100755 --- a/plugins/redis/bin/komand_redis +++ b/plugins/redis/bin/komand_redis @@ -1,50 +1,64 @@ #!/usr/bin/env python -# GENERATED BY KOMAND SDK - DO NOT EDIT -import komand -from komand_redis import connection, actions, triggers +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT +import os +import json +from sys import argv +Name = "Redis" +Vendor = "rapid7" +Version = "1.0.2" +Description = "Redis is an in-memory data structure project implementing a distributed, in-memory key-value database with optional durability. Redis supports different kinds of abstract data structures, such as strings, lists, maps, sets, sorted sets, HyperLogLogs, bitmaps, streams, and spatial indexes.\nThis package allows you to interact with the [Redis](https://redis.io/) database API" -Name = 'Redis' -Vendor = 'rapid7' -Version = '1.0.1' -Description = 'The Redis plugin allows you to add, update, and manage data in a Redis database' - -class ICONRedis(komand.Plugin): - def __init__(self): - super(self.__class__, self).__init__( +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 komand_redis import connection, actions, triggers, tasks + + class ICONRedis(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.Delete()) - - self.add_action(actions.Get()) - - self.add_action(actions.HashGet()) - - self.add_action(actions.HashSet()) - - self.add_action(actions.Hincrby()) - - self.add_action(actions.Hmget()) + ) + self.add_action(actions.Delete()) + + self.add_action(actions.Set()) + + self.add_action(actions.Get()) + + self.add_action(actions.Keys()) + + self.add_action(actions.HashSet()) + + self.add_action(actions.HashGet()) + + self.add_action(actions.ListPush()) + + self.add_action(actions.ListGet()) + + self.add_action(actions.Hmset()) + + self.add_action(actions.Hmget()) + + self.add_action(actions.Hincrby()) + - self.add_action(actions.Hmset()) - - self.add_action(actions.Keys()) - - self.add_action(actions.ListGet()) - - self.add_action(actions.ListPush()) - - self.add_action(actions.Set()) - - -def main(): """Run plugin""" - cli = komand.CLI(ICONRedis()) + cli = insightconnect_plugin_runtime.CLI(ICONRedis()) cli.run() diff --git a/plugins/redis/help.md b/plugins/redis/help.md index 33a7b4682f..65ce557191 100644 --- a/plugins/redis/help.md +++ b/plugins/redis/help.md @@ -1,399 +1,491 @@ # Description -Redis is an in-memory data structure project implementing a distributed, in-memory key-value database with optional durability. Redis supports different kinds of abstract data structures, such as strings, lists, maps, sets, sorted sets, HyperLogLogs, bitmaps, streams, and spatial indexes. - -This package allows you to interact with the [Redis](https://redis.io/) database API. +Redis is an in-memory data structure project implementing a distributed, in-memory key-value database with optional durability. Redis supports different kinds of abstract data structures, such as strings, lists, maps, sets, sorted sets, HyperLogLogs, bitmaps, streams, and spatial indexes.\nThis package allows you to interact with the [Redis](https://redis.io/) database API # Key Features -* Set and retrieve data from Redis. +* Set and retrieve data from Redis # Requirements * Connection information for your Redis database +# Supported Product Versions + +* 2024-11-8 + # Documentation ## Setup -The connection configuration accepts the following parameters: +The connection configuration accepts the following parameters: -|Name|Type|Default|Required|Description|Enum| -|----|----|-------|--------|-----------|----| -|host|string|None|True|Host, e.g. 10.4.4.4|None| -|db|integer|0|True|Db to use usually (0-15)|None| -|port|integer|6379|True|Port|None| +|Name|Type|Default|Required|Description|Enum|Example|Placeholder|Tooltip| +| :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | +|db|integer|0|True|DB to use usually (0-15)|None|10|None|None| +|host|string|None|True|Host, e.g. 10.4.4.4|None|10.4.4.4|None|None| +|port|integer|6379|True|Port|None|6379|None|None| -## Technical Details +Example input: -### Actions +``` +{ + "db": 0, + "host": "10.4.4.4", + "port": 6379 +} +``` -#### Set +## Technical Details -This action is used to set a key to a string value. -There is an optional expiration timeout which will auto remove the key when `expire` seconds have passed. +### Actions -##### Input -|Name|Type|Default|Required|Description|Enum| -|----|----|-------|--------|-----------|----| -|expire|integer|None|False|Expiration in seconds|None| -|key|string|None|True|Key to set|None| -|value|string|None|True|Value to set|None| +#### Delete -##### Output +This action is used to delete a key -|Name|Type|Required|Description| -|----|----|--------|-----------| -|reply|string|False|Reply (usually OK)| +##### Input -Example output: +|Name|Type|Default|Required|Description|Enum|Example|Placeholder|Tooltip| +| :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | +|key|string|None|True|Key to delete|None|example:1234:session|None|None| + +Example input: ``` - { - "reply": "OK" + "key": "example:1234:session" } - ``` -#### List Get - -This action is used to get all elements in a list. - -##### Input - -|Name|Type|Default|Required|Description|Enum| -|----|----|-------|--------|-----------|----| -|count|integer|1000|False|Max results to return|None| -|key|string|None|True|Key to get|None| - ##### Output -|Name|Type|Required|Description| -|----|----|--------|-----------| -|found|boolean|False|True if found| -|values|[]string|False|Values| - +|Name|Type|Required|Description|Example| +| :--- | :--- | :--- | :--- | :--- | +|count|integer|False|Number of keys deleted|1| + Example output: ``` - { - "found": false, - "values": [] + "count": 1 } - ``` #### Get - + This action is used to get a key. Get will return a value at `key` if found, otherwise found will be false ##### Input -|Name|Type|Default|Required|Description|Enum| -|----|----|-------|--------|-----------|----| -|key|string|None|True|Key to get|None| +|Name|Type|Default|Required|Description|Enum|Example|Placeholder|Tooltip| +| :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | +|key|string|None|True|Key to get|None|example:1234:active|None|None| + +Example input: -##### Output +``` +{ + "key": "example:1234:active" +} +``` -|Name|Type|Required|Description| -|----|----|--------|-----------| -|found|boolean|False|True if found| -|value|string|False|Value| +##### Output +|Name|Type|Required|Description|Example| +| :--- | :--- | :--- | :--- | :--- | +|found|boolean|False|True if found|True| +|value|string|False|Value|True| + Example output: ``` - { - "value": "", - "found": false + "found": true, + "value": true } - ``` -#### Keys +#### Hash Get -This action is used to return all keys matching a pattern. +This action is used to return all hash values at `key`. If no hash values are found `false` is returned. ##### Input -|Name|Type|Default|Required|Description|Enum| -|----|----|-------|--------|-----------|----| -|pattern|string|None|True|Pattern, e.g. *o*|None| +|Name|Type|Default|Required|Description|Enum|Example|Placeholder|Tooltip| +| :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | +|key|string|None|True|Key to get|None|user:profile|None|None| + +Example input: -##### Output +``` +{ + "key": "user:profile" +} +``` -|Name|Type|Required|Description| -|----|----|--------|-----------| -|count|integer|False|Count of keys found| -|keys|[]string|False|Keys returned| +##### Output +|Name|Type|Required|Description|Example| +| :--- | :--- | :--- | :--- | :--- | +|found|boolean|False|True if found|True| +|values|object|False|Values|{'name': 'Example Name', 'email': 'Example.email@example.com', 'age': '30'}| + Example output: ``` - { - "count": 27, - "keys": [ - "hashfoo", - "LogonToAssetFilter:1f78ace5-bdef-4512-abed-4c96548dc043:207f28a4-8787-445b-af29-5e467f77c503", - "LogonToAssetFilter:821dfdb4-22c2-46fe-b693-752d00802f9d:e9a804f6-1b84-44e9-8e56-e81d06082c57", - "LogonToAssetFilter:821dfdb4-22c2-46fe-b693-752d00802f9d:316ea7f6-2d1b-44d8-97f9-290460f5b18b", - "LogonToAssetFilter:821dfdb4-22c2-46fe-b693-752d00802f9d:5c74f7fe-9dfd-440a-8b50-ba0acc49b264", - "LogonToAssetFilter:1f78ace5-bdef-4512-abed-4c96548dc043:3e49f67a-1fbf-4207-84d8-2a88f1032239", - "CollectorHeartbeat:821dfdb4-22c2-46fe-b693-752d00802f9d:4fa0c9df-c61a-4d99-935e-633ff7c65112", - "CollectorHeartbeat:a4cabb19-cac1-4e1d-975a-e012d3b68bc8:aa485f7e-854e-4c43-b41c-035baf16b0a7", - "LogonToAssetFilter:1f78ace5-bdef-4512-abed-4c96548dc043:98705784-1c5e-4dc5-af96-838f59ee369b", - "LogonToAssetFilter:1f78ace5-bdef-4512-abed-4c96548dc043:46273cef-0300-4ac6-b9f7-0ccc21d220d4", - "LogonToAssetFilter:1f78ace5-bdef-4512-abed-4c96548dc043:b22dd672-e901-4738-a1dd-7428fbe06749", - "spring:session:index:org.springframework.session.FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME:dev", - "LogonToAssetFilter:1f78ace5-bdef-4512-abed-4c96548dc043:538151a3-5588-49e3-9199-0e06f410dac1", - "LogonToAssetFilter:1f78ace5-bdef-4512-abed-4c96548dc043:d0d31086-4891-4da8-a649-900c672a2c07", - "LogonToAssetFilter:821dfdb4-22c2-46fe-b693-752d00802f9d:1d7677e6-f4a7-48d6-bb31-7cfc0fcc6089", - "LogonToAssetFilter:1f78ace5-bdef-4512-abed-4c96548dc043:9002df97-dabe-4024-9017-2452f3cc56f1", - "CollectorHeartbeat:821dfdb4-22c2-46fe-b693-752d00802f9d:a652b834-fa52-438a-885a-609d84bc44cd", - "LogonToAssetFilter:1f78ace5-bdef-4512-abed-4c96548dc043:c4be1a2a-b5e2-4f52-9b82-815fd26ca32d", - "LogonToAssetFilter:1f78ace5-bdef-4512-abed-4c96548dc043:54eb9391-9524-487b-8352-94e8627bf5a3", - "CollectorHeartbeat:1f78ace5-bdef-4512-abed-4c96548dc043:c8198ec1-5afb-4561-bb0f-d1a308d94471", - "keylist", - "LogonToAssetFilter:821dfdb4-22c2-46fe-b693-752d00802f9d:3e8c29da-fa56-4643-9b1e-5c74f90c1ae6", - "LogonToAssetFilter:1f78ace5-bdef-4512-abed-4c96548dc043:4cafcba4-0614-48b5-9ba9-418c5a3bb95e", - "LogonToAssetFilter:1f78ace5-bdef-4512-abed-4c96548dc043:14038b45-f012-41fc-9c22-ee824e9700c4", - "CollectorHeartbeat:1f78ace5-bdef-4512-abed-4c96548dc043:52253bef-7a4c-4f09-9d3b-f188f1477f41", - "LogonToAssetFilter:821dfdb4-22c2-46fe-b693-752d00802f9d:77efac95-c6ff-437d-b1c4-e5d021ad2bd7", - "LogonToAssetFilter:821dfdb4-22c2-46fe-b693-752d00802f9d:acc4c70f-9440-4ba5-8610-4602935752af" - ] + "found": true, + "values": { + "age": "30", + "email": "Example.email@example.com", + "name": "Example Name" + } } - ``` #### Hash Set This action is used to set a given key to a key:value object. All values must be strings. -There is an optional expiration timeout which will auto remove the key when `expire` seconds have passed. +There is an optional expiration timeout which will auto remove the key when `expire` seconds have passed + ##### Input -|Name|Type|Default|Required|Description|Enum| -|----|----|-------|--------|-----------|----| -|expire|integer|None|False|Expiration in seconds|None| -|values|object|None|True|Object hash field:value to set|None| -|key|string|None|True|Key|None| +|Name|Type|Default|Required|Description|Enum|Example|Placeholder|Tooltip| +| :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | +|expire|integer|None|False|Expiration in seconds|None|100|None|None| +|key|string|None|True|Key|None|user:1234|None|None| +|values|object|None|True|Object hash field:value to set|None|{'name': 'John Doe', 'email': 'johndoe@example.com', 'age': '30'}|None|None| + +Example input: -##### Output +``` +{ + "expire": 100, + "key": "user:1234", + "values": { + "age": "30", + "email": "johndoe@example.com", + "name": "John Doe" + } +} +``` -|Name|Type|Required|Description| -|----|----|--------|-----------| -|reply|string|False|Reply (usually OK)| +##### Output +|Name|Type|Required|Description|Example| +| :--- | :--- | :--- | :--- | :--- | +|reply|string|False|Reply (usually OK)|OK| + Example output: ``` - { "reply": "OK" } - ``` -#### List Push +#### Hash Increment By -This action is used to list key's push. +This action is used to increments the number stored at field in the hash stored at key by increment. +If key does not exist, a new key holding a hash is created. If field does not exist the value is set to 0 before the operation is performed ##### Input -|Name|Type|Default|Required|Description|Enum| -|----|----|-------|--------|-----------|----| -|expire|integer|None|False|Expiration in seconds|None| -|key|string|None|True|Key|None| -|value|string|None|True|Value to append|None| +|Name|Type|Default|Required|Description|Enum|Example|Placeholder|Tooltip| +| :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | +|field|string|None|True|Field to increment|None|login_count|None|None| +|key|string|None|True|Key to lookup|None|user:profile:123|None|None| +|value|integer|0|True|How much to increment by|None|1|None|None| + +Example input: -##### Output +``` +{ + "field": "login_count", + "key": "user:profile:123", + "value": 0 +} +``` -|Name|Type|Required|Description| -|----|----|--------|-----------| -|reply|string|False|Reply (usually OK)| +##### Output +|Name|Type|Required|Description|Example| +| :--- | :--- | :--- | :--- | :--- | +|result|integer|False|Result returned after operation is ran|1| + Example output: ``` - { - "reply": "OK" + "result": 1 } - ``` -#### Hash Get +#### Hash Multi Get -This action is used to return all hash values at `key`. If no hash values are found `false` is returned. +This action is used to returns the values associated with the specified fields in the hash stored at key ##### Input -|Name|Type|Default|Required|Description|Enum| -|----|----|-------|--------|-----------|----| -|key|string|None|True|Key to get|None| +|Name|Type|Default|Required|Description|Enum|Example|Placeholder|Tooltip| +| :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | +|fields|[]string|None|False|Fields to retrieve values from|None|["name", "email"]|None|None| +|get_all|boolean|False|True|Get all values|None|False|None|None| +|key|string|None|True|Key to get|None|user:profile:123|None|None| + +Example input: -##### Output +``` +{ + "fields": [ + "name", + "email" + ], + "get_all": false, + "key": "user:profile:123" +} +``` -|Name|Type|Required|Description| -|----|----|--------|-----------| -|found|boolean|False|True if found| -|values|object|False|Values| +##### Output +|Name|Type|Required|Description|Example| +| :--- | :--- | :--- | :--- | :--- | +|values|object|False|Values returned from HMGET|{'name': 'Ryan Test', 'email': 'Ryan.test@example.com'}| + Example output: ``` - { - "values": {}, - "found": false + "values": { + "email": "Ryan.test@example.com", + "name": "Ryan Test" + } } - ``` -#### Delete +#### Hash Multi Set -This action is used to delete a key. +This action is used to sets the specified fields to their respective values in the hash stored at key. +This command overwrites any specified fields already existing in the hash. If key does not exist, a new key holding a hash is created ##### Input -|Name|Type|Default|Required|Description|Enum| -|----|----|-------|--------|-----------|----| -|key|string|None|True|Key to delete|None| +|Name|Type|Default|Required|Description|Enum|Example|Placeholder|Tooltip| +| :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | +|expire|integer|None|False|Expiration in seconds|None|100|None|None| +|key|string|None|True|Key|None|user:profile:123|None|None| +|values|object|None|True|Object hash field:value to set|None|{'name': 'Test Name', 'email': 'Test.Name@example.com', 'age': '30'}|None|None| + +Example input: -##### Output +``` +{ + "expire": 100, + "key": "user:profile:123", + "values": { + "age": "30", + "email": "Test.Name@example.com", + "name": "Test Name" + } +} +``` -|Name|Type|Required|Description| -|----|----|--------|-----------| -|count|integer|False|Number of keys deleted| +##### Output +|Name|Type|Required|Description|Example| +| :--- | :--- | :--- | :--- | :--- | +|reply|boolean|False|Reply (usually OK)|True| + Example output: ``` - { - "count": 1 + "reply": true } - ``` -#### Hash Increment By +#### Keys -This action is used to increments the number stored at field in the hash stored at key by increment. -If key does not exist, a new key holding a hash is created. If field does not exist the value is set to 0 before the operation is performed +This action is used to return keys matching pattern ##### Input -|Name|Type|Default|Required|Description|Enum| -|----|----|-------|--------|-----------|----| -|key|string|None|True|Key to lookup|None| -|field|string|None|True|Field to increment|None| -|value|integer|0|True|How much to increment by|None| +|Name|Type|Default|Required|Description|Enum|Example|Placeholder|Tooltip| +| :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | +|pattern|string|None|True|Pattern, e.g. *o*|None|example:*:session|None|None| + +Example input: -##### Output +``` +{ + "pattern": "example:*:session" +} +``` -|Name|Type|Required|Description| -|----|----|--------|-----------| -|result|integer|False|Result returned after operation is ran| +##### Output +|Name|Type|Required|Description|Example| +| :--- | :--- | :--- | :--- | :--- | +|count|integer|False|Count of keys found|1| +|keys|[]string|False|Keys returned|["example:1234:session", "example:5678:session", "example:abcd:session"]| + Example output: ``` - { - "result": 18 + "count": 1, + "keys": [ + "example:1234:session", + "example:5678:session", + "example:abcd:session" + ] } - ``` -#### Hash Multi Get +#### List Get -This action is used to returns the values associated with the specified fields in the hash stored at key. +This action is used to get all elements in a list ##### Input -|Name|Type|Default|Required|Description|Enum| -|----|----|-------|--------|-----------|----| -|key|string|None|True|Key to get|None| -|fields|[]string|None|False|Fields to retrieve values from|None| -|get_all|boolean|False|True|Get all values|None| +|Name|Type|Default|Required|Description|Enum|Example|Placeholder|Tooltip| +| :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | +|count|integer|1000|False|Max results to return|None|1000|None|None| +|key|string|None|True|Key to get|None|user:task_list:123|None|None| + +Example input: -##### Output +``` +{ + "count": 1000, + "key": "user:task_list:123" +} +``` -|Name|Type|Required|Description| -|----|----|--------|-----------| -|values|object|False|Values returned from HMGET| +##### Output +|Name|Type|Required|Description|Example| +| :--- | :--- | :--- | :--- | :--- | +|found|boolean|False|True if found|True| +|values|[]string|False|Values|["task1", "task2", "task3", "task4"]| + Example output: ``` - { - "values": { - "address": "192.168.0.1", - "type": "ipv4", - "subnet": "255.255.255.0" - } + "found": true, + "values": [ + "task1", + "task2", + "task3", + "task4" + ] } - ``` -#### Hash Multi Set +#### List Push -This action is used to sets the specified fields to their respective values in the hash stored at key. -This command overwrites any specified fields already existing in the hash. If key does not exist, a new key holding a hash is created +This action is used to list key's push ##### Input -|Name|Type|Default|Required|Description|Enum| -|----|----|-------|--------|-----------|----| -|key|string|None|True|Key|None| -|values|object|None|True|Object hash field:value to set|None| -|expire|integer|None|False|Expiration in seconds|None| +|Name|Type|Default|Required|Description|Enum|Example|Placeholder|Tooltip| +| :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | +|expire|integer|None|False|Expiration in seconds|None|100|None|None| +|key|string|None|True|Key|None|user:task_list:123|None|None| +|value|string|None|True|Value to append|None|Complete monthly report|None|None| + +Example input: -##### Output +``` +{ + "expire": 100, + "key": "user:task_list:123", + "value": "Complete monthly report" +} +``` -|Name|Type|Required|Description| -|----|----|--------|-----------| -|reply|boolean|False|Reply (usually OK)| +##### Output +|Name|Type|Required|Description|Example| +| :--- | :--- | :--- | :--- | :--- | +|reply|string|False|Reply (usually OK)|OK| + Example output: ``` - { - "reply": true + "reply": "OK" } +``` + +#### Set + +This action is used to set a key to a string value. +There is an optional expiration timeout which will auto remove the key when `expire` seconds have passed + +##### Input + +|Name|Type|Default|Required|Description|Enum|Example|Placeholder|Tooltip| +| :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | +|expire|integer|None|False|Expiration in seconds|None|100|None|None| +|key|string|None|True|Key to set|None|example:1234:session|None|None| +|value|string|None|True|Value to set|None|active|None|None| + +Example input: +``` +{ + "expire": 100, + "key": "example:1234:session", + "value": "active" +} ``` -### Triggers +##### Output -_This plugin does not contain any triggers._ +|Name|Type|Required|Description|Example| +| :--- | :--- | :--- | :--- | :--- | +|reply|string|False|Reply (usually OK)|OK| + +Example output: -### Custom Output Types +``` +{ + "reply": "OK" +} +``` +### Triggers + +*This plugin does not contain any triggers.* +### Tasks + +*This plugin does not contain any tasks.* -_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.0.2 - Bumping requirements.txt | SDK bump to 6.2.0 * 1.0.1 - New spec and help.md format for the Extension Library * 1.0.0 - Support web server mode | Add actions HMSET, HMGET and HINCRBY -* 0.1.2 - Update to new plugin architecture, fix action "keys" +* 0.1.2 - Update to new plugin architecture, fix action 'keys' * 0.1.1 - SSL bug fix in SDK * 0.1.0 - Initial plugin # Links -## References - * [REDIS](https://redis.io/) +## References + +* [REDIS API Docs](https://redis.io/docs/latest/apis/) \ No newline at end of file diff --git a/plugins/redis/komand_redis/actions/__init__.py b/plugins/redis/komand_redis/actions/__init__.py index 96b2ab7131..2dc3b80070 100755 --- a/plugins/redis/komand_redis/actions/__init__.py +++ b/plugins/redis/komand_redis/actions/__init__.py @@ -1,12 +1,24 @@ -# GENERATED BY KOMAND SDK - DO NOT EDIT +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT + from .delete.action import Delete + +from .set.action import Set + from .get.action import Get -from .hash_get.action import HashGet -from .hash_set.action import HashSet -from .hincrby.action import Hincrby -from .hmget.action import Hmget -from .hmset.action import Hmset + from .keys.action import Keys -from .list_get.action import ListGet + +from .hash_set.action import HashSet + +from .hash_get.action import HashGet + from .list_push.action import ListPush -from .set.action import Set + +from .list_get.action import ListGet + +from .hmset.action import Hmset + +from .hmget.action import Hmget + +from .hincrby.action import Hincrby + diff --git a/plugins/redis/komand_redis/actions/delete/__init__.py b/plugins/redis/komand_redis/actions/delete/__init__.py index 414f7280cd..1a89540f13 100755 --- a/plugins/redis/komand_redis/actions/delete/__init__.py +++ b/plugins/redis/komand_redis/actions/delete/__init__.py @@ -1,2 +1,2 @@ -# GENERATED BY KOMAND SDK - DO NOT EDIT +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT from .action import Delete diff --git a/plugins/redis/komand_redis/actions/delete/action.py b/plugins/redis/komand_redis/actions/delete/action.py index 70f1547bda..24983eb13e 100755 --- a/plugins/redis/komand_redis/actions/delete/action.py +++ b/plugins/redis/komand_redis/actions/delete/action.py @@ -1,10 +1,10 @@ -import komand +import insightconnect_plugin_runtime from .schema import DeleteInput, DeleteOutput # Custom imports below -class Delete(komand.Action): +class Delete(insightconnect_plugin_runtime.Action): def __init__(self): super(self.__class__, self).__init__( name="delete", description="Delete", input=DeleteInput(), output=DeleteOutput() diff --git a/plugins/redis/komand_redis/actions/delete/schema.py b/plugins/redis/komand_redis/actions/delete/schema.py index cfb10204ae..5efe3992e8 100755 --- a/plugins/redis/komand_redis/actions/delete/schema.py +++ b/plugins/redis/komand_redis/actions/delete/schema.py @@ -1,5 +1,5 @@ -# GENERATED BY KOMAND SDK - DO NOT EDIT -import komand +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT +import insightconnect_plugin_runtime import json @@ -9,14 +9,14 @@ class Component: class Input: KEY = "key" - + class Output: COUNT = "count" - -class DeleteInput(komand.Input): - schema = json.loads(""" + +class DeleteInput(insightconnect_plugin_runtime.Input): + schema = json.loads(r""" { "type": "object", "title": "Variables", @@ -30,7 +30,8 @@ class DeleteInput(komand.Input): }, "required": [ "key" - ] + ], + "definitions": {} } """) @@ -38,8 +39,8 @@ def __init__(self): super(self.__class__, self).__init__(self.schema) -class DeleteOutput(komand.Output): - schema = json.loads(""" +class DeleteOutput(insightconnect_plugin_runtime.Output): + schema = json.loads(r""" { "type": "object", "title": "Variables", @@ -50,7 +51,8 @@ class DeleteOutput(komand.Output): "description": "Number of keys deleted", "order": 1 } - } + }, + "definitions": {} } """) diff --git a/plugins/redis/komand_redis/actions/get/__init__.py b/plugins/redis/komand_redis/actions/get/__init__.py index 7cff8fa89a..98f445da3c 100755 --- a/plugins/redis/komand_redis/actions/get/__init__.py +++ b/plugins/redis/komand_redis/actions/get/__init__.py @@ -1,2 +1,2 @@ -# GENERATED BY KOMAND SDK - DO NOT EDIT +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT from .action import Get diff --git a/plugins/redis/komand_redis/actions/get/action.py b/plugins/redis/komand_redis/actions/get/action.py index 656553cc64..b727bd75ae 100755 --- a/plugins/redis/komand_redis/actions/get/action.py +++ b/plugins/redis/komand_redis/actions/get/action.py @@ -1,10 +1,10 @@ -import komand +import insightconnect_plugin_runtime from .schema import GetInput, GetOutput # Custom imports below -class Get(komand.Action): +class Get(insightconnect_plugin_runtime.Action): def __init__(self): super(self.__class__, self).__init__(name="get", description="Get", input=GetInput(), output=GetOutput()) diff --git a/plugins/redis/komand_redis/actions/get/schema.py b/plugins/redis/komand_redis/actions/get/schema.py index d181fa8f55..20dd699f99 100755 --- a/plugins/redis/komand_redis/actions/get/schema.py +++ b/plugins/redis/komand_redis/actions/get/schema.py @@ -1,23 +1,23 @@ -# GENERATED BY KOMAND SDK - DO NOT EDIT -import komand +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT +import insightconnect_plugin_runtime import json class Component: - DESCRIPTION = "Get a key" + DESCRIPTION = "This action is used to get a key. It will return the key at `value` if found, otherwise found will be false" class Input: KEY = "key" - + class Output: FOUND = "found" VALUE = "value" - -class GetInput(komand.Input): - schema = json.loads(""" + +class GetInput(insightconnect_plugin_runtime.Input): + schema = json.loads(r""" { "type": "object", "title": "Variables", @@ -31,7 +31,8 @@ class GetInput(komand.Input): }, "required": [ "key" - ] + ], + "definitions": {} } """) @@ -39,8 +40,8 @@ def __init__(self): super(self.__class__, self).__init__(self.schema) -class GetOutput(komand.Output): - schema = json.loads(""" +class GetOutput(insightconnect_plugin_runtime.Output): + schema = json.loads(r""" { "type": "object", "title": "Variables", @@ -57,7 +58,8 @@ class GetOutput(komand.Output): "description": "Value", "order": 2 } - } + }, + "definitions": {} } """) diff --git a/plugins/redis/komand_redis/actions/hash_get/__init__.py b/plugins/redis/komand_redis/actions/hash_get/__init__.py index 05dc2ef90e..f24ed19766 100755 --- a/plugins/redis/komand_redis/actions/hash_get/__init__.py +++ b/plugins/redis/komand_redis/actions/hash_get/__init__.py @@ -1,2 +1,2 @@ -# GENERATED BY KOMAND SDK - DO NOT EDIT +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT from .action import HashGet diff --git a/plugins/redis/komand_redis/actions/hash_get/action.py b/plugins/redis/komand_redis/actions/hash_get/action.py index 995ac6fa91..5ab1e9ec8e 100755 --- a/plugins/redis/komand_redis/actions/hash_get/action.py +++ b/plugins/redis/komand_redis/actions/hash_get/action.py @@ -1,10 +1,10 @@ -import komand +import insightconnect_plugin_runtime from .schema import HashGetInput, HashGetOutput # Custom imports below -class HashGet(komand.Action): +class HashGet(insightconnect_plugin_runtime.Action): def __init__(self): super(self.__class__, self).__init__( name="hash_get", description="Get Hash", input=HashGetInput(), output=HashGetOutput() @@ -13,7 +13,8 @@ def __init__(self): def run(self, params={}): """Run action""" values = self.connection.redis.hgetall(params["key"]) - found = not not values + found = bool(values) + if values: v = {} for key, val in values.items(): diff --git a/plugins/redis/komand_redis/actions/hash_get/schema.py b/plugins/redis/komand_redis/actions/hash_get/schema.py index 498170539d..6f65d195b0 100755 --- a/plugins/redis/komand_redis/actions/hash_get/schema.py +++ b/plugins/redis/komand_redis/actions/hash_get/schema.py @@ -1,5 +1,5 @@ -# GENERATED BY KOMAND SDK - DO NOT EDIT -import komand +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT +import insightconnect_plugin_runtime import json @@ -9,15 +9,15 @@ class Component: class Input: KEY = "key" - + class Output: FOUND = "found" VALUES = "values" - -class HashGetInput(komand.Input): - schema = json.loads(""" + +class HashGetInput(insightconnect_plugin_runtime.Input): + schema = json.loads(r""" { "type": "object", "title": "Variables", @@ -31,7 +31,8 @@ class HashGetInput(komand.Input): }, "required": [ "key" - ] + ], + "definitions": {} } """) @@ -39,8 +40,8 @@ def __init__(self): super(self.__class__, self).__init__(self.schema) -class HashGetOutput(komand.Output): - schema = json.loads(""" +class HashGetOutput(insightconnect_plugin_runtime.Output): + schema = json.loads(r""" { "type": "object", "title": "Variables", @@ -57,7 +58,8 @@ class HashGetOutput(komand.Output): "description": "Values", "order": 2 } - } + }, + "definitions": {} } """) diff --git a/plugins/redis/komand_redis/actions/hash_set/__init__.py b/plugins/redis/komand_redis/actions/hash_set/__init__.py index 9dad234d99..28eed021d6 100755 --- a/plugins/redis/komand_redis/actions/hash_set/__init__.py +++ b/plugins/redis/komand_redis/actions/hash_set/__init__.py @@ -1,2 +1,2 @@ -# GENERATED BY KOMAND SDK - DO NOT EDIT +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT from .action import HashSet diff --git a/plugins/redis/komand_redis/actions/hash_set/action.py b/plugins/redis/komand_redis/actions/hash_set/action.py index 5afa1e5683..4e5fbf0a89 100755 --- a/plugins/redis/komand_redis/actions/hash_set/action.py +++ b/plugins/redis/komand_redis/actions/hash_set/action.py @@ -1,10 +1,10 @@ -import komand +import insightconnect_plugin_runtime from .schema import HashSetInput, HashSetOutput # Custom imports below -class HashSet(komand.Action): +class HashSet(insightconnect_plugin_runtime.Action): def __init__(self): super(self.__class__, self).__init__( name="hash_set", description="Set Hash", input=HashSetInput(), output=HashSetOutput() diff --git a/plugins/redis/komand_redis/actions/hash_set/schema.py b/plugins/redis/komand_redis/actions/hash_set/schema.py index 5fc19fab82..eb3e9e7c96 100755 --- a/plugins/redis/komand_redis/actions/hash_set/schema.py +++ b/plugins/redis/komand_redis/actions/hash_set/schema.py @@ -1,5 +1,5 @@ -# GENERATED BY KOMAND SDK - DO NOT EDIT -import komand +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT +import insightconnect_plugin_runtime import json @@ -11,14 +11,14 @@ class Input: EXPIRE = "expire" KEY = "key" VALUES = "values" - + class Output: REPLY = "reply" - -class HashSetInput(komand.Input): - schema = json.loads(""" + +class HashSetInput(insightconnect_plugin_runtime.Input): + schema = json.loads(r""" { "type": "object", "title": "Variables", @@ -45,7 +45,8 @@ class HashSetInput(komand.Input): "required": [ "key", "values" - ] + ], + "definitions": {} } """) @@ -53,8 +54,8 @@ def __init__(self): super(self.__class__, self).__init__(self.schema) -class HashSetOutput(komand.Output): - schema = json.loads(""" +class HashSetOutput(insightconnect_plugin_runtime.Output): + schema = json.loads(r""" { "type": "object", "title": "Variables", @@ -65,7 +66,8 @@ class HashSetOutput(komand.Output): "description": "Reply (usually OK)", "order": 1 } - } + }, + "definitions": {} } """) diff --git a/plugins/redis/komand_redis/actions/hincrby/__init__.py b/plugins/redis/komand_redis/actions/hincrby/__init__.py index c434c1aa89..1bb7f36b53 100755 --- a/plugins/redis/komand_redis/actions/hincrby/__init__.py +++ b/plugins/redis/komand_redis/actions/hincrby/__init__.py @@ -1,2 +1,2 @@ -# GENERATED BY KOMAND SDK - DO NOT EDIT +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT from .action import Hincrby diff --git a/plugins/redis/komand_redis/actions/hincrby/action.py b/plugins/redis/komand_redis/actions/hincrby/action.py index 00e6205f4a..81b5bec637 100755 --- a/plugins/redis/komand_redis/actions/hincrby/action.py +++ b/plugins/redis/komand_redis/actions/hincrby/action.py @@ -1,10 +1,10 @@ -import komand +import insightconnect_plugin_runtime from .schema import HincrbyInput, HincrbyOutput # Custom imports below -class Hincrby(komand.Action): +class Hincrby(insightconnect_plugin_runtime.Action): def __init__(self): super(self.__class__, self).__init__( name="hincrby", diff --git a/plugins/redis/komand_redis/actions/hincrby/schema.py b/plugins/redis/komand_redis/actions/hincrby/schema.py index 910c1a4633..b1b58115d9 100755 --- a/plugins/redis/komand_redis/actions/hincrby/schema.py +++ b/plugins/redis/komand_redis/actions/hincrby/schema.py @@ -1,5 +1,5 @@ -# GENERATED BY KOMAND SDK - DO NOT EDIT -import komand +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT +import insightconnect_plugin_runtime import json @@ -11,14 +11,14 @@ class Input: FIELD = "field" KEY = "key" VALUE = "value" - + class Output: RESULT = "result" - -class HincrbyInput(komand.Input): - schema = json.loads(""" + +class HincrbyInput(insightconnect_plugin_runtime.Input): + schema = json.loads(r""" { "type": "object", "title": "Variables", @@ -47,7 +47,8 @@ class HincrbyInput(komand.Input): "field", "key", "value" - ] + ], + "definitions": {} } """) @@ -55,8 +56,8 @@ def __init__(self): super(self.__class__, self).__init__(self.schema) -class HincrbyOutput(komand.Output): - schema = json.loads(""" +class HincrbyOutput(insightconnect_plugin_runtime.Output): + schema = json.loads(r""" { "type": "object", "title": "Variables", @@ -67,7 +68,8 @@ class HincrbyOutput(komand.Output): "description": "Result returned after operation is ran", "order": 1 } - } + }, + "definitions": {} } """) diff --git a/plugins/redis/komand_redis/actions/hmget/__init__.py b/plugins/redis/komand_redis/actions/hmget/__init__.py index ef77ee03f0..a9956a60f5 100755 --- a/plugins/redis/komand_redis/actions/hmget/__init__.py +++ b/plugins/redis/komand_redis/actions/hmget/__init__.py @@ -1,2 +1,2 @@ -# GENERATED BY KOMAND SDK - DO NOT EDIT +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT from .action import Hmget diff --git a/plugins/redis/komand_redis/actions/hmget/action.py b/plugins/redis/komand_redis/actions/hmget/action.py index 982249bac0..5d507e93b4 100755 --- a/plugins/redis/komand_redis/actions/hmget/action.py +++ b/plugins/redis/komand_redis/actions/hmget/action.py @@ -1,10 +1,10 @@ -import komand +import insightconnect_plugin_runtime from .schema import HmgetInput, HmgetOutput # Custom imports below -class Hmget(komand.Action): +class Hmget(insightconnect_plugin_runtime.Action): def __init__(self): super(self.__class__, self).__init__( name="hmget", @@ -21,18 +21,22 @@ def run(self, params={}): try: if get_all: result = self.connection.redis.hgetall(key) + if result: + v = {} + for key, val in result.items(): + v[key.decode("utf-8")] = val.decode("utf-8") + result = v else: result = self.connection.redis.hmget(key, fields) + if result: + v = {} + for index, item in enumerate(result): + v[fields[index]] = item.decode("utf-8") + result = v except Exception as e: self.logger.error("An error occurred while running HMSET: ", e) raise - if result: - v = {} - for key, val in result.items(): - v[key.decode("utf-8")] = val.decode("utf-8") - result = v - return {"values": result} def test(self): diff --git a/plugins/redis/komand_redis/actions/hmget/schema.py b/plugins/redis/komand_redis/actions/hmget/schema.py index 4f9d89ac3f..49f86726b4 100755 --- a/plugins/redis/komand_redis/actions/hmget/schema.py +++ b/plugins/redis/komand_redis/actions/hmget/schema.py @@ -1,5 +1,5 @@ -# GENERATED BY KOMAND SDK - DO NOT EDIT -import komand +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT +import insightconnect_plugin_runtime import json @@ -11,14 +11,14 @@ class Input: FIELDS = "fields" GET_ALL = "get_all" KEY = "key" - + class Output: VALUES = "values" - -class HmgetInput(komand.Input): - schema = json.loads(""" + +class HmgetInput(insightconnect_plugin_runtime.Input): + schema = json.loads(r""" { "type": "object", "title": "Variables", @@ -49,7 +49,8 @@ class HmgetInput(komand.Input): "required": [ "get_all", "key" - ] + ], + "definitions": {} } """) @@ -57,8 +58,8 @@ def __init__(self): super(self.__class__, self).__init__(self.schema) -class HmgetOutput(komand.Output): - schema = json.loads(""" +class HmgetOutput(insightconnect_plugin_runtime.Output): + schema = json.loads(r""" { "type": "object", "title": "Variables", @@ -69,7 +70,8 @@ class HmgetOutput(komand.Output): "description": "Values returned from HMGET", "order": 1 } - } + }, + "definitions": {} } """) diff --git a/plugins/redis/komand_redis/actions/hmset/__init__.py b/plugins/redis/komand_redis/actions/hmset/__init__.py index 90e1c4a487..1954bc0a19 100755 --- a/plugins/redis/komand_redis/actions/hmset/__init__.py +++ b/plugins/redis/komand_redis/actions/hmset/__init__.py @@ -1,2 +1,2 @@ -# GENERATED BY KOMAND SDK - DO NOT EDIT +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT from .action import Hmset diff --git a/plugins/redis/komand_redis/actions/hmset/action.py b/plugins/redis/komand_redis/actions/hmset/action.py index 67808dab10..29d9018551 100755 --- a/plugins/redis/komand_redis/actions/hmset/action.py +++ b/plugins/redis/komand_redis/actions/hmset/action.py @@ -1,10 +1,10 @@ -import komand +import insightconnect_plugin_runtime from .schema import HmsetInput, HmsetOutput # Custom imports below -class Hmset(komand.Action): +class Hmset(insightconnect_plugin_runtime.Action): def __init__(self): super(self.__class__, self).__init__( name="hmset", diff --git a/plugins/redis/komand_redis/actions/hmset/schema.py b/plugins/redis/komand_redis/actions/hmset/schema.py index 376469c92b..9f98aadf06 100755 --- a/plugins/redis/komand_redis/actions/hmset/schema.py +++ b/plugins/redis/komand_redis/actions/hmset/schema.py @@ -1,5 +1,5 @@ -# GENERATED BY KOMAND SDK - DO NOT EDIT -import komand +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT +import insightconnect_plugin_runtime import json @@ -11,14 +11,14 @@ class Input: EXPIRE = "expire" KEY = "key" VALUES = "values" - + class Output: REPLY = "reply" - -class HmsetInput(komand.Input): - schema = json.loads(""" + +class HmsetInput(insightconnect_plugin_runtime.Input): + schema = json.loads(r""" { "type": "object", "title": "Variables", @@ -45,7 +45,8 @@ class HmsetInput(komand.Input): "required": [ "key", "values" - ] + ], + "definitions": {} } """) @@ -53,8 +54,8 @@ def __init__(self): super(self.__class__, self).__init__(self.schema) -class HmsetOutput(komand.Output): - schema = json.loads(""" +class HmsetOutput(insightconnect_plugin_runtime.Output): + schema = json.loads(r""" { "type": "object", "title": "Variables", @@ -65,7 +66,8 @@ class HmsetOutput(komand.Output): "description": "Reply (usually OK)", "order": 1 } - } + }, + "definitions": {} } """) diff --git a/plugins/redis/komand_redis/actions/keys/__init__.py b/plugins/redis/komand_redis/actions/keys/__init__.py index 50d723228b..7c1d24526d 100755 --- a/plugins/redis/komand_redis/actions/keys/__init__.py +++ b/plugins/redis/komand_redis/actions/keys/__init__.py @@ -1,2 +1,2 @@ -# GENERATED BY KOMAND SDK - DO NOT EDIT +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT from .action import Keys diff --git a/plugins/redis/komand_redis/actions/keys/action.py b/plugins/redis/komand_redis/actions/keys/action.py index 9194561302..a1f3534012 100755 --- a/plugins/redis/komand_redis/actions/keys/action.py +++ b/plugins/redis/komand_redis/actions/keys/action.py @@ -1,10 +1,10 @@ -import komand +import insightconnect_plugin_runtime from .schema import KeysInput, KeysOutput # Custom imports below -class Keys(komand.Action): +class Keys(insightconnect_plugin_runtime.Action): def __init__(self): super(self.__class__, self).__init__( name="keys", diff --git a/plugins/redis/komand_redis/actions/keys/schema.py b/plugins/redis/komand_redis/actions/keys/schema.py index 3b0725502a..4f8660e77e 100755 --- a/plugins/redis/komand_redis/actions/keys/schema.py +++ b/plugins/redis/komand_redis/actions/keys/schema.py @@ -1,5 +1,5 @@ -# GENERATED BY KOMAND SDK - DO NOT EDIT -import komand +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT +import insightconnect_plugin_runtime import json @@ -9,15 +9,15 @@ class Component: class Input: PATTERN = "pattern" - + class Output: COUNT = "count" KEYS = "keys" - -class KeysInput(komand.Input): - schema = json.loads(""" + +class KeysInput(insightconnect_plugin_runtime.Input): + schema = json.loads(r""" { "type": "object", "title": "Variables", @@ -31,7 +31,8 @@ class KeysInput(komand.Input): }, "required": [ "pattern" - ] + ], + "definitions": {} } """) @@ -39,8 +40,8 @@ def __init__(self): super(self.__class__, self).__init__(self.schema) -class KeysOutput(komand.Output): - schema = json.loads(""" +class KeysOutput(insightconnect_plugin_runtime.Output): + schema = json.loads(r""" { "type": "object", "title": "Variables", @@ -60,7 +61,8 @@ class KeysOutput(komand.Output): }, "order": 2 } - } + }, + "definitions": {} } """) diff --git a/plugins/redis/komand_redis/actions/list_get/__init__.py b/plugins/redis/komand_redis/actions/list_get/__init__.py index 8fb52248d9..9d1ae651ed 100755 --- a/plugins/redis/komand_redis/actions/list_get/__init__.py +++ b/plugins/redis/komand_redis/actions/list_get/__init__.py @@ -1,2 +1,2 @@ -# GENERATED BY KOMAND SDK - DO NOT EDIT +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT from .action import ListGet diff --git a/plugins/redis/komand_redis/actions/list_get/action.py b/plugins/redis/komand_redis/actions/list_get/action.py index 45d533a651..cc9f909b49 100755 --- a/plugins/redis/komand_redis/actions/list_get/action.py +++ b/plugins/redis/komand_redis/actions/list_get/action.py @@ -1,10 +1,10 @@ -import komand +import insightconnect_plugin_runtime from .schema import ListGetInput, ListGetOutput # Custom imports below -class ListGet(komand.Action): +class ListGet(insightconnect_plugin_runtime.Action): def __init__(self): super(self.__class__, self).__init__( name="list_get", diff --git a/plugins/redis/komand_redis/actions/list_get/schema.py b/plugins/redis/komand_redis/actions/list_get/schema.py index 12630f70ac..e26d554a45 100755 --- a/plugins/redis/komand_redis/actions/list_get/schema.py +++ b/plugins/redis/komand_redis/actions/list_get/schema.py @@ -1,5 +1,5 @@ -# GENERATED BY KOMAND SDK - DO NOT EDIT -import komand +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT +import insightconnect_plugin_runtime import json @@ -10,15 +10,15 @@ class Component: class Input: COUNT = "count" KEY = "key" - + class Output: FOUND = "found" VALUES = "values" - -class ListGetInput(komand.Input): - schema = json.loads(""" + +class ListGetInput(insightconnect_plugin_runtime.Input): + schema = json.loads(r""" { "type": "object", "title": "Variables", @@ -39,7 +39,8 @@ class ListGetInput(komand.Input): }, "required": [ "key" - ] + ], + "definitions": {} } """) @@ -47,8 +48,8 @@ def __init__(self): super(self.__class__, self).__init__(self.schema) -class ListGetOutput(komand.Output): - schema = json.loads(""" +class ListGetOutput(insightconnect_plugin_runtime.Output): + schema = json.loads(r""" { "type": "object", "title": "Variables", @@ -68,7 +69,8 @@ class ListGetOutput(komand.Output): }, "order": 2 } - } + }, + "definitions": {} } """) diff --git a/plugins/redis/komand_redis/actions/list_push/__init__.py b/plugins/redis/komand_redis/actions/list_push/__init__.py index 4370bc3bfc..5519cd6c18 100755 --- a/plugins/redis/komand_redis/actions/list_push/__init__.py +++ b/plugins/redis/komand_redis/actions/list_push/__init__.py @@ -1,2 +1,2 @@ -# GENERATED BY KOMAND SDK - DO NOT EDIT +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT from .action import ListPush diff --git a/plugins/redis/komand_redis/actions/list_push/action.py b/plugins/redis/komand_redis/actions/list_push/action.py index 20a50aca05..06833d2ffc 100755 --- a/plugins/redis/komand_redis/actions/list_push/action.py +++ b/plugins/redis/komand_redis/actions/list_push/action.py @@ -1,10 +1,10 @@ -import komand +import insightconnect_plugin_runtime from .schema import ListPushInput, ListPushOutput # Custom imports below -class ListPush(komand.Action): +class ListPush(insightconnect_plugin_runtime.Action): def __init__(self): super(self.__class__, self).__init__( name="list_push", diff --git a/plugins/redis/komand_redis/actions/list_push/schema.py b/plugins/redis/komand_redis/actions/list_push/schema.py index d283de2b41..4df6de9b28 100755 --- a/plugins/redis/komand_redis/actions/list_push/schema.py +++ b/plugins/redis/komand_redis/actions/list_push/schema.py @@ -1,5 +1,5 @@ -# GENERATED BY KOMAND SDK - DO NOT EDIT -import komand +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT +import insightconnect_plugin_runtime import json @@ -11,14 +11,14 @@ class Input: EXPIRE = "expire" KEY = "key" VALUE = "value" - + class Output: REPLY = "reply" - -class ListPushInput(komand.Input): - schema = json.loads(""" + +class ListPushInput(insightconnect_plugin_runtime.Input): + schema = json.loads(r""" { "type": "object", "title": "Variables", @@ -45,7 +45,8 @@ class ListPushInput(komand.Input): "required": [ "key", "value" - ] + ], + "definitions": {} } """) @@ -53,8 +54,8 @@ def __init__(self): super(self.__class__, self).__init__(self.schema) -class ListPushOutput(komand.Output): - schema = json.loads(""" +class ListPushOutput(insightconnect_plugin_runtime.Output): + schema = json.loads(r""" { "type": "object", "title": "Variables", @@ -65,7 +66,8 @@ class ListPushOutput(komand.Output): "description": "Reply (usually OK)", "order": 1 } - } + }, + "definitions": {} } """) diff --git a/plugins/redis/komand_redis/actions/set/__init__.py b/plugins/redis/komand_redis/actions/set/__init__.py index 544eef8cb2..0c75a30689 100755 --- a/plugins/redis/komand_redis/actions/set/__init__.py +++ b/plugins/redis/komand_redis/actions/set/__init__.py @@ -1,2 +1,2 @@ -# GENERATED BY KOMAND SDK - DO NOT EDIT +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT from .action import Set diff --git a/plugins/redis/komand_redis/actions/set/action.py b/plugins/redis/komand_redis/actions/set/action.py index 6666400b6a..e897ac33e9 100755 --- a/plugins/redis/komand_redis/actions/set/action.py +++ b/plugins/redis/komand_redis/actions/set/action.py @@ -1,10 +1,10 @@ -import komand +import insightconnect_plugin_runtime from .schema import SetInput, SetOutput # Custom imports below -class Set(komand.Action): +class Set(insightconnect_plugin_runtime.Action): def __init__(self): super(self.__class__, self).__init__(name="set", description="Set", input=SetInput(), output=SetOutput()) diff --git a/plugins/redis/komand_redis/actions/set/schema.py b/plugins/redis/komand_redis/actions/set/schema.py index eb12f240b1..affff14905 100755 --- a/plugins/redis/komand_redis/actions/set/schema.py +++ b/plugins/redis/komand_redis/actions/set/schema.py @@ -1,24 +1,24 @@ -# GENERATED BY KOMAND SDK - DO NOT EDIT -import komand +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT +import insightconnect_plugin_runtime import json class Component: - DESCRIPTION = "Set a key" + DESCRIPTION = "This action is used to set a key to a string value. There is an optional expiration timeout which will auto remove the key when `expire` seconds have passed" class Input: EXPIRE = "expire" KEY = "key" VALUE = "value" - + class Output: REPLY = "reply" - -class SetInput(komand.Input): - schema = json.loads(""" + +class SetInput(insightconnect_plugin_runtime.Input): + schema = json.loads(r""" { "type": "object", "title": "Variables", @@ -45,7 +45,8 @@ class SetInput(komand.Input): "required": [ "key", "value" - ] + ], + "definitions": {} } """) @@ -53,8 +54,8 @@ def __init__(self): super(self.__class__, self).__init__(self.schema) -class SetOutput(komand.Output): - schema = json.loads(""" +class SetOutput(insightconnect_plugin_runtime.Output): + schema = json.loads(r""" { "type": "object", "title": "Variables", @@ -65,7 +66,8 @@ class SetOutput(komand.Output): "description": "Reply (usually OK)", "order": 1 } - } + }, + "definitions": {} } """) diff --git a/plugins/redis/komand_redis/connection/__init__.py b/plugins/redis/komand_redis/connection/__init__.py index a515dcf6b0..c78d3356be 100755 --- a/plugins/redis/komand_redis/connection/__init__.py +++ b/plugins/redis/komand_redis/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/redis/komand_redis/connection/connection.py b/plugins/redis/komand_redis/connection/connection.py index 4bea0eaca6..a1feb8a0c4 100755 --- a/plugins/redis/komand_redis/connection/connection.py +++ b/plugins/redis/komand_redis/connection/connection.py @@ -1,11 +1,11 @@ -import komand +import insightconnect_plugin_runtime from .schema import ConnectionSchema # Custom imports below import redis -class Connection(komand.Connection): +class Connection(insightconnect_plugin_runtime.Connection): def __init__(self): super(self.__class__, self).__init__(input=ConnectionSchema()) self.redis = None diff --git a/plugins/redis/komand_redis/connection/schema.py b/plugins/redis/komand_redis/connection/schema.py index b01bcf34e7..2bb50652dd 100755 --- a/plugins/redis/komand_redis/connection/schema.py +++ b/plugins/redis/komand_redis/connection/schema.py @@ -1,5 +1,5 @@ -# GENERATED BY KOMAND SDK - DO NOT EDIT -import komand +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT +import insightconnect_plugin_runtime import json @@ -7,18 +7,18 @@ class Input: DB = "db" HOST = "host" PORT = "port" - -class ConnectionSchema(komand.Input): - schema = json.loads(""" + +class ConnectionSchema(insightconnect_plugin_runtime.Input): + schema = json.loads(r""" { "type": "object", "title": "Variables", "properties": { "db": { "type": "integer", - "title": "Db", - "description": "Db to use usually (0-15)", + "title": "DB", + "description": "DB to use usually (0-15)", "default": 0, "order": 3 }, @@ -40,7 +40,8 @@ class ConnectionSchema(komand.Input): "db", "host", "port" - ] + ], + "definitions": {} } """) diff --git a/plugins/redis/komand_redis/tasks/__init__.py b/plugins/redis/komand_redis/tasks/__init__.py new file mode 100644 index 0000000000..7020c9a4ad --- /dev/null +++ b/plugins/redis/komand_redis/tasks/__init__.py @@ -0,0 +1,2 @@ +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT + diff --git a/plugins/redis/komand_redis/triggers/__init__.py b/plugins/redis/komand_redis/triggers/__init__.py index bace8db897..7020c9a4ad 100755 --- a/plugins/redis/komand_redis/triggers/__init__.py +++ b/plugins/redis/komand_redis/triggers/__init__.py @@ -1 +1,2 @@ -# GENERATED BY KOMAND SDK - DO NOT EDIT +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT + diff --git a/plugins/redis/plugin.spec.yaml b/plugins/redis/plugin.spec.yaml index cebd28d8af..012481cf25 100644 --- a/plugins/redis/plugin.spec.yaml +++ b/plugins/redis/plugin.spec.yaml @@ -3,15 +3,29 @@ extension: plugin products: [insightconnect] name: redis title: Redis -description: The Redis plugin allows you to add, update, and manage data in a Redis database -version: 1.0.1 +description: Redis is an in-memory data structure project implementing a distributed, in-memory key-value database with optional durability. Redis supports different kinds of abstract data structures, such as strings, lists, maps, sets, sorted sets, HyperLogLogs, bitmaps, streams, and spatial indexes.\nThis package allows you to interact with the [Redis](https://redis.io/) database API +version: 1.0.2 +connection_version: 1 vendor: rapid7 support: community status: [] +supported_versions: ["2024-11-8"] resources: source_url: https://github.com/rapid7/insightconnect-plugins/tree/master/plugins/redis license_url: https://github.com/rapid7/insightconnect-plugins/blob/master/LICENSE vendor_url: https://redis.io/ +sdk: + type: slim + version: 6.2.0 + user: nobody +key_features: + - "Set and retrieve data from Redis" +requirements: + - "Connection information for your Redis database" +links: + - "[REDIS](https://redis.io/)" +references: + - "[REDIS API Docs](https://redis.io/docs/latest/apis/)" tags: - database - redis @@ -19,21 +33,34 @@ hub_tags: use_cases: [data_utility, reporting_and_analytics] keywords: [database, redis] features: [] +version_history: + - "1.0.2 - Bumping requirements.txt | SDK bump to 6.2.0 | Added Unit Tests" + - "1.0.1 - New spec and help.md format for the Extension Library" + - "1.0.0 - Support web server mode | Add actions HMSET, HMGET and HINCRBY" + - "0.1.2 - Update to new plugin architecture, fix action 'keys'" + - "0.1.1 - SSL bug fix in SDK" + - "0.1.0 - Initial plugin" connection: host: + title: Host type: string description: Host, e.g. 10.4.4.4 required: true + example: 10.4.4.4 port: + title: Port type: integer description: Port default: 6379 required: true + example: 6379 db: + title: DB type: integer - description: Db to use usually (0-15) + description: DB to use usually (0-15) default: 0 required: true + example: 10 actions: delete: title: Delete @@ -44,57 +71,66 @@ actions: type: string description: Key to delete required: true + example: example:1234:session output: count: title: Count type: integer description: Number of keys deleted required: false + example: 1 set: title: Set - description: Set a key + description: This action is used to set a key to a string value. There is an optional expiration timeout which will auto remove the key when `expire` seconds have passed input: key: title: Key type: string description: Key to set required: true + example: example:1234:session value: title: Value type: string description: Value to set required: true + example: active expire: title: Expire type: integer description: Expiration in seconds required: false + example: 100 output: reply: title: Reply type: string description: Reply (usually OK) required: false + example: OK get: title: Get - description: Get a key + description: This action is used to get a key. It will return the key at `value` if found, otherwise found will be false input: key: title: Key type: string description: Key to get required: true + example: example:1234:active output: found: title: Found type: boolean description: True if found required: false + example: true value: title: Value type: string description: Value required: false + example: true keys: title: Keys description: Return keys matching pattern @@ -104,17 +140,20 @@ actions: type: string description: Pattern, e.g. *o* required: true + example: example:*:session output: count: title: Count type: integer description: Count of keys found required: false + example: 1 keys: title: Keys type: '[]string' description: Keys returned required: false + example: [ "example:1234:session", "example:5678:session", "example:abcd:session" ] hash_set: title: Hash Set description: Set key's hash @@ -124,22 +163,26 @@ actions: type: string description: Key required: true + example: user:1234 values: title: Values type: object description: Object hash field:value to set required: true + example: {"name": "John Doe", "email": "johndoe@example.com", "age": "30"} expire: title: Expire type: integer description: Expiration in seconds required: false + example: 100 output: reply: title: Reply type: string description: Reply (usually OK) required: false + example: OK hash_get: title: Hash Get description: Get key's hash @@ -149,17 +192,20 @@ actions: type: string description: Key to get required: true + example: user:profile output: found: title: Found type: boolean description: True if found required: false + example: true values: title: Values type: object description: Values required: false + example: { "name": "Example Name", "email": "Example.email@example.com", "age": "30" } list_push: title: List Push description: List key's push @@ -169,22 +215,26 @@ actions: type: string description: Key required: true + example: user:task_list:123 value: title: Value type: string description: Value to append required: true + example: Complete monthly report expire: title: Expire type: integer description: Expiration in seconds required: false + example: 100 output: reply: title: Reply type: string description: Reply (usually OK) required: false + example: OK list_get: title: List Get description: Get all elements in a list @@ -194,23 +244,27 @@ actions: type: string description: Key to get required: true + example: user:task_list:123 count: title: Count type: integer description: Max results to return default: 1000 required: false + example: 1000 output: found: title: Found type: boolean description: True if found required: false + example: true values: title: Values type: '[]string' description: Values required: false + example: ["task1", "task2", "task3", "task4"] hmset: title: Hash Multi Set description: Sets the specified fields to their respective values in the hash @@ -221,22 +275,26 @@ actions: type: string description: Key required: true + example: user:profile:123 values: title: Values type: object description: Object hash field:value to set required: true + example: { "name": "Test Name", "email": "Test.Name@example.com", "age": "30"} expire: title: Expire type: integer description: Expiration in seconds required: false + example: 100 output: reply: title: Reply type: boolean description: Reply (usually OK) required: false + example: true hmget: title: Hash Multi Get description: Returns the values associated with the specified fields in the hash @@ -247,23 +305,27 @@ actions: type: string description: Key to get required: true + example: user:profile:123 fields: title: Fields type: '[]string' description: Fields to retrieve values from required: false + example: ["name", "email"] get_all: title: Get All type: boolean description: Get all values required: true default: false + example: false output: values: title: Values type: object description: Values returned from HMGET required: false + example: { "name": "Ryan Test", "email": "Ryan.test@example.com" } hincrby: title: Hash Increment By description: Increments the number stored at field in the hash stored at key by @@ -274,20 +336,24 @@ actions: description: Key to lookup type: string required: true + example: user:profile:123 field: title: Field description: Field to increment type: string required: true + example: login_count value: title: Value description: How much to increment by type: integer required: true default: 0 + example: 1 output: result: title: Result description: Result returned after operation is ran type: integer required: false + example: 1 diff --git a/plugins/redis/requirements.txt b/plugins/redis/requirements.txt index 6811dab834..047df77fa9 100755 --- a/plugins/redis/requirements.txt +++ b/plugins/redis/requirements.txt @@ -1,4 +1,5 @@ # 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 -redis==2.10.6 +redis==4.3.6 +parameterized==0.9.0 diff --git a/plugins/redis/setup.py b/plugins/redis/setup.py index eb39dd0a15..2480e7f7cd 100644 --- a/plugins/redis/setup.py +++ b/plugins/redis/setup.py @@ -1,14 +1,14 @@ -# GENERATED BY KOMAND SDK - DO NOT EDIT +# GENERATED BY INSIGHT-PLUGIN - DO NOT EDIT from setuptools import setup, find_packages -setup(name='redis-rapid7-plugin', - version='1.0.1', - description='The Redis plugin allows you to add, update, and manage data in a Redis database', - author='rapid7', - author_email='', - url='', +setup(name="redis-rapid7-plugin", + version="1.0.2", + description="Redis is an in-memory data structure project implementing a distributed, in-memory key-value database with optional durability. Redis supports different kinds of abstract data structures, such as strings, lists, maps, sets, sorted sets, HyperLogLogs, bitmaps, streams, and spatial indexes.\nThis package allows you to interact with the [Redis](https://redis.io/) database API", + author="rapid7", + author_email="", + url="", packages=find_packages(), - install_requires=['komand'], # Add third-party dependencies to requirements.txt, not here! + install_requires=['insightconnect-plugin-runtime'], # Add third-party dependencies to requirements.txt, not here! scripts=['bin/komand_redis'] ) diff --git a/plugins/redis/unit_test/__init__.py b/plugins/redis/unit_test/__init__.py new file mode 100644 index 0000000000..d9ae09fc16 --- /dev/null +++ b/plugins/redis/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/redis/unit_test/expected/delete_exp.json.exp b/plugins/redis/unit_test/expected/delete_exp.json.exp new file mode 100644 index 0000000000..6a235e6f03 --- /dev/null +++ b/plugins/redis/unit_test/expected/delete_exp.json.exp @@ -0,0 +1,3 @@ +{ + "count": 10 +} diff --git a/plugins/redis/unit_test/expected/get_exp.json.exp b/plugins/redis/unit_test/expected/get_exp.json.exp new file mode 100644 index 0000000000..b00f878f6f --- /dev/null +++ b/plugins/redis/unit_test/expected/get_exp.json.exp @@ -0,0 +1,4 @@ +{ + "found": false, + "value": "" +} diff --git a/plugins/redis/unit_test/expected/hash_get_exp.json.exp b/plugins/redis/unit_test/expected/hash_get_exp.json.exp new file mode 100644 index 0000000000..76c6f4f4e5 --- /dev/null +++ b/plugins/redis/unit_test/expected/hash_get_exp.json.exp @@ -0,0 +1,8 @@ +{ + "found": true, + "values": { + "age": "20", + "email": "Test@example.com", + "name": "Test User" + } +} diff --git a/plugins/redis/unit_test/expected/hash_set_exp.json.exp b/plugins/redis/unit_test/expected/hash_set_exp.json.exp new file mode 100644 index 0000000000..b2f2933cf9 --- /dev/null +++ b/plugins/redis/unit_test/expected/hash_set_exp.json.exp @@ -0,0 +1,3 @@ +{ + "reply": "OK" +} diff --git a/plugins/redis/unit_test/expected/hincrby_exp.json.exp b/plugins/redis/unit_test/expected/hincrby_exp.json.exp new file mode 100644 index 0000000000..44da7cf42f --- /dev/null +++ b/plugins/redis/unit_test/expected/hincrby_exp.json.exp @@ -0,0 +1,3 @@ +{ + "result": 0 +} diff --git a/plugins/redis/unit_test/expected/hmget_exp.json.exp b/plugins/redis/unit_test/expected/hmget_exp.json.exp new file mode 100644 index 0000000000..5baba355c9 --- /dev/null +++ b/plugins/redis/unit_test/expected/hmget_exp.json.exp @@ -0,0 +1,6 @@ +{ + "values": { + "age": "20", + "name": "Test User" + } +} diff --git a/plugins/redis/unit_test/expected/hmset_exp.json.exp b/plugins/redis/unit_test/expected/hmset_exp.json.exp new file mode 100644 index 0000000000..ae1e8b5fd1 --- /dev/null +++ b/plugins/redis/unit_test/expected/hmset_exp.json.exp @@ -0,0 +1,3 @@ +{ + "reply": true +} diff --git a/plugins/redis/unit_test/expected/keys_exp.json.exp b/plugins/redis/unit_test/expected/keys_exp.json.exp new file mode 100644 index 0000000000..5ec5e5bd94 --- /dev/null +++ b/plugins/redis/unit_test/expected/keys_exp.json.exp @@ -0,0 +1,4 @@ +{ + "count": 2, + "keys": ["count", "keys"] +} diff --git a/plugins/redis/unit_test/expected/list_get_exp.json.exp b/plugins/redis/unit_test/expected/list_get_exp.json.exp new file mode 100644 index 0000000000..062c739aed --- /dev/null +++ b/plugins/redis/unit_test/expected/list_get_exp.json.exp @@ -0,0 +1,4 @@ +{ + "found": false, + "values": [] +} diff --git a/plugins/redis/unit_test/expected/list_push_exp.json.exp b/plugins/redis/unit_test/expected/list_push_exp.json.exp new file mode 100644 index 0000000000..b2f2933cf9 --- /dev/null +++ b/plugins/redis/unit_test/expected/list_push_exp.json.exp @@ -0,0 +1,3 @@ +{ + "reply": "OK" +} diff --git a/plugins/redis/unit_test/expected/set_exp.json.exp b/plugins/redis/unit_test/expected/set_exp.json.exp new file mode 100644 index 0000000000..b2f2933cf9 --- /dev/null +++ b/plugins/redis/unit_test/expected/set_exp.json.exp @@ -0,0 +1,3 @@ +{ + "reply": "OK" +} diff --git a/plugins/redis/unit_test/inputs/delete.json.exp b/plugins/redis/unit_test/inputs/delete.json.exp new file mode 100644 index 0000000000..d95c560f4c --- /dev/null +++ b/plugins/redis/unit_test/inputs/delete.json.exp @@ -0,0 +1,3 @@ +{ + "key": "user:1234" +} diff --git a/plugins/redis/unit_test/inputs/get.json.exp b/plugins/redis/unit_test/inputs/get.json.exp new file mode 100644 index 0000000000..d95c560f4c --- /dev/null +++ b/plugins/redis/unit_test/inputs/get.json.exp @@ -0,0 +1,3 @@ +{ + "key": "user:1234" +} diff --git a/plugins/redis/unit_test/inputs/hash_get.json.exp b/plugins/redis/unit_test/inputs/hash_get.json.exp new file mode 100644 index 0000000000..d95c560f4c --- /dev/null +++ b/plugins/redis/unit_test/inputs/hash_get.json.exp @@ -0,0 +1,3 @@ +{ + "key": "user:1234" +} diff --git a/plugins/redis/unit_test/inputs/hash_set.json.exp b/plugins/redis/unit_test/inputs/hash_set.json.exp new file mode 100644 index 0000000000..5a769508ce --- /dev/null +++ b/plugins/redis/unit_test/inputs/hash_set.json.exp @@ -0,0 +1,8 @@ +{ + "key": "user:1234", + "values": { + "age": "30", + "email": "johndoe@example.com", + "name": "John Doe" + } +} diff --git a/plugins/redis/unit_test/inputs/hincrby.json.exp b/plugins/redis/unit_test/inputs/hincrby.json.exp new file mode 100644 index 0000000000..4f98d0c141 --- /dev/null +++ b/plugins/redis/unit_test/inputs/hincrby.json.exp @@ -0,0 +1,5 @@ +{ + "field": "login_count", + "key": "user:profile:123", + "value": 0 +} diff --git a/plugins/redis/unit_test/inputs/hmget.json.exp b/plugins/redis/unit_test/inputs/hmget.json.exp new file mode 100644 index 0000000000..7e027a21f9 --- /dev/null +++ b/plugins/redis/unit_test/inputs/hmget.json.exp @@ -0,0 +1,8 @@ +{ + "fields": [ + "age", + "name" + ], + "get_all": false, + "key": "user:4567" +} diff --git a/plugins/redis/unit_test/inputs/hmset.json.exp b/plugins/redis/unit_test/inputs/hmset.json.exp new file mode 100644 index 0000000000..4650f899ee --- /dev/null +++ b/plugins/redis/unit_test/inputs/hmset.json.exp @@ -0,0 +1,8 @@ +{ + "key": "user:4567", + "values": { + "age": "30", + "email": "johndoe@example.com", + "name": "John Doe" + } +} diff --git a/plugins/redis/unit_test/inputs/keys.json.exp b/plugins/redis/unit_test/inputs/keys.json.exp new file mode 100644 index 0000000000..d9671e73b5 --- /dev/null +++ b/plugins/redis/unit_test/inputs/keys.json.exp @@ -0,0 +1,3 @@ +{ + "pattern": "example:*:session" +} diff --git a/plugins/redis/unit_test/inputs/list_get.json.exp b/plugins/redis/unit_test/inputs/list_get.json.exp new file mode 100644 index 0000000000..5e97aea615 --- /dev/null +++ b/plugins/redis/unit_test/inputs/list_get.json.exp @@ -0,0 +1,4 @@ +{ + "key": "user:4567", + "count": 1000 +} diff --git a/plugins/redis/unit_test/inputs/list_push.json.exp b/plugins/redis/unit_test/inputs/list_push.json.exp new file mode 100644 index 0000000000..b4c83d6626 --- /dev/null +++ b/plugins/redis/unit_test/inputs/list_push.json.exp @@ -0,0 +1,4 @@ +{ + "key": "user:task_list:123", + "value": "Complete monthly report" +} diff --git a/plugins/redis/unit_test/inputs/set.json.exp b/plugins/redis/unit_test/inputs/set.json.exp new file mode 100644 index 0000000000..e782796735 --- /dev/null +++ b/plugins/redis/unit_test/inputs/set.json.exp @@ -0,0 +1,5 @@ +{ + "key": "example:1234:session", + "expire": 10, + "value": "active" +} diff --git a/plugins/redis/unit_test/test_delete.py b/plugins/redis/unit_test/test_delete.py new file mode 100644 index 0000000000..015794d2ab --- /dev/null +++ b/plugins/redis/unit_test/test_delete.py @@ -0,0 +1,29 @@ +import os +import sys + +sys.path.append(os.path.abspath("../")) + +from util import Util +from unittest import TestCase +from unittest.mock import MagicMock, patch +from jsonschema import validate +from komand_redis.actions.delete import Delete + + +class TestDelete(TestCase): + def setUp(self) -> None: + self.action = None + + @patch("redis.StrictRedis", return_value=Util.mock_redis()) + def mocked_connector(mocked_redis: MagicMock) -> None: + self.action = Util.default_connector(Delete()) + + mocked_connector() + + def test_delete(self): + input_param = Util.load_json("inputs/delete.json.exp") + expect = Util.load_json("expected/delete_exp.json.exp") + actual = self.action.run(input_param) + validate(input_param, self.action.input.schema) + self.assertEqual(expect, actual) + validate(actual, self.action.output.schema) diff --git a/plugins/redis/unit_test/test_get.py b/plugins/redis/unit_test/test_get.py new file mode 100644 index 0000000000..9606969cc6 --- /dev/null +++ b/plugins/redis/unit_test/test_get.py @@ -0,0 +1,29 @@ +import os +import sys + +sys.path.append(os.path.abspath("../")) + +from util import Util +from unittest import TestCase +from unittest.mock import MagicMock, patch +from jsonschema import validate +from komand_redis.actions.get import Get + + +class TestGet(TestCase): + def setUp(self) -> None: + self.action = None + + @patch("redis.StrictRedis", return_value=Util.mock_redis()) + def mocked_connector(mocked_redis: MagicMock) -> None: + self.action = Util.default_connector(Get()) + + mocked_connector() + + def test_get(self): + input_param = Util.load_json("inputs/get.json.exp") + expect = Util.load_json("expected/get_exp.json.exp") + actual = self.action.run(input_param) + validate(input_param, self.action.input.schema) + self.assertEqual(expect, actual) + validate(actual, self.action.output.schema) diff --git a/plugins/redis/unit_test/test_hash_get.py b/plugins/redis/unit_test/test_hash_get.py new file mode 100644 index 0000000000..a03dbbf0a0 --- /dev/null +++ b/plugins/redis/unit_test/test_hash_get.py @@ -0,0 +1,29 @@ +import os +import sys + +sys.path.append(os.path.abspath("../")) + +from util import Util +from unittest import TestCase +from unittest.mock import MagicMock, patch +from jsonschema import validate +from komand_redis.actions.hash_get import HashGet + + +class TestHashGet(TestCase): + def setUp(self) -> None: + self.action = None + + @patch("redis.StrictRedis", return_value=Util.mock_redis()) + def mocked_connector(mocked_redis: MagicMock) -> None: + self.action = Util.default_connector(HashGet()) + + mocked_connector() + + def test_hash_get(self): + input_param = Util.load_json("inputs/hash_get.json.exp") + expect = Util.load_json("expected/hash_get_exp.json.exp") + actual = self.action.run(input_param) + validate(input_param, self.action.input.schema) + self.assertEqual(expect, actual) + validate(actual, self.action.output.schema) diff --git a/plugins/redis/unit_test/test_hash_set.py b/plugins/redis/unit_test/test_hash_set.py new file mode 100644 index 0000000000..a824fd7215 --- /dev/null +++ b/plugins/redis/unit_test/test_hash_set.py @@ -0,0 +1,29 @@ +import os +import sys + +sys.path.append(os.path.abspath("../")) + +from util import Util +from unittest import TestCase +from unittest.mock import MagicMock, patch +from jsonschema import validate +from komand_redis.actions.hash_set import HashSet + + +class TestHashSet(TestCase): + def setUp(self) -> None: + self.action = None + + @patch("redis.StrictRedis", return_value=Util.mock_redis()) + def mocked_connector(mocked_redis: MagicMock) -> None: + self.action = Util.default_connector(HashSet()) + + mocked_connector() + + def test_hash_set(self): + input_param = Util.load_json("inputs/hash_set.json.exp") + expect = Util.load_json("expected/hash_set_exp.json.exp") + actual = self.action.run(input_param) + validate(input_param, self.action.input.schema) + self.assertEqual(expect, actual) + validate(actual, self.action.output.schema) diff --git a/plugins/redis/unit_test/test_hincrby.py b/plugins/redis/unit_test/test_hincrby.py new file mode 100644 index 0000000000..67643637ed --- /dev/null +++ b/plugins/redis/unit_test/test_hincrby.py @@ -0,0 +1,29 @@ +import os +import sys + +sys.path.append(os.path.abspath("../")) + +from util import Util +from unittest import TestCase +from unittest.mock import MagicMock, patch +from jsonschema import validate +from komand_redis.actions.hincrby import Hincrby + + +class TestHincrby(TestCase): + def setUp(self) -> None: + self.action = None + + @patch("redis.StrictRedis", return_value=Util.mock_redis()) + def mocked_connector(mocked_redis: MagicMock) -> None: + self.action = Util.default_connector(Hincrby()) + + mocked_connector() + + def test_hincrby(self): + input_param = Util.load_json("inputs/hincrby.json.exp") + expect = Util.load_json("expected/hincrby_exp.json.exp") + actual = self.action.run(input_param) + validate(input_param, self.action.input.schema) + self.assertEqual(expect, actual) + validate(actual, self.action.output.schema) diff --git a/plugins/redis/unit_test/test_hmget.py b/plugins/redis/unit_test/test_hmget.py new file mode 100644 index 0000000000..02d5f025d5 --- /dev/null +++ b/plugins/redis/unit_test/test_hmget.py @@ -0,0 +1,29 @@ +import os +import sys + +sys.path.append(os.path.abspath("../")) + +from util import Util +from unittest import TestCase +from unittest.mock import MagicMock, patch +from jsonschema import validate +from komand_redis.actions.hmget import Hmget + + +class TestHmget(TestCase): + def setUp(self) -> None: + self.action = None + + @patch("redis.StrictRedis", return_value=Util.mock_redis()) + def mocked_connector(mocked_redis: MagicMock) -> None: + self.action = Util.default_connector(Hmget()) + + mocked_connector() + + def test_hmget(self): + input_param = Util.load_json("inputs/hmget.json.exp") + expect = Util.load_json("expected/hmget_exp.json.exp") + actual = self.action.run(input_param) + validate(input_param, self.action.input.schema) + self.assertEqual(expect, actual) + validate(actual, self.action.output.schema) diff --git a/plugins/redis/unit_test/test_hmset.py b/plugins/redis/unit_test/test_hmset.py new file mode 100644 index 0000000000..176f65de05 --- /dev/null +++ b/plugins/redis/unit_test/test_hmset.py @@ -0,0 +1,29 @@ +import os +import sys + +sys.path.append(os.path.abspath("../")) + +from util import Util +from unittest import TestCase +from unittest.mock import MagicMock, patch +from jsonschema import validate +from komand_redis.actions.hmset import Hmset + + +class TestHmset(TestCase): + def setUp(self) -> None: + self.action = None + + @patch("redis.StrictRedis", return_value=Util.mock_redis()) + def mocked_connector(mocked_redis: MagicMock) -> None: + self.action = Util.default_connector(Hmset()) + + mocked_connector() + + def test_hmset(self): + input_param = Util.load_json("inputs/hmset.json.exp") + expect = Util.load_json("expected/hmset_exp.json.exp") + actual = self.action.run(input_param) + validate(input_param, self.action.input.schema) + self.assertEqual(expect, actual) + validate(actual, self.action.output.schema) diff --git a/plugins/redis/unit_test/test_keys.py b/plugins/redis/unit_test/test_keys.py new file mode 100644 index 0000000000..d935878679 --- /dev/null +++ b/plugins/redis/unit_test/test_keys.py @@ -0,0 +1,29 @@ +import os +import sys + +sys.path.append(os.path.abspath("../")) + +from util import Util +from unittest import TestCase +from unittest.mock import MagicMock, patch +from jsonschema import validate +from komand_redis.actions.keys import Keys + + +class TestKeys(TestCase): + def setUp(self) -> None: + self.action = None + + @patch("redis.StrictRedis", return_value=Util.mock_redis()) + def mocked_connector(mocked_redis: MagicMock) -> None: + self.action = Util.default_connector(Keys()) + + mocked_connector() + + def test_keys(self): + input_param = Util.load_json("inputs/keys.json.exp") + expect = Util.load_json("expected/keys_exp.json.exp") + actual = self.action.run(input_param) + validate(input_param, self.action.input.schema) + self.assertEqual(expect, actual) + validate(actual, self.action.output.schema) diff --git a/plugins/redis/unit_test/test_list_get.py b/plugins/redis/unit_test/test_list_get.py new file mode 100644 index 0000000000..d041b3c6ea --- /dev/null +++ b/plugins/redis/unit_test/test_list_get.py @@ -0,0 +1,29 @@ +import os +import sys + +sys.path.append(os.path.abspath("../")) + +from util import Util +from unittest import TestCase +from unittest.mock import MagicMock, patch +from jsonschema import validate +from komand_redis.actions.list_get import ListGet + + +class TestListGet(TestCase): + def setUp(self) -> None: + self.action = None + + @patch("redis.StrictRedis", return_value=Util.mock_redis()) + def mocked_connector(mocked_redis: MagicMock) -> None: + self.action = Util.default_connector(ListGet()) + + mocked_connector() + + def test_list_get(self): + input_param = Util.load_json("inputs/list_get.json.exp") + expect = Util.load_json("expected/list_get_exp.json.exp") + actual = self.action.run(input_param) + validate(input_param, self.action.input.schema) + self.assertEqual(expect, actual) + validate(actual, self.action.output.schema) diff --git a/plugins/redis/unit_test/test_list_push.py b/plugins/redis/unit_test/test_list_push.py new file mode 100644 index 0000000000..fcce9f7b80 --- /dev/null +++ b/plugins/redis/unit_test/test_list_push.py @@ -0,0 +1,29 @@ +import os +import sys + +sys.path.append(os.path.abspath("../")) + +from util import Util +from unittest import TestCase +from unittest.mock import MagicMock, patch +from jsonschema import validate +from komand_redis.actions.list_push import ListPush + + +class TestListPush(TestCase): + def setUp(self) -> None: + self.action = None + + @patch("redis.StrictRedis", return_value=Util.mock_redis()) + def mocked_connector(mocked_redis: MagicMock) -> None: + self.action = Util.default_connector(ListPush()) + + mocked_connector() + + def test_list_push(self): + input_param = Util.load_json("inputs/list_push.json.exp") + expect = Util.load_json("expected/list_push_exp.json.exp") + actual = self.action.run(input_param) + validate(input_param, self.action.input.schema) + self.assertEqual(expect, actual) + validate(actual, self.action.output.schema) diff --git a/plugins/redis/unit_test/test_set.py b/plugins/redis/unit_test/test_set.py new file mode 100644 index 0000000000..bc48fe4363 --- /dev/null +++ b/plugins/redis/unit_test/test_set.py @@ -0,0 +1,29 @@ +import os +import sys + +sys.path.append(os.path.abspath("../")) + +from util import Util +from unittest import TestCase +from unittest.mock import MagicMock, patch +from jsonschema import validate +from komand_redis.actions.set import Set + + +class TestSet(TestCase): + def setUp(self) -> None: + self.action = None + + @patch("redis.StrictRedis", return_value=Util.mock_redis()) + def mocked_connector(mocked_redis: MagicMock) -> None: + self.action = Util.default_connector(Set()) + + mocked_connector() + + def test_set(self): + input_param = Util.load_json("inputs/set.json.exp") + expect = Util.load_json("expected/set_exp.json.exp") + actual = self.action.run(input_param) + validate(input_param, self.action.input.schema) + self.assertEqual(expect, actual) + validate(actual, self.action.output.schema) diff --git a/plugins/redis/unit_test/util.py b/plugins/redis/unit_test/util.py new file mode 100644 index 0000000000..5dce4c4687 --- /dev/null +++ b/plugins/redis/unit_test/util.py @@ -0,0 +1,79 @@ +import json +import logging +import os.path +import sys + +sys.path.append(os.path.abspath("../")) +from komand_redis.connection import Connection + + +class Util: + @staticmethod + def default_connector(action): + default_connection = Connection() + default_connection.logger = logging.getLogger("connection logger") + params = {"host": "127.0.0.1", "port": 8080, "db": 0} + default_connection.connect(params) + action.connection = default_connection + action.logger = logging.getLogger("action logger") + return action + + @staticmethod + def load_json(filename): + with open((os.path.join(os.path.dirname(os.path.realpath(__file__)), filename))) as file: + return json.loads(file.read()) + + @staticmethod + def mock_redis(): + class MockResponse: + def __init__(self): + pass + + @staticmethod + def delete(key_name: str): + return 10 + + @staticmethod + def hmget(key_name: str, fields: list): + return [b"20", b"Test User"] + + @staticmethod + def hgetall(key_name: str): + return {b"age": b"20", b"email": b"Test@example.com", b"name": b"Test User"} + + @staticmethod + def hmset(key_name: str, key_name2: dict): + # Differentiate between hmset and hash_set action + if key_name == "user:4567": + return True + elif key_name == "user:1234": + return "OK" + + @staticmethod + def hincrby(key_name: str, key_name2: str, key_name3: str): + return 0 + + @staticmethod + def keys(key_name: str): + return {b"count": 2, b"keys": [b"count", b"keys"]} + + @staticmethod + def lrange(key_name: str, key_name2: int, key_name3: int): + return [] + + @staticmethod + def setex(key_name: str, key_name2: str, key_name3: str): + return "OK" + + @staticmethod + def rpush(key_name: str, *values: any): + return "OK" + + @staticmethod + def get(params: str): + if params == "test": + return True + if params == "key": + return "" + + return MockResponse()