Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
6ca4d52
MC-677 Fix search example input in help.md | Add exception message in…
r7-mgorny Aug 20, 2021
b393c6d
Merge branch 'master' into MC-677_fix_search_elasticsearch
jschipp-r7 Aug 23, 2021
a6ab601
Regen and fix docs
jonschipp Aug 24, 2021
59b27a3
Fix syntax in action.py
jonschipp Aug 24, 2021
bd4785c
Merge branch 'master' of github.com:rapid7/insightconnect-plugins int…
r7-mgorny Aug 24, 2021
b4147f6
[MC-677] Fix search example input in help.md | Add exception message …
r7-mgorny Aug 24, 2021
9949d1b
[MC-677] Fix search example input in help.md | Add exception message …
r7-mgorny Aug 24, 2021
928a7eb
[MC-677] Fix search example input in help.md | Add exception message …
r7-mgorny Aug 24, 2021
d7551db
Black reformat
mberezin-r7 Sep 3, 2021
b15b7dc
Merge branch 'master' of github.com:rapid7/insightconnect-plugins int…
mberezin-r7 Sep 3, 2021
d9a7000
Branch was auto-updated from base branch!
github-actions[bot] Sep 8, 2021
807d787
Branch was auto-updated from base branch!
github-actions[bot] Sep 9, 2021
b761db1
Branch was auto-updated from base branch!
github-actions[bot] Sep 9, 2021
624d885
Merge branch 'master' into MC-677_fix_search_elasticsearch
mrinehart-r7 Oct 5, 2021
d81bb4b
Merge branch 'master' of github.com:rapid7/insightconnect-plugins int…
r7-mgorny Nov 17, 2021
d9bccf1
[MC-677] Fix help | Fix unit test | Add unit test to check wrong quer…
r7-mgorny Nov 17, 2021
e8d5a7d
[MC-677] Fix help | Fix unit test | Add unit test to check wrong quer…
r7-mgorny Nov 17, 2021
9f66a2e
Update plugins/elasticsearch/komand_elasticsearch/actions/search_docu…
mberezin-r7 Nov 18, 2021
218c406
Update plugins/elasticsearch/unit_test/test_search_documents.py
mberezin-r7 Nov 18, 2021
a01cbe6
Update expected error string
mberezin-r7 Nov 18, 2021
87ca925
Black format.
mberezin-r7 Nov 18, 2021
0149241
Merge branch 'master' into MC-677_fix_search_elasticsearch
pmara-r7 Nov 24, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions plugins/elasticsearch/.CHECKSUM
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"spec": "97158ecd52a2a014e43fb674e57522b0",
"manifest": "d907862ad358f8e034ae1280a36a89eb",
"setup": "0db39b3c5dd64742886c68ffa85b2f0d",
"spec": "0f2fb6e85b18b309ca242eba660743d3",
"manifest": "020aba10f0b80dde8fd2137390da9c83",
"setup": "39e45f5964dce62ce798423bcef127c8",
"schemas": [
{
"identifier": "cluster_health/schema.py",
Expand Down
2 changes: 1 addition & 1 deletion plugins/elasticsearch/bin/komand_elasticsearch
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ from sys import argv

Name = "Elasticsearch"
Vendor = "rapid7"
Version = "3.0.1"
Version = "3.0.2"
Description = "Distributed Real-Time Search and Analytics Engine"


Expand Down
43 changes: 17 additions & 26 deletions plugins/elasticsearch/help.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ The connection configuration accepts the following parameters:
|----|----|-------|--------|-----------|----|-------|
|credentials|credential_username_password|None|True|Basic Auth username and password|None|{"username":"user1", "password":"mypassword"}|
|ssl_verify|boolean|True|False|The server's TLS/SSL certificate will be verified before a connection can be established|None|True|
|url|string|None|True|Elasticsearch URL|None|https://example.com|
|url|string|None|True|Elasticsearch URL|None|https://www.example.com:9243|
|use_authentication|boolean|True|True|If the Elasticsearch host does not use authentication set this value to false|None|True|

Example input:

```
{
"credentials": {
"username":"user1",
"password":"mypassword"
},
"username": "user1",
"password": "mypassword"
},
"ssl_verify": true,
"url": "https://www.example.com:9243",
"use_authentication": true
Expand Down Expand Up @@ -165,7 +165,7 @@ This action is used to search for documents.
|Name|Type|Default|Required|Description|Enum|Example|
|----|----|-------|--------|-----------|----|-------|
|index|string|None|True|Document Index|None|shakespeare|
|query|object|None|False|JSON Query DSL|None|{"query": {"match": {"line_number": {"query": "1.1.1"}}}}|
|query|object|None|False|JSON Query DSL|None|{"match": {"line_number": {"query": "1.1.1"}}}|
|routing|string|None|False|Optional Shards to Search|None|user1|
|type|string|None|False|Document Type|None|doc|

Expand All @@ -175,17 +175,12 @@ Example input:
{
"index": "shakespeare",
"query": {
"query":
{
"match":
{
"line_number":
{
"query": "1.1.1"
}
}
"match": {
"line_number": {
"query": "1.1.1"
}
},
}
},
"routing": "user1",
"type": "doc"
}
Expand Down Expand Up @@ -316,7 +311,7 @@ This trigger is used to poll for new documents given a query.
|----|----|-------|--------|-----------|----|-------|
|frequency|integer|60|False|Poll frequency in seconds|None|60|
|index|string|None|True|Document Index|None|bank|
|query|object|None|False|JSON Query DSL|None|{"query": {"match": {"line_number": {"query": "1.1.1"}}}}|
|query|object|None|False|JSON Query DSL|None|{"match": {"line_number": {"query": "1.1.1"}}}|
|routing|string|None|False|Optional Shards to Search|None|account|
|type|string|None|False|Document Type|None|doc|

Expand All @@ -327,17 +322,12 @@ Example input:
"frequency": 60,
"index": "bank",
"query": {
"query":
{
"match":
{
"line_number":
{
"query": "1.1.1"
}
}
"match": {
"line_number": {
"query": "1.1.1"
}
},
}
},
"routing": "account",
"type": "doc"
}
Expand Down Expand Up @@ -384,6 +374,7 @@ _This plugin does not contain any troubleshooting information._

# Version History

* 3.0.2 - Fix search example input in help.md | Add exception message in search action
* 3.0.1 - Fix issue where Search Documents and Update Documents action returned no results if optional `routing` field was not provided | Update Index Documents action to handle query parameters correctly
* 3.0.0 - Update to use the `insightconnect-python-3-38-plugin:4` Docker image | Improve error handling | Add `Plugin Exception` | Add `Connection Test` | Add `timeout-decorator` in requirements | Code refactor | Remove input Type from Index Document, Update Document, Search Documents actions and Search Documents trigger | Change inputs name in actions and trigger to not start with `_` | Add `USER nobody` in Dockerfile | Add `api6.py` file for other Elasticsearch version | Add pagination | Add SSL verify
* 2.0.5 - Updated example inputs and outputs for all the actions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import insightconnect_plugin_runtime
from .schema import SearchDocumentsInput, SearchDocumentsOutput, Input, Output, Component
from insightconnect_plugin_runtime.exceptions import PluginException

# Custom imports below

Expand All @@ -15,7 +16,15 @@ def __init__(self):

def run(self, params={}):
index = params.get(Input.INDEX)
query = params.get(Input.QUERY)
query = params.get(Input.QUERY, {})

if isinstance(query, dict) and query.get("query"):
raise PluginException(
cause="Wrong input query format",
assistance="Old query style detected during input. The input shouldn't contain {'query': {'query': ...}}. "
"Please refer to the help.md for more details or to the Elasticsearch API documentation: "
"https://www.elastic.co/guide/en/elasticsearch/reference/current/query-filter-context.html#query-filter-context-ex",
)

results = self.connection.client.search_documents(index, query, params.get(Input.ROUTING))

Expand Down
6 changes: 3 additions & 3 deletions plugins/elasticsearch/plugin.spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ products: [insightconnect]
name: elasticsearch
title: Elasticsearch
description: Distributed Real-Time Search and Analytics Engine
version: 3.0.1
version: 3.0.2
supported_versions: ["7.8.1", "6.0.0"]
vendor: rapid7
support: community
Expand Down Expand Up @@ -391,7 +391,7 @@ actions:
type: object
description: JSON Query DSL
required: false
example: '{"query": {"match": {"line_number": {"query": "1.1.1"}}}}'
example: '{"match": {"line_number": {"query": "1.1.1"}}}'
output:
took:
title: Took
Expand Down Expand Up @@ -448,7 +448,7 @@ triggers:
type: object
description: JSON Query DSL
required: false
example: '{"query": {"match": {"line_number": {"query": "1.1.1"}}}}'
example: '{"match": {"line_number": {"query": "1.1.1"}}}'
output:
hits:
title: Hits
Expand Down
2 changes: 1 addition & 1 deletion plugins/elasticsearch/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


setup(name="elasticsearch-rapid7-plugin",
version="3.0.1",
version="3.0.2",
description="Distributed Real-Time Search and Analytics Engine",
author="rapid7",
author_email="",
Expand Down
31 changes: 21 additions & 10 deletions plugins/elasticsearch/unit_test/test_search_documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,33 +64,31 @@ def setUpClass(cls, mock_request) -> None:

@patch("requests.request", side_effect=Util.mocked_requests_get)
def test_search_documents(self, mock_request):
actual = self.action.run(
{Input.INDEX: "search", Input.QUERY: {"query": {"match_all": {}}}, Input.ROUTING: None}
)
actual = self.action.run({Input.INDEX: "search", Input.QUERY: {"match_all": {}}, Input.ROUTING: None})
self.assertEqual(actual, self.expected)

@patch("requests.request", side_effect=Util.mocked_requests_get)
def test_search_documents_with_route(self, mock_request):
actual = self.action.run(
{Input.INDEX: "search-with-route", Input.QUERY: {"query": {"match_all": {}}}, Input.ROUTING: "test-route"}
{Input.INDEX: "search-with-route", Input.QUERY: {"match_all": {}}, Input.ROUTING: "test-route"}
)
self.assertEqual(actual, self.expected_with_route)

@patch("requests.request", side_effect=Util.mocked_requests_get)
def test_search_documents_without_route(self, mock_request):
actual = self.action.run({Input.INDEX: "search-without-route", Input.QUERY: {"query": {"match_all": {}}}})
actual = self.action.run({Input.INDEX: "search-without-route", Input.QUERY: {"match_all": {}}})
self.assertEqual(actual, self.expected)

@patch("requests.request", side_effect=Util.mocked_requests_get)
def test_search_documents_with_route_none(self, mock_request):
actual = self.action.run(
{Input.INDEX: "search-without-route", Input.QUERY: {"query": {"match_all": {}}}, Input.ROUTING: None}
{Input.INDEX: "search-without-route", Input.QUERY: {"match_all": {}}, Input.ROUTING: None}
)
self.assertEqual(actual, self.expected)

@patch("requests.request", side_effect=Util.mocked_requests_get)
def test_search_documents_empty(self, mock_request):
actual = self.action.run({Input.INDEX: "empty", Input.QUERY: {"query": {"match_all": {}}}, Input.ROUTING: None})
actual = self.action.run({Input.INDEX: "empty", Input.QUERY: {"match_all": {}}, Input.ROUTING: None})

self.assertEqual(
actual,
Expand All @@ -104,9 +102,7 @@ def test_search_documents_empty(self, mock_request):

@patch("requests.request", side_effect=Util.mocked_requests_get)
def test_search_documents_wrong_object(self, mock_request):
actual = self.action.run(
{Input.INDEX: "wrong_object", Input.QUERY: {"query": {"match_all": {}}}, Input.ROUTING: None}
)
actual = self.action.run({Input.INDEX: "wrong_object", Input.QUERY: {"match_all": {}}, Input.ROUTING: None})

self.assertEqual(
{
Expand All @@ -121,3 +117,18 @@ def test_search_documents_wrong_object(self, mock_request):
},
actual,
)

@patch("requests.request", side_effect=Util.mocked_requests_get)
def test_index_document_with_empty_response(self, mock_request):
with self.assertRaises(PluginException) as error:
self.action.run(
{Input.INDEX: "wrong_object", Input.QUERY: {"query": {"match_all": {}}}, Input.ROUTING: None}
)

self.assertEqual(error.exception.cause, "Wrong input query format")
self.assertEqual(
error.exception.assistance,
"Old query style detected during input. The input shouldn't contain {'query': {'query': ...}}. "
"Please refer to the help.md for more details or to the Elasticsearch API documentation: "
"https://www.elastic.co/guide/en/elasticsearch/reference/current/query-filter-context.html#query-filter-context-ex",
)