Use new context constants for SearchScript and ExecutableScript (elastic/x-pack-elasticsearch#1550)
This is the xpack side of https://github.com/elastic/elasticsearch/pull/24883. Original commit: elastic/x-pack-elasticsearch@9e612ec222
This commit is contained in:
parent
404ba010ad
commit
d3b3fe783d
|
@ -56,6 +56,7 @@ import org.elasticsearch.index.shard.IndexSearcherWrapper;
|
|||
import org.elasticsearch.index.shard.ShardId;
|
||||
import org.elasticsearch.index.shard.ShardUtils;
|
||||
import org.elasticsearch.license.XPackLicenseState;
|
||||
import org.elasticsearch.script.ExecutableScript;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.script.ScriptContext;
|
||||
import org.elasticsearch.script.ScriptService;
|
||||
|
@ -274,7 +275,7 @@ public class SecurityIndexSearcherWrapper extends IndexSearcherWrapper {
|
|||
params.put("_user", userModel);
|
||||
// Always enforce mustache script lang:
|
||||
script = new Script(script.getType(), "mustache", script.getIdOrCode(), script.getOptions(), params);
|
||||
CompiledTemplate compiledTemplate = scriptService.compileTemplate(script, ScriptContext.EXECUTABLE);
|
||||
CompiledTemplate compiledTemplate = scriptService.compileTemplate(script, ExecutableScript.CONTEXT);
|
||||
return compiledTemplate.run(script.getParams());
|
||||
} else {
|
||||
return querySource;
|
||||
|
|
|
@ -68,6 +68,7 @@ import org.elasticsearch.index.shard.IndexShard;
|
|||
import org.elasticsearch.index.shard.ShardId;
|
||||
import org.elasticsearch.indices.TermsLookup;
|
||||
import org.elasticsearch.license.XPackLicenseState;
|
||||
import org.elasticsearch.script.ExecutableScript;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.script.ScriptContext;
|
||||
import org.elasticsearch.script.ScriptService;
|
||||
|
@ -458,7 +459,7 @@ public class SecurityIndexSearcherWrapperUnitTests extends ESTestCase {
|
|||
};
|
||||
|
||||
CompiledTemplate compiledScript = mock(CompiledTemplate.class);
|
||||
when(scriptService.compileTemplate(any(Script.class), eq(ScriptContext.EXECUTABLE))).thenReturn(compiledScript);
|
||||
when(scriptService.compileTemplate(any(Script.class), eq(ExecutableScript.CONTEXT))).thenReturn(compiledScript);
|
||||
|
||||
XContentBuilder builder = jsonBuilder();
|
||||
String query = new TermQueryBuilder("field", "{{_user.username}}").toXContent(builder, ToXContent.EMPTY_PARAMS).string();
|
||||
|
@ -469,7 +470,7 @@ public class SecurityIndexSearcherWrapperUnitTests extends ESTestCase {
|
|||
|
||||
securityIndexSearcherWrapper.evaluateTemplate(querySource);
|
||||
ArgumentCaptor<Script> argument = ArgumentCaptor.forClass(Script.class);
|
||||
verify(scriptService).compileTemplate(argument.capture(), eq(ScriptContext.EXECUTABLE));
|
||||
verify(scriptService).compileTemplate(argument.capture(), eq(ExecutableScript.CONTEXT));
|
||||
Script usedScript = argument.getValue();
|
||||
assertThat(usedScript.getIdOrCode(), equalTo(script.getIdOrCode()));
|
||||
assertThat(usedScript.getType(), equalTo(script.getType()));
|
||||
|
|
|
@ -17,6 +17,7 @@ import org.elasticsearch.common.xcontent.XContent;
|
|||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.script.ScriptContext;
|
||||
import org.elasticsearch.script.ScriptModule;
|
||||
import org.elasticsearch.script.ScriptService;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.elasticsearch.test.ESIntegTestCase;
|
||||
|
@ -236,7 +237,7 @@ public final class WatcherTestUtils {
|
|||
Settings settings = Settings.builder()
|
||||
.put("path.home", createTempDir())
|
||||
.build();
|
||||
Map<String, ScriptContext> contexts = new HashMap<>(ScriptContext.BUILTINS);
|
||||
Map<String, ScriptContext> contexts = new HashMap<>(ScriptModule.CORE_CONTEXTS);
|
||||
contexts.put(Watcher.SCRIPT_EXECUTABLE_CONTEXT.name, Watcher.SCRIPT_EXECUTABLE_CONTEXT);
|
||||
return new ScriptService(settings, Collections.emptyMap(), Collections.emptyMap());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue