Skip to content

Commit 9a781c6

Browse files
authored
Support "accept_enterprise" param in get license (#50067)
In 7.6 (#49474) we added an "accept_enterprise" parameter to the GET _license endpoint. This commit adds the same parameter to 8.0, except that (a) it is deprecated (b) the only acceptable value is "true" This change also updates the license service to recognise 7.6 as a supported cluster version for the enterprise license type.
1 parent e1f2f0f commit 9a781c6

File tree

4 files changed

+72
-1
lines changed

4 files changed

+72
-1
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/license/LicenseService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ public ClusterState execute(ClusterState currentState) throws Exception {
292292

293293
private static boolean licenseIsCompatible(License license, Version version) {
294294
if (License.LicenseType.ENTERPRISE.getTypeName().equalsIgnoreCase(license.type())) {
295-
return version.onOrAfter(Version.V_8_0_0);
295+
return version.onOrAfter(Version.V_7_6_0);
296296
} else {
297297
return true;
298298
}

x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestGetLicenseAction.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
package org.elasticsearch.license;
88

9+
import org.apache.logging.log4j.LogManager;
910
import org.elasticsearch.client.node.NodeClient;
11+
import org.elasticsearch.common.logging.DeprecationLogger;
1012
import org.elasticsearch.common.xcontent.ToXContent;
1113
import org.elasticsearch.common.xcontent.XContentBuilder;
1214
import org.elasticsearch.protocol.xpack.license.GetLicenseRequest;
@@ -27,6 +29,8 @@
2729

2830
public class RestGetLicenseAction extends BaseRestHandler {
2931

32+
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetLicenseAction.class));
33+
3034
RestGetLicenseAction(RestController controller) {
3135
controller.registerHandler(GET, "/_license", this);
3236
}
@@ -47,6 +51,18 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
4751
final Map<String, String> overrideParams = new HashMap<>(2);
4852
overrideParams.put(License.REST_VIEW_MODE, "true");
4953
overrideParams.put(License.LICENSE_VERSION_MODE, String.valueOf(License.VERSION_CURRENT));
54+
55+
// 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
56+
// TODO Remove this from 9.0
57+
if (request.hasParam("accept_enterprise")) {
58+
deprecationLogger.deprecatedAndMaybeLog("get_license_accept_enterprise",
59+
"Including [accept_enterprise] in get license requests is deprecated." +
60+
" The parameter will be removed in the next major version");
61+
if (request.paramAsBoolean("accept_enterprise", true) == false) {
62+
throw new IllegalArgumentException("The [accept_enterprise] parameters may not be false");
63+
}
64+
}
65+
5066
final ToXContent.Params params = new ToXContent.DelegatingMapParams(overrideParams, request);
5167
GetLicenseRequest getLicenseRequest = new GetLicenseRequest();
5268
getLicenseRequest.local(request.paramAsBoolean("local", getLicenseRequest.local()));

x-pack/plugin/src/test/resources/rest-api-spec/api/license.get.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
"local":{
1919
"type":"boolean",
2020
"description":"Return local information, do not retrieve the state from master node (default: false)"
21+
},
22+
"accept_enterprise":{
23+
"type":"boolean",
24+
"deprecated":true,
25+
"description":"Supported for backwards compatibility with 7.x. If this param is used it must be set to true"
2126
}
2227
}
2328
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
teardown:
3+
- do:
4+
license.post:
5+
acknowledge: true
6+
body: |
7+
{"licenses":[{"uid":"3aa62ffe-36e1-4fad-bfdc-9dff8301eb22","type":"trial","issue_date_in_millis":1523456691721,"expiry_date_in_millis":1838816691721,"max_nodes":5,"issued_to":"customer","issuer":"elasticsearch","signature":"AAAABAAAAA2kWNcuc+DT0lrlmYZKAAAAIAo5/x6hrsGh1GqqrJmy4qgmEC7gK0U4zQ6q5ZEMhm4jAAABAEn6fG9y2VxKBu2T3D5hffh56kzOQODCOdhr0y2d17ZSIJMZRqO7ZywPCWNS1aR33GhfIHkTER0ysML0xMH/gXavhyRvMBndJj0UBKzuwpTawSlnxYtcqN8mSBIvJC7Ki+uJ1SpAILC2ZP9fnkRlqwXqBlTwfYn7xnZgu9DKrOWru/ipTPObo7jcePl8VTK6nWFen7/hCFDQTUFZ0jQvd+nq7A1PAcHGNxGfdbMVmAXCXgGWkRfT3clo9/vadgo+isNyh1sPq9mN7gwsvBAKtA1FrpH2EXYYbfOsSpBvUmhYMgErLg1k3/CbS0pCWLKOaX1xTMayosdZOjagU3auZXY=","start_date_in_millis":-1}]}
8+
---
9+
"Installing enterprise license":
10+
- skip:
11+
features: warnings
12+
13+
## current license version
14+
- do:
15+
license.post:
16+
acknowledge: true
17+
body: |
18+
{"license":{"uid":"6e57906b-a8d1-4c1f-acb7-73a16edc3934","type":"enterprise","issue_date_in_millis":1523456691721,"expiry_date_in_millis":1838816691721,"max_nodes":50,"issued_to":"rest-test","issuer":"elasticsearch","signature":"AAAABAAAAA03e8BZRVXaCV4CpPGRAAAAIAo5/x6hrsGh1GqqrJmy4qgmEC7gK0U4zQ6q5ZEMhm4jAAABAAZNhjABV6PRfa7P7sJgn70XCGoKtAVT75yU13JvKBd/UjD4TPhuZcztqZ/tcLEPxm/TSvGlogWmnw/Rw8xs8jMpBpKsJ+LOXjHhDdvXb2y7JJhCH8nlSEblMDRXysNvWpKe60Z/hb7hS4JynEUt0EBb6ji7BL42O07PNll1EGmkfsHazfs46iV91BG1VxXksI78XgWSaA0F/h7tvrNW9PTgsUaLo06InlQ8jA1dal90AoXp+MVDOHWQjVFZzUnO87/7lEb+VXt0IwchaW17ahihJqkCtGvKpWFwpuhx9xiFvkySN/g5LIVjYCvgBkiWExQ9p0Zzg3VoSlMBnVy0BWo=","start_date_in_millis":-1}}
19+
20+
- match: { license_status: "valid" }
21+
22+
- do:
23+
license.get: {}
24+
25+
## a license object has 11 attributes
26+
- length: { license: 11 }
27+
28+
## In 8.0, the enterprise license is always reports truthfully
29+
- match: { license.type: "enterprise" }
30+
31+
- do:
32+
warnings:
33+
- "Including [accept_enterprise] in get license requests is deprecated. The parameter will be removed in the next major version"
34+
license.get:
35+
accept_enterprise: "true"
36+
37+
## a license object has 11 attributes
38+
- length: { license: 11 }
39+
40+
## Always returns real type
41+
- match: { license.type: "enterprise" }
42+
43+
## "false" is rejected
44+
- do:
45+
catch: bad_request
46+
warnings:
47+
- "Including [accept_enterprise] in get license requests is deprecated. The parameter will be removed in the next major version"
48+
license.get:
49+
accept_enterprise: "false"
50+

0 commit comments

Comments
 (0)