Skip to content

Commit 1b2c817

Browse files
authored
Merge pull request #27 from squaredup/work/rb/opensearch
2 parents c46350b + 303e981 commit 1b2c817

8 files changed

Lines changed: 243 additions & 0 deletions

File tree

plugins/OpenSearch/v1/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## Overview
2+
3+
Query OpenSearch databases using DSL. This plugin is primarily a wrapper around the `_search` API endpoint that allows for a range of queries.
4+
5+
See the [OpenSearch API docs](https://docs.opensearch.org/latest/api-reference/search-apis/search/) for more information.
6+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "indices",
3+
"displayName": "Indices",
4+
"baseDataSourceName": "httpRequestUnscoped",
5+
"config": {
6+
"httpMethod": "get",
7+
"pagingConfig_mode": "none",
8+
"pagingConfig_offset_base": 1,
9+
"expandInnerObjects": true,
10+
"endpointPath": "_cat/indices",
11+
"pathToData": "",
12+
"getArgs": [],
13+
"headers": []
14+
},
15+
"timeframes": false,
16+
"matches": "none",
17+
"visibility": {
18+
"type": "hidden"
19+
},
20+
"metadata": [
21+
{
22+
"name": "index",
23+
"shape": "string",
24+
"displayName": "Index",
25+
"role": "value"
26+
}
27+
]
28+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
if (data.aggregations && Object.keys(data.aggregations).length > 0) {
2+
3+
const agg = data.aggregations[Object.keys(data.aggregations).at(-1)]; // last aggregation to support pipelining
4+
5+
if(agg.buckets) {
6+
7+
result = agg.buckets;
8+
9+
} else if (agg.values) {
10+
11+
result = [agg.values];
12+
13+
} else if (agg.value) {
14+
15+
result = [{
16+
value: agg.value
17+
}];
18+
19+
} else {
20+
21+
result = [agg];
22+
23+
}
24+
25+
} else {
26+
27+
result = data.hits.hits.map(hit => hit._source);
28+
29+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"name": "search",
3+
"displayName": "Search",
4+
"baseDataSourceName": "httpRequestUnscoped",
5+
"matches": "none",
6+
"manualConfigApply": true,
7+
"config": {
8+
"httpMethod": "post",
9+
"pagingConfig_mode": "none",
10+
"pagingConfig_offset_base": 1,
11+
"expandInnerObjects": true,
12+
"endpointPath": "{{index}}/_search",
13+
"postRequestScript": "search.js",
14+
"getArgs": [],
15+
"headers": [],
16+
"postBody": "{{query}}"
17+
},
18+
"ui": [
19+
{
20+
"name": "index",
21+
"type": "autocomplete",
22+
"label": "Index",
23+
"validation": {
24+
"required": true
25+
},
26+
"placeholder": "Select index",
27+
"isMulti": false,
28+
"allowCustomValues": true,
29+
"data": {
30+
"source": "dataStream",
31+
"dataStreamName": "indices"
32+
}
33+
},
34+
{
35+
"name": "query",
36+
"type": "json",
37+
"defaultValue": {
38+
"size": 100
39+
},
40+
"label": "Query body",
41+
"help": "The Query DSL JSON. See [OpenSearch API docs](https://docs.opensearch.org/latest/api-reference/search-apis/search/#request-body).",
42+
"validation": {
43+
"required": true
44+
}
45+
}
46+
],
47+
"supportsNoneTimeframe": true,
48+
"requiresParameterTimeframe": true,
49+
"defaultTimeframe": "none"
50+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Configuration
2+
3+
## Instance URL
4+
5+
The base URL of your OpenSearch database.
6+
7+
For example:
8+
`https://<your-opensearch-host>:9200`
9+
10+
Do *not* include the `/api` path.
11+
12+
## Authentication
13+
14+
The data source supports basic (username and password) or anonymous authentication.
15+
16+
If using basic authentication, ensure the user only has read permissions.
17+
18+
If using anonymous, ensure the endpoint is secured in some other form.
19+
20+
If you need to whitelist the IP addresses for SquaredUp these can be found on the [Data Security](https://docs.squaredup.com/reference/security/data-security) KB article.
21+

plugins/OpenSearch/v1/icon.svg

Lines changed: 6 additions & 0 deletions
Loading
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"name": "open-search",
3+
"displayName": "OpenSearch",
4+
"version": "1.0.3",
5+
"author": {
6+
"name": "SquaredUp Labs",
7+
"type": "labs"
8+
},
9+
"description": "Query OpenSearch databases using DSL.",
10+
"category": "Database",
11+
"type": "cloud",
12+
"restrictedToPlatforms": [],
13+
"importNotSupported": true,
14+
"schemaVersion": "2.0",
15+
"base": {
16+
"plugin": "WebAPI",
17+
"majorVersion": "1",
18+
"config": {
19+
"authMode": "{{authMode}}",
20+
"basicAuthUsername": "{{basicAuthUsername}}",
21+
"basicAuthPassword": "{{basicAuthPassword}}",
22+
"queryArgs": [],
23+
"headers": [
24+
{
25+
"key": "Content-Type",
26+
"value": "application/json"
27+
}
28+
],
29+
"baseUrl": "{{instanceUrl}}",
30+
"ignoreCertificateErrors": "{{ignoreCertificateErrors}}"
31+
}
32+
},
33+
"links": [
34+
{
35+
"category": "documentation",
36+
"url": "https://github.com/squaredup/plugins/blob/main/plugins/OpenSearch/v1/docs/setup.md",
37+
"label": "Help adding this plugin"
38+
},
39+
{
40+
"category": "source",
41+
"url": "https://github.com/squaredup/plugins/tree/main/plugins/OpenSearch/v1",
42+
"label": "Repository"
43+
}
44+
]
45+
}

plugins/OpenSearch/v1/ui.json

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
[
2+
{
3+
"type": "text",
4+
"name": "instanceUrl",
5+
"label": "Instance URL",
6+
"validation": { "required": true },
7+
"placeholder": "Enter the OpenSearch URL"
8+
},
9+
{
10+
"name": "authMode",
11+
"type": "radio",
12+
"label": "Authentication",
13+
"help": "**Basic:** Authenticate with username and password. \n**Anonymous access:** No authentication required",
14+
"defaultValue": "basic",
15+
"validation": {
16+
"required": true
17+
},
18+
"options": [
19+
{
20+
"label": "Basic",
21+
"value": "basic"
22+
},
23+
{
24+
"label": "Anonymous access",
25+
"value": "none"
26+
}
27+
28+
]
29+
},
30+
{
31+
"type": "fieldGroup",
32+
"visible": {
33+
"authMode": "basic"
34+
},
35+
"fields": [
36+
{
37+
"type": "text",
38+
"name": "basicAuthUsername",
39+
"label": "Username",
40+
"validation": { "required": true },
41+
"placeholder": "Enter a username"
42+
},
43+
{
44+
"type": "password",
45+
"name": "basicAuthPassword",
46+
"label": "Password",
47+
"validation": { "required": true },
48+
"placeholder": "Enter a password"
49+
}
50+
]
51+
},
52+
{
53+
"type": "checkbox",
54+
"name": "ignoreCertificateErrors",
55+
"label": "Ignore certificate errors",
56+
"help": "Ignore certificate errors when connecting to an OpenSearch instance with a self-signed certificate"
57+
}
58+
]

0 commit comments

Comments
 (0)