forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Connector API] Implement _features endpoint (elastic#109248)
- Loading branch information
Showing
13 changed files
with
552 additions
and
2 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
rest-api-spec/src/main/resources/rest-api-spec/api/connector.update_features.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"connector.update_features": { | ||
"documentation": { | ||
"url": "https://www.elastic.co/guide/en/elasticsearch/reference/master/update-connector-features-api.html", | ||
"description": "Updates the connector features in the connector document." | ||
}, | ||
"stability": "experimental", | ||
"visibility": "public", | ||
"headers": { | ||
"accept": [ | ||
"application/json" | ||
], | ||
"content_type": [ | ||
"application/json" | ||
] | ||
}, | ||
"url": { | ||
"paths": [ | ||
{ | ||
"path": "/_connector/{connector_id}/_features", | ||
"methods": [ | ||
"PUT" | ||
], | ||
"parts": { | ||
"connector_id": { | ||
"type": "string", | ||
"description": "The unique identifier of the connector to be updated." | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
"body": { | ||
"description": "An object containing the connector's features definition.", | ||
"required": true | ||
} | ||
} | ||
} |
108 changes: 108 additions & 0 deletions
108
...stTest/resources/rest-api-spec/test/entsearch/connector/170_connector_update_features.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
setup: | ||
- requires: | ||
cluster_features: ["gte_v8.15.0"] | ||
reason: Introduced in 8.15.0 | ||
|
||
- do: | ||
connector.put: | ||
connector_id: test-connector | ||
body: | ||
index_name: search-1-test | ||
name: my-connector | ||
language: pl | ||
is_native: false | ||
service_type: super-connector | ||
|
||
--- | ||
"Update Connector Features": | ||
- do: | ||
connector.update_features: | ||
connector_id: test-connector | ||
body: | ||
features: | ||
document_level_security: { enabled: true } | ||
native_connector_api_keys: { enabled: true } | ||
incremental_sync: { enabled: false } | ||
sync_rules: | ||
basic: { enabled: true } | ||
advanced: { enabled: false } | ||
|
||
|
||
- match: { result: updated } | ||
|
||
- do: | ||
connector.get: | ||
connector_id: test-connector | ||
|
||
- match: { features.document_level_security.enabled: true } | ||
- match: { features.native_connector_api_keys.enabled: true } | ||
- match: { features.incremental_sync.enabled: false } | ||
- match: { features.sync_rules.basic.enabled: true } | ||
- match: { features.sync_rules.advanced.enabled: false } | ||
|
||
--- | ||
"Update Connector Features - Partial Update": | ||
- do: | ||
connector.update_features: | ||
connector_id: test-connector | ||
body: | ||
features: | ||
document_level_security: { enabled: true } | ||
|
||
|
||
- match: { result: updated } | ||
|
||
- do: | ||
connector.get: | ||
connector_id: test-connector | ||
|
||
- match: { features.document_level_security.enabled: true } | ||
|
||
|
||
- do: | ||
connector.update_features: | ||
connector_id: test-connector | ||
body: | ||
features: | ||
native_connector_api_keys: { enabled: true } | ||
|
||
|
||
- match: { result: updated } | ||
|
||
- do: | ||
connector.get: | ||
connector_id: test-connector | ||
|
||
# Assert that existing feature remains unchanged | ||
- match: { features.document_level_security.enabled: true } | ||
- match: { features.native_connector_api_keys.enabled: true } | ||
|
||
--- | ||
"Update Connector Features - 404 when connector doesn't exist": | ||
- do: | ||
catch: "missing" | ||
connector.update_features: | ||
connector_id: test-non-existent-connector | ||
body: | ||
features: | ||
native_connector_api_keys: { enabled: true } | ||
|
||
--- | ||
"Update Connector Features - 400 status code when connector_id is empty": | ||
- do: | ||
catch: "bad_request" | ||
connector.update_features: | ||
connector_id: "" | ||
body: | ||
features: | ||
native_connector_api_keys: { enabled: true } | ||
|
||
--- | ||
"Update Connector Features - 400 status code when payload unknown": | ||
- do: | ||
catch: "bad_request" | ||
connector.update_features: | ||
connector_id: test-connector | ||
body: | ||
featuresss: | ||
not_a_feature: 12423 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...g/elasticsearch/xpack/application/connector/action/RestUpdateConnectorFeaturesAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.application.connector.action; | ||
|
||
import org.elasticsearch.client.internal.node.NodeClient; | ||
import org.elasticsearch.rest.BaseRestHandler; | ||
import org.elasticsearch.rest.RestRequest; | ||
import org.elasticsearch.rest.Scope; | ||
import org.elasticsearch.rest.ServerlessScope; | ||
import org.elasticsearch.rest.action.RestToXContentListener; | ||
import org.elasticsearch.xpack.application.EnterpriseSearch; | ||
|
||
import java.util.List; | ||
|
||
import static org.elasticsearch.rest.RestRequest.Method.PUT; | ||
|
||
@ServerlessScope(Scope.PUBLIC) | ||
public class RestUpdateConnectorFeaturesAction extends BaseRestHandler { | ||
|
||
@Override | ||
public String getName() { | ||
return "connector_update_features_action"; | ||
} | ||
|
||
@Override | ||
public List<Route> routes() { | ||
return List.of(new Route(PUT, "/" + EnterpriseSearch.CONNECTOR_API_ENDPOINT + "/{connector_id}/_features")); | ||
} | ||
|
||
@Override | ||
protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) { | ||
UpdateConnectorFeaturesAction.Request request = UpdateConnectorFeaturesAction.Request.fromXContentBytes( | ||
restRequest.param("connector_id"), | ||
restRequest.content(), | ||
restRequest.getXContentType() | ||
); | ||
return channel -> client.execute( | ||
UpdateConnectorFeaturesAction.INSTANCE, | ||
request, | ||
new RestToXContentListener<>(channel, ConnectorUpdateActionResponse::status) | ||
); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...sticsearch/xpack/application/connector/action/TransportUpdateConnectorFeaturesAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.application.connector.action; | ||
|
||
import org.elasticsearch.action.ActionListener; | ||
import org.elasticsearch.action.support.ActionFilters; | ||
import org.elasticsearch.action.support.HandledTransportAction; | ||
import org.elasticsearch.client.internal.Client; | ||
import org.elasticsearch.common.inject.Inject; | ||
import org.elasticsearch.common.util.concurrent.EsExecutors; | ||
import org.elasticsearch.tasks.Task; | ||
import org.elasticsearch.transport.TransportService; | ||
import org.elasticsearch.xpack.application.connector.ConnectorIndexService; | ||
|
||
public class TransportUpdateConnectorFeaturesAction extends HandledTransportAction< | ||
UpdateConnectorFeaturesAction.Request, | ||
ConnectorUpdateActionResponse> { | ||
|
||
protected final ConnectorIndexService connectorIndexService; | ||
|
||
@Inject | ||
public TransportUpdateConnectorFeaturesAction(TransportService transportService, ActionFilters actionFilters, Client client) { | ||
super( | ||
UpdateConnectorFeaturesAction.NAME, | ||
transportService, | ||
actionFilters, | ||
UpdateConnectorFeaturesAction.Request::new, | ||
EsExecutors.DIRECT_EXECUTOR_SERVICE | ||
); | ||
this.connectorIndexService = new ConnectorIndexService(client); | ||
} | ||
|
||
@Override | ||
protected void doExecute( | ||
Task task, | ||
UpdateConnectorFeaturesAction.Request request, | ||
ActionListener<ConnectorUpdateActionResponse> listener | ||
) { | ||
connectorIndexService.updateConnectorFeatures( | ||
request.getConnectorId(), | ||
request.getFeatures(), | ||
listener.map(r -> new ConnectorUpdateActionResponse(r.getResult())) | ||
); | ||
} | ||
} |
Oops, something went wrong.