diff --git a/datasources/src/test/java/org/opensearch/sql/datasources/transport/TransportPatchDataSourceActionTest.java b/datasources/src/test/java/org/opensearch/sql/datasources/transport/TransportPatchDataSourceActionTest.java index d8fc2a8346..5e1e7df112 100644 --- a/datasources/src/test/java/org/opensearch/sql/datasources/transport/TransportPatchDataSourceActionTest.java +++ b/datasources/src/test/java/org/opensearch/sql/datasources/transport/TransportPatchDataSourceActionTest.java @@ -58,7 +58,7 @@ public void testDoExecute() { .onResponse(patchDataSourceActionResponseArgumentCaptor.capture()); PatchDataSourceActionResponse patchDataSourceActionResponse = patchDataSourceActionResponseArgumentCaptor.getValue(); - String responseAsJson = "\"Created DataSource with name test_datasource\""; + String responseAsJson = "\"Updated DataSource with name test_datasource\""; Assertions.assertEquals(responseAsJson, patchDataSourceActionResponse.getResult()); } diff --git a/docs/user/ppl/admin/datasources.rst b/docs/user/ppl/admin/datasources.rst index 3682153b9d..bf37cc196d 100644 --- a/docs/user/ppl/admin/datasources.rst +++ b/docs/user/ppl/admin/datasources.rst @@ -93,6 +93,17 @@ we can remove authorization and other details in case of security disabled domai "allowedRoles" : ["prometheus_access"] } +* Datasource modification PATCH API ("_plugins/_query/_datasources") :: + + PATCH https://localhost:9200/_plugins/_query/_datasources + content-type: application/json + Authorization: Basic {{username}} {{password}} + + { + "name" : "my_prometheus", + "allowedRoles" : ["all_access"] + } + * Datasource Read GET API("_plugins/_query/_datasources/{{dataSourceName}}" :: GET https://localhost:9200/_plugins/_query/_datasources/my_prometheus diff --git a/integ-test/src/test/java/org/opensearch/sql/datasource/DataSourceAPIsIT.java b/integ-test/src/test/java/org/opensearch/sql/datasource/DataSourceAPIsIT.java index c22bb83189..2799282f7b 100644 --- a/integ-test/src/test/java/org/opensearch/sql/datasource/DataSourceAPIsIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/datasource/DataSourceAPIsIT.java @@ -141,10 +141,10 @@ public void updateDataSourceAPITest() { Map updateDS = new HashMap<>(Map.of(NAME_FIELD, "update_prometheus", DESCRIPTION_FIELD, "test")); Request patchRequest = getPatchDataSourceRequest(updateDS); - Response patchResponse = client().performRequest(updateRequest); + Response patchResponse = client().performRequest(patchRequest); Assert.assertEquals(200, patchResponse.getStatusLine().getStatusCode()); String patchResponseString = getResponseBody(updateResponse); - Assert.assertEquals("\"Updated DataSource with name update_prometheus\"", updateResponseString); + Assert.assertEquals("\"Updated DataSource with name update_prometheus\"", patchResponseString); // Datasource is not immediately updated. so introducing a sleep of 2s. Thread.sleep(2000); @@ -152,11 +152,11 @@ public void updateDataSourceAPITest() { // get datasource to validate the modification. // get datasource Request getRequestAfterPatch = getFetchDataSourceRequest("update_prometheus"); - Response getResponseAfterPatch = client().performRequest(getRequest); - Assert.assertEquals(200, getResponse.getStatusLine().getStatusCode()); + Response getResponseAfterPatch = client().performRequest(getRequestAfterPatch); + Assert.assertEquals(200, getResponseAfterPatch.getStatusLine().getStatusCode()); String getResponseStringAfterPatch = getResponseBody(getResponse); DataSourceMetadata dataSourceMetadataAfterPatch = - new Gson().fromJson(getResponseString, DataSourceMetadata.class); + new Gson().fromJson(getResponseStringAfterPatch, DataSourceMetadata.class); Assert.assertEquals( "https://randomtest.com:9090", dataSourceMetadataAfterPatch.getProperties().get("prometheus.uri"));