Skip to content

Commit 6f379dd

Browse files
committed
renaming
1 parent d7104a0 commit 6f379dd

File tree

3 files changed

+32
-33
lines changed

3 files changed

+32
-33
lines changed

libs/entitlement/src/main/java/org/elasticsearch/entitlement/runtime/policy/PolicyUtils.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public static Map<String, Policy> createPluginPolicies(Collection<PluginData> pl
5757
String pluginName = pluginRoot.getFileName().toString();
5858
final Set<String> moduleNames = getModuleNames(pluginRoot, entry.isModular());
5959

60-
var overriddenPolicy = parsePolicyOverrideIfExists(
60+
var overriddenPolicy = parseEncodedPolicyIfExists(
6161
overrides.get(pluginName),
6262
version,
6363
entry.isExternalPlugin(),
@@ -76,25 +76,25 @@ public static Map<String, Policy> createPluginPolicies(Collection<PluginData> pl
7676
return pluginPolicies;
7777
}
7878

79-
public static Policy parsePolicyOverrideIfExists(
80-
String policyOverride,
79+
public static Policy parseEncodedPolicyIfExists(
80+
String encodedPolicy,
8181
String version,
8282
boolean externalPlugin,
8383
String layerName,
8484
Set<String> moduleNames
8585
) {
86-
if (policyOverride != null) {
86+
if (encodedPolicy != null) {
8787
try {
88-
var versionedPolicy = decodeOverriddenPluginPolicy(policyOverride, layerName, externalPlugin);
89-
validatePolicyScopes(layerName, versionedPolicy.policy(), moduleNames, "<override>");
88+
var versionedPolicy = decodeEncodedPolicy(encodedPolicy, layerName, externalPlugin);
89+
validatePolicyScopes(layerName, versionedPolicy.policy(), moduleNames, "<patch>");
9090

9191
// Empty versions defaults to "any"
9292
if (versionedPolicy.versions().isEmpty() || versionedPolicy.versions().contains(version)) {
93-
logger.info("Using policy override for layer [{}]", layerName);
93+
logger.info("Using policy patch for layer [{}]", layerName);
9494
return versionedPolicy.policy();
9595
} else {
9696
logger.warn(
97-
"Found a policy override with version mismatch. The override will not be applied. "
97+
"Found a policy patch with version mismatch. The patch will not be applied. "
9898
+ "Layer [{}]; policy versions [{}]; current version [{}]",
9999
layerName,
100100
String.join(",", versionedPolicy.versions()),
@@ -103,16 +103,15 @@ public static Policy parsePolicyOverrideIfExists(
103103
}
104104
} catch (Exception ex) {
105105
logger.warn(
106-
Strings.format("Found a policy override with invalid content. The override will not be applied. Layer [%s]", layerName),
106+
Strings.format("Found a policy patch with invalid content. The patch will not be applied. Layer [%s]", layerName),
107107
ex
108108
);
109109
}
110110
}
111111
return null;
112112
}
113113

114-
static VersionedPolicy decodeOverriddenPluginPolicy(String base64String, String layerName, boolean isExternalPlugin)
115-
throws IOException {
114+
static VersionedPolicy decodeEncodedPolicy(String base64String, String layerName, boolean isExternalPlugin) throws IOException {
116115
byte[] policyDefinition = Base64.getDecoder().decode(base64String);
117116
return new PolicyParser(new ByteArrayInputStream(policyDefinition), layerName, isExternalPlugin).parseVersionedPolicy();
118117
}

libs/entitlement/src/test/java/org/elasticsearch/entitlement/runtime/policy/PolicyUtilsTests.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737
@ESTestCase.WithoutSecurityManager
3838
public class PolicyUtilsTests extends ESTestCase {
3939

40-
public void testCreatePluginPolicyWithOverride() {
40+
public void testCreatePluginPolicyWithPatch() {
4141

42-
var policyForOverride = """
42+
var policyPatch = """
4343
versions:
4444
- 9.0.0
4545
- 9.0.0-SNAPSHOT
@@ -50,7 +50,7 @@ public void testCreatePluginPolicyWithOverride() {
5050
- set_https_connection_properties
5151
""";
5252
var base64EncodedPolicy = new String(
53-
Base64.getEncoder().encode(policyForOverride.getBytes(StandardCharsets.UTF_8)),
53+
Base64.getEncoder().encode(policyPatch.getBytes(StandardCharsets.UTF_8)),
5454
StandardCharsets.UTF_8
5555
);
5656
final Policy expectedPolicy = new Policy(
@@ -61,7 +61,7 @@ public void testCreatePluginPolicyWithOverride() {
6161
)
6262
);
6363

64-
var policy = PolicyUtils.parsePolicyOverrideIfExists(
64+
var policy = PolicyUtils.parseEncodedPolicyIfExists(
6565
base64EncodedPolicy,
6666
"9.0.0",
6767
true,
@@ -72,17 +72,17 @@ public void testCreatePluginPolicyWithOverride() {
7272
assertThat(policy, equalTo(expectedPolicy));
7373
}
7474

75-
public void testCreatePluginPolicyWithOverrideAnyVersion() {
75+
public void testCreatePluginPolicyWithPatchAnyVersion() {
7676

77-
var policyForOverride = """
77+
var policyPatch = """
7878
policy:
7979
entitlement-module-name:
8080
- load_native_libraries
8181
entitlement-module-name-2:
8282
- set_https_connection_properties
8383
""";
8484
var base64EncodedPolicy = new String(
85-
Base64.getEncoder().encode(policyForOverride.getBytes(StandardCharsets.UTF_8)),
85+
Base64.getEncoder().encode(policyPatch.getBytes(StandardCharsets.UTF_8)),
8686
StandardCharsets.UTF_8
8787
);
8888

@@ -94,7 +94,7 @@ public void testCreatePluginPolicyWithOverrideAnyVersion() {
9494
)
9595
);
9696

97-
var policy = PolicyUtils.parsePolicyOverrideIfExists(
97+
var policy = PolicyUtils.parseEncodedPolicyIfExists(
9898
base64EncodedPolicy,
9999
"abcdef",
100100
true,
@@ -105,9 +105,9 @@ public void testCreatePluginPolicyWithOverrideAnyVersion() {
105105
assertThat(policy, equalTo(expectedPolicy));
106106
}
107107

108-
public void testNoOverriddenPolicyWithVersionMismatch() {
108+
public void testNoPatchWithVersionMismatch() {
109109

110-
var policyForOverride = """
110+
var policyPatch = """
111111
versions:
112112
- 9.0.0
113113
- 9.0.0-SNAPSHOT
@@ -118,11 +118,11 @@ public void testNoOverriddenPolicyWithVersionMismatch() {
118118
- set_https_connection_properties
119119
""";
120120
var base64EncodedPolicy = new String(
121-
Base64.getEncoder().encode(policyForOverride.getBytes(StandardCharsets.UTF_8)),
121+
Base64.getEncoder().encode(policyPatch.getBytes(StandardCharsets.UTF_8)),
122122
StandardCharsets.UTF_8
123123
);
124124

125-
var policy = PolicyUtils.parsePolicyOverrideIfExists(
125+
var policy = PolicyUtils.parseEncodedPolicyIfExists(
126126
base64EncodedPolicy,
127127
"9.1.0",
128128
true,
@@ -133,9 +133,9 @@ public void testNoOverriddenPolicyWithVersionMismatch() {
133133
assertThat(policy, nullValue());
134134
}
135135

136-
public void testNoOverriddenPolicyWithValidationError() {
136+
public void testNoPatchWithValidationError() {
137137

138-
var policyForOverride = """
138+
var policyPatch = """
139139
versions:
140140
- 9.0.0
141141
- 9.0.0-SNAPSHOT
@@ -146,29 +146,29 @@ public void testNoOverriddenPolicyWithValidationError() {
146146
- set_https_connection_properties
147147
""";
148148
var base64EncodedPolicy = new String(
149-
Base64.getEncoder().encode(policyForOverride.getBytes(StandardCharsets.UTF_8)),
149+
Base64.getEncoder().encode(policyPatch.getBytes(StandardCharsets.UTF_8)),
150150
StandardCharsets.UTF_8
151151
);
152152

153-
var policy = PolicyUtils.parsePolicyOverrideIfExists(base64EncodedPolicy, "9.0.0", true, "test-plugin", Set.of());
153+
var policy = PolicyUtils.parseEncodedPolicyIfExists(base64EncodedPolicy, "9.0.0", true, "test-plugin", Set.of());
154154

155155
assertThat(policy, nullValue());
156156
}
157157

158-
public void testNoOverriddenPolicyWithParsingError() {
158+
public void testNoPatchWithParsingError() {
159159

160-
var policyForOverride = """
160+
var policyPatch = """
161161
entitlement-module-name:
162162
- load_native_libraries
163163
entitlement-module-name-2:
164164
- set_https_connection_properties
165165
""";
166166
var base64EncodedPolicy = new String(
167-
Base64.getEncoder().encode(policyForOverride.getBytes(StandardCharsets.UTF_8)),
167+
Base64.getEncoder().encode(policyPatch.getBytes(StandardCharsets.UTF_8)),
168168
StandardCharsets.UTF_8
169169
);
170170

171-
var policy = PolicyUtils.parsePolicyOverrideIfExists(base64EncodedPolicy, "9.0.0", true, "test-plugin", Set.of());
171+
var policy = PolicyUtils.parseEncodedPolicyIfExists(base64EncodedPolicy, "9.0.0", true, "test-plugin", Set.of());
172172

173173
assertThat(policy, nullValue());
174174
}

server/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ private static void initPhase2(Bootstrap bootstrap) throws IOException {
249249

250250
var pluginPolicyOverrides = collectPluginPolicyOverrides(modulesBundles, pluginsBundles, logger);
251251
var pluginPolicies = PolicyUtils.createPluginPolicies(pluginData, pluginPolicyOverrides, Build.current().version());
252-
var serverPolicyOverride = PolicyUtils.parsePolicyOverrideIfExists(
252+
var serverPolicyPatch = PolicyUtils.parseEncodedPolicyIfExists(
253253
System.getProperty(SERVER_POLICY_OVERRIDE),
254254
Build.current().version(),
255255
false,
@@ -263,7 +263,7 @@ private static void initPhase2(Bootstrap bootstrap) throws IOException {
263263
Map<String, Path> sourcePaths = Stream.concat(modulesBundles.stream(), pluginsBundles.stream())
264264
.collect(Collectors.toUnmodifiableMap(bundle -> bundle.pluginDescriptor().getName(), PluginBundle::getDir));
265265
EntitlementBootstrap.bootstrap(
266-
serverPolicyOverride,
266+
serverPolicyPatch,
267267
pluginPolicies,
268268
pluginsResolver::resolveClassToPluginName,
269269
nodeEnv.settings()::getValues,

0 commit comments

Comments
 (0)