Skip to content

Commit aee53fd

Browse files
committed
Add deprecated accept_enterprise param to /_xpack
This change introduces support for the "accept_enterprise" parameter to the /_xpack endpoint, to match the parameter on the /_license endpoint. This parameter is deprecated, it does nothing, and may not be set to any value other than true. It exists solely to support upgrades from 7.x versions where the parameter does have meaning. Relates: elastic#58217
1 parent 54c2931 commit aee53fd

File tree

6 files changed

+76
-1
lines changed

6 files changed

+76
-1
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/protocol/xpack/XPackInfoRequest.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
*/
66
package org.elasticsearch.protocol.xpack;
77

8+
import org.elasticsearch.Version;
89
import org.elasticsearch.action.ActionRequest;
910
import org.elasticsearch.action.ActionRequestValidationException;
1011
import org.elasticsearch.common.io.stream.StreamInput;
1112
import org.elasticsearch.common.io.stream.StreamOutput;
13+
import org.elasticsearch.license.License;
1214

1315
import java.io.IOException;
1416
import java.util.EnumSet;
@@ -40,8 +42,10 @@ public static EnumSet<Category> toSet(String... categories) {
4042

4143
private boolean verbose;
4244
private EnumSet<Category> categories = EnumSet.noneOf(Category.class);
45+
private int licenseVersion = License.VERSION_CURRENT;
4346

44-
public XPackInfoRequest() {}
47+
public XPackInfoRequest() {
48+
}
4549

4650
public XPackInfoRequest(StreamInput in) throws IOException {
4751
// NOTE: this does *not* call super, THIS IS A BUG
@@ -52,6 +56,9 @@ public XPackInfoRequest(StreamInput in) throws IOException {
5256
categories.add(Category.valueOf(in.readString()));
5357
}
5458
this.categories = categories;
59+
if (in.getVersion().after(Version.V_7_8_0)) {
60+
this.licenseVersion = in.readVInt();
61+
}
5562
}
5663

5764
public void setVerbose(boolean verbose) {
@@ -70,6 +77,14 @@ public EnumSet<Category> getCategories() {
7077
return categories;
7178
}
7279

80+
public int getLicenseVersion() {
81+
return licenseVersion;
82+
}
83+
84+
public void setLicenseVersion(int licenseVersion) {
85+
this.licenseVersion = licenseVersion;
86+
}
87+
7388
@Override
7489
public ActionRequestValidationException validate() {
7590
return null;
@@ -82,5 +97,8 @@ public void writeTo(StreamOutput out) throws IOException {
8297
for (Category category : categories) {
8398
out.writeString(category.name());
8499
}
100+
if (out.getVersion().after(Version.V_7_8_0)) {
101+
out.writeVInt(this.licenseVersion);
102+
}
85103
}
86104
}

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/XPackInfoRequestBuilder.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,8 @@ public XPackInfoRequestBuilder setCategories(EnumSet<XPackInfoRequest.Category>
3333
return this;
3434
}
3535

36+
public XPackInfoRequestBuilder setLicenseVersion(int licenseVersion) {
37+
request.setLicenseVersion(licenseVersion);
38+
return this;
39+
}
3640
}

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rest/action/RestXPackInfoAction.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
*/
66
package org.elasticsearch.xpack.core.rest.action;
77

8+
import org.apache.logging.log4j.LogManager;
89
import org.elasticsearch.client.node.NodeClient;
10+
import org.elasticsearch.common.logging.DeprecationLogger;
11+
import org.elasticsearch.license.RestGetLicenseAction;
912
import org.elasticsearch.protocol.xpack.XPackInfoRequest;
1013
import org.elasticsearch.rest.BaseRestHandler;
1114
import org.elasticsearch.rest.RestRequest;
@@ -21,6 +24,8 @@
2124

2225
public class RestXPackInfoAction extends BaseRestHandler {
2326

27+
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestXPackInfoAction.class));
28+
2429
@Override
2530
public List<Route> routes() {
2631
return List.of(
@@ -39,6 +44,17 @@ public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client
3944
// we piggyback verbosity on "human" output
4045
boolean verbose = request.paramAsBoolean("human", true);
4146

47+
// In 7.x, there was an opt-in flag to show "enterprise" licenses. In 8.0 the flag is deprecated and can only be true
48+
// TODO Remove this from 9.0
49+
if (request.hasParam("accept_enterprise")) {
50+
deprecationLogger.deprecate("get_license_accept_enterprise",
51+
"Including [accept_enterprise] in get license requests is deprecated." +
52+
" The parameter will be removed in the next major version");
53+
if (request.paramAsBoolean("accept_enterprise", true) == false) {
54+
throw new IllegalArgumentException("The [accept_enterprise] parameters may not be false");
55+
}
56+
}
57+
4258
EnumSet<XPackInfoRequest.Category> categories = XPackInfoRequest.Category
4359
.toSet(request.paramAsStringArray("categories", new String[] { "_all" }));
4460
return channel ->

x-pack/plugin/src/test/resources/rest-api-spec/api/xpack.info.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
"categories":{
2020
"type":"list",
2121
"description":"Comma-separated list of info categories. Can be any of: build, license, features"
22+
},
23+
"accept_enterprise":{
24+
"type":"boolean",
25+
"description":"Supported for backwards compatibility with 7.x. If this param is used it must be set to true",
26+
"deprecated":true
2227
}
2328
}
2429
}

x-pack/plugin/src/test/resources/rest-api-spec/test/license/30_enterprise_license.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ teardown:
3030
- match: { license.max_resource_units: 50 }
3131
- match: { license.max_nodes: null }
3232

33+
## Check the xpack info API as well
34+
- do:
35+
xpack.info: {}
36+
- match: { license.type: "enterprise" }
37+
- match: { license.mode: "enterprise" }
38+
39+
## Check the opt-in v5 license type
3340
- do:
3441
warnings:
3542
- "Including [accept_enterprise] in get license requests is deprecated. The parameter will be removed in the next major version"
@@ -42,6 +49,15 @@ teardown:
4249
## Always returns real type
4350
- match: { license.type: "enterprise" }
4451

52+
## Check the xpack info API as well
53+
- do:
54+
warnings:
55+
- "Including [accept_enterprise] in get license requests is deprecated. The parameter will be removed in the next major version"
56+
xpack.info:
57+
accept_enterprise: true
58+
- match: { license.type: "enterprise" }
59+
- match: { license.mode: "enterprise" }
60+
4561
## "false" is rejected
4662
- do:
4763
catch: bad_request
@@ -50,3 +66,10 @@ teardown:
5066
license.get:
5167
accept_enterprise: false
5268

69+
- do:
70+
catch: bad_request
71+
warnings:
72+
- "Including [accept_enterprise] in get license requests is deprecated. The parameter will be removed in the next major version"
73+
xpack.info:
74+
accept_enterprise: false
75+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"XPack Info API":
2+
- do:
3+
xpack.info: {}
4+
5+
- match: { license.type: "trial" }
6+
- match: { license.mode: "trial" }
7+
- match: { license.status: "active" }
8+
9+

0 commit comments

Comments
 (0)