forked from elastic/elasticsearch
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Scripting: add support for fine-grained settings
Allow to on/off scripting based on their source (where they get loaded from), the operation that executes them and their language. The settings cover the following combinations: - mode: on, off, sandbox - source: indexed, dynamic, file - engine: groovy, expressions, mustache, etc - operation: update, search, aggs, mapping The following settings are supported for every engine: script.engine.groovy.indexed.update: sandbox/on/off script.engine.groovy.indexed.search: sandbox/on/off script.engine.groovy.indexed.aggs: sandbox/on/off script.engine.groovy.indexed.mapping: sandbox/on/off script.engine.groovy.dynamic.update: sandbox/on/off script.engine.groovy.dynamic.search: sandbox/on/off script.engine.groovy.dynamic.aggs: sandbox/on/off script.engine.groovy.dynamic.mapping: sandbox/on/off script.engine.groovy.file.update: sandbox/on/off script.engine.groovy.file.search: sandbox/on/off script.engine.groovy.file.aggs: sandbox/on/off script.engine.groovy.file.mapping: sandbox/on/off For ease of use, the following more generic settings are supported too: script.indexed: sandbox/on/off script.dynamic: sandbox/on/off script.file: sandbox/on/off script.update: sandbox/on/off script.search: sandbox/on/off script.aggs: sandbox/on/off script.mapping: sandbox/on/off These will be used to calculate the more specific settings, using the stricter setting of each combination. Operation based settings have precedence over conflicting source based ones. Note that the `mustache` engine is affected by generic settings applied to any language, while native scripts aren't as they are static by definition. Also, the previous `script.disable_dynamic` setting can now be deprecated. Closes elastic#6418 Closes elastic#10116 Closes elastic#10274
- Loading branch information
Showing
40 changed files
with
1,618 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.script; | ||
|
||
import java.util.Locale; | ||
|
||
/** | ||
* Operation/api that uses a script as part of its execution. | ||
* Note that the suggest api is considered part of search for simplicity, as well as the percolate api. | ||
*/ | ||
public enum ScriptContext { | ||
MAPPING, | ||
UPDATE, | ||
SEARCH, | ||
AGGS; | ||
|
||
@Override | ||
public String toString() { | ||
return name().toLowerCase(Locale.ROOT); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.script; | ||
|
||
import org.elasticsearch.ElasticsearchIllegalArgumentException; | ||
import org.elasticsearch.common.Booleans; | ||
|
||
import java.util.Locale; | ||
|
||
/** | ||
* Mode for a specific script, used for script settings. | ||
* Defines whether a certain script or catefory of scripts can be executed or not, or whether it can | ||
* only be executed by a sandboxed scripting language. | ||
*/ | ||
enum ScriptMode { | ||
ON, | ||
OFF, | ||
SANDBOX; | ||
|
||
static ScriptMode parse(String input) { | ||
input = input.toLowerCase(Locale.ROOT); | ||
if (Booleans.isExplicitTrue(input)) { | ||
return ON; | ||
} | ||
if (Booleans.isExplicitFalse(input)) { | ||
return OFF; | ||
} | ||
if (SANDBOX.toString().equals(input)) { | ||
return SANDBOX; | ||
} | ||
throw new ElasticsearchIllegalArgumentException("script mode [" + input + "] not supported"); | ||
} | ||
|
||
|
||
@Override | ||
public String toString() { | ||
return name().toLowerCase(Locale.ROOT); | ||
} | ||
} |
Oops, something went wrong.