Remove lenient URL parameter parsing
This commit adapts x-plugins for a change in core Elasticsearch that removes lenient URL parameter parsing. Relates elastic/elasticsearch#3641 Original commit: elastic/x-pack-elasticsearch@cc0687f32c
This commit is contained in:
parent
ddae0694c9
commit
a0e1d44a44
|
@ -5,29 +5,22 @@
|
||||||
*/
|
*/
|
||||||
package org.elasticsearch.license;
|
package org.elasticsearch.license;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.elasticsearch.action.ActionRequest;
|
import org.elasticsearch.action.ActionRequest;
|
||||||
import org.elasticsearch.action.ActionResponse;
|
import org.elasticsearch.action.ActionResponse;
|
||||||
import org.elasticsearch.cluster.metadata.MetaData;
|
import org.elasticsearch.cluster.metadata.MetaData;
|
||||||
import org.elasticsearch.cluster.service.ClusterService;
|
|
||||||
import org.elasticsearch.common.inject.Module;
|
|
||||||
import org.elasticsearch.common.settings.Setting;
|
import org.elasticsearch.common.settings.Setting;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.env.Environment;
|
|
||||||
import org.elasticsearch.plugins.ActionPlugin;
|
import org.elasticsearch.plugins.ActionPlugin;
|
||||||
import org.elasticsearch.rest.RestHandler;
|
import org.elasticsearch.rest.RestHandler;
|
||||||
import org.elasticsearch.watcher.ResourceWatcherService;
|
|
||||||
import org.elasticsearch.xpack.support.clock.Clock;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import static java.util.Collections.emptyList;
|
import static java.util.Collections.emptyList;
|
||||||
import static org.elasticsearch.xpack.XPackPlugin.isTribeNode;
|
import static org.elasticsearch.xpack.XPackPlugin.isTribeNode;
|
||||||
import static org.elasticsearch.xpack.XPackPlugin.transportClientMode;
|
import static org.elasticsearch.xpack.XPackPlugin.transportClientMode;
|
||||||
|
|
||||||
|
|
||||||
public class Licensing implements ActionPlugin {
|
public class Licensing implements ActionPlugin {
|
||||||
|
|
||||||
public static final String NAME = "license";
|
public static final String NAME = "license";
|
||||||
|
@ -69,4 +62,5 @@ public class Licensing implements ActionPlugin {
|
||||||
// TODO convert this wildcard to a real setting
|
// TODO convert this wildcard to a real setting
|
||||||
return Collections.singletonList(Setting.groupSetting("license.", Setting.Property.NodeScope));
|
return Collections.singletonList(Setting.groupSetting("license.", Setting.Property.NodeScope));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,13 +7,14 @@ package org.elasticsearch.license;
|
||||||
|
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.rest.RestChannel;
|
|
||||||
import org.elasticsearch.rest.RestController;
|
import org.elasticsearch.rest.RestController;
|
||||||
import org.elasticsearch.rest.RestRequest;
|
import org.elasticsearch.rest.RestRequest;
|
||||||
import org.elasticsearch.rest.action.AcknowledgedRestListener;
|
import org.elasticsearch.rest.action.AcknowledgedRestListener;
|
||||||
import org.elasticsearch.xpack.XPackClient;
|
import org.elasticsearch.xpack.XPackClient;
|
||||||
import org.elasticsearch.xpack.rest.XPackRestHandler;
|
import org.elasticsearch.xpack.rest.XPackRestHandler;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.DELETE;
|
import static org.elasticsearch.rest.RestRequest.Method.DELETE;
|
||||||
|
|
||||||
public class RestDeleteLicenseAction extends XPackRestHandler {
|
public class RestDeleteLicenseAction extends XPackRestHandler {
|
||||||
|
@ -33,9 +34,10 @@ public class RestDeleteLicenseAction extends XPackRestHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleRequest(final RestRequest request, final RestChannel channel, final XPackClient client) {
|
public RestChannelConsumer doPrepareRequest(final RestRequest request, final XPackClient client) throws IOException {
|
||||||
client.es().admin().cluster().execute(DeleteLicenseAction.INSTANCE,
|
return channel -> client.es().admin().cluster().execute(DeleteLicenseAction.INSTANCE,
|
||||||
new DeleteLicenseRequest(),
|
new DeleteLicenseRequest(),
|
||||||
new AcknowledgedRestListener<>(channel));
|
new AcknowledgedRestListener<>(channel));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@ import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.xcontent.ToXContent;
|
import org.elasticsearch.common.xcontent.ToXContent;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.rest.BytesRestResponse;
|
import org.elasticsearch.rest.BytesRestResponse;
|
||||||
import org.elasticsearch.rest.RestChannel;
|
|
||||||
import org.elasticsearch.rest.RestController;
|
import org.elasticsearch.rest.RestController;
|
||||||
import org.elasticsearch.rest.RestRequest;
|
import org.elasticsearch.rest.RestRequest;
|
||||||
import org.elasticsearch.rest.RestResponse;
|
import org.elasticsearch.rest.RestResponse;
|
||||||
|
@ -18,6 +17,7 @@ import org.elasticsearch.rest.action.RestBuilderListener;
|
||||||
import org.elasticsearch.xpack.XPackClient;
|
import org.elasticsearch.xpack.XPackClient;
|
||||||
import org.elasticsearch.xpack.rest.XPackRestHandler;
|
import org.elasticsearch.xpack.rest.XPackRestHandler;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -48,14 +48,14 @@ public class RestGetLicenseAction extends XPackRestHandler {
|
||||||
* The licenses are sorted by latest issue_date
|
* The licenses are sorted by latest issue_date
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void handleRequest(final RestRequest request, final RestChannel channel, final XPackClient client) {
|
public RestChannelConsumer doPrepareRequest(final RestRequest request, final XPackClient client) throws IOException {
|
||||||
final Map<String, String> overrideParams = new HashMap<>(2);
|
final Map<String, String> overrideParams = new HashMap<>(2);
|
||||||
overrideParams.put(License.REST_VIEW_MODE, "true");
|
overrideParams.put(License.REST_VIEW_MODE, "true");
|
||||||
overrideParams.put(License.LICENSE_VERSION_MODE, String.valueOf(License.VERSION_CURRENT));
|
overrideParams.put(License.LICENSE_VERSION_MODE, String.valueOf(License.VERSION_CURRENT));
|
||||||
final ToXContent.Params params = new ToXContent.DelegatingMapParams(overrideParams, request);
|
final ToXContent.Params params = new ToXContent.DelegatingMapParams(overrideParams, request);
|
||||||
GetLicenseRequest getLicenseRequest = new GetLicenseRequest();
|
GetLicenseRequest getLicenseRequest = new GetLicenseRequest();
|
||||||
getLicenseRequest.local(request.paramAsBoolean("local", getLicenseRequest.local()));
|
getLicenseRequest.local(request.paramAsBoolean("local", getLicenseRequest.local()));
|
||||||
client.es().admin().cluster().execute(GetLicenseAction.INSTANCE, getLicenseRequest,
|
return channel -> client.es().admin().cluster().execute(GetLicenseAction.INSTANCE, getLicenseRequest,
|
||||||
new RestBuilderListener<GetLicenseResponse>(channel) {
|
new RestBuilderListener<GetLicenseResponse>(channel) {
|
||||||
@Override
|
@Override
|
||||||
public RestResponse buildResponse(GetLicenseResponse response, XContentBuilder builder) throws Exception {
|
public RestResponse buildResponse(GetLicenseResponse response, XContentBuilder builder) throws Exception {
|
||||||
|
|
|
@ -10,7 +10,6 @@ import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.xcontent.ToXContent;
|
import org.elasticsearch.common.xcontent.ToXContent;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.rest.BytesRestResponse;
|
import org.elasticsearch.rest.BytesRestResponse;
|
||||||
import org.elasticsearch.rest.RestChannel;
|
|
||||||
import org.elasticsearch.rest.RestController;
|
import org.elasticsearch.rest.RestController;
|
||||||
import org.elasticsearch.rest.RestRequest;
|
import org.elasticsearch.rest.RestRequest;
|
||||||
import org.elasticsearch.rest.RestResponse;
|
import org.elasticsearch.rest.RestResponse;
|
||||||
|
@ -19,6 +18,8 @@ import org.elasticsearch.rest.action.RestBuilderListener;
|
||||||
import org.elasticsearch.xpack.XPackClient;
|
import org.elasticsearch.xpack.XPackClient;
|
||||||
import org.elasticsearch.xpack.rest.XPackRestHandler;
|
import org.elasticsearch.xpack.rest.XPackRestHandler;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.POST;
|
import static org.elasticsearch.rest.RestRequest.Method.POST;
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.PUT;
|
import static org.elasticsearch.rest.RestRequest.Method.PUT;
|
||||||
|
|
||||||
|
@ -45,11 +46,11 @@ public class RestPutLicenseAction extends XPackRestHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleRequest(final RestRequest request, final RestChannel channel, final XPackClient client) {
|
public RestChannelConsumer doPrepareRequest(final RestRequest request, final XPackClient client) throws IOException {
|
||||||
PutLicenseRequest putLicenseRequest = new PutLicenseRequest();
|
PutLicenseRequest putLicenseRequest = new PutLicenseRequest();
|
||||||
putLicenseRequest.license(request.content().utf8ToString());
|
putLicenseRequest.license(request.content().utf8ToString());
|
||||||
putLicenseRequest.acknowledge(request.paramAsBoolean("acknowledge", false));
|
putLicenseRequest.acknowledge(request.paramAsBoolean("acknowledge", false));
|
||||||
client.es().admin().cluster().execute(PutLicenseAction.INSTANCE, putLicenseRequest,
|
return channel -> client.es().admin().cluster().execute(PutLicenseAction.INSTANCE, putLicenseRequest,
|
||||||
new RestBuilderListener<PutLicenseResponse>(channel) {
|
new RestBuilderListener<PutLicenseResponse>(channel) {
|
||||||
@Override
|
@Override
|
||||||
public RestResponse buildResponse(PutLicenseResponse response, XContentBuilder builder) throws Exception {
|
public RestResponse buildResponse(PutLicenseResponse response, XContentBuilder builder) throws Exception {
|
||||||
|
|
|
@ -26,20 +26,17 @@ import org.elasticsearch.common.xcontent.XContentFactory;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.index.query.QueryParseContext;
|
import org.elasticsearch.index.query.QueryParseContext;
|
||||||
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
|
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
|
||||||
import org.elasticsearch.rest.RestChannel;
|
|
||||||
import org.elasticsearch.rest.RestController;
|
import org.elasticsearch.rest.RestController;
|
||||||
import org.elasticsearch.rest.RestRequest;
|
import org.elasticsearch.rest.RestRequest;
|
||||||
import org.elasticsearch.rest.action.RestActions;
|
import org.elasticsearch.rest.action.RestActions;
|
||||||
import org.elasticsearch.rest.action.RestToXContentListener;
|
import org.elasticsearch.rest.action.RestToXContentListener;
|
||||||
import org.elasticsearch.xpack.XPackClient;
|
import org.elasticsearch.xpack.XPackClient;
|
||||||
import org.elasticsearch.xpack.graph.action.GraphExploreRequest;
|
import org.elasticsearch.xpack.graph.action.GraphExploreRequest;
|
||||||
import org.elasticsearch.xpack.graph.action.GraphExploreResponse;
|
|
||||||
import org.elasticsearch.xpack.graph.action.Hop;
|
import org.elasticsearch.xpack.graph.action.Hop;
|
||||||
import org.elasticsearch.xpack.graph.action.VertexRequest;
|
import org.elasticsearch.xpack.graph.action.VertexRequest;
|
||||||
import org.elasticsearch.xpack.graph.action.GraphExploreRequest.TermBoost;
|
import org.elasticsearch.xpack.graph.action.GraphExploreRequest.TermBoost;
|
||||||
import org.elasticsearch.xpack.rest.XPackRestHandler;
|
import org.elasticsearch.xpack.rest.XPackRestHandler;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see GraphExploreRequest
|
* @see GraphExploreRequest
|
||||||
*/
|
*/
|
||||||
|
@ -84,7 +81,7 @@ public class RestGraphAction extends XPackRestHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleRequest(final RestRequest request, final RestChannel channel, final XPackClient client) throws IOException {
|
public RestChannelConsumer doPrepareRequest(final RestRequest request, final XPackClient client) throws IOException {
|
||||||
GraphExploreRequest graphRequest = new GraphExploreRequest(Strings.splitStringByCommaToArray(request.param("index")));
|
GraphExploreRequest graphRequest = new GraphExploreRequest(Strings.splitStringByCommaToArray(request.param("index")));
|
||||||
graphRequest.indicesOptions(IndicesOptions.fromRequest(request, graphRequest.indicesOptions()));
|
graphRequest.indicesOptions(IndicesOptions.fromRequest(request, graphRequest.indicesOptions()));
|
||||||
graphRequest.routing(request.param("routing"));
|
graphRequest.routing(request.param("routing"));
|
||||||
|
@ -111,7 +108,7 @@ public class RestGraphAction extends XPackRestHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
graphRequest.types(Strings.splitStringByCommaToArray(request.param("type")));
|
graphRequest.types(Strings.splitStringByCommaToArray(request.param("type")));
|
||||||
client.es().execute(INSTANCE, graphRequest, new RestToXContentListener<GraphExploreResponse>(channel));
|
return channel -> client.es().execute(INSTANCE, graphRequest, new RestToXContentListener<>(channel));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseHop(XContentParser parser, QueryParseContext context, Hop currentHop,
|
private void parseHop(XContentParser parser, QueryParseContext context, Hop currentHop,
|
||||||
|
|
|
@ -85,7 +85,7 @@ public class MonitoringBulkRequest extends ActionRequest<MonitoringBulkRequest>
|
||||||
* Parses a monitoring bulk request and builds the list of documents to be indexed.
|
* Parses a monitoring bulk request and builds the list of documents to be indexed.
|
||||||
*/
|
*/
|
||||||
public MonitoringBulkRequest add(BytesReference content, String defaultMonitoringId, String defaultMonitoringApiVersion,
|
public MonitoringBulkRequest add(BytesReference content, String defaultMonitoringId, String defaultMonitoringApiVersion,
|
||||||
String defaultType) throws Exception {
|
String defaultType) throws IOException {
|
||||||
// MonitoringBulkRequest accepts a body request that has the same format as the BulkRequest:
|
// MonitoringBulkRequest accepts a body request that has the same format as the BulkRequest:
|
||||||
// instead of duplicating the parsing logic here we use a new BulkRequest instance to parse the content.
|
// instead of duplicating the parsing logic here we use a new BulkRequest instance to parse the content.
|
||||||
BulkRequest bulkRequest = Requests.bulkRequest().add(content, null, defaultType);
|
BulkRequest bulkRequest = Requests.bulkRequest().add(content, null, defaultType);
|
||||||
|
|
|
@ -9,6 +9,8 @@ import org.elasticsearch.action.ActionRequestBuilder;
|
||||||
import org.elasticsearch.client.ElasticsearchClient;
|
import org.elasticsearch.client.ElasticsearchClient;
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
import org.elasticsearch.common.bytes.BytesReference;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public class MonitoringBulkRequestBuilder
|
public class MonitoringBulkRequestBuilder
|
||||||
extends ActionRequestBuilder<MonitoringBulkRequest, MonitoringBulkResponse, MonitoringBulkRequestBuilder> {
|
extends ActionRequestBuilder<MonitoringBulkRequest, MonitoringBulkResponse, MonitoringBulkRequestBuilder> {
|
||||||
|
|
||||||
|
@ -22,8 +24,9 @@ public class MonitoringBulkRequestBuilder
|
||||||
}
|
}
|
||||||
|
|
||||||
public MonitoringBulkRequestBuilder add(BytesReference content, String defaultId, String defaultApiVersion, String defaultType)
|
public MonitoringBulkRequestBuilder add(BytesReference content, String defaultId, String defaultApiVersion, String defaultType)
|
||||||
throws Exception {
|
throws IOException {
|
||||||
request.add(content, defaultId, defaultApiVersion, defaultType);
|
request.add(content, defaultId, defaultApiVersion, defaultType);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||||
import org.elasticsearch.rest.RestStatus;
|
import org.elasticsearch.rest.RestStatus;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -52,9 +53,7 @@ public class BackwardsCompatibilityAliasesResource extends HttpResource {
|
||||||
boolean needNewAliases = false;
|
boolean needNewAliases = false;
|
||||||
XContentBuilder request;
|
XContentBuilder request;
|
||||||
try {
|
try {
|
||||||
Map<String, String> params = parameters();
|
Response response = client.performRequest("GET", "/.marvel-es-1-*", Collections.singletonMap("filter_path", "*.aliases"));
|
||||||
params.put("filter_path", "*.aliases");
|
|
||||||
Response response = client.performRequest("GET", "/.marvel-es-1-*", params);
|
|
||||||
try (XContentParser parser = JsonXContent.jsonXContent.createParser(response.getEntity().getContent())) {
|
try (XContentParser parser = JsonXContent.jsonXContent.createParser(response.getEntity().getContent())) {
|
||||||
Map<String, Object> indices = parser.map();
|
Map<String, Object> indices = parser.map();
|
||||||
request = JsonXContent.contentBuilder();
|
request = JsonXContent.contentBuilder();
|
||||||
|
|
|
@ -15,4 +15,5 @@ public abstract class MonitoringRestHandler extends XPackRestHandler {
|
||||||
public MonitoringRestHandler(Settings settings) {
|
public MonitoringRestHandler(Settings settings) {
|
||||||
super(settings);
|
super(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,6 @@ import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.rest.BytesRestResponse;
|
import org.elasticsearch.rest.BytesRestResponse;
|
||||||
import org.elasticsearch.rest.RestChannel;
|
|
||||||
import org.elasticsearch.rest.RestController;
|
import org.elasticsearch.rest.RestController;
|
||||||
import org.elasticsearch.rest.RestRequest;
|
import org.elasticsearch.rest.RestRequest;
|
||||||
import org.elasticsearch.rest.RestResponse;
|
import org.elasticsearch.rest.RestResponse;
|
||||||
|
@ -22,6 +21,8 @@ import org.elasticsearch.xpack.monitoring.action.MonitoringBulkRequestBuilder;
|
||||||
import org.elasticsearch.xpack.monitoring.action.MonitoringBulkResponse;
|
import org.elasticsearch.xpack.monitoring.action.MonitoringBulkResponse;
|
||||||
import org.elasticsearch.xpack.monitoring.rest.MonitoringRestHandler;
|
import org.elasticsearch.xpack.monitoring.rest.MonitoringRestHandler;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.POST;
|
import static org.elasticsearch.rest.RestRequest.Method.POST;
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.PUT;
|
import static org.elasticsearch.rest.RestRequest.Method.PUT;
|
||||||
|
|
||||||
|
@ -41,7 +42,7 @@ public class RestMonitoringBulkAction extends MonitoringRestHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleRequest(RestRequest request, RestChannel channel, XPackClient client) throws Exception {
|
public RestChannelConsumer doPrepareRequest(RestRequest request, XPackClient client) throws IOException {
|
||||||
String defaultType = request.param("type");
|
String defaultType = request.param("type");
|
||||||
|
|
||||||
String id = request.param(MONITORING_ID);
|
String id = request.param(MONITORING_ID);
|
||||||
|
@ -64,7 +65,7 @@ public class RestMonitoringBulkAction extends MonitoringRestHandler {
|
||||||
|
|
||||||
MonitoringBulkRequestBuilder requestBuilder = client.monitoring().prepareMonitoringBulk();
|
MonitoringBulkRequestBuilder requestBuilder = client.monitoring().prepareMonitoringBulk();
|
||||||
requestBuilder.add(request.content(), id, version, defaultType);
|
requestBuilder.add(request.content(), id, version, defaultType);
|
||||||
requestBuilder.execute(new RestBuilderListener<MonitoringBulkResponse>(channel) {
|
return channel -> requestBuilder.execute(new RestBuilderListener<MonitoringBulkResponse>(channel) {
|
||||||
@Override
|
@Override
|
||||||
public RestResponse buildResponse(MonitoringBulkResponse response, XContentBuilder builder) throws Exception {
|
public RestResponse buildResponse(MonitoringBulkResponse response, XContentBuilder builder) throws Exception {
|
||||||
builder.startObject();
|
builder.startObject();
|
||||||
|
@ -87,4 +88,5 @@ public class RestMonitoringBulkAction extends MonitoringRestHandler {
|
||||||
static final String ERRORS = "errors";
|
static final String ERRORS = "errors";
|
||||||
static final String ERROR = "error";
|
static final String ERROR = "error";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,13 +8,11 @@ package org.elasticsearch.xpack.rest;
|
||||||
import org.elasticsearch.client.node.NodeClient;
|
import org.elasticsearch.client.node.NodeClient;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.rest.BaseRestHandler;
|
import org.elasticsearch.rest.BaseRestHandler;
|
||||||
import org.elasticsearch.rest.RestChannel;
|
|
||||||
import org.elasticsearch.rest.RestRequest;
|
import org.elasticsearch.rest.RestRequest;
|
||||||
import org.elasticsearch.xpack.XPackClient;
|
import org.elasticsearch.xpack.XPackClient;
|
||||||
|
|
||||||
/**
|
import java.io.IOException;
|
||||||
*
|
|
||||||
*/
|
|
||||||
public abstract class XPackRestHandler extends BaseRestHandler {
|
public abstract class XPackRestHandler extends BaseRestHandler {
|
||||||
|
|
||||||
protected static String URI_BASE = "/_xpack";
|
protected static String URI_BASE = "/_xpack";
|
||||||
|
@ -24,9 +22,10 @@ public abstract class XPackRestHandler extends BaseRestHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void handleRequest(RestRequest request, RestChannel channel, NodeClient client) throws Exception {
|
public final RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
|
||||||
handleRequest(request, channel, new XPackClient(client));
|
return doPrepareRequest(request, new XPackClient(client));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void handleRequest(RestRequest request, RestChannel channel, XPackClient client) throws Exception;
|
protected abstract RestChannelConsumer doPrepareRequest(RestRequest request, XPackClient client) throws IOException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,13 +5,13 @@
|
||||||
*/
|
*/
|
||||||
package org.elasticsearch.xpack.rest.action;
|
package org.elasticsearch.xpack.rest.action;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
|
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.rest.BytesRestResponse;
|
import org.elasticsearch.rest.BytesRestResponse;
|
||||||
import org.elasticsearch.rest.RestChannel;
|
|
||||||
import org.elasticsearch.rest.RestController;
|
import org.elasticsearch.rest.RestController;
|
||||||
import org.elasticsearch.rest.RestRequest;
|
import org.elasticsearch.rest.RestRequest;
|
||||||
import org.elasticsearch.rest.RestResponse;
|
import org.elasticsearch.rest.RestResponse;
|
||||||
|
@ -35,49 +35,53 @@ public class RestXPackInfoAction extends XPackRestHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleRequest(RestRequest request, RestChannel restChannel, XPackClient client) throws Exception {
|
public RestChannelConsumer doPrepareRequest(RestRequest request, XPackClient client) throws IOException {
|
||||||
|
|
||||||
// we piggyback verbosity on "human" output
|
// we piggyback verbosity on "human" output
|
||||||
boolean verbose = request.paramAsBoolean("human", true);
|
boolean verbose = request.paramAsBoolean("human", true);
|
||||||
|
|
||||||
EnumSet<XPackInfoRequest.Category> categories = XPackInfoRequest.Category
|
EnumSet<XPackInfoRequest.Category> categories = XPackInfoRequest.Category
|
||||||
.toSet(request.paramAsStringArray("categories", new String[] { "_all" }));
|
.toSet(request.paramAsStringArray("categories", new String[] { "_all" }));
|
||||||
client.prepareInfo().setVerbose(verbose).setCategories(categories).execute(new RestBuilderListener<XPackInfoResponse>(restChannel) {
|
return channel ->
|
||||||
@Override
|
client.prepareInfo()
|
||||||
public RestResponse buildResponse(XPackInfoResponse infoResponse, XContentBuilder builder) throws Exception {
|
.setVerbose(verbose)
|
||||||
|
.setCategories(categories)
|
||||||
|
.execute(new RestBuilderListener<XPackInfoResponse>(channel) {
|
||||||
|
@Override
|
||||||
|
public RestResponse buildResponse(XPackInfoResponse infoResponse, XContentBuilder builder) throws Exception {
|
||||||
|
|
||||||
// we treat HEAD requests as simple pings to ensure that X-Pack is installed
|
// we treat HEAD requests as simple pings to ensure that X-Pack is installed
|
||||||
// we still execute the action as we want this request to be authorized
|
// we still execute the action as we want this request to be authorized
|
||||||
if (request.method() == RestRequest.Method.HEAD) {
|
if (request.method() == RestRequest.Method.HEAD) {
|
||||||
return new BytesRestResponse(OK, builder);
|
return new BytesRestResponse(OK, builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.startObject();
|
builder.startObject();
|
||||||
|
|
||||||
if (infoResponse.getBuildInfo() != null) {
|
if (infoResponse.getBuildInfo() != null) {
|
||||||
builder.field("build", infoResponse.getBuildInfo(), request);
|
builder.field("build", infoResponse.getBuildInfo(), request);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (infoResponse.getLicenseInfo() != null) {
|
if (infoResponse.getLicenseInfo() != null) {
|
||||||
builder.field("license", infoResponse.getLicenseInfo(), request);
|
builder.field("license", infoResponse.getLicenseInfo(), request);
|
||||||
} else if (categories.contains(XPackInfoRequest.Category.LICENSE)) {
|
} else if (categories.contains(XPackInfoRequest.Category.LICENSE)) {
|
||||||
// if the user requested the license info, and there is no license, we should send
|
// if the user requested the license info, and there is no license, we should send
|
||||||
// back an explicit null value (indicating there is no license). This is different
|
// back an explicit null value (indicating there is no license). This is different
|
||||||
// than not adding the license info at all
|
// than not adding the license info at all
|
||||||
builder.nullField("license");
|
builder.nullField("license");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (infoResponse.getFeatureSetsInfo() != null) {
|
if (infoResponse.getFeatureSetsInfo() != null) {
|
||||||
builder.field("features", infoResponse.getFeatureSetsInfo(), request);
|
builder.field("features", infoResponse.getFeatureSetsInfo(), request);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
builder.field("tagline", "You know, for X");
|
builder.field("tagline", "You know, for X");
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
return new BytesRestResponse(OK, builder);
|
return new BytesRestResponse(OK, builder);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,9 +8,9 @@ package org.elasticsearch.xpack.rest.action;
|
||||||
import org.elasticsearch.action.support.master.MasterNodeRequest;
|
import org.elasticsearch.action.support.master.MasterNodeRequest;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
|
import org.elasticsearch.common.unit.TimeValue;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.rest.BytesRestResponse;
|
import org.elasticsearch.rest.BytesRestResponse;
|
||||||
import org.elasticsearch.rest.RestChannel;
|
|
||||||
import org.elasticsearch.rest.RestController;
|
import org.elasticsearch.rest.RestController;
|
||||||
import org.elasticsearch.rest.RestRequest;
|
import org.elasticsearch.rest.RestRequest;
|
||||||
import org.elasticsearch.rest.RestResponse;
|
import org.elasticsearch.rest.RestResponse;
|
||||||
|
@ -21,6 +21,8 @@ import org.elasticsearch.xpack.action.XPackUsageRequestBuilder;
|
||||||
import org.elasticsearch.xpack.action.XPackUsageResponse;
|
import org.elasticsearch.xpack.action.XPackUsageResponse;
|
||||||
import org.elasticsearch.xpack.rest.XPackRestHandler;
|
import org.elasticsearch.xpack.rest.XPackRestHandler;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
||||||
import static org.elasticsearch.rest.RestStatus.OK;
|
import static org.elasticsearch.rest.RestStatus.OK;
|
||||||
|
|
||||||
|
@ -33,19 +35,20 @@ public class RestXPackUsageAction extends XPackRestHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleRequest(RestRequest request, RestChannel restChannel, XPackClient client) throws Exception {
|
public RestChannelConsumer doPrepareRequest(RestRequest request, XPackClient client) throws IOException {
|
||||||
new XPackUsageRequestBuilder(client.es())
|
final TimeValue masterTimeout = request.paramAsTime("master_timeout", MasterNodeRequest.DEFAULT_MASTER_NODE_TIMEOUT);
|
||||||
.setMasterNodeTimeout(request.paramAsTime("master_timeout", MasterNodeRequest.DEFAULT_MASTER_NODE_TIMEOUT))
|
return channel -> new XPackUsageRequestBuilder(client.es())
|
||||||
.execute(new RestBuilderListener<XPackUsageResponse>(restChannel) {
|
.setMasterNodeTimeout(masterTimeout)
|
||||||
@Override
|
.execute(new RestBuilderListener<XPackUsageResponse>(channel) {
|
||||||
public RestResponse buildResponse(XPackUsageResponse response, XContentBuilder builder) throws Exception {
|
@Override
|
||||||
builder.startObject();
|
public RestResponse buildResponse(XPackUsageResponse response, XContentBuilder builder) throws Exception {
|
||||||
for (XPackFeatureSet.Usage usage : response.getUsages()) {
|
builder.startObject();
|
||||||
builder.field(usage.name(), usage);
|
for (XPackFeatureSet.Usage usage : response.getUsages()) {
|
||||||
}
|
builder.field(usage.name(), usage);
|
||||||
builder.endObject();
|
}
|
||||||
return new BytesRestResponse(OK, builder);
|
builder.endObject();
|
||||||
}
|
return new BytesRestResponse(OK, builder);
|
||||||
});
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ import org.elasticsearch.common.bytes.BytesReference;
|
||||||
import org.elasticsearch.xpack.security.authz.RoleDescriptor;
|
import org.elasticsearch.xpack.security.authz.RoleDescriptor;
|
||||||
import org.elasticsearch.xpack.security.authz.permission.FieldPermissions;
|
import org.elasticsearch.xpack.security.authz.permission.FieldPermissions;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,7 +30,7 @@ public class PutRoleRequestBuilder extends ActionRequestBuilder<PutRoleRequest,
|
||||||
super(client, action, new PutRoleRequest());
|
super(client, action, new PutRoleRequest());
|
||||||
}
|
}
|
||||||
|
|
||||||
public PutRoleRequestBuilder source(String name, BytesReference source) throws Exception {
|
public PutRoleRequestBuilder source(String name, BytesReference source) throws IOException {
|
||||||
// we pass false as last parameter because we want to reject the request if field permissions
|
// we pass false as last parameter because we want to reject the request if field permissions
|
||||||
// are given in 2.x syntax
|
// are given in 2.x syntax
|
||||||
RoleDescriptor descriptor = RoleDescriptor.parse(name, source, false);
|
RoleDescriptor descriptor = RoleDescriptor.parse(name, source, false);
|
||||||
|
|
|
@ -197,7 +197,7 @@ public class SecurityClient {
|
||||||
return new PutRoleRequestBuilder(client).name(name);
|
return new PutRoleRequestBuilder(client).name(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PutRoleRequestBuilder preparePutRole(String name, BytesReference source) throws Exception {
|
public PutRoleRequestBuilder preparePutRole(String name, BytesReference source) throws IOException {
|
||||||
return new PutRoleRequestBuilder(client).source(name, source);
|
return new PutRoleRequestBuilder(client).source(name, source);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,6 @@ import org.elasticsearch.license.LicenseUtils;
|
||||||
import org.elasticsearch.license.XPackLicenseState;
|
import org.elasticsearch.license.XPackLicenseState;
|
||||||
import org.elasticsearch.rest.BaseRestHandler;
|
import org.elasticsearch.rest.BaseRestHandler;
|
||||||
import org.elasticsearch.rest.BytesRestResponse;
|
import org.elasticsearch.rest.BytesRestResponse;
|
||||||
import org.elasticsearch.rest.RestChannel;
|
|
||||||
import org.elasticsearch.rest.RestController;
|
import org.elasticsearch.rest.RestController;
|
||||||
import org.elasticsearch.rest.RestRequest;
|
import org.elasticsearch.rest.RestRequest;
|
||||||
import org.elasticsearch.rest.RestResponse;
|
import org.elasticsearch.rest.RestResponse;
|
||||||
|
@ -22,10 +21,12 @@ import org.elasticsearch.rest.RestStatus;
|
||||||
import org.elasticsearch.rest.action.RestBuilderListener;
|
import org.elasticsearch.rest.action.RestBuilderListener;
|
||||||
import org.elasticsearch.xpack.XPackPlugin;
|
import org.elasticsearch.xpack.XPackPlugin;
|
||||||
import org.elasticsearch.xpack.security.SecurityContext;
|
import org.elasticsearch.xpack.security.SecurityContext;
|
||||||
import org.elasticsearch.xpack.security.user.User;
|
|
||||||
import org.elasticsearch.xpack.security.action.user.AuthenticateAction;
|
import org.elasticsearch.xpack.security.action.user.AuthenticateAction;
|
||||||
import org.elasticsearch.xpack.security.action.user.AuthenticateRequest;
|
import org.elasticsearch.xpack.security.action.user.AuthenticateRequest;
|
||||||
import org.elasticsearch.xpack.security.action.user.AuthenticateResponse;
|
import org.elasticsearch.xpack.security.action.user.AuthenticateResponse;
|
||||||
|
import org.elasticsearch.xpack.security.user.User;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
||||||
|
|
||||||
|
@ -50,7 +51,7 @@ public class RestAuthenticateAction extends BaseRestHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleRequest(RestRequest request, RestChannel channel, NodeClient client) throws Exception {
|
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
|
||||||
// this API is a special case since we access the user here and we want it to fail with the proper error instead of a request
|
// this API is a special case since we access the user here and we want it to fail with the proper error instead of a request
|
||||||
// validation error
|
// validation error
|
||||||
if (licenseState.isAuthAllowed() == false) {
|
if (licenseState.isAuthAllowed() == false) {
|
||||||
|
@ -61,7 +62,7 @@ public class RestAuthenticateAction extends BaseRestHandler {
|
||||||
assert user != null;
|
assert user != null;
|
||||||
final String username = user.runAs() == null ? user.principal() : user.runAs().principal();
|
final String username = user.runAs() == null ? user.principal() : user.runAs().principal();
|
||||||
|
|
||||||
client.execute(AuthenticateAction.INSTANCE, new AuthenticateRequest(username),
|
return channel -> client.execute(AuthenticateAction.INSTANCE, new AuthenticateRequest(username),
|
||||||
new RestBuilderListener<AuthenticateResponse>(channel) {
|
new RestBuilderListener<AuthenticateResponse>(channel) {
|
||||||
@Override
|
@Override
|
||||||
public RestResponse buildResponse(AuthenticateResponse authenticateResponse, XContentBuilder builder) throws Exception {
|
public RestResponse buildResponse(AuthenticateResponse authenticateResponse, XContentBuilder builder) throws Exception {
|
||||||
|
|
|
@ -9,13 +9,14 @@ import org.elasticsearch.client.node.NodeClient;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.rest.BaseRestHandler;
|
import org.elasticsearch.rest.BaseRestHandler;
|
||||||
import org.elasticsearch.rest.RestChannel;
|
|
||||||
import org.elasticsearch.rest.RestController;
|
import org.elasticsearch.rest.RestController;
|
||||||
import org.elasticsearch.rest.RestRequest;
|
import org.elasticsearch.rest.RestRequest;
|
||||||
import org.elasticsearch.rest.action.RestActions.NodesResponseRestListener;
|
import org.elasticsearch.rest.action.RestActions.NodesResponseRestListener;
|
||||||
import org.elasticsearch.xpack.security.action.realm.ClearRealmCacheRequest;
|
import org.elasticsearch.xpack.security.action.realm.ClearRealmCacheRequest;
|
||||||
import org.elasticsearch.xpack.security.client.SecurityClient;
|
import org.elasticsearch.xpack.security.client.SecurityClient;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.POST;
|
import static org.elasticsearch.rest.RestRequest.Method.POST;
|
||||||
|
|
||||||
public class RestClearRealmCacheAction extends BaseRestHandler {
|
public class RestClearRealmCacheAction extends BaseRestHandler {
|
||||||
|
@ -37,14 +38,14 @@ public class RestClearRealmCacheAction extends BaseRestHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleRequest(RestRequest request, final RestChannel channel, NodeClient client) throws Exception {
|
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
|
||||||
|
|
||||||
String[] realms = request.paramAsStringArrayOrEmptyIfAll("realms");
|
String[] realms = request.paramAsStringArrayOrEmptyIfAll("realms");
|
||||||
String[] usernames = request.paramAsStringArrayOrEmptyIfAll("usernames");
|
String[] usernames = request.paramAsStringArrayOrEmptyIfAll("usernames");
|
||||||
|
|
||||||
ClearRealmCacheRequest req = new ClearRealmCacheRequest().realms(realms).usernames(usernames);
|
ClearRealmCacheRequest req = new ClearRealmCacheRequest().realms(realms).usernames(usernames);
|
||||||
|
|
||||||
new SecurityClient(client).clearRealmCache(req, new NodesResponseRestListener<>(channel));
|
return channel -> new SecurityClient(client).clearRealmCache(req, new NodesResponseRestListener<>(channel));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,13 +9,14 @@ import org.elasticsearch.client.node.NodeClient;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.rest.BaseRestHandler;
|
import org.elasticsearch.rest.BaseRestHandler;
|
||||||
import org.elasticsearch.rest.RestChannel;
|
|
||||||
import org.elasticsearch.rest.RestController;
|
import org.elasticsearch.rest.RestController;
|
||||||
import org.elasticsearch.rest.RestRequest;
|
import org.elasticsearch.rest.RestRequest;
|
||||||
import org.elasticsearch.rest.action.RestActions.NodesResponseRestListener;
|
import org.elasticsearch.rest.action.RestActions.NodesResponseRestListener;
|
||||||
import org.elasticsearch.xpack.security.action.role.ClearRolesCacheRequest;
|
import org.elasticsearch.xpack.security.action.role.ClearRolesCacheRequest;
|
||||||
import org.elasticsearch.xpack.security.client.SecurityClient;
|
import org.elasticsearch.xpack.security.client.SecurityClient;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.POST;
|
import static org.elasticsearch.rest.RestRequest.Method.POST;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -36,12 +37,12 @@ public class RestClearRolesCacheAction extends BaseRestHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleRequest(RestRequest request, final RestChannel channel, NodeClient client) throws Exception {
|
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
|
||||||
|
|
||||||
String[] roles = request.paramAsStringArrayOrEmptyIfAll("name");
|
String[] roles = request.paramAsStringArrayOrEmptyIfAll("name");
|
||||||
|
|
||||||
ClearRolesCacheRequest req = new ClearRolesCacheRequest().names(roles);
|
ClearRolesCacheRequest req = new ClearRolesCacheRequest().names(roles);
|
||||||
|
|
||||||
new SecurityClient(client).clearRolesCache(req, new NodesResponseRestListener<>(channel));
|
return channel -> new SecurityClient(client).clearRolesCache(req, new NodesResponseRestListener<>(channel));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,6 @@ import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.rest.BaseRestHandler;
|
import org.elasticsearch.rest.BaseRestHandler;
|
||||||
import org.elasticsearch.rest.BytesRestResponse;
|
import org.elasticsearch.rest.BytesRestResponse;
|
||||||
import org.elasticsearch.rest.RestChannel;
|
|
||||||
import org.elasticsearch.rest.RestController;
|
import org.elasticsearch.rest.RestController;
|
||||||
import org.elasticsearch.rest.RestRequest;
|
import org.elasticsearch.rest.RestRequest;
|
||||||
import org.elasticsearch.rest.RestResponse;
|
import org.elasticsearch.rest.RestResponse;
|
||||||
|
@ -20,6 +19,8 @@ import org.elasticsearch.rest.action.RestBuilderListener;
|
||||||
import org.elasticsearch.xpack.security.action.role.DeleteRoleResponse;
|
import org.elasticsearch.xpack.security.action.role.DeleteRoleResponse;
|
||||||
import org.elasticsearch.xpack.security.client.SecurityClient;
|
import org.elasticsearch.xpack.security.client.SecurityClient;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.DELETE;
|
import static org.elasticsearch.rest.RestRequest.Method.DELETE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -40,16 +41,18 @@ public class RestDeleteRoleAction extends BaseRestHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleRequest(RestRequest request, final RestChannel channel, NodeClient client) throws Exception {
|
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
|
||||||
new SecurityClient(client).prepareDeleteRole(request.param("name"))
|
final String name = request.param("name");
|
||||||
.setRefreshPolicy(request.param("refresh"))
|
final String refresh = request.param("refresh");
|
||||||
|
|
||||||
|
return channel -> new SecurityClient(client).prepareDeleteRole(name)
|
||||||
|
.setRefreshPolicy(refresh)
|
||||||
.execute(new RestBuilderListener<DeleteRoleResponse>(channel) {
|
.execute(new RestBuilderListener<DeleteRoleResponse>(channel) {
|
||||||
@Override
|
@Override
|
||||||
public RestResponse buildResponse(DeleteRoleResponse response, XContentBuilder builder) throws Exception {
|
public RestResponse buildResponse(DeleteRoleResponse response, XContentBuilder builder) throws Exception {
|
||||||
return new BytesRestResponse(response.found() ? RestStatus.OK : RestStatus.NOT_FOUND,
|
return new BytesRestResponse(
|
||||||
builder.startObject()
|
response.found() ? RestStatus.OK : RestStatus.NOT_FOUND,
|
||||||
.field("found", response.found())
|
builder.startObject().field("found", response.found()).endObject());
|
||||||
.endObject());
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,15 +12,16 @@ import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.rest.BaseRestHandler;
|
import org.elasticsearch.rest.BaseRestHandler;
|
||||||
import org.elasticsearch.rest.BytesRestResponse;
|
import org.elasticsearch.rest.BytesRestResponse;
|
||||||
import org.elasticsearch.rest.RestChannel;
|
|
||||||
import org.elasticsearch.rest.RestController;
|
import org.elasticsearch.rest.RestController;
|
||||||
import org.elasticsearch.rest.RestRequest;
|
import org.elasticsearch.rest.RestRequest;
|
||||||
import org.elasticsearch.rest.RestResponse;
|
import org.elasticsearch.rest.RestResponse;
|
||||||
import org.elasticsearch.rest.RestStatus;
|
import org.elasticsearch.rest.RestStatus;
|
||||||
import org.elasticsearch.rest.action.RestBuilderListener;
|
import org.elasticsearch.rest.action.RestBuilderListener;
|
||||||
import org.elasticsearch.xpack.security.action.role.GetRolesResponse;
|
import org.elasticsearch.xpack.security.action.role.GetRolesResponse;
|
||||||
import org.elasticsearch.xpack.security.client.SecurityClient;
|
|
||||||
import org.elasticsearch.xpack.security.authz.RoleDescriptor;
|
import org.elasticsearch.xpack.security.authz.RoleDescriptor;
|
||||||
|
import org.elasticsearch.xpack.security.client.SecurityClient;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
||||||
|
|
||||||
|
@ -47,9 +48,9 @@ public class RestGetRolesAction extends BaseRestHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleRequest(RestRequest request, RestChannel channel, NodeClient client) throws Exception {
|
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
|
||||||
final String[] roles = request.paramAsStringArray("name", Strings.EMPTY_ARRAY);
|
final String[] roles = request.paramAsStringArray("name", Strings.EMPTY_ARRAY);
|
||||||
new SecurityClient(client).prepareGetRoles(roles).execute(new RestBuilderListener<GetRolesResponse>(channel) {
|
return channel -> new SecurityClient(client).prepareGetRoles(roles).execute(new RestBuilderListener<GetRolesResponse>(channel) {
|
||||||
@Override
|
@Override
|
||||||
public RestResponse buildResponse(GetRolesResponse response, XContentBuilder builder) throws Exception {
|
public RestResponse buildResponse(GetRolesResponse response, XContentBuilder builder) throws Exception {
|
||||||
builder.startObject();
|
builder.startObject();
|
||||||
|
|
|
@ -11,7 +11,6 @@ import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.rest.BaseRestHandler;
|
import org.elasticsearch.rest.BaseRestHandler;
|
||||||
import org.elasticsearch.rest.BytesRestResponse;
|
import org.elasticsearch.rest.BytesRestResponse;
|
||||||
import org.elasticsearch.rest.RestChannel;
|
|
||||||
import org.elasticsearch.rest.RestController;
|
import org.elasticsearch.rest.RestController;
|
||||||
import org.elasticsearch.rest.RestRequest;
|
import org.elasticsearch.rest.RestRequest;
|
||||||
import org.elasticsearch.rest.RestResponse;
|
import org.elasticsearch.rest.RestResponse;
|
||||||
|
@ -21,6 +20,8 @@ import org.elasticsearch.xpack.security.action.role.PutRoleRequestBuilder;
|
||||||
import org.elasticsearch.xpack.security.action.role.PutRoleResponse;
|
import org.elasticsearch.xpack.security.action.role.PutRoleResponse;
|
||||||
import org.elasticsearch.xpack.security.client.SecurityClient;
|
import org.elasticsearch.xpack.security.client.SecurityClient;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.POST;
|
import static org.elasticsearch.rest.RestRequest.Method.POST;
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.PUT;
|
import static org.elasticsearch.rest.RestRequest.Method.PUT;
|
||||||
|
|
||||||
|
@ -47,16 +48,13 @@ public class RestPutRoleAction extends BaseRestHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleRequest(RestRequest request, final RestChannel channel, NodeClient client) throws Exception {
|
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
|
||||||
PutRoleRequestBuilder requestBuilder = new SecurityClient(client).preparePutRole(request.param("name"), request.content());
|
PutRoleRequestBuilder requestBuilder = new SecurityClient(client).preparePutRole(request.param("name"), request.content());
|
||||||
requestBuilder.setRefreshPolicy(request.param("refresh"));
|
requestBuilder.setRefreshPolicy(request.param("refresh"));
|
||||||
requestBuilder.execute(new RestBuilderListener<PutRoleResponse>(channel) {
|
return channel -> requestBuilder.execute(new RestBuilderListener<PutRoleResponse>(channel) {
|
||||||
@Override
|
@Override
|
||||||
public RestResponse buildResponse(PutRoleResponse putRoleResponse, XContentBuilder builder) throws Exception {
|
public RestResponse buildResponse(PutRoleResponse putRoleResponse, XContentBuilder builder) throws Exception {
|
||||||
return new BytesRestResponse(RestStatus.OK,
|
return new BytesRestResponse(RestStatus.OK, builder.startObject().field("role", putRoleResponse).endObject());
|
||||||
builder.startObject()
|
|
||||||
.field("role", putRoleResponse)
|
|
||||||
.endObject());
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,16 +11,17 @@ import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.rest.BaseRestHandler;
|
import org.elasticsearch.rest.BaseRestHandler;
|
||||||
import org.elasticsearch.rest.BytesRestResponse;
|
import org.elasticsearch.rest.BytesRestResponse;
|
||||||
import org.elasticsearch.rest.RestChannel;
|
|
||||||
import org.elasticsearch.rest.RestController;
|
import org.elasticsearch.rest.RestController;
|
||||||
import org.elasticsearch.rest.RestRequest;
|
import org.elasticsearch.rest.RestRequest;
|
||||||
import org.elasticsearch.rest.RestResponse;
|
import org.elasticsearch.rest.RestResponse;
|
||||||
import org.elasticsearch.rest.RestStatus;
|
import org.elasticsearch.rest.RestStatus;
|
||||||
import org.elasticsearch.rest.action.RestBuilderListener;
|
import org.elasticsearch.rest.action.RestBuilderListener;
|
||||||
import org.elasticsearch.xpack.security.SecurityContext;
|
import org.elasticsearch.xpack.security.SecurityContext;
|
||||||
import org.elasticsearch.xpack.security.user.User;
|
|
||||||
import org.elasticsearch.xpack.security.action.user.ChangePasswordResponse;
|
import org.elasticsearch.xpack.security.action.user.ChangePasswordResponse;
|
||||||
import org.elasticsearch.xpack.security.client.SecurityClient;
|
import org.elasticsearch.xpack.security.client.SecurityClient;
|
||||||
|
import org.elasticsearch.xpack.security.user.User;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.POST;
|
import static org.elasticsearch.rest.RestRequest.Method.POST;
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.PUT;
|
import static org.elasticsearch.rest.RestRequest.Method.PUT;
|
||||||
|
@ -42,21 +43,27 @@ public class RestChangePasswordAction extends BaseRestHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleRequest(RestRequest request, RestChannel channel, NodeClient client) throws Exception {
|
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
|
||||||
final User user = securityContext.getUser();
|
final User user = securityContext.getUser();
|
||||||
String username = request.param("username");
|
final String username;
|
||||||
if (username == null) {
|
if (request.param("username") == null) {
|
||||||
username = user.runAs() == null ? user.principal() : user.runAs().principal();
|
username = user.runAs() == null ? user.principal() : user.runAs().principal();
|
||||||
|
} else {
|
||||||
|
username = request.param("username");
|
||||||
}
|
}
|
||||||
|
|
||||||
new SecurityClient(client).prepareChangePassword(username, request.content())
|
final String refresh = request.param("refresh");
|
||||||
.setRefreshPolicy(request.param("refresh"))
|
return channel ->
|
||||||
.execute(new RestBuilderListener<ChangePasswordResponse>(channel) {
|
new SecurityClient(client).prepareChangePassword(username, request.content())
|
||||||
@Override
|
.setRefreshPolicy(refresh)
|
||||||
public RestResponse buildResponse(ChangePasswordResponse changePasswordResponse, XContentBuilder builder) throws
|
.execute(new RestBuilderListener<ChangePasswordResponse>(channel) {
|
||||||
Exception {
|
@Override
|
||||||
return new BytesRestResponse(RestStatus.OK, channel.newBuilder().startObject().endObject());
|
public RestResponse buildResponse(
|
||||||
}
|
ChangePasswordResponse changePasswordResponse,
|
||||||
});
|
XContentBuilder builder)
|
||||||
|
throws Exception {
|
||||||
|
return new BytesRestResponse(RestStatus.OK, channel.newBuilder().startObject().endObject());
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,6 @@ import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.rest.BaseRestHandler;
|
import org.elasticsearch.rest.BaseRestHandler;
|
||||||
import org.elasticsearch.rest.BytesRestResponse;
|
import org.elasticsearch.rest.BytesRestResponse;
|
||||||
import org.elasticsearch.rest.RestChannel;
|
|
||||||
import org.elasticsearch.rest.RestController;
|
import org.elasticsearch.rest.RestController;
|
||||||
import org.elasticsearch.rest.RestRequest;
|
import org.elasticsearch.rest.RestRequest;
|
||||||
import org.elasticsearch.rest.RestResponse;
|
import org.elasticsearch.rest.RestResponse;
|
||||||
|
@ -20,6 +19,8 @@ import org.elasticsearch.rest.action.RestBuilderListener;
|
||||||
import org.elasticsearch.xpack.security.action.user.DeleteUserResponse;
|
import org.elasticsearch.xpack.security.action.user.DeleteUserResponse;
|
||||||
import org.elasticsearch.xpack.security.client.SecurityClient;
|
import org.elasticsearch.xpack.security.client.SecurityClient;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.DELETE;
|
import static org.elasticsearch.rest.RestRequest.Method.DELETE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -40,9 +41,11 @@ public class RestDeleteUserAction extends BaseRestHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleRequest(RestRequest request, final RestChannel channel, NodeClient client) throws Exception {
|
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
|
||||||
new SecurityClient(client).prepareDeleteUser(request.param("username"))
|
final String username = request.param("username");
|
||||||
.setRefreshPolicy(request.param("refresh"))
|
final String refresh = request.param("refresh");
|
||||||
|
return channel -> new SecurityClient(client).prepareDeleteUser(username)
|
||||||
|
.setRefreshPolicy(refresh)
|
||||||
.execute(new RestBuilderListener<DeleteUserResponse>(channel) {
|
.execute(new RestBuilderListener<DeleteUserResponse>(channel) {
|
||||||
@Override
|
@Override
|
||||||
public RestResponse buildResponse(DeleteUserResponse response, XContentBuilder builder) throws Exception {
|
public RestResponse buildResponse(DeleteUserResponse response, XContentBuilder builder) throws Exception {
|
||||||
|
|
|
@ -12,15 +12,16 @@ import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.rest.BaseRestHandler;
|
import org.elasticsearch.rest.BaseRestHandler;
|
||||||
import org.elasticsearch.rest.BytesRestResponse;
|
import org.elasticsearch.rest.BytesRestResponse;
|
||||||
import org.elasticsearch.rest.RestChannel;
|
|
||||||
import org.elasticsearch.rest.RestController;
|
import org.elasticsearch.rest.RestController;
|
||||||
import org.elasticsearch.rest.RestRequest;
|
import org.elasticsearch.rest.RestRequest;
|
||||||
import org.elasticsearch.rest.RestResponse;
|
import org.elasticsearch.rest.RestResponse;
|
||||||
import org.elasticsearch.rest.RestStatus;
|
import org.elasticsearch.rest.RestStatus;
|
||||||
import org.elasticsearch.rest.action.RestBuilderListener;
|
import org.elasticsearch.rest.action.RestBuilderListener;
|
||||||
import org.elasticsearch.xpack.security.user.User;
|
|
||||||
import org.elasticsearch.xpack.security.action.user.GetUsersResponse;
|
import org.elasticsearch.xpack.security.action.user.GetUsersResponse;
|
||||||
import org.elasticsearch.xpack.security.client.SecurityClient;
|
import org.elasticsearch.xpack.security.client.SecurityClient;
|
||||||
|
import org.elasticsearch.xpack.security.user.User;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
||||||
|
|
||||||
|
@ -47,10 +48,10 @@ public class RestGetUsersAction extends BaseRestHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleRequest(RestRequest request, final RestChannel channel, NodeClient client) throws Exception {
|
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
|
||||||
String[] usernames = request.paramAsStringArray("username", Strings.EMPTY_ARRAY);
|
String[] usernames = request.paramAsStringArray("username", Strings.EMPTY_ARRAY);
|
||||||
|
|
||||||
new SecurityClient(client).prepareGetUsers(usernames).execute(new RestBuilderListener<GetUsersResponse>(channel) {
|
return channel -> new SecurityClient(client).prepareGetUsers(usernames).execute(new RestBuilderListener<GetUsersResponse>(channel) {
|
||||||
@Override
|
@Override
|
||||||
public RestResponse buildResponse(GetUsersResponse response, XContentBuilder builder) throws Exception {
|
public RestResponse buildResponse(GetUsersResponse response, XContentBuilder builder) throws Exception {
|
||||||
builder.startObject();
|
builder.startObject();
|
||||||
|
|
|
@ -11,7 +11,6 @@ import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.rest.BaseRestHandler;
|
import org.elasticsearch.rest.BaseRestHandler;
|
||||||
import org.elasticsearch.rest.BytesRestResponse;
|
import org.elasticsearch.rest.BytesRestResponse;
|
||||||
import org.elasticsearch.rest.RestChannel;
|
|
||||||
import org.elasticsearch.rest.RestController;
|
import org.elasticsearch.rest.RestController;
|
||||||
import org.elasticsearch.rest.RestRequest;
|
import org.elasticsearch.rest.RestRequest;
|
||||||
import org.elasticsearch.rest.RestResponse;
|
import org.elasticsearch.rest.RestResponse;
|
||||||
|
@ -21,6 +20,8 @@ import org.elasticsearch.xpack.security.action.user.PutUserRequestBuilder;
|
||||||
import org.elasticsearch.xpack.security.action.user.PutUserResponse;
|
import org.elasticsearch.xpack.security.action.user.PutUserResponse;
|
||||||
import org.elasticsearch.xpack.security.client.SecurityClient;
|
import org.elasticsearch.xpack.security.client.SecurityClient;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.POST;
|
import static org.elasticsearch.rest.RestRequest.Method.POST;
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.PUT;
|
import static org.elasticsearch.rest.RestRequest.Method.PUT;
|
||||||
|
|
||||||
|
@ -47,10 +48,10 @@ public class RestPutUserAction extends BaseRestHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleRequest(RestRequest request, final RestChannel channel, NodeClient client) throws Exception {
|
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
|
||||||
PutUserRequestBuilder requestBuilder = new SecurityClient(client).preparePutUser(request.param("username"), request.content());
|
PutUserRequestBuilder requestBuilder = new SecurityClient(client).preparePutUser(request.param("username"), request.content());
|
||||||
requestBuilder.setRefreshPolicy(request.param("refresh"));
|
requestBuilder.setRefreshPolicy(request.param("refresh"));
|
||||||
requestBuilder.execute(new RestBuilderListener<PutUserResponse>(channel) {
|
return channel -> requestBuilder.execute(new RestBuilderListener<PutUserResponse>(channel) {
|
||||||
@Override
|
@Override
|
||||||
public RestResponse buildResponse(PutUserResponse putUserResponse, XContentBuilder builder) throws Exception {
|
public RestResponse buildResponse(PutUserResponse putUserResponse, XContentBuilder builder) throws Exception {
|
||||||
return new BytesRestResponse(RestStatus.OK,
|
return new BytesRestResponse(RestStatus.OK,
|
||||||
|
|
|
@ -11,7 +11,6 @@ import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.rest.BaseRestHandler;
|
import org.elasticsearch.rest.BaseRestHandler;
|
||||||
import org.elasticsearch.rest.BytesRestResponse;
|
import org.elasticsearch.rest.BytesRestResponse;
|
||||||
import org.elasticsearch.rest.RestChannel;
|
|
||||||
import org.elasticsearch.rest.RestController;
|
import org.elasticsearch.rest.RestController;
|
||||||
import org.elasticsearch.rest.RestRequest;
|
import org.elasticsearch.rest.RestRequest;
|
||||||
import org.elasticsearch.rest.RestResponse;
|
import org.elasticsearch.rest.RestResponse;
|
||||||
|
@ -20,6 +19,8 @@ import org.elasticsearch.rest.action.RestBuilderListener;
|
||||||
import org.elasticsearch.xpack.security.action.user.SetEnabledResponse;
|
import org.elasticsearch.xpack.security.action.user.SetEnabledResponse;
|
||||||
import org.elasticsearch.xpack.security.client.SecurityClient;
|
import org.elasticsearch.xpack.security.client.SecurityClient;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.POST;
|
import static org.elasticsearch.rest.RestRequest.Method.POST;
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.PUT;
|
import static org.elasticsearch.rest.RestRequest.Method.PUT;
|
||||||
|
|
||||||
|
@ -39,15 +40,16 @@ public class RestSetEnabledAction extends BaseRestHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleRequest(RestRequest request, RestChannel channel, NodeClient client) throws Exception {
|
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
|
||||||
final boolean enabled = request.path().endsWith("_enable");
|
final boolean enabled = request.path().endsWith("_enable");
|
||||||
assert enabled || request.path().endsWith("_disable");
|
assert enabled || request.path().endsWith("_disable");
|
||||||
new SecurityClient(client).prepareSetEnabled(request.param("username"), enabled)
|
final String username = request.param("username");
|
||||||
|
return channel -> new SecurityClient(client).prepareSetEnabled(username, enabled)
|
||||||
.execute(new RestBuilderListener<SetEnabledResponse>(channel) {
|
.execute(new RestBuilderListener<SetEnabledResponse>(channel) {
|
||||||
@Override
|
@Override
|
||||||
public RestResponse buildResponse(SetEnabledResponse setEnabledResponse, XContentBuilder builder) throws Exception {
|
public RestResponse buildResponse(SetEnabledResponse setEnabledResponse, XContentBuilder builder) throws Exception {
|
||||||
return new BytesRestResponse(RestStatus.OK, channel.newBuilder().startObject().endObject());
|
return new BytesRestResponse(RestStatus.OK, channel.newBuilder().startObject().endObject());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,17 +5,14 @@
|
||||||
*/
|
*/
|
||||||
package org.elasticsearch.xpack.watcher.rest;
|
package org.elasticsearch.xpack.watcher.rest;
|
||||||
|
|
||||||
import org.elasticsearch.client.Client;
|
|
||||||
import org.elasticsearch.client.node.NodeClient;
|
import org.elasticsearch.client.node.NodeClient;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.rest.BaseRestHandler;
|
import org.elasticsearch.rest.BaseRestHandler;
|
||||||
import org.elasticsearch.rest.RestChannel;
|
|
||||||
import org.elasticsearch.rest.RestRequest;
|
import org.elasticsearch.rest.RestRequest;
|
||||||
import org.elasticsearch.xpack.watcher.client.WatcherClient;
|
import org.elasticsearch.xpack.watcher.client.WatcherClient;
|
||||||
|
|
||||||
/**
|
import java.io.IOException;
|
||||||
*
|
|
||||||
*/
|
|
||||||
public abstract class WatcherRestHandler extends BaseRestHandler {
|
public abstract class WatcherRestHandler extends BaseRestHandler {
|
||||||
|
|
||||||
protected static String URI_BASE = "_xpack/watcher";
|
protected static String URI_BASE = "_xpack/watcher";
|
||||||
|
@ -25,9 +22,10 @@ public abstract class WatcherRestHandler extends BaseRestHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void handleRequest(RestRequest request, RestChannel channel, NodeClient client) throws Exception {
|
public final RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
|
||||||
handleRequest(request, channel, new WatcherClient(client));
|
return doPrepareRequest(request, new WatcherClient(client));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void handleRequest(RestRequest request, RestChannel channel, WatcherClient client) throws Exception;
|
protected abstract RestChannelConsumer doPrepareRequest(RestRequest request, WatcherClient client) throws IOException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,6 @@ import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.rest.BytesRestResponse;
|
import org.elasticsearch.rest.BytesRestResponse;
|
||||||
import org.elasticsearch.rest.RestChannel;
|
|
||||||
import org.elasticsearch.rest.RestController;
|
import org.elasticsearch.rest.RestController;
|
||||||
import org.elasticsearch.rest.RestRequest;
|
import org.elasticsearch.rest.RestRequest;
|
||||||
import org.elasticsearch.rest.RestResponse;
|
import org.elasticsearch.rest.RestResponse;
|
||||||
|
@ -22,6 +21,8 @@ import org.elasticsearch.xpack.watcher.transport.actions.ack.AckWatchRequest;
|
||||||
import org.elasticsearch.xpack.watcher.transport.actions.ack.AckWatchResponse;
|
import org.elasticsearch.xpack.watcher.transport.actions.ack.AckWatchResponse;
|
||||||
import org.elasticsearch.xpack.watcher.watch.Watch;
|
import org.elasticsearch.xpack.watcher.watch.Watch;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.POST;
|
import static org.elasticsearch.rest.RestRequest.Method.POST;
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.PUT;
|
import static org.elasticsearch.rest.RestRequest.Method.PUT;
|
||||||
|
|
||||||
|
@ -56,14 +57,14 @@ public class RestAckWatchAction extends WatcherRestHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleRequest(RestRequest request, RestChannel restChannel, WatcherClient client) throws Exception {
|
public RestChannelConsumer doPrepareRequest(RestRequest request, WatcherClient client) throws IOException {
|
||||||
AckWatchRequest ackWatchRequest = new AckWatchRequest(request.param("id"));
|
AckWatchRequest ackWatchRequest = new AckWatchRequest(request.param("id"));
|
||||||
String[] actions = request.paramAsStringArray("actions", null);
|
String[] actions = request.paramAsStringArray("actions", null);
|
||||||
if (actions != null) {
|
if (actions != null) {
|
||||||
ackWatchRequest.setActionIds(actions);
|
ackWatchRequest.setActionIds(actions);
|
||||||
}
|
}
|
||||||
ackWatchRequest.masterNodeTimeout(request.paramAsTime("master_timeout", ackWatchRequest.masterNodeTimeout()));
|
ackWatchRequest.masterNodeTimeout(request.paramAsTime("master_timeout", ackWatchRequest.masterNodeTimeout()));
|
||||||
client.ackWatch(ackWatchRequest, new RestBuilderListener<AckWatchResponse>(restChannel) {
|
return channel -> client.ackWatch(ackWatchRequest, new RestBuilderListener<AckWatchResponse>(channel) {
|
||||||
@Override
|
@Override
|
||||||
public RestResponse buildResponse(AckWatchResponse response, XContentBuilder builder) throws Exception {
|
public RestResponse buildResponse(AckWatchResponse response, XContentBuilder builder) throws Exception {
|
||||||
return new BytesRestResponse(RestStatus.OK, builder.startObject()
|
return new BytesRestResponse(RestStatus.OK, builder.startObject()
|
||||||
|
|
|
@ -9,7 +9,6 @@ import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.rest.BytesRestResponse;
|
import org.elasticsearch.rest.BytesRestResponse;
|
||||||
import org.elasticsearch.rest.RestChannel;
|
|
||||||
import org.elasticsearch.rest.RestController;
|
import org.elasticsearch.rest.RestController;
|
||||||
import org.elasticsearch.rest.RestRequest;
|
import org.elasticsearch.rest.RestRequest;
|
||||||
import org.elasticsearch.rest.RestResponse;
|
import org.elasticsearch.rest.RestResponse;
|
||||||
|
@ -22,6 +21,8 @@ import org.elasticsearch.xpack.watcher.transport.actions.activate.ActivateWatchR
|
||||||
import org.elasticsearch.xpack.watcher.transport.actions.activate.ActivateWatchResponse;
|
import org.elasticsearch.xpack.watcher.transport.actions.activate.ActivateWatchResponse;
|
||||||
import org.elasticsearch.xpack.watcher.watch.Watch;
|
import org.elasticsearch.xpack.watcher.watch.Watch;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.POST;
|
import static org.elasticsearch.rest.RestRequest.Method.POST;
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.PUT;
|
import static org.elasticsearch.rest.RestRequest.Method.PUT;
|
||||||
|
|
||||||
|
@ -48,35 +49,37 @@ public class RestActivateWatchAction extends WatcherRestHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleRequest(RestRequest request, RestChannel channel, WatcherClient client) throws Exception {
|
public RestChannelConsumer doPrepareRequest(RestRequest request, WatcherClient client) throws IOException {
|
||||||
String watchId = request.param("id");
|
String watchId = request.param("id");
|
||||||
client.activateWatch(new ActivateWatchRequest(watchId, true), new RestBuilderListener<ActivateWatchResponse>(channel) {
|
return channel ->
|
||||||
@Override
|
client.activateWatch(new ActivateWatchRequest(watchId, true), new RestBuilderListener<ActivateWatchResponse>(channel) {
|
||||||
public RestResponse buildResponse(ActivateWatchResponse response, XContentBuilder builder) throws Exception {
|
@Override
|
||||||
return new BytesRestResponse(RestStatus.OK, builder.startObject()
|
public RestResponse buildResponse(ActivateWatchResponse response, XContentBuilder builder) throws Exception {
|
||||||
.field(Watch.Field.STATUS.getPreferredName(), response.getStatus(), WatcherParams.HIDE_SECRETS)
|
return new BytesRestResponse(RestStatus.OK, builder.startObject()
|
||||||
.endObject());
|
.field(Watch.Field.STATUS.getPreferredName(), response.getStatus(), WatcherParams.HIDE_SECRETS)
|
||||||
}
|
.endObject());
|
||||||
});
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static class DeactivateRestHandler extends WatcherRestHandler {
|
private static class DeactivateRestHandler extends WatcherRestHandler {
|
||||||
|
|
||||||
public DeactivateRestHandler(Settings settings) {
|
DeactivateRestHandler(Settings settings) {
|
||||||
super(settings);
|
super(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleRequest(RestRequest request, RestChannel channel, WatcherClient client) throws Exception {
|
public RestChannelConsumer doPrepareRequest(RestRequest request, WatcherClient client) throws IOException {
|
||||||
String watchId = request.param("id");
|
String watchId = request.param("id");
|
||||||
client.activateWatch(new ActivateWatchRequest(watchId, false), new RestBuilderListener<ActivateWatchResponse>(channel) {
|
return channel ->
|
||||||
@Override
|
client.activateWatch(new ActivateWatchRequest(watchId, false), new RestBuilderListener<ActivateWatchResponse>(channel) {
|
||||||
public RestResponse buildResponse(ActivateWatchResponse response, XContentBuilder builder) throws Exception {
|
@Override
|
||||||
return new BytesRestResponse(RestStatus.OK, builder.startObject()
|
public RestResponse buildResponse(ActivateWatchResponse response, XContentBuilder builder) throws Exception {
|
||||||
.field(Watch.Field.STATUS.getPreferredName(), response.getStatus(), WatcherParams.HIDE_SECRETS)
|
return new BytesRestResponse(RestStatus.OK, builder.startObject()
|
||||||
.endObject());
|
.field(Watch.Field.STATUS.getPreferredName(), response.getStatus(), WatcherParams.HIDE_SECRETS)
|
||||||
}
|
.endObject());
|
||||||
});
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,6 @@ import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.rest.BytesRestResponse;
|
import org.elasticsearch.rest.BytesRestResponse;
|
||||||
import org.elasticsearch.rest.RestChannel;
|
|
||||||
import org.elasticsearch.rest.RestController;
|
import org.elasticsearch.rest.RestController;
|
||||||
import org.elasticsearch.rest.RestRequest;
|
import org.elasticsearch.rest.RestRequest;
|
||||||
import org.elasticsearch.rest.RestResponse;
|
import org.elasticsearch.rest.RestResponse;
|
||||||
|
@ -20,12 +19,12 @@ import org.elasticsearch.xpack.watcher.rest.WatcherRestHandler;
|
||||||
import org.elasticsearch.xpack.watcher.transport.actions.delete.DeleteWatchRequest;
|
import org.elasticsearch.xpack.watcher.transport.actions.delete.DeleteWatchRequest;
|
||||||
import org.elasticsearch.xpack.watcher.transport.actions.delete.DeleteWatchResponse;
|
import org.elasticsearch.xpack.watcher.transport.actions.delete.DeleteWatchResponse;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.DELETE;
|
import static org.elasticsearch.rest.RestRequest.Method.DELETE;
|
||||||
import static org.elasticsearch.rest.RestStatus.NOT_FOUND;
|
import static org.elasticsearch.rest.RestStatus.NOT_FOUND;
|
||||||
import static org.elasticsearch.rest.RestStatus.OK;
|
import static org.elasticsearch.rest.RestStatus.OK;
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
public class RestDeleteWatchAction extends WatcherRestHandler {
|
public class RestDeleteWatchAction extends WatcherRestHandler {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
|
@ -37,10 +36,10 @@ public class RestDeleteWatchAction extends WatcherRestHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void handleRequest(final RestRequest request, RestChannel channel, WatcherClient client) throws Exception {
|
protected RestChannelConsumer doPrepareRequest(final RestRequest request, WatcherClient client) throws IOException {
|
||||||
DeleteWatchRequest deleteWatchRequest = new DeleteWatchRequest(request.param("id"));
|
DeleteWatchRequest deleteWatchRequest = new DeleteWatchRequest(request.param("id"));
|
||||||
deleteWatchRequest.masterNodeTimeout(request.paramAsTime("master_timeout", deleteWatchRequest.masterNodeTimeout()));
|
deleteWatchRequest.masterNodeTimeout(request.paramAsTime("master_timeout", deleteWatchRequest.masterNodeTimeout()));
|
||||||
client.deleteWatch(deleteWatchRequest, new RestBuilderListener<DeleteWatchResponse>(channel) {
|
return channel -> client.deleteWatch(deleteWatchRequest, new RestBuilderListener<DeleteWatchResponse>(channel) {
|
||||||
@Override
|
@Override
|
||||||
public RestResponse buildResponse(DeleteWatchResponse response, XContentBuilder builder) throws Exception {
|
public RestResponse buildResponse(DeleteWatchResponse response, XContentBuilder builder) throws Exception {
|
||||||
builder.startObject()
|
builder.startObject()
|
||||||
|
@ -53,4 +52,5 @@ public class RestDeleteWatchAction extends WatcherRestHandler {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.rest.BytesRestResponse;
|
import org.elasticsearch.rest.BytesRestResponse;
|
||||||
import org.elasticsearch.rest.RestChannel;
|
|
||||||
import org.elasticsearch.rest.RestController;
|
import org.elasticsearch.rest.RestController;
|
||||||
import org.elasticsearch.rest.RestRequest;
|
import org.elasticsearch.rest.RestRequest;
|
||||||
import org.elasticsearch.rest.RestResponse;
|
import org.elasticsearch.rest.RestResponse;
|
||||||
|
@ -59,10 +58,10 @@ public class RestExecuteWatchAction extends WatcherRestHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void handleRequest(final RestRequest request, RestChannel channel, WatcherClient client) throws Exception {
|
protected RestChannelConsumer doPrepareRequest(final RestRequest request, WatcherClient client) throws IOException {
|
||||||
ExecuteWatchRequest executeWatchRequest = parseRequest(request, client);
|
ExecuteWatchRequest executeWatchRequest = parseRequest(request, client);
|
||||||
|
|
||||||
client.executeWatch(executeWatchRequest, new RestBuilderListener<ExecuteWatchResponse>(channel) {
|
return channel -> client.executeWatch(executeWatchRequest, new RestBuilderListener<ExecuteWatchResponse>(channel) {
|
||||||
@Override
|
@Override
|
||||||
public RestResponse buildResponse(ExecuteWatchResponse response, XContentBuilder builder) throws Exception {
|
public RestResponse buildResponse(ExecuteWatchResponse response, XContentBuilder builder) throws Exception {
|
||||||
builder.startObject();
|
builder.startObject();
|
||||||
|
|
|
@ -9,7 +9,6 @@ import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.rest.BytesRestResponse;
|
import org.elasticsearch.rest.BytesRestResponse;
|
||||||
import org.elasticsearch.rest.RestChannel;
|
|
||||||
import org.elasticsearch.rest.RestController;
|
import org.elasticsearch.rest.RestController;
|
||||||
import org.elasticsearch.rest.RestRequest;
|
import org.elasticsearch.rest.RestRequest;
|
||||||
import org.elasticsearch.rest.RestResponse;
|
import org.elasticsearch.rest.RestResponse;
|
||||||
|
@ -22,6 +21,8 @@ import org.elasticsearch.xpack.watcher.transport.actions.get.GetWatchRequest;
|
||||||
import org.elasticsearch.xpack.watcher.transport.actions.get.GetWatchResponse;
|
import org.elasticsearch.xpack.watcher.transport.actions.get.GetWatchResponse;
|
||||||
import org.elasticsearch.xpack.watcher.watch.WatchStatus;
|
import org.elasticsearch.xpack.watcher.watch.WatchStatus;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
||||||
import static org.elasticsearch.rest.RestStatus.NOT_FOUND;
|
import static org.elasticsearch.rest.RestStatus.NOT_FOUND;
|
||||||
import static org.elasticsearch.rest.RestStatus.OK;
|
import static org.elasticsearch.rest.RestStatus.OK;
|
||||||
|
@ -38,9 +39,9 @@ public class RestGetWatchAction extends WatcherRestHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void handleRequest(final RestRequest request, RestChannel channel, WatcherClient client) throws Exception {
|
protected RestChannelConsumer doPrepareRequest(final RestRequest request, WatcherClient client) throws IOException {
|
||||||
final GetWatchRequest getWatchRequest = new GetWatchRequest(request.param("id"));
|
final GetWatchRequest getWatchRequest = new GetWatchRequest(request.param("id"));
|
||||||
client.getWatch(getWatchRequest, new RestBuilderListener<GetWatchResponse>(channel) {
|
return channel -> client.getWatch(getWatchRequest, new RestBuilderListener<GetWatchResponse>(channel) {
|
||||||
@Override
|
@Override
|
||||||
public RestResponse buildResponse(GetWatchResponse response, XContentBuilder builder) throws Exception {
|
public RestResponse buildResponse(GetWatchResponse response, XContentBuilder builder) throws Exception {
|
||||||
builder.startObject()
|
builder.startObject()
|
||||||
|
|
|
@ -10,7 +10,6 @@ import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||||
import org.elasticsearch.rest.BytesRestResponse;
|
import org.elasticsearch.rest.BytesRestResponse;
|
||||||
import org.elasticsearch.rest.RestChannel;
|
|
||||||
import org.elasticsearch.rest.RestController;
|
import org.elasticsearch.rest.RestController;
|
||||||
import org.elasticsearch.rest.RestRequest;
|
import org.elasticsearch.rest.RestRequest;
|
||||||
import org.elasticsearch.rest.RestStatus;
|
import org.elasticsearch.rest.RestStatus;
|
||||||
|
@ -18,13 +17,13 @@ import org.elasticsearch.xpack.watcher.client.WatcherClient;
|
||||||
import org.elasticsearch.xpack.watcher.rest.WatcherRestHandler;
|
import org.elasticsearch.xpack.watcher.rest.WatcherRestHandler;
|
||||||
import org.elasticsearch.xpack.watcher.watch.WatchStore;
|
import org.elasticsearch.xpack.watcher.watch.WatchStore;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.DELETE;
|
import static org.elasticsearch.rest.RestRequest.Method.DELETE;
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.POST;
|
import static org.elasticsearch.rest.RestRequest.Method.POST;
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.PUT;
|
import static org.elasticsearch.rest.RestRequest.Method.PUT;
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
public class RestHijackOperationAction extends WatcherRestHandler {
|
public class RestHijackOperationAction extends WatcherRestHandler {
|
||||||
|
|
||||||
private static final String ALLOW_DIRECT_ACCESS_TO_WATCH_INDEX_SETTING = "xpack.watcher.index.rest.direct_access";
|
private static final String ALLOW_DIRECT_ACCESS_TO_WATCH_INDEX_SETTING = "xpack.watcher.index.rest.direct_access";
|
||||||
|
@ -50,32 +49,40 @@ public class RestHijackOperationAction extends WatcherRestHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleRequest(RestRequest request, RestChannel channel, WatcherClient client) throws Exception {
|
public RestChannelConsumer doPrepareRequest(RestRequest request, WatcherClient client) throws IOException {
|
||||||
|
// we have to consume the id parameter lest the request will fail for the wrong reason
|
||||||
|
if (request.hasParam("id")) {
|
||||||
|
request.param("id");
|
||||||
|
}
|
||||||
XContentBuilder jsonBuilder = XContentFactory.jsonBuilder();
|
XContentBuilder jsonBuilder = XContentFactory.jsonBuilder();
|
||||||
jsonBuilder.startObject().field("error","This endpoint is not supported for " +
|
jsonBuilder.startObject().field("error", "This endpoint is not supported for " +
|
||||||
request.method().name() + " on " + WatchStore.INDEX + " index. Please use " +
|
request.method().name() + " on " + WatchStore.INDEX + " index. Please use " +
|
||||||
request.method().name() + " " + URI_BASE + "/watch/<watch_id> instead");
|
request.method().name() + " " + URI_BASE + "/watch/<watch_id> instead");
|
||||||
jsonBuilder.field("status", RestStatus.BAD_REQUEST.getStatus());
|
jsonBuilder.field("status", RestStatus.BAD_REQUEST.getStatus());
|
||||||
jsonBuilder.endObject();
|
jsonBuilder.endObject();
|
||||||
channel.sendResponse(new BytesRestResponse(RestStatus.BAD_REQUEST, jsonBuilder));
|
return channel -> channel.sendResponse(new BytesRestResponse(RestStatus.BAD_REQUEST, jsonBuilder));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class UnsupportedHandler extends WatcherRestHandler {
|
private static class UnsupportedHandler extends WatcherRestHandler {
|
||||||
|
|
||||||
public UnsupportedHandler(Settings settings) {
|
private UnsupportedHandler(Settings settings) {
|
||||||
super(settings);
|
super(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleRequest(RestRequest request, RestChannel channel, WatcherClient client) throws Exception {
|
public RestChannelConsumer doPrepareRequest(RestRequest request, WatcherClient client) throws IOException {
|
||||||
request.path();
|
// we have to consume the id parameter lest the request will fail for the wrong reason
|
||||||
|
if (request.hasParam("id")) {
|
||||||
|
request.param("id");
|
||||||
|
}
|
||||||
XContentBuilder jsonBuilder = XContentFactory.jsonBuilder();
|
XContentBuilder jsonBuilder = XContentFactory.jsonBuilder();
|
||||||
jsonBuilder.startObject().field("error","This endpoint is not supported for " +
|
jsonBuilder.startObject().field("error", "This endpoint is not supported for " +
|
||||||
request.method().name() + " on " + WatchStore.INDEX + " index.");
|
request.method().name() + " on " + WatchStore.INDEX + " index.");
|
||||||
jsonBuilder.field("status", RestStatus.BAD_REQUEST.getStatus());
|
jsonBuilder.field("status", RestStatus.BAD_REQUEST.getStatus());
|
||||||
jsonBuilder.endObject();
|
jsonBuilder.endObject();
|
||||||
channel.sendResponse(new BytesRestResponse(RestStatus.BAD_REQUEST, jsonBuilder));
|
return channel -> channel.sendResponse(new BytesRestResponse(RestStatus.BAD_REQUEST, jsonBuilder));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,6 @@ import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.rest.BytesRestResponse;
|
import org.elasticsearch.rest.BytesRestResponse;
|
||||||
import org.elasticsearch.rest.RestChannel;
|
|
||||||
import org.elasticsearch.rest.RestController;
|
import org.elasticsearch.rest.RestController;
|
||||||
import org.elasticsearch.rest.RestRequest;
|
import org.elasticsearch.rest.RestRequest;
|
||||||
import org.elasticsearch.rest.RestResponse;
|
import org.elasticsearch.rest.RestResponse;
|
||||||
|
@ -20,13 +19,13 @@ import org.elasticsearch.xpack.watcher.rest.WatcherRestHandler;
|
||||||
import org.elasticsearch.xpack.watcher.transport.actions.put.PutWatchRequest;
|
import org.elasticsearch.xpack.watcher.transport.actions.put.PutWatchRequest;
|
||||||
import org.elasticsearch.xpack.watcher.transport.actions.put.PutWatchResponse;
|
import org.elasticsearch.xpack.watcher.transport.actions.put.PutWatchResponse;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.POST;
|
import static org.elasticsearch.rest.RestRequest.Method.POST;
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.PUT;
|
import static org.elasticsearch.rest.RestRequest.Method.PUT;
|
||||||
import static org.elasticsearch.rest.RestStatus.CREATED;
|
import static org.elasticsearch.rest.RestStatus.CREATED;
|
||||||
import static org.elasticsearch.rest.RestStatus.OK;
|
import static org.elasticsearch.rest.RestStatus.OK;
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
public class RestPutWatchAction extends WatcherRestHandler {
|
public class RestPutWatchAction extends WatcherRestHandler {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
|
@ -41,11 +40,11 @@ public class RestPutWatchAction extends WatcherRestHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void handleRequest(final RestRequest request, RestChannel channel, WatcherClient client) throws Exception {
|
protected RestChannelConsumer doPrepareRequest(final RestRequest request, WatcherClient client) throws IOException {
|
||||||
PutWatchRequest putWatchRequest = new PutWatchRequest(request.param("id"), request.content());
|
PutWatchRequest putWatchRequest = new PutWatchRequest(request.param("id"), request.content());
|
||||||
putWatchRequest.masterNodeTimeout(request.paramAsTime("master_timeout", putWatchRequest.masterNodeTimeout()));
|
putWatchRequest.masterNodeTimeout(request.paramAsTime("master_timeout", putWatchRequest.masterNodeTimeout()));
|
||||||
putWatchRequest.setActive(request.paramAsBoolean("active", putWatchRequest.isActive()));
|
putWatchRequest.setActive(request.paramAsBoolean("active", putWatchRequest.isActive()));
|
||||||
client.putWatch(putWatchRequest, new RestBuilderListener<PutWatchResponse>(channel) {
|
return channel -> client.putWatch(putWatchRequest, new RestBuilderListener<PutWatchResponse>(channel) {
|
||||||
@Override
|
@Override
|
||||||
public RestResponse buildResponse(PutWatchResponse response, XContentBuilder builder) throws Exception {
|
public RestResponse buildResponse(PutWatchResponse response, XContentBuilder builder) throws Exception {
|
||||||
builder.startObject()
|
builder.startObject()
|
||||||
|
@ -58,4 +57,5 @@ public class RestPutWatchAction extends WatcherRestHandler {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ package org.elasticsearch.xpack.watcher.rest.action;
|
||||||
|
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.rest.RestChannel;
|
|
||||||
import org.elasticsearch.rest.RestController;
|
import org.elasticsearch.rest.RestController;
|
||||||
import org.elasticsearch.rest.RestRequest;
|
import org.elasticsearch.rest.RestRequest;
|
||||||
import org.elasticsearch.rest.action.AcknowledgedRestListener;
|
import org.elasticsearch.rest.action.AcknowledgedRestListener;
|
||||||
|
@ -15,11 +14,11 @@ import org.elasticsearch.xpack.watcher.client.WatcherClient;
|
||||||
import org.elasticsearch.xpack.watcher.rest.WatcherRestHandler;
|
import org.elasticsearch.xpack.watcher.rest.WatcherRestHandler;
|
||||||
import org.elasticsearch.xpack.watcher.transport.actions.service.WatcherServiceRequest;
|
import org.elasticsearch.xpack.watcher.transport.actions.service.WatcherServiceRequest;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.POST;
|
import static org.elasticsearch.rest.RestRequest.Method.POST;
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.PUT;
|
import static org.elasticsearch.rest.RestRequest.Method.PUT;
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
public class RestWatchServiceAction extends WatcherRestHandler {
|
public class RestWatchServiceAction extends WatcherRestHandler {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
|
@ -37,31 +36,34 @@ public class RestWatchServiceAction extends WatcherRestHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleRequest(RestRequest request, RestChannel channel, WatcherClient client) throws Exception {
|
public RestChannelConsumer doPrepareRequest(RestRequest request, WatcherClient client) throws IOException {
|
||||||
client.watcherService(new WatcherServiceRequest().restart(), new AcknowledgedRestListener<>(channel));
|
return channel -> client.watcherService(new WatcherServiceRequest().restart(), new AcknowledgedRestListener<>(channel));
|
||||||
}
|
}
|
||||||
|
|
||||||
static class StartRestHandler extends WatcherRestHandler {
|
private static class StartRestHandler extends WatcherRestHandler {
|
||||||
|
|
||||||
public StartRestHandler(Settings settings) {
|
StartRestHandler(Settings settings) {
|
||||||
super(settings);
|
super(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleRequest(RestRequest request, RestChannel channel, WatcherClient client) throws Exception {
|
public RestChannelConsumer doPrepareRequest(RestRequest request, WatcherClient client) throws IOException {
|
||||||
client.watcherService(new WatcherServiceRequest().start(), new AcknowledgedRestListener<>(channel));
|
return channel -> client.watcherService(new WatcherServiceRequest().start(), new AcknowledgedRestListener<>(channel));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static class StopRestHandler extends WatcherRestHandler {
|
private static class StopRestHandler extends WatcherRestHandler {
|
||||||
|
|
||||||
public StopRestHandler(Settings settings) {
|
StopRestHandler(Settings settings) {
|
||||||
super(settings);
|
super(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleRequest(RestRequest request, RestChannel channel, WatcherClient client) throws Exception {
|
public RestChannelConsumer doPrepareRequest(RestRequest request, WatcherClient client) throws IOException {
|
||||||
client.watcherService(new WatcherServiceRequest().stop(), new AcknowledgedRestListener<>(channel));
|
return channel -> client.watcherService(new WatcherServiceRequest().stop(), new AcknowledgedRestListener<>(channel));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@ import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.rest.BytesRestResponse;
|
import org.elasticsearch.rest.BytesRestResponse;
|
||||||
import org.elasticsearch.rest.RestChannel;
|
|
||||||
import org.elasticsearch.rest.RestController;
|
import org.elasticsearch.rest.RestController;
|
||||||
import org.elasticsearch.rest.RestRequest;
|
import org.elasticsearch.rest.RestRequest;
|
||||||
import org.elasticsearch.rest.RestResponse;
|
import org.elasticsearch.rest.RestResponse;
|
||||||
|
@ -20,6 +19,7 @@ import org.elasticsearch.xpack.watcher.rest.WatcherRestHandler;
|
||||||
import org.elasticsearch.xpack.watcher.transport.actions.stats.WatcherStatsRequest;
|
import org.elasticsearch.xpack.watcher.transport.actions.stats.WatcherStatsRequest;
|
||||||
import org.elasticsearch.xpack.watcher.transport.actions.stats.WatcherStatsResponse;
|
import org.elasticsearch.xpack.watcher.transport.actions.stats.WatcherStatsResponse;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
||||||
|
@ -39,7 +39,7 @@ public class RestWatcherStatsAction extends WatcherRestHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void handleRequest(final RestRequest restRequest, RestChannel restChannel, WatcherClient client) throws Exception {
|
protected RestChannelConsumer doPrepareRequest(final RestRequest restRequest, WatcherClient client) throws IOException {
|
||||||
Set<String> metrics = Strings.splitStringByCommaToSet(restRequest.param("metric", ""));
|
Set<String> metrics = Strings.splitStringByCommaToSet(restRequest.param("metric", ""));
|
||||||
|
|
||||||
WatcherStatsRequest request = new WatcherStatsRequest();
|
WatcherStatsRequest request = new WatcherStatsRequest();
|
||||||
|
@ -51,7 +51,7 @@ public class RestWatcherStatsAction extends WatcherRestHandler {
|
||||||
request.includeQueuedWatches(metrics.contains("pending_watches"));
|
request.includeQueuedWatches(metrics.contains("pending_watches"));
|
||||||
}
|
}
|
||||||
|
|
||||||
client.watcherStats(request, new RestBuilderListener<WatcherStatsResponse>(restChannel) {
|
return channel -> client.watcherStats(request, new RestBuilderListener<WatcherStatsResponse>(channel) {
|
||||||
@Override
|
@Override
|
||||||
public RestResponse buildResponse(WatcherStatsResponse watcherStatsResponse, XContentBuilder builder) throws Exception {
|
public RestResponse buildResponse(WatcherStatsResponse watcherStatsResponse, XContentBuilder builder) throws Exception {
|
||||||
watcherStatsResponse.toXContent(builder, restRequest);
|
watcherStatsResponse.toXContent(builder, restRequest);
|
||||||
|
|
|
@ -424,7 +424,6 @@ public class HttpExporterIT extends MonitoringIntegTestCase {
|
||||||
assertThat(request.getMethod(), equalTo("GET"));
|
assertThat(request.getMethod(), equalTo("GET"));
|
||||||
assertThat(request.getPath(), startsWith(pathPrefix + "/.marvel-es-1-*"));
|
assertThat(request.getPath(), startsWith(pathPrefix + "/.marvel-es-1-*"));
|
||||||
assertThat(request.getPath(), containsString("filter_path=*.aliases"));
|
assertThat(request.getPath(), containsString("filter_path=*.aliases"));
|
||||||
assertThat(request.getPath(), containsString("master_timeout=30s"));
|
|
||||||
assertHeaders(request, customHeaders);
|
assertHeaders(request, customHeaders);
|
||||||
|
|
||||||
if (expectPost) {
|
if (expectPost) {
|
||||||
|
|
|
@ -41,8 +41,8 @@ public class RestExecuteWatchActionTests extends ESTestCase {
|
||||||
|
|
||||||
RestExecuteWatchAction restExecuteWatchAction = new RestExecuteWatchAction(Settings.EMPTY, restController,
|
RestExecuteWatchAction restExecuteWatchAction = new RestExecuteWatchAction(Settings.EMPTY, restController,
|
||||||
triggerService);
|
triggerService);
|
||||||
restExecuteWatchAction.handleRequest(createFakeRestRequest(randomId, recordExecution, ignoreCondition,
|
restExecuteWatchAction.doPrepareRequest(createFakeRestRequest(randomId, recordExecution, ignoreCondition,
|
||||||
debugCondition), restChannel, watcherClient);
|
debugCondition), watcherClient);
|
||||||
|
|
||||||
assertThat(builder.request().getId(), is(randomId));
|
assertThat(builder.request().getId(), is(randomId));
|
||||||
assertThat(builder.request().isRecordExecution(), is(Boolean.parseBoolean(recordExecution)));
|
assertThat(builder.request().isRecordExecution(), is(Boolean.parseBoolean(recordExecution)));
|
||||||
|
|
Loading…
Reference in New Issue