diff --git a/plugins/OpenSearch/v1/README.md b/plugins/OpenSearch/v1/README.md new file mode 100644 index 0000000..2a590c5 --- /dev/null +++ b/plugins/OpenSearch/v1/README.md @@ -0,0 +1,6 @@ +## Overview + +Query OpenSearch databases using DSL. This plugin is primarily a wrapper around the `_search` API endpoint that allows for a range of queries. + +See the [OpenSearch API docs](https://docs.opensearch.org/latest/api-reference/search-apis/search/) for more information. + diff --git a/plugins/OpenSearch/v1/dataStreams/indices.json b/plugins/OpenSearch/v1/dataStreams/indices.json new file mode 100644 index 0000000..bc2a253 --- /dev/null +++ b/plugins/OpenSearch/v1/dataStreams/indices.json @@ -0,0 +1,28 @@ +{ + "name": "indices", + "displayName": "Indices", + "baseDataSourceName": "httpRequestUnscoped", + "config": { + "httpMethod": "get", + "pagingConfig_mode": "none", + "pagingConfig_offset_base": 1, + "expandInnerObjects": true, + "endpointPath": "_cat/indices", + "pathToData": "", + "getArgs": [], + "headers": [] + }, + "timeframes": false, + "matches": "none", + "visibility": { + "type": "hidden" + }, + "metadata": [ + { + "name": "index", + "shape": "string", + "displayName": "Index", + "role": "value" + } + ] +} \ No newline at end of file diff --git a/plugins/OpenSearch/v1/dataStreams/scripts/search.js b/plugins/OpenSearch/v1/dataStreams/scripts/search.js new file mode 100644 index 0000000..cc8c056 --- /dev/null +++ b/plugins/OpenSearch/v1/dataStreams/scripts/search.js @@ -0,0 +1,29 @@ +if (data.aggregations && Object.keys(data.aggregations).length > 0) { + + const agg = data.aggregations[Object.keys(data.aggregations).at(-1)]; // last aggregation to support pipelining + + if(agg.buckets) { + + result = agg.buckets; + + } else if (agg.values) { + + result = [agg.values]; + + } else if (agg.value) { + + result = [{ + value: agg.value + }]; + + } else { + + result = [agg]; + + } + +} else { + + result = data.hits.hits.map(hit => hit._source); + +} \ No newline at end of file diff --git a/plugins/OpenSearch/v1/dataStreams/search.json b/plugins/OpenSearch/v1/dataStreams/search.json new file mode 100644 index 0000000..c1dd8e3 --- /dev/null +++ b/plugins/OpenSearch/v1/dataStreams/search.json @@ -0,0 +1,50 @@ +{ + "name": "search", + "displayName": "Search", + "baseDataSourceName": "httpRequestUnscoped", + "matches": "none", + "manualConfigApply": true, + "config": { + "httpMethod": "post", + "pagingConfig_mode": "none", + "pagingConfig_offset_base": 1, + "expandInnerObjects": true, + "endpointPath": "{{index}}/_search", + "postRequestScript": "search.js", + "getArgs": [], + "headers": [], + "postBody": "{{query}}" + }, + "ui": [ + { + "name": "index", + "type": "autocomplete", + "label": "Index", + "validation": { + "required": true + }, + "placeholder": "Select index", + "isMulti": false, + "allowCustomValues": true, + "data": { + "source": "dataStream", + "dataStreamName": "indices" + } + }, + { + "name": "query", + "type": "json", + "defaultValue": { + "size": 100 + }, + "label": "Query body", + "help": "The Query DSL JSON. See [OpenSearch API docs](https://docs.opensearch.org/latest/api-reference/search-apis/search/#request-body).", + "validation": { + "required": true + } + } + ], + "supportsNoneTimeframe": true, + "requiresParameterTimeframe": true, + "defaultTimeframe": "none" +} \ No newline at end of file diff --git a/plugins/OpenSearch/v1/docs/setup.md b/plugins/OpenSearch/v1/docs/setup.md new file mode 100644 index 0000000..73ba1f4 --- /dev/null +++ b/plugins/OpenSearch/v1/docs/setup.md @@ -0,0 +1,21 @@ +# Configuration + +## Instance URL + +The base URL of your OpenSearch database. + +For example: +`https://:9200` + +Do *not* include the `/api` path. + +## Authentication + +The data source supports basic (username and password) or anonymous authentication. + +If using basic authentication, ensure the user only has read permissions. + +If using anonymous, ensure the endpoint is secured in some other form. + +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. + diff --git a/plugins/OpenSearch/v1/icon.svg b/plugins/OpenSearch/v1/icon.svg new file mode 100644 index 0000000..65bc2fe --- /dev/null +++ b/plugins/OpenSearch/v1/icon.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/plugins/OpenSearch/v1/metadata.json b/plugins/OpenSearch/v1/metadata.json new file mode 100644 index 0000000..95342bc --- /dev/null +++ b/plugins/OpenSearch/v1/metadata.json @@ -0,0 +1,45 @@ +{ + "name": "open-search", + "displayName": "OpenSearch", + "version": "1.0.3", + "author": { + "name": "SquaredUp Labs", + "type": "labs" + }, + "description": "Query OpenSearch databases using DSL.", + "category": "Database", + "type": "cloud", + "restrictedToPlatforms": [], + "importNotSupported": true, + "schemaVersion": "2.0", + "base": { + "plugin": "WebAPI", + "majorVersion": "1", + "config": { + "authMode": "{{authMode}}", + "basicAuthUsername": "{{basicAuthUsername}}", + "basicAuthPassword": "{{basicAuthPassword}}", + "queryArgs": [], + "headers": [ + { + "key": "Content-Type", + "value": "application/json" + } + ], + "baseUrl": "{{instanceUrl}}", + "ignoreCertificateErrors": "{{ignoreCertificateErrors}}" + } + }, + "links": [ + { + "category": "documentation", + "url": "https://github.com/squaredup/plugins/blob/main/plugins/OpenSearch/v1/docs/setup.md", + "label": "Help adding this plugin" + }, + { + "category": "source", + "url": "https://github.com/squaredup/plugins/tree/main/plugins/OpenSearch/v1", + "label": "Repository" + } + ] +} \ No newline at end of file diff --git a/plugins/OpenSearch/v1/ui.json b/plugins/OpenSearch/v1/ui.json new file mode 100644 index 0000000..8ec9c70 --- /dev/null +++ b/plugins/OpenSearch/v1/ui.json @@ -0,0 +1,58 @@ +[ + { + "type": "text", + "name": "instanceUrl", + "label": "Instance URL", + "validation": { "required": true }, + "placeholder": "Enter the OpenSearch URL" + }, + { + "name": "authMode", + "type": "radio", + "label": "Authentication", + "help": "**Basic:** Authenticate with username and password. \n**Anonymous access:** No authentication required", + "defaultValue": "basic", + "validation": { + "required": true + }, + "options": [ + { + "label": "Basic", + "value": "basic" + }, + { + "label": "Anonymous access", + "value": "none" + } + + ] + }, + { + "type": "fieldGroup", + "visible": { + "authMode": "basic" + }, + "fields": [ + { + "type": "text", + "name": "basicAuthUsername", + "label": "Username", + "validation": { "required": true }, + "placeholder": "Enter a username" + }, + { + "type": "password", + "name": "basicAuthPassword", + "label": "Password", + "validation": { "required": true }, + "placeholder": "Enter a password" + } + ] + }, + { + "type": "checkbox", + "name": "ignoreCertificateErrors", + "label": "Ignore certificate errors", + "help": "Ignore certificate errors when connecting to an OpenSearch instance with a self-signed certificate" + } +]