Skip to content

Commit 720bbdb

Browse files
committed
Convert encrypted snapshot license object to LicensedFeature (elastic#78731)
This commit moves the encrypted snapshot license checks to use the new LicensedFeature class.
1 parent c3933ba commit 720bbdb

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ public enum Feature {
5252
MONITORING_CLUSTER_ALERTS(OperationMode.STANDARD, true),
5353
MONITORING_UPDATE_RETENTION(OperationMode.STANDARD, false),
5454

55-
ENCRYPTED_SNAPSHOT(OperationMode.PLATINUM, true),
56-
5755
CCR(OperationMode.PLATINUM, true),
5856

5957
MACHINE_LEARNING(OperationMode.PLATINUM, true),

x-pack/plugin/repository-encrypted/src/main/java/org/elasticsearch/repositories/encrypted/EncryptedRepository.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
import javax.crypto.KeyGenerator;
6161
import javax.crypto.SecretKey;
6262

63+
import static org.elasticsearch.repositories.encrypted.EncryptedRepositoryPlugin.ENCRYPTED_SNAPSHOT_FEATURE;
64+
6365
public class EncryptedRepository extends BlobStoreRepository {
6466
static final Logger logger = LogManager.getLogger(EncryptedRepository.class);
6567
// the following constants are fixed by definition
@@ -176,7 +178,7 @@ public RepositoryStats stats() {
176178
public Map<String, Object> adaptUserMetadata(Map<String, Object> userMetadata) {
177179
// because populating the snapshot metadata must be done before the actual snapshot is first initialized,
178180
// we take the opportunity to validate the license and abort if non-compliant
179-
if (false == licenseStateSupplier.get().isAllowed(XPackLicenseState.Feature.ENCRYPTED_SNAPSHOT)) {
181+
if (false == ENCRYPTED_SNAPSHOT_FEATURE.checkWithoutTracking(licenseStateSupplier.get())) {
180182
throw LicenseUtils.newComplianceException("encrypted snapshots");
181183
}
182184
Map<String, Object> snapshotUserMetadata = new HashMap<>();

x-pack/plugin/repository-encrypted/src/main/java/org/elasticsearch/repositories/encrypted/EncryptedRepositoryPlugin.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
2222
import org.elasticsearch.env.Environment;
2323
import org.elasticsearch.indices.recovery.RecoverySettings;
24+
import org.elasticsearch.license.License;
2425
import org.elasticsearch.license.LicenseUtils;
26+
import org.elasticsearch.license.LicensedFeature;
2527
import org.elasticsearch.license.XPackLicenseState;
2628
import org.elasticsearch.plugins.Plugin;
2729
import org.elasticsearch.plugins.RepositoryPlugin;
@@ -40,6 +42,12 @@
4042

4143
public class EncryptedRepositoryPlugin extends Plugin implements RepositoryPlugin {
4244

45+
static final LicensedFeature.Momentary ENCRYPTED_SNAPSHOT_FEATURE = LicensedFeature.momentary(
46+
null,
47+
"encrypted-snapshot",
48+
License.OperationMode.PLATINUM
49+
);
50+
4351
private static final Boolean ENCRYPTED_REPOSITORY_FEATURE_FLAG_REGISTERED;
4452
static {
4553
final String property = System.getProperty("es.encrypted_repository_feature_flag_registered");
@@ -155,7 +163,7 @@ public Repository create(RepositoryMetadata metadata, Function<String, Repositor
155163
if (false == (delegatedRepository instanceof BlobStoreRepository) || delegatedRepository instanceof EncryptedRepository) {
156164
throw new IllegalArgumentException("Unsupported delegate repository type [" + DELEGATE_TYPE_SETTING.getKey() + "]");
157165
}
158-
if (false == getLicenseState().checkFeature(XPackLicenseState.Feature.ENCRYPTED_SNAPSHOT)) {
166+
if (false == ENCRYPTED_SNAPSHOT_FEATURE.check(getLicenseState())) {
159167
logger.warn(
160168
new ParameterizedMessage(
161169
"Encrypted snapshots are not allowed for the currently installed license [{}]."

0 commit comments

Comments
 (0)