Skip to content

Commit

Permalink
Convert sql license objects to LicensedFeature (#78539)
Browse files Browse the repository at this point in the history
This commit moves the license checks for sql jdbc and odbc functionality
to use the new LicensedFeature class.
  • Loading branch information
rjernst authored Oct 4, 2021
1 parent 2a02940 commit a019d41
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ public enum Feature {

LOGSTASH(OperationMode.STANDARD, true),

JDBC(OperationMode.PLATINUM, true),

ODBC(OperationMode.PLATINUM, true),

SPATIAL_GEO_CENTROID(OperationMode.GOLD, true),

SPATIAL_GEO_GRID(OperationMode.GOLD, true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.env.Environment;
import org.elasticsearch.env.NodeEnvironment;
import org.elasticsearch.license.License;
import org.elasticsearch.license.LicenseUtils;
import org.elasticsearch.license.LicensedFeature;
import org.elasticsearch.license.XPackLicenseState;
import org.elasticsearch.plugins.ActionPlugin;
import org.elasticsearch.plugins.Plugin;
Expand Down Expand Up @@ -49,17 +51,20 @@

public class SqlPlugin extends Plugin implements ActionPlugin {

private final LicensedFeature.Momentary JDBC_FEATURE = LicensedFeature.momentary("sql", "jdbc", License.OperationMode.PLATINUM);
private final LicensedFeature.Momentary ODBC_FEATURE = LicensedFeature.momentary("sql", "odbc", License.OperationMode.PLATINUM);

private final SqlLicenseChecker sqlLicenseChecker = new SqlLicenseChecker(
(mode) -> {
XPackLicenseState licenseState = getLicenseState();
switch (mode) {
case JDBC:
if (licenseState.checkFeature(XPackLicenseState.Feature.JDBC) == false) {
if (JDBC_FEATURE.check(licenseState) == false) {
throw LicenseUtils.newComplianceException("jdbc");
}
break;
case ODBC:
if (licenseState.checkFeature(XPackLicenseState.Feature.ODBC) == false) {
if (ODBC_FEATURE.check(licenseState) == false) {
throw LicenseUtils.newComplianceException("odbc");
}
break;
Expand Down

0 comments on commit a019d41

Please sign in to comment.