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