[License] Log Deprecation Warnings for old API usage
This makes use of the registerAsDeprecatedHandler method to automatically warn users when they're using deprecated functionality. This will also automatically provide a Warning header for anyone using HTTP clients (though they have to be looking for it...). - This also adds deprecated `/_licenses` variants of the endpoint. Users are consistently making that mistake, and it's easy enough to support this way. Can remove it if people disagree though. License portion only Original commit: elastic/x-pack-elasticsearch@431c871fcf
This commit is contained in:
parent
641caabdae
commit
a7c884be61
|
@ -5,29 +5,39 @@
|
||||||
*/
|
*/
|
||||||
package org.elasticsearch.license.plugin.rest;
|
package org.elasticsearch.license.plugin.rest;
|
||||||
|
|
||||||
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.license.plugin.action.delete.DeleteLicenseAction;
|
import org.elasticsearch.license.plugin.action.delete.DeleteLicenseAction;
|
||||||
import org.elasticsearch.license.plugin.action.delete.DeleteLicenseRequest;
|
import org.elasticsearch.license.plugin.action.delete.DeleteLicenseRequest;
|
||||||
import org.elasticsearch.rest.BaseRestHandler;
|
|
||||||
import org.elasticsearch.rest.RestChannel;
|
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.support.AcknowledgedRestListener;
|
import org.elasticsearch.rest.action.support.AcknowledgedRestListener;
|
||||||
|
import org.elasticsearch.xpack.XPackClient;
|
||||||
|
import org.elasticsearch.xpack.rest.XPackRestHandler;
|
||||||
|
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.DELETE;
|
import static org.elasticsearch.rest.RestRequest.Method.DELETE;
|
||||||
|
|
||||||
public class RestDeleteLicenseAction extends BaseRestHandler {
|
public class RestDeleteLicenseAction extends XPackRestHandler {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public RestDeleteLicenseAction(Settings settings, RestController controller) {
|
public RestDeleteLicenseAction(Settings settings, RestController controller) {
|
||||||
super(settings);
|
super(settings);
|
||||||
controller.registerHandler(DELETE, "/_xpack/license", this);
|
// @deprecated Remove deprecations in 6.0
|
||||||
|
controller.registerWithDeprecatedHandler(DELETE, URI_BASE + "/_license", this,
|
||||||
|
DELETE, "/_license", deprecationLogger);
|
||||||
|
|
||||||
|
// Remove _licenses support entirely in 6.0
|
||||||
|
controller.registerAsDeprecatedHandler(DELETE, "/_licenses", this,
|
||||||
|
"[DELETE /_licenses] is deprecated! Use " +
|
||||||
|
"[DELETE /_xpack/license] instead.",
|
||||||
|
deprecationLogger);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleRequest(final RestRequest request, final RestChannel channel, final NodeClient client) {
|
public void handleRequest(final RestRequest request, final RestChannel channel, final XPackClient client) {
|
||||||
client.admin().cluster().execute(DeleteLicenseAction.INSTANCE, new DeleteLicenseRequest(), new AcknowledgedRestListener<>(channel));
|
client.es().admin().cluster().execute(DeleteLicenseAction.INSTANCE,
|
||||||
|
new DeleteLicenseRequest(),
|
||||||
|
new AcknowledgedRestListener<>(channel));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
*/
|
*/
|
||||||
package org.elasticsearch.license.plugin.rest;
|
package org.elasticsearch.license.plugin.rest;
|
||||||
|
|
||||||
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.common.xcontent.ToXContent;
|
import org.elasticsearch.common.xcontent.ToXContent;
|
||||||
|
@ -14,13 +13,14 @@ import org.elasticsearch.license.core.License;
|
||||||
import org.elasticsearch.license.plugin.action.get.GetLicenseAction;
|
import org.elasticsearch.license.plugin.action.get.GetLicenseAction;
|
||||||
import org.elasticsearch.license.plugin.action.get.GetLicenseRequest;
|
import org.elasticsearch.license.plugin.action.get.GetLicenseRequest;
|
||||||
import org.elasticsearch.license.plugin.action.get.GetLicenseResponse;
|
import org.elasticsearch.license.plugin.action.get.GetLicenseResponse;
|
||||||
import org.elasticsearch.rest.BaseRestHandler;
|
|
||||||
import org.elasticsearch.rest.BytesRestResponse;
|
import org.elasticsearch.rest.BytesRestResponse;
|
||||||
import org.elasticsearch.rest.RestChannel;
|
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.action.support.RestBuilderListener;
|
import org.elasticsearch.rest.action.support.RestBuilderListener;
|
||||||
|
import org.elasticsearch.xpack.XPackClient;
|
||||||
|
import org.elasticsearch.xpack.rest.XPackRestHandler;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -29,12 +29,20 @@ 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;
|
||||||
|
|
||||||
public class RestGetLicenseAction extends BaseRestHandler {
|
public class RestGetLicenseAction extends XPackRestHandler {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public RestGetLicenseAction(Settings settings, RestController controller) {
|
public RestGetLicenseAction(Settings settings, RestController controller) {
|
||||||
super(settings);
|
super(settings);
|
||||||
controller.registerHandler(GET, "/_xpack/license", this);
|
// @deprecated Remove deprecations in 6.0
|
||||||
|
controller.registerWithDeprecatedHandler(GET, URI_BASE + "/_license", this,
|
||||||
|
GET, "/_license", deprecationLogger);
|
||||||
|
|
||||||
|
// Remove _licenses support entirely in 6.0
|
||||||
|
controller.registerAsDeprecatedHandler(GET, "/_licenses", this,
|
||||||
|
"[GET /_licenses] is deprecated! Use " +
|
||||||
|
"[GET /_xpack/license] instead.",
|
||||||
|
deprecationLogger);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -44,14 +52,14 @@ public class RestGetLicenseAction extends BaseRestHandler {
|
||||||
* 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 NodeClient client) {
|
public void handleRequest(final RestRequest request, final RestChannel channel, final XPackClient client) {
|
||||||
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.admin().cluster().execute(GetLicenseAction.INSTANCE, getLicenseRequest,
|
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 {
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
*/
|
*/
|
||||||
package org.elasticsearch.license.plugin.rest;
|
package org.elasticsearch.license.plugin.rest;
|
||||||
|
|
||||||
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.common.xcontent.ToXContent;
|
import org.elasticsearch.common.xcontent.ToXContent;
|
||||||
|
@ -13,7 +12,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.license.plugin.action.put.PutLicenseAction;
|
import org.elasticsearch.license.plugin.action.put.PutLicenseAction;
|
||||||
import org.elasticsearch.license.plugin.action.put.PutLicenseRequest;
|
import org.elasticsearch.license.plugin.action.put.PutLicenseRequest;
|
||||||
import org.elasticsearch.license.plugin.action.put.PutLicenseResponse;
|
import org.elasticsearch.license.plugin.action.put.PutLicenseResponse;
|
||||||
import org.elasticsearch.rest.BaseRestHandler;
|
|
||||||
import org.elasticsearch.rest.BytesRestResponse;
|
import org.elasticsearch.rest.BytesRestResponse;
|
||||||
import org.elasticsearch.rest.RestChannel;
|
import org.elasticsearch.rest.RestChannel;
|
||||||
import org.elasticsearch.rest.RestController;
|
import org.elasticsearch.rest.RestController;
|
||||||
|
@ -21,25 +19,40 @@ 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.support.RestBuilderListener;
|
import org.elasticsearch.rest.action.support.RestBuilderListener;
|
||||||
|
import org.elasticsearch.xpack.XPackClient;
|
||||||
|
import org.elasticsearch.xpack.rest.XPackRestHandler;
|
||||||
|
|
||||||
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 RestPutLicenseAction extends BaseRestHandler {
|
public class RestPutLicenseAction extends XPackRestHandler {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public RestPutLicenseAction(Settings settings, RestController controller) {
|
public RestPutLicenseAction(Settings settings, RestController controller) {
|
||||||
super(settings);
|
super(settings);
|
||||||
controller.registerHandler(PUT, "/_xpack/license", this);
|
// @deprecated Remove deprecations in 6.0
|
||||||
controller.registerHandler(POST, "/_xpack/license", this);
|
controller.registerWithDeprecatedHandler(POST, URI_BASE + "/_license", this,
|
||||||
|
POST, "/_license", deprecationLogger);
|
||||||
|
controller.registerWithDeprecatedHandler(PUT, URI_BASE + "/_license", this,
|
||||||
|
PUT, "/_license", deprecationLogger);
|
||||||
|
|
||||||
|
// Remove _licenses support entirely in 6.0
|
||||||
|
controller.registerAsDeprecatedHandler(POST, "/_licenses", this,
|
||||||
|
"[POST /_licenses] is deprecated! Use " +
|
||||||
|
"[POST /_xpack/license] instead.",
|
||||||
|
deprecationLogger);
|
||||||
|
controller.registerAsDeprecatedHandler(PUT, "/_licenses", this,
|
||||||
|
"[PUT /_licenses] is deprecated! Use " +
|
||||||
|
"[PUT /_xpack/license] instead.",
|
||||||
|
deprecationLogger);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleRequest(final RestRequest request, final RestChannel channel, final NodeClient client) {
|
public void handleRequest(final RestRequest request, final RestChannel channel, final XPackClient client) {
|
||||||
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.admin().cluster().execute(PutLicenseAction.INSTANCE, putLicenseRequest,
|
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 {
|
||||||
|
|
Loading…
Reference in New Issue