|
80 | 80 | */ |
81 | 81 | class Elasticsearch { |
82 | 82 |
|
83 | | - private static final String PLUGIN_POLICY_OVERRIDE_PREFIX = "es.entitlements.policy."; |
84 | | - private static final String SERVER_POLICY_OVERRIDE = "es.entitlements.server_policy"; |
| 83 | + private static final String POLICY_PATCH_PREFIX = "es.entitlements.policy."; |
| 84 | + private static final String SERVER_POLICY_PATCH_NAME = POLICY_PATCH_PREFIX + "server"; |
85 | 85 |
|
86 | 86 | /** |
87 | 87 | * Main entry point for starting elasticsearch. |
@@ -239,10 +239,10 @@ private static void initPhase2(Bootstrap bootstrap) throws IOException { |
239 | 239 | .map(bundle -> new PolicyUtils.PluginData(bundle.getDir(), bundle.pluginDescriptor().isModular(), true)) |
240 | 240 | ).toList(); |
241 | 241 |
|
242 | | - var pluginPolicyOverrides = collectPluginPolicyOverrides(modulesBundles, pluginsBundles, logger); |
243 | | - var pluginPolicies = PolicyUtils.createPluginPolicies(pluginData, pluginPolicyOverrides, Build.current().version()); |
| 242 | + var pluginPolicyPatches = collectPluginPolicyPatches(modulesBundles, pluginsBundles, logger); |
| 243 | + var pluginPolicies = PolicyUtils.createPluginPolicies(pluginData, pluginPolicyPatches, Build.current().version()); |
244 | 244 | var serverPolicyPatch = PolicyUtils.parseEncodedPolicyIfExists( |
245 | | - System.getProperty(SERVER_POLICY_OVERRIDE), |
| 245 | + System.getProperty(SERVER_POLICY_PATCH_NAME), |
246 | 246 | Build.current().version(), |
247 | 247 | false, |
248 | 248 | "server", |
@@ -288,33 +288,36 @@ private static void initPhase2(Bootstrap bootstrap) throws IOException { |
288 | 288 | bootstrap.setPluginsLoader(pluginsLoader); |
289 | 289 | } |
290 | 290 |
|
291 | | - private static Map<String, String> collectPluginPolicyOverrides( |
| 291 | + private static Map<String, String> collectPluginPolicyPatches( |
292 | 292 | Set<PluginBundle> modulesBundles, |
293 | 293 | Set<PluginBundle> pluginsBundles, |
294 | 294 | Logger logger |
295 | 295 | ) { |
296 | | - var policyOverrides = new HashMap<String, String>(); |
| 296 | + var policyPatches = new HashMap<String, String>(); |
297 | 297 | var systemProperties = BootstrapInfo.getSystemProperties(); |
298 | 298 | systemProperties.keys().asIterator().forEachRemaining(key -> { |
299 | 299 | var value = systemProperties.get(key); |
300 | | - if (key instanceof String k && k.startsWith(PLUGIN_POLICY_OVERRIDE_PREFIX) && value instanceof String v) { |
301 | | - policyOverrides.put(k.substring(PLUGIN_POLICY_OVERRIDE_PREFIX.length()), v); |
| 300 | + if (key instanceof String k |
| 301 | + && value instanceof String v |
| 302 | + && k.startsWith(POLICY_PATCH_PREFIX) |
| 303 | + && k.equals(SERVER_POLICY_PATCH_NAME) == false) { |
| 304 | + policyPatches.put(k.substring(POLICY_PATCH_PREFIX.length()), v); |
302 | 305 | } |
303 | 306 | }); |
304 | 307 | var pluginNames = Stream.concat(modulesBundles.stream(), pluginsBundles.stream()) |
305 | 308 | .map(bundle -> bundle.pluginDescriptor().getName()) |
306 | 309 | .collect(Collectors.toUnmodifiableSet()); |
307 | 310 |
|
308 | | - for (var overriddenPluginName : policyOverrides.keySet()) { |
309 | | - if (pluginNames.contains(overriddenPluginName) == false) { |
| 311 | + for (var patchedPluginName : policyPatches.keySet()) { |
| 312 | + if (pluginNames.contains(patchedPluginName) == false) { |
310 | 313 | logger.warn( |
311 | | - "Found command-line override for unknown plugin [{}] (available plugins: [{}])", |
312 | | - overriddenPluginName, |
| 314 | + "Found command-line policy patch for unknown plugin [{}] (available plugins: [{}])", |
| 315 | + patchedPluginName, |
313 | 316 | String.join(", ", pluginNames) |
314 | 317 | ); |
315 | 318 | } |
316 | 319 | } |
317 | | - return policyOverrides; |
| 320 | + return policyPatches; |
318 | 321 | } |
319 | 322 |
|
320 | 323 | private static class EntitlementSelfTester { |
|
0 commit comments