Skip to content

Commit c4a219d

Browse files
authored
Merge branch '9.0' into date-processor-refactoring-9.0
2 parents 8d06248 + 0e0fdf5 commit c4a219d

File tree

8 files changed

+172
-166
lines changed

8 files changed

+172
-166
lines changed

libs/entitlement/qa/entitlement-test-plugin/src/main/java/org/elasticsearch/entitlement/qa/test/EntitlementTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ enum ExpectedAccess {
2121
PLUGINS,
2222
ES_MODULES_ONLY,
2323
SERVER_ONLY,
24-
ALWAYS_DENIED
24+
ALWAYS_DENIED,
25+
ALWAYS_ALLOWED
2526
}
2627

2728
ExpectedAccess expectedAccess();

libs/entitlement/qa/entitlement-test-plugin/src/main/java/org/elasticsearch/entitlement/qa/test/RestEntitlementsCheckAction.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@
5555
import javax.net.ssl.SSLContext;
5656

5757
import static java.util.Map.entry;
58+
import static org.elasticsearch.entitlement.qa.test.EntitlementTest.ExpectedAccess.ALWAYS_ALLOWED;
59+
import static org.elasticsearch.entitlement.qa.test.EntitlementTest.ExpectedAccess.ALWAYS_DENIED;
5860
import static org.elasticsearch.entitlement.qa.test.EntitlementTest.ExpectedAccess.PLUGINS;
61+
import static org.elasticsearch.entitlement.qa.test.EntitlementTest.ExpectedAccess.SERVER_ONLY;
5962
import static org.elasticsearch.entitlement.qa.test.RestEntitlementsCheckAction.CheckAction.alwaysDenied;
6063
import static org.elasticsearch.entitlement.qa.test.RestEntitlementsCheckAction.CheckAction.deniedToPlugins;
6164
import static org.elasticsearch.entitlement.qa.test.RestEntitlementsCheckAction.CheckAction.forPlugins;
@@ -65,20 +68,20 @@
6568
public class RestEntitlementsCheckAction extends BaseRestHandler {
6669
private static final Logger logger = LogManager.getLogger(RestEntitlementsCheckAction.class);
6770

68-
record CheckAction(CheckedRunnable<Exception> action, boolean isAlwaysDeniedToPlugins, Integer fromJavaVersion) {
71+
record CheckAction(CheckedRunnable<Exception> action, EntitlementTest.ExpectedAccess expectedAccess, Integer fromJavaVersion) {
6972
/**
7073
* These cannot be granted to plugins, so our test plugins cannot test the "allowed" case.
7174
*/
7275
static CheckAction deniedToPlugins(CheckedRunnable<Exception> action) {
73-
return new CheckAction(action, true, null);
76+
return new CheckAction(action, SERVER_ONLY, null);
7477
}
7578

7679
static CheckAction forPlugins(CheckedRunnable<Exception> action) {
77-
return new CheckAction(action, false, null);
80+
return new CheckAction(action, PLUGINS, null);
7881
}
7982

8083
static CheckAction alwaysDenied(CheckedRunnable<Exception> action) {
81-
return new CheckAction(action, true, null);
84+
return new CheckAction(action, ALWAYS_DENIED, null);
8285
}
8386
}
8487

@@ -125,7 +128,7 @@ static CheckAction alwaysDenied(CheckedRunnable<Exception> action) {
125128
entry("responseCache_setDefault", alwaysDenied(RestEntitlementsCheckAction::setDefaultResponseCache)),
126129
entry(
127130
"createInetAddressResolverProvider",
128-
new CheckAction(VersionSpecificNetworkChecks::createInetAddressResolverProvider, true, 18)
131+
new CheckAction(VersionSpecificNetworkChecks::createInetAddressResolverProvider, SERVER_ONLY, 18)
129132
),
130133
entry("createURLStreamHandlerProvider", alwaysDenied(RestEntitlementsCheckAction::createURLStreamHandlerProvider)),
131134
entry("createURLWithURLStreamHandler", alwaysDenied(RestEntitlementsCheckAction::createURLWithURLStreamHandler)),
@@ -233,9 +236,8 @@ private static Stream<Entry<String, CheckAction>> getTestEntries(Class<?> action
233236
}
234237
}
235238
};
236-
boolean deniedToPlugins = testAnnotation.expectedAccess() != PLUGINS;
237239
Integer fromJavaVersion = testAnnotation.fromJavaVersion() == -1 ? null : testAnnotation.fromJavaVersion();
238-
entries.add(entry(method.getName(), new CheckAction(runnable, deniedToPlugins, fromJavaVersion)));
240+
entries.add(entry(method.getName(), new CheckAction(runnable, testAnnotation.expectedAccess(), fromJavaVersion)));
239241
}
240242
return entries.stream();
241243
}
@@ -398,13 +400,17 @@ private static void receiveDatagramSocket() throws IOException {
398400
public static Set<String> getCheckActionsAllowedInPlugins() {
399401
return checkActions.entrySet()
400402
.stream()
401-
.filter(kv -> kv.getValue().isAlwaysDeniedToPlugins() == false)
403+
.filter(kv -> kv.getValue().expectedAccess().equals(PLUGINS) || kv.getValue().expectedAccess().equals(ALWAYS_ALLOWED))
402404
.map(Entry::getKey)
403405
.collect(Collectors.toSet());
404406
}
405407

406-
public static Set<String> getAllCheckActions() {
407-
return checkActions.keySet();
408+
public static Set<String> getDeniableCheckActions() {
409+
return checkActions.entrySet()
410+
.stream()
411+
.filter(kv -> kv.getValue().expectedAccess().equals(ALWAYS_ALLOWED) == false)
412+
.map(Entry::getKey)
413+
.collect(Collectors.toSet());
408414
}
409415

410416
@Override

libs/entitlement/qa/src/javaRestTest/java/org/elasticsearch/entitlement/qa/EntitlementsDeniedIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public EntitlementsDeniedIT(@Name("actionName") String actionName) {
2626

2727
@ParametersFactory
2828
public static Iterable<Object[]> data() {
29-
return RestEntitlementsCheckAction.getAllCheckActions().stream().map(action -> new Object[] { action }).toList();
29+
return RestEntitlementsCheckAction.getDeniableCheckActions().stream().map(action -> new Object[] { action }).toList();
3030
}
3131

3232
@Override

libs/entitlement/qa/src/javaRestTest/java/org/elasticsearch/entitlement/qa/EntitlementsDeniedNonModularIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public EntitlementsDeniedNonModularIT(@Name("actionName") String actionName) {
2626

2727
@ParametersFactory
2828
public static Iterable<Object[]> data() {
29-
return RestEntitlementsCheckAction.getAllCheckActions().stream().map(action -> new Object[] { action }).toList();
29+
return RestEntitlementsCheckAction.getDeniableCheckActions().stream().map(action -> new Object[] { action }).toList();
3030
}
3131

3232
@Override

server/src/main/java/org/elasticsearch/common/util/LocaleUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
import java.util.MissingResourceException;
1515

1616
/**
17-
* Utilities for for dealing with {@link Locale} objects
17+
* Utilities for dealing with {@link Locale} objects
1818
*/
1919
public class LocaleUtils {
2020

2121
/**
2222
* Parse the given locale as {@code language}, {@code language-country} or
2323
* {@code language-country-variant}.
24-
* Either underscores or hyphens may be used as separators, but consistently, ie.
25-
* you may not use an hyphen to separate the language from the country and an
24+
* Either underscores or hyphens may be used as separators, but consistently, i.e.
25+
* you may not use a hyphen to separate the language from the country and an
2626
* underscore to separate the country from the variant.
2727
* @throws IllegalArgumentException if there are too many parts in the locale string
2828
* @throws IllegalArgumentException if the language or country is not recognized

server/src/main/java/org/elasticsearch/ingest/ConfigurationUtils.java

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -541,18 +541,38 @@ public static TemplateScript.Factory compileTemplate(
541541
Script script = new Script(ScriptType.INLINE, DEFAULT_TEMPLATE_LANG, propertyValue, Map.of());
542542
return scriptService.compile(script, TemplateScript.CONTEXT);
543543
} else {
544-
return (params) -> new TemplateScript(params) {
545-
@Override
546-
public String execute() {
547-
return propertyValue;
548-
}
549-
};
544+
return new ConstantTemplateScriptFactory(propertyValue);
550545
}
551546
} catch (Exception e) {
552547
throw ConfigurationUtils.newConfigurationException(processorType, processorTag, propertyName, e);
553548
}
554549
}
555550

551+
/**
552+
* A 'template script' that ignores the model to which it is applied and just always returns a constant String.
553+
* <p>
554+
* Having a separate named class for this allows for some hot code paths to pre-apply the 'template script' statically,
555+
* rather than bothering to invoke it per-document. Note that this is probably only useful if something expensive
556+
* is being done with the result of calling the script, and the code can then avoid doing that thing per-document.
557+
*/
558+
public static class ConstantTemplateScriptFactory implements TemplateScript.Factory {
559+
final TemplateScript script;
560+
561+
private ConstantTemplateScriptFactory(String value) {
562+
this.script = new TemplateScript(Map.of()) {
563+
@Override
564+
public String execute() {
565+
return value;
566+
}
567+
};
568+
}
569+
570+
@Override
571+
public TemplateScript newInstance(Map<String, Object> params) {
572+
return script;
573+
}
574+
}
575+
556576
private static void addMetadataToException(
557577
ElasticsearchException exception,
558578
String processorType,

0 commit comments

Comments
 (0)