Since some of the rest handlers depend on components constructed
in `createComponents` we use `SetOnce` to save a reference to
the components at the class level and reuse the reference in
`initRestHandlers`. This does require that `initRestHandlers`
is called after `createComponents` but I think that is fairly
reasonable.

Original commit: elastic/x-pack-elasticsearch@4fd87ad911
This commit is contained in:
Nik Everett 2017-01-20 11:49:20 -05:00 committed by GitHub
parent 8f70653233
commit d690c5f789
34 changed files with 112 additions and 138 deletions

View File

@ -8,21 +8,27 @@ package org.elasticsearch.license;
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.cluster.NamedDiff;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.settings.ClusterSettings;
import org.elasticsearch.common.settings.IndexScopedSettings;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsFilter;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.plugins.ActionPlugin;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestHandler;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.function.Supplier;
import static java.util.Collections.emptyList;
import static org.elasticsearch.xpack.XPackPlugin.isTribeNode;
import static org.elasticsearch.xpack.XPackPlugin.transportClientMode;
@ -64,13 +70,16 @@ public class Licensing implements ActionPlugin {
}
@Override
public List<Class<? extends RestHandler>> getRestHandlers() {
if (isTribeNode) {
return Collections.singletonList(RestGetLicenseAction.class);
public List<RestHandler> getRestHandlers(Settings settings, RestController restController, ClusterSettings clusterSettings,
IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver,
Supplier<DiscoveryNodes> nodesInCluster) {
List<RestHandler> handlers = new ArrayList<>();
handlers.add(new RestGetLicenseAction(settings, restController));
if (false == isTribeNode) {
handlers.add(new RestPutLicenseAction(settings, restController));
handlers.add(new RestDeleteLicenseAction(settings, restController));
}
return Arrays.asList(RestPutLicenseAction.class,
RestGetLicenseAction.class,
RestDeleteLicenseAction.class);
return handlers;
}
public List<Setting<?>> getSettings() {

View File

@ -5,7 +5,6 @@
*/
package org.elasticsearch.license;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
@ -18,8 +17,6 @@ import java.io.IOException;
import static org.elasticsearch.rest.RestRequest.Method.DELETE;
public class RestDeleteLicenseAction extends XPackRestHandler {
@Inject
public RestDeleteLicenseAction(Settings settings, RestController controller) {
super(settings);
// @deprecated Remove deprecations in 6.0

View File

@ -5,7 +5,6 @@
*/
package org.elasticsearch.license;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
@ -24,8 +23,6 @@ import static org.elasticsearch.rest.RestRequest.Method.POST;
import static org.elasticsearch.rest.RestRequest.Method.PUT;
public class RestPutLicenseAction extends XPackRestHandler {
@Inject
public RestPutLicenseAction(Settings settings, RestController controller) {
super(settings);
// @deprecated Remove deprecations in 6.0

View File

@ -11,6 +11,8 @@ import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.action.support.ActionFilter;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.inject.Binder;
import org.elasticsearch.common.inject.Module;
@ -19,8 +21,10 @@ import org.elasticsearch.common.inject.util.Providers;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.network.NetworkService;
import org.elasticsearch.common.settings.ClusterSettings;
import org.elasticsearch.common.settings.IndexScopedSettings;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsFilter;
import org.elasticsearch.common.util.BigArrays;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
@ -37,6 +41,7 @@ import org.elasticsearch.plugins.IngestPlugin;
import org.elasticsearch.plugins.NetworkPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.plugins.ScriptPlugin;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestHandler;
import org.elasticsearch.script.ScriptContext;
import org.elasticsearch.script.ScriptService;
@ -387,15 +392,22 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin, I
}
@Override
public List<Class<? extends RestHandler>> getRestHandlers() {
List<Class<? extends RestHandler>> handlers = new ArrayList<>();
handlers.add(RestXPackInfoAction.class);
handlers.add(RestXPackUsageAction.class);
handlers.addAll(licensing.getRestHandlers());
handlers.addAll(monitoring.getRestHandlers());
handlers.addAll(security.getRestHandlers());
handlers.addAll(watcher.getRestHandlers());
handlers.addAll(graph.getRestHandlers());
public List<RestHandler> getRestHandlers(Settings settings, RestController restController, ClusterSettings clusterSettings,
IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver,
Supplier<DiscoveryNodes> nodesInCluster) {
List<RestHandler> handlers = new ArrayList<>();
handlers.add(new RestXPackInfoAction(settings, restController));
handlers.add(new RestXPackUsageAction(settings, restController));
handlers.addAll(licensing.getRestHandlers(settings, restController, clusterSettings, indexScopedSettings, settingsFilter,
indexNameExpressionResolver, nodesInCluster));
handlers.addAll(monitoring.getRestHandlers(settings, restController, clusterSettings, indexScopedSettings, settingsFilter,
indexNameExpressionResolver, nodesInCluster));
handlers.addAll(security.getRestHandlers(settings, restController, clusterSettings, indexScopedSettings, settingsFilter,
indexNameExpressionResolver, nodesInCluster));
handlers.addAll(watcher.getRestHandlers(settings, restController, clusterSettings, indexScopedSettings, settingsFilter,
indexNameExpressionResolver, nodesInCluster));
handlers.addAll(graph.getRestHandlers(settings, restController, clusterSettings, indexScopedSettings, settingsFilter,
indexNameExpressionResolver, nodesInCluster));
return handlers;
}

View File

@ -7,10 +7,16 @@ package org.elasticsearch.xpack.graph;
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.common.inject.Module;
import org.elasticsearch.common.settings.ClusterSettings;
import org.elasticsearch.common.settings.IndexScopedSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsFilter;
import org.elasticsearch.plugins.ActionPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestHandler;
import org.elasticsearch.xpack.XPackPlugin;
import org.elasticsearch.xpack.XPackSettings;
@ -21,6 +27,7 @@ import org.elasticsearch.xpack.graph.rest.action.RestGraphAction;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.function.Supplier;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
@ -50,10 +57,12 @@ public class Graph extends Plugin implements ActionPlugin {
}
@Override
public List<Class<? extends RestHandler>> getRestHandlers() {
public List<RestHandler> getRestHandlers(Settings settings, RestController restController, ClusterSettings clusterSettings,
IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver,
Supplier<DiscoveryNodes> nodesInCluster) {
if (false == enabled) {
return emptyList();
}
return singletonList(RestGraphAction.class);
return singletonList(new RestGraphAction(settings, restController));
}
}

View File

@ -9,7 +9,6 @@ import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentParser;
@ -56,7 +55,6 @@ public class RestGraphAction extends XPackRestHandler {
public static final ParseField BOOST_FIELD = new ParseField("boost");
public static final ParseField TERM_FIELD = new ParseField("term");
@Inject
public RestGraphAction(Settings settings, RestController controller) {
super(settings);

View File

@ -7,18 +7,26 @@ package org.elasticsearch.xpack.monitoring;
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.inject.Module;
import org.elasticsearch.common.inject.util.Providers;
import org.elasticsearch.common.settings.ClusterSettings;
import org.elasticsearch.common.settings.IndexScopedSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsFilter;
import org.elasticsearch.license.LicenseService;
import org.elasticsearch.license.XPackLicenseState;
import org.elasticsearch.plugins.ActionPlugin;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestHandler;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.XPackPlugin;
import org.elasticsearch.xpack.XPackSettings;
import org.elasticsearch.xpack.monitoring.action.MonitoringBulkAction;
import org.elasticsearch.xpack.monitoring.action.TransportMonitoringBulkAction;
import org.elasticsearch.xpack.monitoring.cleaner.CleanerService;
import org.elasticsearch.xpack.monitoring.collector.Collector;
import org.elasticsearch.xpack.monitoring.collector.cluster.ClusterStateCollector;
import org.elasticsearch.xpack.monitoring.collector.cluster.ClusterStatsCollector;
@ -31,14 +39,10 @@ import org.elasticsearch.xpack.monitoring.exporter.Exporter;
import org.elasticsearch.xpack.monitoring.exporter.Exporters;
import org.elasticsearch.xpack.monitoring.exporter.http.HttpExporter;
import org.elasticsearch.xpack.monitoring.exporter.local.LocalExporter;
import org.elasticsearch.xpack.monitoring.cleaner.CleanerService;
import org.elasticsearch.xpack.monitoring.rest.action.RestMonitoringBulkAction;
import org.elasticsearch.plugins.ActionPlugin;
import org.elasticsearch.rest.RestHandler;
import org.elasticsearch.xpack.security.InternalClient;
import org.elasticsearch.xpack.ssl.SSLService;
import java.time.Clock;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@ -48,6 +52,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Supplier;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
@ -135,10 +140,12 @@ public class Monitoring implements ActionPlugin {
}
@Override
public List<Class<? extends RestHandler>> getRestHandlers() {
public List<RestHandler> getRestHandlers(Settings settings, RestController restController, ClusterSettings clusterSettings,
IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver,
Supplier<DiscoveryNodes> nodesInCluster) {
if (false == enabled || tribeNode) {
return emptyList();
}
return singletonList(RestMonitoringBulkAction.class);
return singletonList(new RestMonitoringBulkAction(settings, restController));
}
}

View File

@ -7,7 +7,6 @@ package org.elasticsearch.xpack.monitoring.rest.action;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.rest.BytesRestResponse;
@ -31,7 +30,6 @@ public class RestMonitoringBulkAction extends MonitoringRestHandler {
public static final String MONITORING_VERSION = "system_api_version";
public static final String INTERVAL = "interval";
@Inject
public RestMonitoringBulkAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(POST, URI_BASE + "/_bulk", this);

View File

@ -5,12 +5,9 @@
*/
package org.elasticsearch.xpack.rest.action;
import java.io.IOException;
import java.util.EnumSet;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.license.XPackInfoResponse;
import org.elasticsearch.rest.BytesRestResponse;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
@ -18,16 +15,16 @@ import org.elasticsearch.rest.RestResponse;
import org.elasticsearch.rest.action.RestBuilderListener;
import org.elasticsearch.xpack.XPackClient;
import org.elasticsearch.xpack.action.XPackInfoRequest;
import org.elasticsearch.license.XPackInfoResponse;
import org.elasticsearch.xpack.rest.XPackRestHandler;
import java.io.IOException;
import java.util.EnumSet;
import static org.elasticsearch.rest.RestRequest.Method.GET;
import static org.elasticsearch.rest.RestRequest.Method.HEAD;
import static org.elasticsearch.rest.RestStatus.OK;
public class RestXPackInfoAction extends XPackRestHandler {
@Inject
public RestXPackInfoAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(HEAD, URI_BASE, this);

View File

@ -6,7 +6,6 @@
package org.elasticsearch.xpack.rest.action;
import org.elasticsearch.action.support.master.MasterNodeRequest;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentBuilder;
@ -27,8 +26,6 @@ import static org.elasticsearch.rest.RestRequest.Method.GET;
import static org.elasticsearch.rest.RestStatus.OK;
public class RestXPackUsageAction extends XPackRestHandler {
@Inject
public RestXPackUsageAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(GET, URI_BASE + "/usage", this);

View File

@ -11,6 +11,8 @@ import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.action.support.ActionFilter;
import org.elasticsearch.action.support.DestructiveOperations;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.Booleans;
import org.elasticsearch.common.Nullable;
@ -23,9 +25,12 @@ import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.network.NetworkModule;
import org.elasticsearch.common.network.NetworkService;
import org.elasticsearch.common.regex.Regex;
import org.elasticsearch.common.settings.ClusterSettings;
import org.elasticsearch.common.settings.IndexScopedSettings;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Setting.Property;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsFilter;
import org.elasticsearch.common.util.BigArrays;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
@ -38,6 +43,7 @@ import org.elasticsearch.license.XPackLicenseState;
import org.elasticsearch.plugins.ActionPlugin;
import org.elasticsearch.plugins.IngestPlugin;
import org.elasticsearch.plugins.NetworkPlugin;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestHandler;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.Transport;
@ -169,6 +175,7 @@ public class Security implements ActionPlugin, IngestPlugin, NetworkPlugin {
private final SetOnce<TransportInterceptor> securityInterceptor = new SetOnce<>();
private final SetOnce<IPFilter> ipFilter = new SetOnce<>();
private final SetOnce<AuthenticationService> authcService = new SetOnce<>();
private final SetOnce<SecurityContext> securityContext = new SetOnce<>();
public Security(Settings settings, Environment env, XPackLicenseState licenseState, SSLService sslService) throws IOException {
this.settings = settings;
@ -241,8 +248,8 @@ public class Security implements ActionPlugin, IngestPlugin, NetworkPlugin {
}
List<Object> components = new ArrayList<>();
final SecurityContext securityContext = new SecurityContext(settings, threadPool.getThreadContext(), cryptoService);
components.add(securityContext);
securityContext.set(new SecurityContext(settings, threadPool.getThreadContext(), cryptoService));
components.add(securityContext.get());
// realms construction
final NativeUsersStore nativeUsersStore = new NativeUsersStore(settings, client);
@ -335,7 +342,7 @@ public class Security implements ActionPlugin, IngestPlugin, NetworkPlugin {
components.add(ipFilter.get());
DestructiveOperations destructiveOperations = new DestructiveOperations(settings, clusterService.getClusterSettings());
securityInterceptor.set(new SecurityServerTransportInterceptor(settings, threadPool, authcService.get(), authzService, licenseState,
sslService, securityContext, destructiveOperations));
sslService, securityContext.get(), destructiveOperations));
return components;
}
@ -500,21 +507,24 @@ public class Security implements ActionPlugin, IngestPlugin, NetworkPlugin {
}
@Override
public List<Class<? extends RestHandler>> getRestHandlers() {
public List<RestHandler> getRestHandlers(Settings settings, RestController restController, ClusterSettings clusterSettings,
IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver,
Supplier<DiscoveryNodes> nodesInCluster) {
if (enabled == false) {
return emptyList();
}
return Arrays.asList(RestAuthenticateAction.class,
RestClearRealmCacheAction.class,
RestClearRolesCacheAction.class,
RestGetUsersAction.class,
RestPutUserAction.class,
RestDeleteUserAction.class,
RestGetRolesAction.class,
RestPutRoleAction.class,
RestDeleteRoleAction.class,
RestChangePasswordAction.class,
RestSetEnabledAction.class);
return Arrays.asList(
new RestAuthenticateAction(settings, restController, securityContext.get(), licenseState),
new RestClearRealmCacheAction(settings, restController),
new RestClearRolesCacheAction(settings, restController),
new RestGetUsersAction(settings, restController),
new RestPutUserAction(settings, restController),
new RestDeleteUserAction(settings, restController),
new RestGetRolesAction(settings, restController),
new RestPutRoleAction(settings, restController),
new RestDeleteRoleAction(settings, restController),
new RestChangePasswordAction(settings, restController, securityContext.get()),
new RestSetEnabledAction(settings, restController));
}
@Override

View File

@ -11,7 +11,6 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.common.util.concurrent.ThreadContext.StoredContext;
import org.elasticsearch.node.Node;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.security.authc.Authentication;
import org.elasticsearch.xpack.security.authc.AuthenticationService;
import org.elasticsearch.xpack.security.crypto.CryptoService;

View File

@ -6,7 +6,6 @@
package org.elasticsearch.xpack.security.rest.action;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
@ -35,7 +34,6 @@ public class RestAuthenticateAction extends BaseRestHandler {
private final SecurityContext securityContext;
private final XPackLicenseState licenseState;
@Inject
public RestAuthenticateAction(Settings settings, RestController controller, SecurityContext securityContext,
XPackLicenseState licenseState) {
super(settings);

View File

@ -6,7 +6,6 @@
package org.elasticsearch.xpack.security.rest.action.realm;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestController;
@ -20,8 +19,6 @@ import java.io.IOException;
import static org.elasticsearch.rest.RestRequest.Method.POST;
public class RestClearRealmCacheAction extends BaseRestHandler {
@Inject
public RestClearRealmCacheAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(POST, "/_xpack/security/realm/{realms}/_clear_cache", this);

View File

@ -6,7 +6,6 @@
package org.elasticsearch.xpack.security.rest.action.role;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestController;
@ -20,8 +19,6 @@ import java.io.IOException;
import static org.elasticsearch.rest.RestRequest.Method.POST;
public class RestClearRolesCacheAction extends BaseRestHandler {
@Inject
public RestClearRolesCacheAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(POST, "/_xpack/security/role/{name}/_clear_cache", this);

View File

@ -6,7 +6,6 @@
package org.elasticsearch.xpack.security.rest.action.role;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.rest.BaseRestHandler;
@ -27,8 +26,6 @@ import static org.elasticsearch.rest.RestRequest.Method.DELETE;
* Rest endpoint to delete a Role from the security index
*/
public class RestDeleteRoleAction extends BaseRestHandler {
@Inject
public RestDeleteRoleAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(DELETE, "/_xpack/security/role/{name}", this);

View File

@ -7,7 +7,6 @@ package org.elasticsearch.xpack.security.rest.action.role;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.rest.BaseRestHandler;
@ -29,8 +28,6 @@ import static org.elasticsearch.rest.RestRequest.Method.GET;
* Rest endpoint to retrieve a Role from the security index
*/
public class RestGetRolesAction extends BaseRestHandler {
@Inject
public RestGetRolesAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(GET, "/_xpack/security/role/", this);

View File

@ -6,7 +6,6 @@
package org.elasticsearch.xpack.security.rest.action.role;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.rest.BaseRestHandler;
@ -29,8 +28,6 @@ import static org.elasticsearch.rest.RestRequest.Method.PUT;
* Rest endpoint to add a Role to the security index
*/
public class RestPutRoleAction extends BaseRestHandler {
@Inject
public RestPutRoleAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(POST, "/_xpack/security/role/{name}", this);

View File

@ -6,7 +6,6 @@
package org.elasticsearch.xpack.security.rest.action.user;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.rest.BaseRestHandler;
@ -30,7 +29,6 @@ public class RestChangePasswordAction extends BaseRestHandler {
private final SecurityContext securityContext;
@Inject
public RestChangePasswordAction(Settings settings, RestController controller, SecurityContext securityContext) {
super(settings);
this.securityContext = securityContext;

View File

@ -6,7 +6,6 @@
package org.elasticsearch.xpack.security.rest.action.user;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.rest.BaseRestHandler;
@ -27,8 +26,6 @@ import static org.elasticsearch.rest.RestRequest.Method.DELETE;
* Rest action to delete a user from the security index
*/
public class RestDeleteUserAction extends BaseRestHandler {
@Inject
public RestDeleteUserAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(DELETE, "/_xpack/security/user/{username}", this);

View File

@ -7,7 +7,6 @@ package org.elasticsearch.xpack.security.rest.action.user;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.rest.BaseRestHandler;
@ -29,8 +28,6 @@ import static org.elasticsearch.rest.RestRequest.Method.GET;
* Rest action to retrieve a user from the security index
*/
public class RestGetUsersAction extends BaseRestHandler {
@Inject
public RestGetUsersAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(GET, "/_xpack/security/user/", this);

View File

@ -6,7 +6,6 @@
package org.elasticsearch.xpack.security.rest.action.user;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.rest.BaseRestHandler;
@ -29,8 +28,6 @@ import static org.elasticsearch.rest.RestRequest.Method.PUT;
* Rest endpoint to add a User to the security index
*/
public class RestPutUserAction extends BaseRestHandler {
@Inject
public RestPutUserAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(POST, "/_xpack/security/user/{username}", this);

View File

@ -6,7 +6,6 @@
package org.elasticsearch.xpack.security.rest.action.user;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.rest.BaseRestHandler;
@ -29,8 +28,6 @@ import static org.elasticsearch.rest.RestRequest.Method.PUT;
* enabled or disabled.
*/
public class RestSetEnabledAction extends BaseRestHandler {
@Inject
public RestSetEnabledAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(POST, "/_xpack/security/user/{username}/_enable", this);

View File

@ -10,7 +10,9 @@ import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.cluster.NamedDiff;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.Booleans;
import org.elasticsearch.common.ParseField;
@ -21,14 +23,18 @@ import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.logging.LoggerMessageFormat;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.regex.Regex;
import org.elasticsearch.common.settings.ClusterSettings;
import org.elasticsearch.common.settings.IndexScopedSettings;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsFilter;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.util.concurrent.EsExecutors;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.license.XPackLicenseState;
import org.elasticsearch.plugins.ActionPlugin;
import org.elasticsearch.plugins.ScriptPlugin;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestHandler;
import org.elasticsearch.script.ScriptContext;
import org.elasticsearch.script.ScriptService;
@ -157,6 +163,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import static java.util.Collections.emptyList;
@ -419,19 +426,22 @@ public class Watcher implements ActionPlugin, ScriptPlugin {
}
@Override
public List<Class<? extends RestHandler>> getRestHandlers() {
public List<RestHandler> getRestHandlers(Settings settings, RestController restController, ClusterSettings clusterSettings,
IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver,
Supplier<DiscoveryNodes> nodesInCluster) {
if (false == enabled) {
return emptyList();
}
return Arrays.asList(RestPutWatchAction.class,
RestDeleteWatchAction.class,
RestWatcherStatsAction.class,
RestGetWatchAction.class,
RestWatchServiceAction.class,
RestAckWatchAction.class,
RestActivateWatchAction.class,
RestExecuteWatchAction.class,
RestHijackOperationAction.class);
return Arrays.asList(
new RestPutWatchAction(settings, restController),
new RestDeleteWatchAction(settings, restController),
new RestWatcherStatsAction(settings, restController),
new RestGetWatchAction(settings, restController),
new RestWatchServiceAction(settings, restController),
new RestAckWatchAction(settings, restController),
new RestActivateWatchAction(settings, restController),
new RestExecuteWatchAction(settings, restController),
new RestHijackOperationAction(settings, restController));
}
@Override

View File

@ -5,7 +5,6 @@
*/
package org.elasticsearch.xpack.watcher.rest.action;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.rest.BytesRestResponse;
@ -30,8 +29,6 @@ import static org.elasticsearch.rest.RestRequest.Method.PUT;
* The rest action to ack a watch
*/
public class RestAckWatchAction extends WatcherRestHandler {
@Inject
public RestAckWatchAction(Settings settings, RestController controller) {
super(settings);
// @deprecated Remove deprecations in 6.0

View File

@ -5,7 +5,6 @@
*/
package org.elasticsearch.xpack.watcher.rest.action;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.rest.BytesRestResponse;
@ -30,8 +29,6 @@ import static org.elasticsearch.rest.RestRequest.Method.PUT;
* The rest action to de/activate a watch
*/
public class RestActivateWatchAction extends WatcherRestHandler {
@Inject
public RestActivateWatchAction(Settings settings, RestController controller) {
super(settings);

View File

@ -5,7 +5,6 @@
*/
package org.elasticsearch.xpack.watcher.rest.action;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.rest.BytesRestResponse;
@ -26,8 +25,6 @@ import static org.elasticsearch.rest.RestStatus.NOT_FOUND;
import static org.elasticsearch.rest.RestStatus.OK;
public class RestDeleteWatchAction extends WatcherRestHandler {
@Inject
public RestDeleteWatchAction(Settings settings, RestController controller) {
super(settings);
// @deprecated Remove deprecations in 6.0

View File

@ -7,7 +7,6 @@ package org.elasticsearch.xpack.watcher.rest.action;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentHelper;
@ -25,7 +24,6 @@ import org.elasticsearch.xpack.watcher.support.xcontent.WatcherParams;
import org.elasticsearch.xpack.watcher.transport.actions.execute.ExecuteWatchRequest;
import org.elasticsearch.xpack.watcher.transport.actions.execute.ExecuteWatchRequestBuilder;
import org.elasticsearch.xpack.watcher.transport.actions.execute.ExecuteWatchResponse;
import org.elasticsearch.xpack.watcher.trigger.TriggerService;
import java.io.IOException;
@ -35,13 +33,8 @@ import static org.elasticsearch.xpack.watcher.rest.action.RestExecuteWatchAction
import static org.elasticsearch.xpack.watcher.rest.action.RestExecuteWatchAction.Field.RECORD_EXECUTION;
public class RestExecuteWatchAction extends WatcherRestHandler {
final TriggerService triggerService;
@Inject
public RestExecuteWatchAction(Settings settings, RestController controller, TriggerService triggerService) {
public RestExecuteWatchAction(Settings settings, RestController controller) {
super(settings);
this.triggerService = triggerService;
// @deprecated Remove deprecations in 6.0
controller.registerWithDeprecatedHandler(POST, URI_BASE + "/watch/{id}/_execute", this,

View File

@ -5,7 +5,6 @@
*/
package org.elasticsearch.xpack.watcher.rest.action;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
@ -27,8 +26,6 @@ import static org.elasticsearch.rest.RestStatus.NOT_FOUND;
import static org.elasticsearch.rest.RestStatus.OK;
public class RestGetWatchAction extends WatcherRestHandler {
@Inject
public RestGetWatchAction(Settings settings, RestController controller) {
super(settings);

View File

@ -5,7 +5,6 @@
*/
package org.elasticsearch.xpack.watcher.rest.action;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
@ -28,7 +27,6 @@ public class RestHijackOperationAction extends WatcherRestHandler {
private static final String ALLOW_DIRECT_ACCESS_TO_WATCH_INDEX_SETTING = "xpack.watcher.index.rest.direct_access";
@Inject
public RestHijackOperationAction(Settings settings, RestController controller) {
super(settings);
if (!settings.getAsBoolean(ALLOW_DIRECT_ACCESS_TO_WATCH_INDEX_SETTING, false)) {

View File

@ -5,7 +5,6 @@
*/
package org.elasticsearch.xpack.watcher.rest.action;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.rest.BytesRestResponse;
@ -27,8 +26,6 @@ import static org.elasticsearch.rest.RestStatus.CREATED;
import static org.elasticsearch.rest.RestStatus.OK;
public class RestPutWatchAction extends WatcherRestHandler {
@Inject
public RestPutWatchAction(Settings settings, RestController controller) {
super(settings);

View File

@ -5,7 +5,6 @@
*/
package org.elasticsearch.xpack.watcher.rest.action;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
@ -20,8 +19,6 @@ import static org.elasticsearch.rest.RestRequest.Method.POST;
import static org.elasticsearch.rest.RestRequest.Method.PUT;
public class RestWatchServiceAction extends WatcherRestHandler {
@Inject
public RestWatchServiceAction(Settings settings, RestController controller) {
super(settings);

View File

@ -6,7 +6,6 @@
package org.elasticsearch.xpack.watcher.rest.action;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.rest.BytesRestResponse;
@ -26,8 +25,6 @@ import static org.elasticsearch.rest.RestRequest.Method.GET;
import static org.elasticsearch.rest.RestStatus.OK;
public class RestWatcherStatsAction extends WatcherRestHandler {
@Inject
public RestWatcherStatsAction(Settings settings, RestController controller) {
super(settings);

View File

@ -9,13 +9,11 @@ import org.elasticsearch.client.Client;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.rest.RestChannel;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.rest.FakeRestRequest;
import org.elasticsearch.xpack.watcher.client.WatcherClient;
import org.elasticsearch.xpack.watcher.transport.actions.execute.ExecuteWatchRequestBuilder;
import org.elasticsearch.xpack.watcher.trigger.TriggerService;
import java.util.Arrays;
@ -27,8 +25,6 @@ public class RestExecuteWatchActionTests extends ESTestCase {
private RestController restController = mock(RestController.class);
private Client client = mock(Client.class);
private TriggerService triggerService = mock(TriggerService.class);
private RestChannel restChannel = mock(RestChannel.class);
private WatcherClient watcherClient = mock(WatcherClient.class);
public void testThatFlagsCanBeSpecifiedViaParameters() throws Exception {
@ -39,8 +35,7 @@ public class RestExecuteWatchActionTests extends ESTestCase {
ExecuteWatchRequestBuilder builder = new ExecuteWatchRequestBuilder(client);
when(watcherClient.prepareExecuteWatch()).thenReturn(builder);
RestExecuteWatchAction restExecuteWatchAction = new RestExecuteWatchAction(Settings.EMPTY, restController,
triggerService);
RestExecuteWatchAction restExecuteWatchAction = new RestExecuteWatchAction(Settings.EMPTY, restController);
restExecuteWatchAction.doPrepareRequest(createFakeRestRequest(randomId, recordExecution, ignoreCondition,
debugCondition), watcherClient);