Replace 'whitelist' terminology in Java API (#3350)
Signed-off-by: Tianli Feng <ftianli@amazon.com>
This commit is contained in:
parent
00c0bf2dd9
commit
8f8909fd54
|
@ -529,7 +529,7 @@ updates:
|
||||||
package-ecosystem: gradle
|
package-ecosystem: gradle
|
||||||
schedule:
|
schedule:
|
||||||
interval: weekly
|
interval: weekly
|
||||||
- directory: /plugins/examples/painless-whitelist/
|
- directory: /plugins/examples/painless-allowlist/
|
||||||
open-pull-requests-limit: 1
|
open-pull-requests-limit: 1
|
||||||
package-ecosystem: gradle
|
package-ecosystem: gradle
|
||||||
schedule:
|
schedule:
|
||||||
|
|
|
@ -103,7 +103,7 @@ configure([
|
||||||
project(":example-plugins:custom-settings"),
|
project(":example-plugins:custom-settings"),
|
||||||
project(":example-plugins:custom-significance-heuristic"),
|
project(":example-plugins:custom-significance-heuristic"),
|
||||||
project(":example-plugins:custom-suggester"),
|
project(":example-plugins:custom-suggester"),
|
||||||
project(":example-plugins:painless-whitelist"),
|
project(":example-plugins:painless-allowlist"),
|
||||||
project(":example-plugins:rescore"),
|
project(":example-plugins:rescore"),
|
||||||
project(":example-plugins:rest-handler"),
|
project(":example-plugins:rest-handler"),
|
||||||
project(":example-plugins:script-expert-scoring"),
|
project(":example-plugins:script-expert-scoring"),
|
||||||
|
|
|
@ -33,8 +33,8 @@
|
||||||
package org.opensearch.analysis.common;
|
package org.opensearch.analysis.common;
|
||||||
|
|
||||||
import org.opensearch.painless.spi.PainlessExtension;
|
import org.opensearch.painless.spi.PainlessExtension;
|
||||||
import org.opensearch.painless.spi.Whitelist;
|
import org.opensearch.painless.spi.Allowlist;
|
||||||
import org.opensearch.painless.spi.WhitelistLoader;
|
import org.opensearch.painless.spi.AllowlistLoader;
|
||||||
import org.opensearch.script.ScriptContext;
|
import org.opensearch.script.ScriptContext;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -43,13 +43,13 @@ import java.util.Map;
|
||||||
|
|
||||||
public class AnalysisPainlessExtension implements PainlessExtension {
|
public class AnalysisPainlessExtension implements PainlessExtension {
|
||||||
|
|
||||||
private static final Whitelist ALLOWLIST = WhitelistLoader.loadFromResourceFiles(
|
private static final Allowlist ALLOWLIST = AllowlistLoader.loadFromResourceFiles(
|
||||||
AnalysisPainlessExtension.class,
|
AnalysisPainlessExtension.class,
|
||||||
"painless_whitelist.txt"
|
"painless_allowlist.txt"
|
||||||
);
|
);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<ScriptContext<?>, List<Whitelist>> getContextWhitelists() {
|
public Map<ScriptContext<?>, List<Allowlist>> getContextAllowlists() {
|
||||||
return Collections.singletonMap(AnalysisPredicateScript.CONTEXT, Collections.singletonList(ALLOWLIST));
|
return Collections.singletonMap(AnalysisPredicateScript.CONTEXT, Collections.singletonList(ALLOWLIST));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,8 +33,8 @@
|
||||||
package org.opensearch.ingest.common;
|
package org.opensearch.ingest.common;
|
||||||
|
|
||||||
import org.opensearch.painless.spi.PainlessExtension;
|
import org.opensearch.painless.spi.PainlessExtension;
|
||||||
import org.opensearch.painless.spi.Whitelist;
|
import org.opensearch.painless.spi.Allowlist;
|
||||||
import org.opensearch.painless.spi.WhitelistLoader;
|
import org.opensearch.painless.spi.AllowlistLoader;
|
||||||
import org.opensearch.script.IngestScript;
|
import org.opensearch.script.IngestScript;
|
||||||
import org.opensearch.script.ScriptContext;
|
import org.opensearch.script.ScriptContext;
|
||||||
|
|
||||||
|
@ -42,15 +42,15 @@ import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class ProcessorsWhitelistExtension implements PainlessExtension {
|
public class ProcessorsAllowlistExtension implements PainlessExtension {
|
||||||
|
|
||||||
private static final Whitelist ALLOWLIST = WhitelistLoader.loadFromResourceFiles(
|
private static final Allowlist ALLOWLIST = AllowlistLoader.loadFromResourceFiles(
|
||||||
ProcessorsWhitelistExtension.class,
|
ProcessorsAllowlistExtension.class,
|
||||||
"processors_whitelist.txt"
|
"processors_allowlist.txt"
|
||||||
);
|
);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<ScriptContext<?>, List<Whitelist>> getContextWhitelists() {
|
public Map<ScriptContext<?>, List<Allowlist>> getContextAllowlists() {
|
||||||
return Collections.singletonMap(IngestScript.CONTEXT, Collections.singletonList(ALLOWLIST));
|
return Collections.singletonMap(IngestScript.CONTEXT, Collections.singletonList(ALLOWLIST));
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1 +1 @@
|
||||||
org.opensearch.ingest.common.ProcessorsWhitelistExtension
|
org.opensearch.ingest.common.ProcessorsAllowlistExtension
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
|
|
||||||
package org.opensearch.painless.spi;
|
package org.opensearch.painless.spi;
|
||||||
|
|
||||||
import org.opensearch.painless.spi.annotation.WhitelistAnnotationParser;
|
import org.opensearch.painless.spi.annotation.AllowlistAnnotationParser;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -43,12 +43,12 @@ import java.util.Objects;
|
||||||
* constructors, methods, and fields that can be used within a Painless script at both compile-time
|
* constructors, methods, and fields that can be used within a Painless script at both compile-time
|
||||||
* and run-time.
|
* and run-time.
|
||||||
*
|
*
|
||||||
* A Allowlist consists of several pieces with {@link WhitelistClass}s as the top level. Each
|
* A Allowlist consists of several pieces with {@link AllowlistClass}s as the top level. Each
|
||||||
* {@link WhitelistClass} will contain zero-to-many {@link WhitelistConstructor}s, {@link WhitelistMethod}s, and
|
* {@link AllowlistClass} will contain zero-to-many {@link AllowlistConstructor}s, {@link AllowlistMethod}s, and
|
||||||
* {@link WhitelistField}s which are what will be available with a Painless script. See each individual
|
* {@link AllowlistField}s which are what will be available with a Painless script. See each individual
|
||||||
* allowlist object for more detail.
|
* allowlist object for more detail.
|
||||||
*/
|
*/
|
||||||
public final class Whitelist {
|
public final class Allowlist {
|
||||||
|
|
||||||
private static final String[] BASE_ALLOWLIST_FILES = new String[] {
|
private static final String[] BASE_ALLOWLIST_FILES = new String[] {
|
||||||
"org.opensearch.txt",
|
"org.opensearch.txt",
|
||||||
|
@ -65,38 +65,38 @@ public final class Whitelist {
|
||||||
"java.util.regex.txt",
|
"java.util.regex.txt",
|
||||||
"java.util.stream.txt" };
|
"java.util.stream.txt" };
|
||||||
|
|
||||||
public static final List<Whitelist> BASE_WHITELISTS = Collections.singletonList(
|
public static final List<Allowlist> BASE_ALLOWLISTS = Collections.singletonList(
|
||||||
WhitelistLoader.loadFromResourceFiles(Whitelist.class, WhitelistAnnotationParser.BASE_ANNOTATION_PARSERS, BASE_ALLOWLIST_FILES)
|
AllowlistLoader.loadFromResourceFiles(Allowlist.class, AllowlistAnnotationParser.BASE_ANNOTATION_PARSERS, BASE_ALLOWLIST_FILES)
|
||||||
);
|
);
|
||||||
|
|
||||||
/** The {@link ClassLoader} used to look up the allowlisted Java classes, constructors, methods, and fields. */
|
/** The {@link ClassLoader} used to look up the allowlisted Java classes, constructors, methods, and fields. */
|
||||||
public final ClassLoader classLoader;
|
public final ClassLoader classLoader;
|
||||||
|
|
||||||
/** The {@link List} of all the allowlisted Painless classes. */
|
/** The {@link List} of all the allowlisted Painless classes. */
|
||||||
public final List<WhitelistClass> whitelistClasses;
|
public final List<AllowlistClass> allowlistClasses;
|
||||||
|
|
||||||
/** The {@link List} of all the allowlisted static Painless methods. */
|
/** The {@link List} of all the allowlisted static Painless methods. */
|
||||||
public final List<WhitelistMethod> whitelistImportedMethods;
|
public final List<AllowlistMethod> allowlistImportedMethods;
|
||||||
|
|
||||||
/** The {@link List} of all the allowlisted Painless class bindings. */
|
/** The {@link List} of all the allowlisted Painless class bindings. */
|
||||||
public final List<WhitelistClassBinding> whitelistClassBindings;
|
public final List<AllowlistClassBinding> allowlistClassBindings;
|
||||||
|
|
||||||
/** The {@link List} of all the allowlisted Painless instance bindings. */
|
/** The {@link List} of all the allowlisted Painless instance bindings. */
|
||||||
public final List<WhitelistInstanceBinding> whitelistInstanceBindings;
|
public final List<AllowlistInstanceBinding> allowlistInstanceBindings;
|
||||||
|
|
||||||
/** Standard constructor. All values must be not {@code null}. */
|
/** Standard constructor. All values must be not {@code null}. */
|
||||||
public Whitelist(
|
public Allowlist(
|
||||||
ClassLoader classLoader,
|
ClassLoader classLoader,
|
||||||
List<WhitelistClass> allowlistClasses,
|
List<AllowlistClass> allowlistClasses,
|
||||||
List<WhitelistMethod> allowlistImportedMethods,
|
List<AllowlistMethod> allowlistImportedMethods,
|
||||||
List<WhitelistClassBinding> allowlistClassBindings,
|
List<AllowlistClassBinding> allowlistClassBindings,
|
||||||
List<WhitelistInstanceBinding> allowlistInstanceBindings
|
List<AllowlistInstanceBinding> allowlistInstanceBindings
|
||||||
) {
|
) {
|
||||||
|
|
||||||
this.classLoader = Objects.requireNonNull(classLoader);
|
this.classLoader = Objects.requireNonNull(classLoader);
|
||||||
this.whitelistClasses = Collections.unmodifiableList(Objects.requireNonNull(allowlistClasses));
|
this.allowlistClasses = Collections.unmodifiableList(Objects.requireNonNull(allowlistClasses));
|
||||||
this.whitelistImportedMethods = Collections.unmodifiableList(Objects.requireNonNull(allowlistImportedMethods));
|
this.allowlistImportedMethods = Collections.unmodifiableList(Objects.requireNonNull(allowlistImportedMethods));
|
||||||
this.whitelistClassBindings = Collections.unmodifiableList(Objects.requireNonNull(allowlistClassBindings));
|
this.allowlistClassBindings = Collections.unmodifiableList(Objects.requireNonNull(allowlistClassBindings));
|
||||||
this.whitelistInstanceBindings = Collections.unmodifiableList(Objects.requireNonNull(allowlistInstanceBindings));
|
this.allowlistInstanceBindings = Collections.unmodifiableList(Objects.requireNonNull(allowlistInstanceBindings));
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -54,42 +54,42 @@ import java.util.stream.Collectors;
|
||||||
* Classes will automatically extend other allowlisted classes if the Java class they represent is a
|
* Classes will automatically extend other allowlisted classes if the Java class they represent is a
|
||||||
* subclass of other classes including Java interfaces.
|
* subclass of other classes including Java interfaces.
|
||||||
*/
|
*/
|
||||||
public final class WhitelistClass {
|
public final class AllowlistClass {
|
||||||
|
|
||||||
/** Information about where this class was white-listed from. */
|
/** Information about where this class was allow-listed from. */
|
||||||
public final String origin;
|
public final String origin;
|
||||||
|
|
||||||
/** The Java class name this class represents. */
|
/** The Java class name this class represents. */
|
||||||
public final String javaClassName;
|
public final String javaClassName;
|
||||||
|
|
||||||
/** The {@link List} of allowlisted ({@link WhitelistConstructor}s) available to this class. */
|
/** The {@link List} of allowlisted ({@link AllowlistConstructor}s) available to this class. */
|
||||||
public final List<WhitelistConstructor> whitelistConstructors;
|
public final List<AllowlistConstructor> allowlistConstructors;
|
||||||
|
|
||||||
/** The {@link List} of allowlisted ({@link WhitelistMethod}s) available to this class. */
|
/** The {@link List} of allowlisted ({@link AllowlistMethod}s) available to this class. */
|
||||||
public final List<WhitelistMethod> whitelistMethods;
|
public final List<AllowlistMethod> allowlistMethods;
|
||||||
|
|
||||||
/** The {@link List} of allowlisted ({@link WhitelistField}s) available to this class. */
|
/** The {@link List} of allowlisted ({@link AllowlistField}s) available to this class. */
|
||||||
public final List<WhitelistField> whitelistFields;
|
public final List<AllowlistField> allowlistFields;
|
||||||
|
|
||||||
/** The {@link Map} of annotations for this class. */
|
/** The {@link Map} of annotations for this class. */
|
||||||
public final Map<Class<?>, Object> painlessAnnotations;
|
public final Map<Class<?>, Object> painlessAnnotations;
|
||||||
|
|
||||||
/** Standard constructor. All values must be not {@code null}. */
|
/** Standard constructor. All values must be not {@code null}. */
|
||||||
public WhitelistClass(
|
public AllowlistClass(
|
||||||
String origin,
|
String origin,
|
||||||
String javaClassName,
|
String javaClassName,
|
||||||
List<WhitelistConstructor> allowlistConstructors,
|
List<AllowlistConstructor> allowlistConstructors,
|
||||||
List<WhitelistMethod> allowlistMethods,
|
List<AllowlistMethod> allowlistMethods,
|
||||||
List<WhitelistField> allowlistFields,
|
List<AllowlistField> allowlistFields,
|
||||||
List<Object> painlessAnnotations
|
List<Object> painlessAnnotations
|
||||||
) {
|
) {
|
||||||
|
|
||||||
this.origin = Objects.requireNonNull(origin);
|
this.origin = Objects.requireNonNull(origin);
|
||||||
this.javaClassName = Objects.requireNonNull(javaClassName);
|
this.javaClassName = Objects.requireNonNull(javaClassName);
|
||||||
|
|
||||||
this.whitelistConstructors = Collections.unmodifiableList(Objects.requireNonNull(allowlistConstructors));
|
this.allowlistConstructors = Collections.unmodifiableList(Objects.requireNonNull(allowlistConstructors));
|
||||||
this.whitelistMethods = Collections.unmodifiableList(Objects.requireNonNull(allowlistMethods));
|
this.allowlistMethods = Collections.unmodifiableList(Objects.requireNonNull(allowlistMethods));
|
||||||
this.whitelistFields = Collections.unmodifiableList(Objects.requireNonNull(allowlistFields));
|
this.allowlistFields = Collections.unmodifiableList(Objects.requireNonNull(allowlistFields));
|
||||||
|
|
||||||
if (painlessAnnotations.isEmpty()) {
|
if (painlessAnnotations.isEmpty()) {
|
||||||
this.painlessAnnotations = Collections.emptyMap();
|
this.painlessAnnotations = Collections.emptyMap();
|
|
@ -48,7 +48,7 @@ import java.util.stream.Collectors;
|
||||||
* arguments passed into the constructor. The method for a binding class will be called each time
|
* arguments passed into the constructor. The method for a binding class will be called each time
|
||||||
* the binding method is called and may use the previously stored state.
|
* the binding method is called and may use the previously stored state.
|
||||||
*/
|
*/
|
||||||
public class WhitelistClassBinding {
|
public class AllowlistClassBinding {
|
||||||
|
|
||||||
/** Information about where this constructor was allowlisted from. */
|
/** Information about where this constructor was allowlisted from. */
|
||||||
public final String origin;
|
public final String origin;
|
||||||
|
@ -72,7 +72,7 @@ public class WhitelistClassBinding {
|
||||||
public final Map<Class<?>, Object> painlessAnnotations;
|
public final Map<Class<?>, Object> painlessAnnotations;
|
||||||
|
|
||||||
/** Standard constructor. All values must be not {@code null}. */
|
/** Standard constructor. All values must be not {@code null}. */
|
||||||
public WhitelistClassBinding(
|
public AllowlistClassBinding(
|
||||||
String origin,
|
String origin,
|
||||||
String targetJavaClassName,
|
String targetJavaClassName,
|
||||||
String methodName,
|
String methodName,
|
|
@ -43,9 +43,9 @@ import java.util.stream.Collectors;
|
||||||
* Constructor represents the equivalent of a Java constructor available as a allowlisted class
|
* Constructor represents the equivalent of a Java constructor available as a allowlisted class
|
||||||
* constructor within Painless. Constructors for Painless classes may be accessed exactly as
|
* constructor within Painless. Constructors for Painless classes may be accessed exactly as
|
||||||
* constructors for Java classes are using the 'new' keyword. Painless classes may have multiple
|
* constructors for Java classes are using the 'new' keyword. Painless classes may have multiple
|
||||||
* constructors as long as they comply with arity overloading described for {@link WhitelistClass}.
|
* constructors as long as they comply with arity overloading described for {@link AllowlistClass}.
|
||||||
*/
|
*/
|
||||||
public final class WhitelistConstructor {
|
public final class AllowlistConstructor {
|
||||||
|
|
||||||
/** Information about where this constructor was allowlisted from. */
|
/** Information about where this constructor was allowlisted from. */
|
||||||
public final String origin;
|
public final String origin;
|
||||||
|
@ -60,7 +60,7 @@ public final class WhitelistConstructor {
|
||||||
public final Map<Class<?>, Object> painlessAnnotations;
|
public final Map<Class<?>, Object> painlessAnnotations;
|
||||||
|
|
||||||
/** Standard constructor. All values must be not {@code null}. */
|
/** Standard constructor. All values must be not {@code null}. */
|
||||||
public WhitelistConstructor(String origin, List<String> canonicalTypeNameParameters, List<Object> painlessAnnotations) {
|
public AllowlistConstructor(String origin, List<String> canonicalTypeNameParameters, List<Object> painlessAnnotations) {
|
||||||
this.origin = Objects.requireNonNull(origin);
|
this.origin = Objects.requireNonNull(origin);
|
||||||
this.canonicalTypeNameParameters = Collections.unmodifiableList(Objects.requireNonNull(canonicalTypeNameParameters));
|
this.canonicalTypeNameParameters = Collections.unmodifiableList(Objects.requireNonNull(canonicalTypeNameParameters));
|
||||||
|
|
|
@ -44,7 +44,7 @@ import java.util.stream.Collectors;
|
||||||
* within Painless. Fields for Painless classes may be accessed exactly as fields for Java classes
|
* within Painless. Fields for Painless classes may be accessed exactly as fields for Java classes
|
||||||
* are using the '.' operator on an existing class variable/field.
|
* are using the '.' operator on an existing class variable/field.
|
||||||
*/
|
*/
|
||||||
public class WhitelistField {
|
public class AllowlistField {
|
||||||
|
|
||||||
/** Information about where this method was allowlisted from. */
|
/** Information about where this method was allowlisted from. */
|
||||||
public final String origin;
|
public final String origin;
|
||||||
|
@ -59,7 +59,7 @@ public class WhitelistField {
|
||||||
public final Map<Class<?>, Object> painlessAnnotations;
|
public final Map<Class<?>, Object> painlessAnnotations;
|
||||||
|
|
||||||
/** Standard constructor. All values must be not {@code null}. */
|
/** Standard constructor. All values must be not {@code null}. */
|
||||||
public WhitelistField(String origin, String fieldName, String canonicalTypeNameParameter, List<Object> painlessAnnotations) {
|
public AllowlistField(String origin, String fieldName, String canonicalTypeNameParameter, List<Object> painlessAnnotations) {
|
||||||
this.origin = Objects.requireNonNull(origin);
|
this.origin = Objects.requireNonNull(origin);
|
||||||
this.fieldName = Objects.requireNonNull(fieldName);
|
this.fieldName = Objects.requireNonNull(fieldName);
|
||||||
this.canonicalTypeNameParameter = Objects.requireNonNull(canonicalTypeNameParameter);
|
this.canonicalTypeNameParameter = Objects.requireNonNull(canonicalTypeNameParameter);
|
|
@ -44,7 +44,7 @@ import java.util.stream.Collectors;
|
||||||
* exactly one public method name. The canonical type name parameters provided must match those of the
|
* exactly one public method name. The canonical type name parameters provided must match those of the
|
||||||
* method. The method for an instance binding will target the specified Java instance.
|
* method. The method for an instance binding will target the specified Java instance.
|
||||||
*/
|
*/
|
||||||
public class WhitelistInstanceBinding {
|
public class AllowlistInstanceBinding {
|
||||||
|
|
||||||
/** Information about where this constructor was allowlisted from. */
|
/** Information about where this constructor was allowlisted from. */
|
||||||
public final String origin;
|
public final String origin;
|
||||||
|
@ -68,7 +68,7 @@ public class WhitelistInstanceBinding {
|
||||||
public final Map<Class<?>, Object> painlessAnnotations;
|
public final Map<Class<?>, Object> painlessAnnotations;
|
||||||
|
|
||||||
/** Standard constructor. All values must be not {@code null}. */
|
/** Standard constructor. All values must be not {@code null}. */
|
||||||
public WhitelistInstanceBinding(
|
public AllowlistInstanceBinding(
|
||||||
String origin,
|
String origin,
|
||||||
Object targetInstance,
|
Object targetInstance,
|
||||||
String methodName,
|
String methodName,
|
|
@ -32,7 +32,7 @@
|
||||||
|
|
||||||
package org.opensearch.painless.spi;
|
package org.opensearch.painless.spi;
|
||||||
|
|
||||||
import org.opensearch.painless.spi.annotation.WhitelistAnnotationParser;
|
import org.opensearch.painless.spi.annotation.AllowlistAnnotationParser;
|
||||||
|
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.LineNumberReader;
|
import java.io.LineNumberReader;
|
||||||
|
@ -49,20 +49,20 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/** Loads and creates a {@link Whitelist} from one to many text files. */
|
/** Loads and creates a {@link Allowlist} from one to many text files. */
|
||||||
public final class WhitelistLoader {
|
public final class AllowlistLoader {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads and creates a {@link Whitelist} from one to many text files using only the base annotation parsers.
|
* Loads and creates a {@link Allowlist} from one to many text files using only the base annotation parsers.
|
||||||
* See {@link #loadFromResourceFiles(Class, Map, String...)} for information on how to structure an allowlist
|
* See {@link #loadFromResourceFiles(Class, Map, String...)} for information on how to structure an allowlist
|
||||||
* text file.
|
* text file.
|
||||||
*/
|
*/
|
||||||
public static Whitelist loadFromResourceFiles(Class<?> resource, String... filepaths) {
|
public static Allowlist loadFromResourceFiles(Class<?> resource, String... filepaths) {
|
||||||
return loadFromResourceFiles(resource, WhitelistAnnotationParser.BASE_ANNOTATION_PARSERS, filepaths);
|
return loadFromResourceFiles(resource, AllowlistAnnotationParser.BASE_ANNOTATION_PARSERS, filepaths);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads and creates a {@link Whitelist} from one to many text files. The file paths are passed in as an array of
|
* Loads and creates a {@link Allowlist} from one to many text files. The file paths are passed in as an array of
|
||||||
* {@link String}s with a single {@link Class} to be be used to load the resources where each {@link String}
|
* {@link String}s with a single {@link Class} to be be used to load the resources where each {@link String}
|
||||||
* is the path of a single text file. The {@link Class}'s {@link ClassLoader} will be used to lookup the Java
|
* is the path of a single text file. The {@link Class}'s {@link ClassLoader} will be used to lookup the Java
|
||||||
* reflection objects for each individual {@link Class}, {@link Constructor}, {@link Method}, and {@link Field}
|
* reflection objects for each individual {@link Class}, {@link Constructor}, {@link Method}, and {@link Field}
|
||||||
|
@ -163,10 +163,10 @@ public final class WhitelistLoader {
|
||||||
* }
|
* }
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
public static Whitelist loadFromResourceFiles(Class<?> resource, Map<String, WhitelistAnnotationParser> parsers, String... filepaths) {
|
public static Allowlist loadFromResourceFiles(Class<?> resource, Map<String, AllowlistAnnotationParser> parsers, String... filepaths) {
|
||||||
List<WhitelistClass> allowlistClasses = new ArrayList<>();
|
List<AllowlistClass> allowlistClasses = new ArrayList<>();
|
||||||
List<WhitelistMethod> allowlistStatics = new ArrayList<>();
|
List<AllowlistMethod> allowlistStatics = new ArrayList<>();
|
||||||
List<WhitelistClassBinding> allowlistClassBindings = new ArrayList<>();
|
List<AllowlistClassBinding> allowlistClassBindings = new ArrayList<>();
|
||||||
|
|
||||||
// Execute a single pass through the allowlist text files. This will gather all the
|
// Execute a single pass through the allowlist text files. This will gather all the
|
||||||
// constructors, methods, augmented methods, and fields for each allowlisted class.
|
// constructors, methods, augmented methods, and fields for each allowlisted class.
|
||||||
|
@ -183,9 +183,9 @@ public final class WhitelistLoader {
|
||||||
String parseType = null;
|
String parseType = null;
|
||||||
String allowlistClassOrigin = null;
|
String allowlistClassOrigin = null;
|
||||||
String javaClassName = null;
|
String javaClassName = null;
|
||||||
List<WhitelistConstructor> allowlistConstructors = null;
|
List<AllowlistConstructor> allowlistConstructors = null;
|
||||||
List<WhitelistMethod> allowlistMethods = null;
|
List<AllowlistMethod> allowlistMethods = null;
|
||||||
List<WhitelistField> allowlistFields = null;
|
List<AllowlistField> allowlistFields = null;
|
||||||
List<Object> classAnnotations = null;
|
List<Object> classAnnotations = null;
|
||||||
|
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
|
@ -254,7 +254,7 @@ public final class WhitelistLoader {
|
||||||
// augmented methods, and fields, and add it to the list of allowlisted classes.
|
// augmented methods, and fields, and add it to the list of allowlisted classes.
|
||||||
if ("class".equals(parseType)) {
|
if ("class".equals(parseType)) {
|
||||||
allowlistClasses.add(
|
allowlistClasses.add(
|
||||||
new WhitelistClass(
|
new AllowlistClass(
|
||||||
allowlistClassOrigin,
|
allowlistClassOrigin,
|
||||||
javaClassName,
|
javaClassName,
|
||||||
allowlistConstructors,
|
allowlistConstructors,
|
||||||
|
@ -350,7 +350,7 @@ public final class WhitelistLoader {
|
||||||
// Add a static import method or binding depending on the static import type.
|
// Add a static import method or binding depending on the static import type.
|
||||||
if ("from_class".equals(staticImportType)) {
|
if ("from_class".equals(staticImportType)) {
|
||||||
allowlistStatics.add(
|
allowlistStatics.add(
|
||||||
new WhitelistMethod(
|
new AllowlistMethod(
|
||||||
origin,
|
origin,
|
||||||
targetJavaClassName,
|
targetJavaClassName,
|
||||||
methodName,
|
methodName,
|
||||||
|
@ -361,7 +361,7 @@ public final class WhitelistLoader {
|
||||||
);
|
);
|
||||||
} else if ("bound_to".equals(staticImportType)) {
|
} else if ("bound_to".equals(staticImportType)) {
|
||||||
allowlistClassBindings.add(
|
allowlistClassBindings.add(
|
||||||
new WhitelistClassBinding(
|
new AllowlistClassBinding(
|
||||||
origin,
|
origin,
|
||||||
targetJavaClassName,
|
targetJavaClassName,
|
||||||
methodName,
|
methodName,
|
||||||
|
@ -413,7 +413,7 @@ public final class WhitelistLoader {
|
||||||
: parseAllowlistAnnotations(parsers, line.substring(annotationIndex));
|
: parseAllowlistAnnotations(parsers, line.substring(annotationIndex));
|
||||||
|
|
||||||
allowlistConstructors.add(
|
allowlistConstructors.add(
|
||||||
new WhitelistConstructor(origin, Arrays.asList(canonicalTypeNameParameters), annotations)
|
new AllowlistConstructor(origin, Arrays.asList(canonicalTypeNameParameters), annotations)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Handle the case for a method or augmented method definition.
|
// Handle the case for a method or augmented method definition.
|
||||||
|
@ -465,7 +465,7 @@ public final class WhitelistLoader {
|
||||||
: parseAllowlistAnnotations(parsers, line.substring(annotationIndex));
|
: parseAllowlistAnnotations(parsers, line.substring(annotationIndex));
|
||||||
|
|
||||||
allowlistMethods.add(
|
allowlistMethods.add(
|
||||||
new WhitelistMethod(
|
new AllowlistMethod(
|
||||||
origin,
|
origin,
|
||||||
javaAugmentedClassName,
|
javaAugmentedClassName,
|
||||||
methodName,
|
methodName,
|
||||||
|
@ -497,7 +497,7 @@ public final class WhitelistLoader {
|
||||||
throw new IllegalArgumentException("invalid field definition: unexpected format [" + line + "]");
|
throw new IllegalArgumentException("invalid field definition: unexpected format [" + line + "]");
|
||||||
}
|
}
|
||||||
|
|
||||||
allowlistFields.add(new WhitelistField(origin, tokens[1], tokens[0], annotations));
|
allowlistFields.add(new AllowlistField(origin, tokens[1], tokens[0], annotations));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("invalid definition: unable to parse line [" + line + "]");
|
throw new IllegalArgumentException("invalid definition: unable to parse line [" + line + "]");
|
||||||
|
@ -515,10 +515,10 @@ public final class WhitelistLoader {
|
||||||
|
|
||||||
ClassLoader loader = AccessController.doPrivileged((PrivilegedAction<ClassLoader>) resource::getClassLoader);
|
ClassLoader loader = AccessController.doPrivileged((PrivilegedAction<ClassLoader>) resource::getClassLoader);
|
||||||
|
|
||||||
return new Whitelist(loader, allowlistClasses, allowlistStatics, allowlistClassBindings, Collections.emptyList());
|
return new Allowlist(loader, allowlistClasses, allowlistStatics, allowlistClassBindings, Collections.emptyList());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<Object> parseAllowlistAnnotations(Map<String, WhitelistAnnotationParser> parsers, String line) {
|
private static List<Object> parseAllowlistAnnotations(Map<String, AllowlistAnnotationParser> parsers, String line) {
|
||||||
|
|
||||||
List<Object> annotations;
|
List<Object> annotations;
|
||||||
|
|
||||||
|
@ -585,7 +585,7 @@ public final class WhitelistLoader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WhitelistAnnotationParser parser = parsers.get(name);
|
AllowlistAnnotationParser parser = parsers.get(name);
|
||||||
|
|
||||||
if (parser == null) {
|
if (parser == null) {
|
||||||
throw new IllegalArgumentException("invalid annotation: parser not found for [" + name + "] [" + line + "]");
|
throw new IllegalArgumentException("invalid annotation: parser not found for [" + name + "] [" + line + "]");
|
||||||
|
@ -598,5 +598,5 @@ public final class WhitelistLoader {
|
||||||
return annotations;
|
return annotations;
|
||||||
}
|
}
|
||||||
|
|
||||||
private WhitelistLoader() {}
|
private AllowlistLoader() {}
|
||||||
}
|
}
|
|
@ -44,7 +44,7 @@ import java.util.stream.Collectors;
|
||||||
* within Painless. Methods for Painless classes may be accessed exactly as methods for Java classes
|
* within Painless. Methods for Painless classes may be accessed exactly as methods for Java classes
|
||||||
* are using the '.' operator on an existing class variable/field. Painless classes may have multiple
|
* are using the '.' operator on an existing class variable/field. Painless classes may have multiple
|
||||||
* methods with the same name as long as they comply with arity overloading described in
|
* methods with the same name as long as they comply with arity overloading described in
|
||||||
* {@link WhitelistClass}.
|
* {@link AllowlistClass}.
|
||||||
*
|
*
|
||||||
* Classes may also have additional methods that are not part of the Java class the class represents -
|
* Classes may also have additional methods that are not part of the Java class the class represents -
|
||||||
* these are known as augmented methods. An augmented method can be added to a class as a part of any
|
* these are known as augmented methods. An augmented method can be added to a class as a part of any
|
||||||
|
@ -52,7 +52,7 @@ import java.util.stream.Collectors;
|
||||||
* represented by the class. Note that the augmented method's parent Java class does not need to be
|
* represented by the class. Note that the augmented method's parent Java class does not need to be
|
||||||
* allowlisted.
|
* allowlisted.
|
||||||
*/
|
*/
|
||||||
public class WhitelistMethod {
|
public class AllowlistMethod {
|
||||||
|
|
||||||
/** Information about where this method was allowlisted from. */
|
/** Information about where this method was allowlisted from. */
|
||||||
public final String origin;
|
public final String origin;
|
||||||
|
@ -85,7 +85,7 @@ public class WhitelistMethod {
|
||||||
* augmentedCanonicalClassName; augmentedCanonicalClassName will be {@code null} unless the method
|
* augmentedCanonicalClassName; augmentedCanonicalClassName will be {@code null} unless the method
|
||||||
* is augmented as described in the class documentation.
|
* is augmented as described in the class documentation.
|
||||||
*/
|
*/
|
||||||
public WhitelistMethod(
|
public AllowlistMethod(
|
||||||
String origin,
|
String origin,
|
||||||
String augmentedCanonicalClassName,
|
String augmentedCanonicalClassName,
|
||||||
String methodName,
|
String methodName,
|
|
@ -39,5 +39,5 @@ import java.util.Map;
|
||||||
|
|
||||||
public interface PainlessExtension {
|
public interface PainlessExtension {
|
||||||
|
|
||||||
Map<ScriptContext<?>, List<Whitelist>> getContextWhitelists();
|
Map<ScriptContext<?>, List<Allowlist>> getContextAllowlists();
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,9 +42,9 @@ import java.util.stream.Stream;
|
||||||
* AllowlistAnnotationParser is an interface used to define how to
|
* AllowlistAnnotationParser is an interface used to define how to
|
||||||
* parse an annotation against any allowlist object while loading.
|
* parse an annotation against any allowlist object while loading.
|
||||||
*/
|
*/
|
||||||
public interface WhitelistAnnotationParser {
|
public interface AllowlistAnnotationParser {
|
||||||
|
|
||||||
Map<String, WhitelistAnnotationParser> BASE_ANNOTATION_PARSERS = Collections.unmodifiableMap(
|
Map<String, AllowlistAnnotationParser> BASE_ANNOTATION_PARSERS = Collections.unmodifiableMap(
|
||||||
Stream.of(
|
Stream.of(
|
||||||
new AbstractMap.SimpleEntry<>(NoImportAnnotation.NAME, NoImportAnnotationParser.INSTANCE),
|
new AbstractMap.SimpleEntry<>(NoImportAnnotation.NAME, NoImportAnnotationParser.INSTANCE),
|
||||||
new AbstractMap.SimpleEntry<>(DeprecatedAnnotation.NAME, DeprecatedAnnotationParser.INSTANCE),
|
new AbstractMap.SimpleEntry<>(DeprecatedAnnotation.NAME, DeprecatedAnnotationParser.INSTANCE),
|
|
@ -34,7 +34,7 @@ package org.opensearch.painless.spi.annotation;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class DeprecatedAnnotationParser implements WhitelistAnnotationParser {
|
public class DeprecatedAnnotationParser implements AllowlistAnnotationParser {
|
||||||
|
|
||||||
public static final DeprecatedAnnotationParser INSTANCE = new DeprecatedAnnotationParser();
|
public static final DeprecatedAnnotationParser INSTANCE = new DeprecatedAnnotationParser();
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ package org.opensearch.painless.spi.annotation;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class InjectConstantAnnotationParser implements WhitelistAnnotationParser {
|
public class InjectConstantAnnotationParser implements AllowlistAnnotationParser {
|
||||||
|
|
||||||
public static final InjectConstantAnnotationParser INSTANCE = new InjectConstantAnnotationParser();
|
public static final InjectConstantAnnotationParser INSTANCE = new InjectConstantAnnotationParser();
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ package org.opensearch.painless.spi.annotation;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class NoImportAnnotationParser implements WhitelistAnnotationParser {
|
public class NoImportAnnotationParser implements AllowlistAnnotationParser {
|
||||||
|
|
||||||
public static final NoImportAnnotationParser INSTANCE = new NoImportAnnotationParser();
|
public static final NoImportAnnotationParser INSTANCE = new NoImportAnnotationParser();
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ package org.opensearch.painless.spi.annotation;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class NonDeterministicAnnotationParser implements WhitelistAnnotationParser {
|
public class NonDeterministicAnnotationParser implements AllowlistAnnotationParser {
|
||||||
|
|
||||||
public static final NonDeterministicAnnotationParser INSTANCE = new NonDeterministicAnnotationParser();
|
public static final NonDeterministicAnnotationParser INSTANCE = new NonDeterministicAnnotationParser();
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ import org.opensearch.painless.phase.DocFieldsPhase;
|
||||||
import org.opensearch.painless.phase.PainlessSemanticAnalysisPhase;
|
import org.opensearch.painless.phase.PainlessSemanticAnalysisPhase;
|
||||||
import org.opensearch.painless.phase.PainlessSemanticHeaderPhase;
|
import org.opensearch.painless.phase.PainlessSemanticHeaderPhase;
|
||||||
import org.opensearch.painless.phase.PainlessUserTreeToIRTreePhase;
|
import org.opensearch.painless.phase.PainlessUserTreeToIRTreePhase;
|
||||||
import org.opensearch.painless.spi.Whitelist;
|
import org.opensearch.painless.spi.Allowlist;
|
||||||
import org.opensearch.painless.symbol.Decorations.IRNodeDecoration;
|
import org.opensearch.painless.symbol.Decorations.IRNodeDecoration;
|
||||||
import org.opensearch.painless.symbol.ScriptScope;
|
import org.opensearch.painless.symbol.ScriptScope;
|
||||||
import org.objectweb.asm.util.Printer;
|
import org.objectweb.asm.util.Printer;
|
||||||
|
@ -100,7 +100,7 @@ final class Compiler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Will check to see if the {@link Class} has already been loaded when
|
* Will check to see if the {@link Class} has already been loaded when
|
||||||
* the {@link PainlessLookup} was initially created. Allows for {@link Whitelist}ed
|
* the {@link PainlessLookup} was initially created. Allows for {@link Allowlist}ed
|
||||||
* classes to be loaded from other modules/plugins without a direct relationship
|
* classes to be loaded from other modules/plugins without a direct relationship
|
||||||
* to the module's/plugin's {@link ClassLoader}.
|
* to the module's/plugin's {@link ClassLoader}.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -51,8 +51,8 @@ import org.opensearch.env.NodeEnvironment;
|
||||||
import org.opensearch.painless.action.PainlessContextAction;
|
import org.opensearch.painless.action.PainlessContextAction;
|
||||||
import org.opensearch.painless.action.PainlessExecuteAction;
|
import org.opensearch.painless.action.PainlessExecuteAction;
|
||||||
import org.opensearch.painless.spi.PainlessExtension;
|
import org.opensearch.painless.spi.PainlessExtension;
|
||||||
import org.opensearch.painless.spi.Whitelist;
|
import org.opensearch.painless.spi.Allowlist;
|
||||||
import org.opensearch.painless.spi.WhitelistLoader;
|
import org.opensearch.painless.spi.AllowlistLoader;
|
||||||
import org.opensearch.plugins.ActionPlugin;
|
import org.opensearch.plugins.ActionPlugin;
|
||||||
import org.opensearch.plugins.ExtensiblePlugin;
|
import org.opensearch.plugins.ExtensiblePlugin;
|
||||||
import org.opensearch.plugins.Plugin;
|
import org.opensearch.plugins.Plugin;
|
||||||
|
@ -83,7 +83,7 @@ import java.util.function.Supplier;
|
||||||
*/
|
*/
|
||||||
public final class PainlessPlugin extends Plugin implements ScriptPlugin, ExtensiblePlugin, ActionPlugin {
|
public final class PainlessPlugin extends Plugin implements ScriptPlugin, ExtensiblePlugin, ActionPlugin {
|
||||||
|
|
||||||
private static final Map<ScriptContext<?>, List<Whitelist>> allowlists;
|
private static final Map<ScriptContext<?>, List<Allowlist>> allowlists;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Contexts from Core that need custom allowlists can add them to the map below.
|
* Contexts from Core that need custom allowlists can add them to the map below.
|
||||||
|
@ -91,21 +91,21 @@ public final class PainlessPlugin extends Plugin implements ScriptPlugin, Extens
|
||||||
* under Painless' resources
|
* under Painless' resources
|
||||||
*/
|
*/
|
||||||
static {
|
static {
|
||||||
Map<ScriptContext<?>, List<Whitelist>> map = new HashMap<>();
|
Map<ScriptContext<?>, List<Allowlist>> map = new HashMap<>();
|
||||||
|
|
||||||
// Moving Function Pipeline Agg
|
// Moving Function Pipeline Agg
|
||||||
List<Whitelist> movFn = new ArrayList<>(Whitelist.BASE_WHITELISTS);
|
List<Allowlist> movFn = new ArrayList<>(Allowlist.BASE_ALLOWLISTS);
|
||||||
movFn.add(WhitelistLoader.loadFromResourceFiles(Whitelist.class, "org.opensearch.aggs.movfn.txt"));
|
movFn.add(AllowlistLoader.loadFromResourceFiles(Allowlist.class, "org.opensearch.aggs.movfn.txt"));
|
||||||
map.put(MovingFunctionScript.CONTEXT, movFn);
|
map.put(MovingFunctionScript.CONTEXT, movFn);
|
||||||
|
|
||||||
// Functions used for scoring docs
|
// Functions used for scoring docs
|
||||||
List<Whitelist> scoreFn = new ArrayList<>(Whitelist.BASE_WHITELISTS);
|
List<Allowlist> scoreFn = new ArrayList<>(Allowlist.BASE_ALLOWLISTS);
|
||||||
scoreFn.add(WhitelistLoader.loadFromResourceFiles(Whitelist.class, "org.opensearch.score.txt"));
|
scoreFn.add(AllowlistLoader.loadFromResourceFiles(Allowlist.class, "org.opensearch.score.txt"));
|
||||||
map.put(ScoreScript.CONTEXT, scoreFn);
|
map.put(ScoreScript.CONTEXT, scoreFn);
|
||||||
|
|
||||||
// Functions available to ingest pipelines
|
// Functions available to ingest pipelines
|
||||||
List<Whitelist> ingest = new ArrayList<>(Whitelist.BASE_WHITELISTS);
|
List<Allowlist> ingest = new ArrayList<>(Allowlist.BASE_ALLOWLISTS);
|
||||||
ingest.add(WhitelistLoader.loadFromResourceFiles(Whitelist.class, "org.opensearch.ingest.txt"));
|
ingest.add(AllowlistLoader.loadFromResourceFiles(Allowlist.class, "org.opensearch.ingest.txt"));
|
||||||
map.put(IngestScript.CONTEXT, ingest);
|
map.put(IngestScript.CONTEXT, ingest);
|
||||||
|
|
||||||
allowlists = map;
|
allowlists = map;
|
||||||
|
@ -115,12 +115,12 @@ public final class PainlessPlugin extends Plugin implements ScriptPlugin, Extens
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ScriptEngine getScriptEngine(Settings settings, Collection<ScriptContext<?>> contexts) {
|
public ScriptEngine getScriptEngine(Settings settings, Collection<ScriptContext<?>> contexts) {
|
||||||
Map<ScriptContext<?>, List<Whitelist>> contextsWithAllowlists = new HashMap<>();
|
Map<ScriptContext<?>, List<Allowlist>> contextsWithAllowlists = new HashMap<>();
|
||||||
for (ScriptContext<?> context : contexts) {
|
for (ScriptContext<?> context : contexts) {
|
||||||
// we might have a context that only uses the base allowlists, so would not have been filled in by reloadSPI
|
// we might have a context that only uses the base allowlists, so would not have been filled in by reloadSPI
|
||||||
List<Whitelist> contextAllowlists = allowlists.get(context);
|
List<Allowlist> contextAllowlists = allowlists.get(context);
|
||||||
if (contextAllowlists == null) {
|
if (contextAllowlists == null) {
|
||||||
contextAllowlists = new ArrayList<>(Whitelist.BASE_WHITELISTS);
|
contextAllowlists = new ArrayList<>(Allowlist.BASE_ALLOWLISTS);
|
||||||
}
|
}
|
||||||
contextsWithAllowlists.put(context, contextAllowlists);
|
contextsWithAllowlists.put(context, contextAllowlists);
|
||||||
}
|
}
|
||||||
|
@ -156,9 +156,9 @@ public final class PainlessPlugin extends Plugin implements ScriptPlugin, Extens
|
||||||
public void loadExtensions(ExtensionLoader loader) {
|
public void loadExtensions(ExtensionLoader loader) {
|
||||||
loader.loadExtensions(PainlessExtension.class)
|
loader.loadExtensions(PainlessExtension.class)
|
||||||
.stream()
|
.stream()
|
||||||
.flatMap(extension -> extension.getContextWhitelists().entrySet().stream())
|
.flatMap(extension -> extension.getContextAllowlists().entrySet().stream())
|
||||||
.forEach(entry -> {
|
.forEach(entry -> {
|
||||||
List<Whitelist> existing = allowlists.computeIfAbsent(entry.getKey(), c -> new ArrayList<>(Whitelist.BASE_WHITELISTS));
|
List<Allowlist> existing = allowlists.computeIfAbsent(entry.getKey(), c -> new ArrayList<>(Allowlist.BASE_ALLOWLISTS));
|
||||||
existing.addAll(entry.getValue());
|
existing.addAll(entry.getValue());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ import org.opensearch.common.settings.Settings;
|
||||||
import org.opensearch.painless.Compiler.Loader;
|
import org.opensearch.painless.Compiler.Loader;
|
||||||
import org.opensearch.painless.lookup.PainlessLookup;
|
import org.opensearch.painless.lookup.PainlessLookup;
|
||||||
import org.opensearch.painless.lookup.PainlessLookupBuilder;
|
import org.opensearch.painless.lookup.PainlessLookupBuilder;
|
||||||
import org.opensearch.painless.spi.Whitelist;
|
import org.opensearch.painless.spi.Allowlist;
|
||||||
import org.opensearch.painless.symbol.ScriptScope;
|
import org.opensearch.painless.symbol.ScriptScope;
|
||||||
import org.opensearch.script.ScriptContext;
|
import org.opensearch.script.ScriptContext;
|
||||||
import org.opensearch.script.ScriptEngine;
|
import org.opensearch.script.ScriptEngine;
|
||||||
|
@ -101,16 +101,16 @@ public final class PainlessScriptEngine implements ScriptEngine {
|
||||||
* Constructor.
|
* Constructor.
|
||||||
* @param settings The settings to initialize the engine with.
|
* @param settings The settings to initialize the engine with.
|
||||||
*/
|
*/
|
||||||
public PainlessScriptEngine(Settings settings, Map<ScriptContext<?>, List<Whitelist>> contexts) {
|
public PainlessScriptEngine(Settings settings, Map<ScriptContext<?>, List<Allowlist>> contexts) {
|
||||||
defaultCompilerSettings.setRegexesEnabled(CompilerSettings.REGEX_ENABLED.get(settings));
|
defaultCompilerSettings.setRegexesEnabled(CompilerSettings.REGEX_ENABLED.get(settings));
|
||||||
defaultCompilerSettings.setRegexLimitFactor(CompilerSettings.REGEX_LIMIT_FACTOR.get(settings));
|
defaultCompilerSettings.setRegexLimitFactor(CompilerSettings.REGEX_LIMIT_FACTOR.get(settings));
|
||||||
|
|
||||||
Map<ScriptContext<?>, Compiler> contextsToCompilers = new HashMap<>();
|
Map<ScriptContext<?>, Compiler> contextsToCompilers = new HashMap<>();
|
||||||
Map<ScriptContext<?>, PainlessLookup> contextsToLookups = new HashMap<>();
|
Map<ScriptContext<?>, PainlessLookup> contextsToLookups = new HashMap<>();
|
||||||
|
|
||||||
for (Map.Entry<ScriptContext<?>, List<Whitelist>> entry : contexts.entrySet()) {
|
for (Map.Entry<ScriptContext<?>, List<Allowlist>> entry : contexts.entrySet()) {
|
||||||
ScriptContext<?> context = entry.getKey();
|
ScriptContext<?> context = entry.getKey();
|
||||||
PainlessLookup lookup = PainlessLookupBuilder.buildFromWhitelists(entry.getValue());
|
PainlessLookup lookup = PainlessLookupBuilder.buildFromAllowlists(entry.getValue());
|
||||||
contextsToCompilers.put(
|
contextsToCompilers.put(
|
||||||
context,
|
context,
|
||||||
new Compiler(context.instanceClazz, context.factoryClazz, context.statefulFactoryClazz, lookup)
|
new Compiler(context.instanceClazz, context.factoryClazz, context.statefulFactoryClazz, lookup)
|
||||||
|
|
|
@ -103,7 +103,7 @@ public class ScriptClassInfo {
|
||||||
+ "type ["
|
+ "type ["
|
||||||
+ componentType.getName()
|
+ componentType.getName()
|
||||||
+ "]. Painless can only support getters with return types that are "
|
+ "]. Painless can only support getters with return types that are "
|
||||||
+ "whitelisted."
|
+ "allowlisted."
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -156,11 +156,11 @@ public class ScriptClassInfo {
|
||||||
executeMethodReturnType = definitionTypeForClass(
|
executeMethodReturnType = definitionTypeForClass(
|
||||||
painlessLookup,
|
painlessLookup,
|
||||||
executeMethod.getReturnType(),
|
executeMethod.getReturnType(),
|
||||||
componentType -> "Painless can only implement execute methods returning a whitelisted type but ["
|
componentType -> "Painless can only implement execute methods returning a allowlisted type but ["
|
||||||
+ baseClass.getName()
|
+ baseClass.getName()
|
||||||
+ "#execute] returns ["
|
+ "#execute] returns ["
|
||||||
+ componentType.getName()
|
+ componentType.getName()
|
||||||
+ "] which isn't whitelisted."
|
+ "] which isn't allowlisted."
|
||||||
);
|
);
|
||||||
|
|
||||||
// Look up the argument
|
// Look up the argument
|
||||||
|
@ -261,7 +261,7 @@ public class ScriptClassInfo {
|
||||||
+ argName
|
+ argName
|
||||||
+ "] is of unknown type ["
|
+ "] is of unknown type ["
|
||||||
+ componentType.getName()
|
+ componentType.getName()
|
||||||
+ ". Painless interfaces can only accept arguments that are of whitelisted types."
|
+ ". Painless interfaces can only accept arguments that are of allowlisted types."
|
||||||
);
|
);
|
||||||
return new MethodArgument(defClass, argName);
|
return new MethodArgument(defClass, argName);
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,13 +36,13 @@ import org.opensearch.bootstrap.BootstrapInfo;
|
||||||
import org.opensearch.painless.Def;
|
import org.opensearch.painless.Def;
|
||||||
import org.opensearch.painless.MethodWriter;
|
import org.opensearch.painless.MethodWriter;
|
||||||
import org.opensearch.painless.WriterConstants;
|
import org.opensearch.painless.WriterConstants;
|
||||||
import org.opensearch.painless.spi.Whitelist;
|
import org.opensearch.painless.spi.Allowlist;
|
||||||
import org.opensearch.painless.spi.WhitelistClass;
|
import org.opensearch.painless.spi.AllowlistClass;
|
||||||
import org.opensearch.painless.spi.WhitelistClassBinding;
|
import org.opensearch.painless.spi.AllowlistClassBinding;
|
||||||
import org.opensearch.painless.spi.WhitelistConstructor;
|
import org.opensearch.painless.spi.AllowlistConstructor;
|
||||||
import org.opensearch.painless.spi.WhitelistField;
|
import org.opensearch.painless.spi.AllowlistField;
|
||||||
import org.opensearch.painless.spi.WhitelistInstanceBinding;
|
import org.opensearch.painless.spi.AllowlistInstanceBinding;
|
||||||
import org.opensearch.painless.spi.WhitelistMethod;
|
import org.opensearch.painless.spi.AllowlistMethod;
|
||||||
import org.opensearch.painless.spi.annotation.InjectConstantAnnotation;
|
import org.opensearch.painless.spi.annotation.InjectConstantAnnotation;
|
||||||
import org.opensearch.painless.spi.annotation.NoImportAnnotation;
|
import org.opensearch.painless.spi.annotation.NoImportAnnotation;
|
||||||
import org.objectweb.asm.ClassWriter;
|
import org.objectweb.asm.ClassWriter;
|
||||||
|
@ -126,13 +126,13 @@ public final class PainlessLookupBuilder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PainlessLookup buildFromWhitelists(List<Whitelist> allowlists) {
|
public static PainlessLookup buildFromAllowlists(List<Allowlist> allowlists) {
|
||||||
PainlessLookupBuilder painlessLookupBuilder = new PainlessLookupBuilder();
|
PainlessLookupBuilder painlessLookupBuilder = new PainlessLookupBuilder();
|
||||||
String origin = "internal error";
|
String origin = "internal error";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (Whitelist allowlist : allowlists) {
|
for (Allowlist allowlist : allowlists) {
|
||||||
for (WhitelistClass allowlistClass : allowlist.whitelistClasses) {
|
for (AllowlistClass allowlistClass : allowlist.allowlistClasses) {
|
||||||
origin = allowlistClass.origin;
|
origin = allowlistClass.origin;
|
||||||
painlessLookupBuilder.addPainlessClass(
|
painlessLookupBuilder.addPainlessClass(
|
||||||
allowlist.classLoader,
|
allowlist.classLoader,
|
||||||
|
@ -142,11 +142,11 @@ public final class PainlessLookupBuilder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Whitelist allowlist : allowlists) {
|
for (Allowlist allowlist : allowlists) {
|
||||||
for (WhitelistClass allowlistClass : allowlist.whitelistClasses) {
|
for (AllowlistClass allowlistClass : allowlist.allowlistClasses) {
|
||||||
String targetCanonicalClassName = allowlistClass.javaClassName.replace('$', '.');
|
String targetCanonicalClassName = allowlistClass.javaClassName.replace('$', '.');
|
||||||
|
|
||||||
for (WhitelistConstructor allowlistConstructor : allowlistClass.whitelistConstructors) {
|
for (AllowlistConstructor allowlistConstructor : allowlistClass.allowlistConstructors) {
|
||||||
origin = allowlistConstructor.origin;
|
origin = allowlistConstructor.origin;
|
||||||
painlessLookupBuilder.addPainlessConstructor(
|
painlessLookupBuilder.addPainlessConstructor(
|
||||||
targetCanonicalClassName,
|
targetCanonicalClassName,
|
||||||
|
@ -155,7 +155,7 @@ public final class PainlessLookupBuilder {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (WhitelistMethod allowlistMethod : allowlistClass.whitelistMethods) {
|
for (AllowlistMethod allowlistMethod : allowlistClass.allowlistMethods) {
|
||||||
origin = allowlistMethod.origin;
|
origin = allowlistMethod.origin;
|
||||||
painlessLookupBuilder.addPainlessMethod(
|
painlessLookupBuilder.addPainlessMethod(
|
||||||
allowlist.classLoader,
|
allowlist.classLoader,
|
||||||
|
@ -168,7 +168,7 @@ public final class PainlessLookupBuilder {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (WhitelistField allowlistField : allowlistClass.whitelistFields) {
|
for (AllowlistField allowlistField : allowlistClass.allowlistFields) {
|
||||||
origin = allowlistField.origin;
|
origin = allowlistField.origin;
|
||||||
painlessLookupBuilder.addPainlessField(
|
painlessLookupBuilder.addPainlessField(
|
||||||
targetCanonicalClassName,
|
targetCanonicalClassName,
|
||||||
|
@ -178,7 +178,7 @@ public final class PainlessLookupBuilder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (WhitelistMethod allowlistStatic : allowlist.whitelistImportedMethods) {
|
for (AllowlistMethod allowlistStatic : allowlist.allowlistImportedMethods) {
|
||||||
origin = allowlistStatic.origin;
|
origin = allowlistStatic.origin;
|
||||||
painlessLookupBuilder.addImportedPainlessMethod(
|
painlessLookupBuilder.addImportedPainlessMethod(
|
||||||
allowlist.classLoader,
|
allowlist.classLoader,
|
||||||
|
@ -190,7 +190,7 @@ public final class PainlessLookupBuilder {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (WhitelistClassBinding allowlistClassBinding : allowlist.whitelistClassBindings) {
|
for (AllowlistClassBinding allowlistClassBinding : allowlist.allowlistClassBindings) {
|
||||||
origin = allowlistClassBinding.origin;
|
origin = allowlistClassBinding.origin;
|
||||||
painlessLookupBuilder.addPainlessClassBinding(
|
painlessLookupBuilder.addPainlessClassBinding(
|
||||||
allowlist.classLoader,
|
allowlist.classLoader,
|
||||||
|
@ -202,7 +202,7 @@ public final class PainlessLookupBuilder {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (WhitelistInstanceBinding allowlistInstanceBinding : allowlist.whitelistInstanceBindings) {
|
for (AllowlistInstanceBinding allowlistInstanceBinding : allowlist.allowlistInstanceBindings) {
|
||||||
origin = allowlistInstanceBinding.origin;
|
origin = allowlistInstanceBinding.origin;
|
||||||
painlessLookupBuilder.addPainlessInstanceBinding(
|
painlessLookupBuilder.addPainlessInstanceBinding(
|
||||||
allowlistInstanceBinding.targetInstance,
|
allowlistInstanceBinding.targetInstance,
|
||||||
|
|
|
@ -32,24 +32,24 @@
|
||||||
|
|
||||||
package org.opensearch.painless;
|
package org.opensearch.painless;
|
||||||
|
|
||||||
import org.opensearch.painless.spi.Whitelist;
|
import org.opensearch.painless.spi.Allowlist;
|
||||||
import org.opensearch.painless.spi.WhitelistClass;
|
import org.opensearch.painless.spi.AllowlistClass;
|
||||||
import org.opensearch.painless.spi.WhitelistLoader;
|
import org.opensearch.painless.spi.AllowlistLoader;
|
||||||
import org.opensearch.painless.spi.WhitelistMethod;
|
import org.opensearch.painless.spi.AllowlistMethod;
|
||||||
import org.opensearch.painless.spi.annotation.DeprecatedAnnotation;
|
import org.opensearch.painless.spi.annotation.DeprecatedAnnotation;
|
||||||
import org.opensearch.painless.spi.annotation.NoImportAnnotation;
|
import org.opensearch.painless.spi.annotation.NoImportAnnotation;
|
||||||
import org.opensearch.painless.spi.annotation.WhitelistAnnotationParser;
|
import org.opensearch.painless.spi.annotation.AllowlistAnnotationParser;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class WhitelistLoaderTests extends ScriptTestCase {
|
public class AllowlistLoaderTests extends ScriptTestCase {
|
||||||
public void testUnknownAnnotations() {
|
public void testUnknownAnnotations() {
|
||||||
Map<String, WhitelistAnnotationParser> parsers = new HashMap<>(WhitelistAnnotationParser.BASE_ANNOTATION_PARSERS);
|
Map<String, AllowlistAnnotationParser> parsers = new HashMap<>(AllowlistAnnotationParser.BASE_ANNOTATION_PARSERS);
|
||||||
|
|
||||||
RuntimeException expected = expectThrows(
|
RuntimeException expected = expectThrows(
|
||||||
RuntimeException.class,
|
RuntimeException.class,
|
||||||
() -> { WhitelistLoader.loadFromResourceFiles(Whitelist.class, parsers, "org.opensearch.painless.annotation.unknown"); }
|
() -> { AllowlistLoader.loadFromResourceFiles(Allowlist.class, parsers, "org.opensearch.painless.annotation.unknown"); }
|
||||||
);
|
);
|
||||||
assertEquals("invalid annotation: parser not found for [unknownAnnotation] [@unknownAnnotation]", expected.getCause().getMessage());
|
assertEquals("invalid annotation: parser not found for [unknownAnnotation] [@unknownAnnotation]", expected.getCause().getMessage());
|
||||||
assertEquals(IllegalArgumentException.class, expected.getCause().getClass());
|
assertEquals(IllegalArgumentException.class, expected.getCause().getClass());
|
||||||
|
@ -57,7 +57,7 @@ public class WhitelistLoaderTests extends ScriptTestCase {
|
||||||
expected = expectThrows(
|
expected = expectThrows(
|
||||||
RuntimeException.class,
|
RuntimeException.class,
|
||||||
() -> {
|
() -> {
|
||||||
WhitelistLoader.loadFromResourceFiles(Whitelist.class, parsers, "org.opensearch.painless.annotation.unknown_with_options");
|
AllowlistLoader.loadFromResourceFiles(Allowlist.class, parsers, "org.opensearch.painless.annotation.unknown_with_options");
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
assertEquals(
|
assertEquals(
|
||||||
|
@ -68,21 +68,21 @@ public class WhitelistLoaderTests extends ScriptTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAnnotations() {
|
public void testAnnotations() {
|
||||||
Map<String, WhitelistAnnotationParser> parsers = new HashMap<>(WhitelistAnnotationParser.BASE_ANNOTATION_PARSERS);
|
Map<String, AllowlistAnnotationParser> parsers = new HashMap<>(AllowlistAnnotationParser.BASE_ANNOTATION_PARSERS);
|
||||||
parsers.put(AnnotationTestObject.TestAnnotation.NAME, AnnotationTestObject.TestAnnotationParser.INSTANCE);
|
parsers.put(AnnotationTestObject.TestAnnotation.NAME, AnnotationTestObject.TestAnnotationParser.INSTANCE);
|
||||||
Whitelist allowlist = WhitelistLoader.loadFromResourceFiles(Whitelist.class, parsers, "org.opensearch.painless.annotation");
|
Allowlist allowlist = AllowlistLoader.loadFromResourceFiles(Allowlist.class, parsers, "org.opensearch.painless.annotation");
|
||||||
|
|
||||||
assertEquals(1, allowlist.whitelistClasses.size());
|
assertEquals(1, allowlist.allowlistClasses.size());
|
||||||
|
|
||||||
WhitelistClass allowlistClass = allowlist.whitelistClasses.get(0);
|
AllowlistClass allowlistClass = allowlist.allowlistClasses.get(0);
|
||||||
|
|
||||||
assertNotNull(allowlistClass.painlessAnnotations.get(NoImportAnnotation.class));
|
assertNotNull(allowlistClass.painlessAnnotations.get(NoImportAnnotation.class));
|
||||||
assertEquals(1, allowlistClass.painlessAnnotations.size());
|
assertEquals(1, allowlistClass.painlessAnnotations.size());
|
||||||
assertEquals(3, allowlistClass.whitelistMethods.size());
|
assertEquals(3, allowlistClass.allowlistMethods.size());
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
for (WhitelistMethod allowlistMethod : allowlistClass.whitelistMethods) {
|
for (AllowlistMethod allowlistMethod : allowlistClass.allowlistMethods) {
|
||||||
if ("deprecatedMethod".equals(allowlistMethod.methodName)) {
|
if ("deprecatedMethod".equals(allowlistMethod.methodName)) {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"use another method",
|
"use another method",
|
|
@ -32,7 +32,7 @@
|
||||||
|
|
||||||
package org.opensearch.painless;
|
package org.opensearch.painless;
|
||||||
|
|
||||||
import org.opensearch.painless.spi.annotation.WhitelistAnnotationParser;
|
import org.opensearch.painless.spi.annotation.AllowlistAnnotationParser;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ public class AnnotationTestObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class TestAnnotationParser implements WhitelistAnnotationParser {
|
public static class TestAnnotationParser implements AllowlistAnnotationParser {
|
||||||
|
|
||||||
public static final TestAnnotationParser INSTANCE = new TestAnnotationParser();
|
public static final TestAnnotationParser INSTANCE = new TestAnnotationParser();
|
||||||
|
|
||||||
|
|
|
@ -35,8 +35,8 @@ package org.opensearch.painless;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.opensearch.common.settings.Settings;
|
import org.opensearch.common.settings.Settings;
|
||||||
import org.opensearch.painless.spi.Whitelist;
|
import org.opensearch.painless.spi.Allowlist;
|
||||||
import org.opensearch.painless.spi.WhitelistLoader;
|
import org.opensearch.painless.spi.AllowlistLoader;
|
||||||
import org.opensearch.script.ScriptContext;
|
import org.opensearch.script.ScriptContext;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -52,9 +52,9 @@ public class AugmentationTests extends ScriptTestCase {
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void beforeClass() {
|
public static void beforeClass() {
|
||||||
Map<ScriptContext<?>, List<Whitelist>> contexts = newDefaultContexts();
|
Map<ScriptContext<?>, List<Allowlist>> contexts = newDefaultContexts();
|
||||||
List<Whitelist> digestAllowlist = new ArrayList<>(Whitelist.BASE_WHITELISTS);
|
List<Allowlist> digestAllowlist = new ArrayList<>(Allowlist.BASE_ALLOWLISTS);
|
||||||
digestAllowlist.add(WhitelistLoader.loadFromResourceFiles(Whitelist.class, "org.opensearch.ingest.txt"));
|
digestAllowlist.add(AllowlistLoader.loadFromResourceFiles(Allowlist.class, "org.opensearch.ingest.txt"));
|
||||||
contexts.put(DigestTestScript.CONTEXT, digestAllowlist);
|
contexts.put(DigestTestScript.CONTEXT, digestAllowlist);
|
||||||
SCRIPT_ENGINE = new PainlessScriptEngine(Settings.EMPTY, contexts);
|
SCRIPT_ENGINE = new PainlessScriptEngine(Settings.EMPTY, contexts);
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ package org.opensearch.painless;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.opensearch.common.settings.Settings;
|
import org.opensearch.common.settings.Settings;
|
||||||
import org.opensearch.painless.spi.Whitelist;
|
import org.opensearch.painless.spi.Allowlist;
|
||||||
import org.opensearch.script.ScriptContext;
|
import org.opensearch.script.ScriptContext;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -56,28 +56,28 @@ public class BaseClassTests extends ScriptTestCase {
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void beforeClass() {
|
public static void beforeClass() {
|
||||||
Map<ScriptContext<?>, List<Whitelist>> contexts = new HashMap<>();
|
Map<ScriptContext<?>, List<Allowlist>> contexts = new HashMap<>();
|
||||||
contexts.put(Gets.CONTEXT, Whitelist.BASE_WHITELISTS);
|
contexts.put(Gets.CONTEXT, Allowlist.BASE_ALLOWLISTS);
|
||||||
contexts.put(NoArgs.CONTEXT, Whitelist.BASE_WHITELISTS);
|
contexts.put(NoArgs.CONTEXT, Allowlist.BASE_ALLOWLISTS);
|
||||||
contexts.put(OneArg.CONTEXT, Whitelist.BASE_WHITELISTS);
|
contexts.put(OneArg.CONTEXT, Allowlist.BASE_ALLOWLISTS);
|
||||||
contexts.put(ArrayArg.CONTEXT, Whitelist.BASE_WHITELISTS);
|
contexts.put(ArrayArg.CONTEXT, Allowlist.BASE_ALLOWLISTS);
|
||||||
contexts.put(PrimitiveArrayArg.CONTEXT, Whitelist.BASE_WHITELISTS);
|
contexts.put(PrimitiveArrayArg.CONTEXT, Allowlist.BASE_ALLOWLISTS);
|
||||||
contexts.put(DefArrayArg.CONTEXT, Whitelist.BASE_WHITELISTS);
|
contexts.put(DefArrayArg.CONTEXT, Allowlist.BASE_ALLOWLISTS);
|
||||||
contexts.put(ManyArgs.CONTEXT, Whitelist.BASE_WHITELISTS);
|
contexts.put(ManyArgs.CONTEXT, Allowlist.BASE_ALLOWLISTS);
|
||||||
contexts.put(VarArgs.CONTEXT, Whitelist.BASE_WHITELISTS);
|
contexts.put(VarArgs.CONTEXT, Allowlist.BASE_ALLOWLISTS);
|
||||||
contexts.put(DefaultMethods.CONTEXT, Whitelist.BASE_WHITELISTS);
|
contexts.put(DefaultMethods.CONTEXT, Allowlist.BASE_ALLOWLISTS);
|
||||||
contexts.put(ReturnsVoid.CONTEXT, Whitelist.BASE_WHITELISTS);
|
contexts.put(ReturnsVoid.CONTEXT, Allowlist.BASE_ALLOWLISTS);
|
||||||
contexts.put(ReturnsPrimitiveBoolean.CONTEXT, Whitelist.BASE_WHITELISTS);
|
contexts.put(ReturnsPrimitiveBoolean.CONTEXT, Allowlist.BASE_ALLOWLISTS);
|
||||||
contexts.put(ReturnsPrimitiveInt.CONTEXT, Whitelist.BASE_WHITELISTS);
|
contexts.put(ReturnsPrimitiveInt.CONTEXT, Allowlist.BASE_ALLOWLISTS);
|
||||||
contexts.put(ReturnsPrimitiveFloat.CONTEXT, Whitelist.BASE_WHITELISTS);
|
contexts.put(ReturnsPrimitiveFloat.CONTEXT, Allowlist.BASE_ALLOWLISTS);
|
||||||
contexts.put(ReturnsPrimitiveDouble.CONTEXT, Whitelist.BASE_WHITELISTS);
|
contexts.put(ReturnsPrimitiveDouble.CONTEXT, Allowlist.BASE_ALLOWLISTS);
|
||||||
contexts.put(NoArgsConstant.CONTEXT, Whitelist.BASE_WHITELISTS);
|
contexts.put(NoArgsConstant.CONTEXT, Allowlist.BASE_ALLOWLISTS);
|
||||||
contexts.put(WrongArgsConstant.CONTEXT, Whitelist.BASE_WHITELISTS);
|
contexts.put(WrongArgsConstant.CONTEXT, Allowlist.BASE_ALLOWLISTS);
|
||||||
contexts.put(WrongLengthOfArgConstant.CONTEXT, Whitelist.BASE_WHITELISTS);
|
contexts.put(WrongLengthOfArgConstant.CONTEXT, Allowlist.BASE_ALLOWLISTS);
|
||||||
contexts.put(UnknownArgType.CONTEXT, Whitelist.BASE_WHITELISTS);
|
contexts.put(UnknownArgType.CONTEXT, Allowlist.BASE_ALLOWLISTS);
|
||||||
contexts.put(UnknownReturnType.CONTEXT, Whitelist.BASE_WHITELISTS);
|
contexts.put(UnknownReturnType.CONTEXT, Allowlist.BASE_ALLOWLISTS);
|
||||||
contexts.put(UnknownArgTypeInArray.CONTEXT, Whitelist.BASE_WHITELISTS);
|
contexts.put(UnknownArgTypeInArray.CONTEXT, Allowlist.BASE_ALLOWLISTS);
|
||||||
contexts.put(TwoExecuteMethods.CONTEXT, Whitelist.BASE_WHITELISTS);
|
contexts.put(TwoExecuteMethods.CONTEXT, Allowlist.BASE_ALLOWLISTS);
|
||||||
SCRIPT_ENGINE = new PainlessScriptEngine(Settings.EMPTY, contexts);
|
SCRIPT_ENGINE = new PainlessScriptEngine(Settings.EMPTY, contexts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -931,7 +931,7 @@ public class BaseClassTests extends ScriptTestCase {
|
||||||
"[foo] is of unknown type ["
|
"[foo] is of unknown type ["
|
||||||
+ UnknownArgType.class.getName()
|
+ UnknownArgType.class.getName()
|
||||||
+ ". Painless interfaces can only accept arguments "
|
+ ". Painless interfaces can only accept arguments "
|
||||||
+ "that are of whitelisted types.",
|
+ "that are of allowlisted types.",
|
||||||
e.getMessage()
|
e.getMessage()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -955,11 +955,11 @@ public class BaseClassTests extends ScriptTestCase {
|
||||||
() -> getEngine().compile("testUnknownReturnType0", "1", UnknownReturnType.CONTEXT, emptyMap())
|
() -> getEngine().compile("testUnknownReturnType0", "1", UnknownReturnType.CONTEXT, emptyMap())
|
||||||
);
|
);
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"Painless can only implement execute methods returning a whitelisted type but ["
|
"Painless can only implement execute methods returning a allowlisted type but ["
|
||||||
+ UnknownReturnType.class.getName()
|
+ UnknownReturnType.class.getName()
|
||||||
+ "#execute] returns ["
|
+ "#execute] returns ["
|
||||||
+ UnknownReturnType.class.getName()
|
+ UnknownReturnType.class.getName()
|
||||||
+ "] which isn't whitelisted.",
|
+ "] which isn't allowlisted.",
|
||||||
e.getMessage()
|
e.getMessage()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -986,7 +986,7 @@ public class BaseClassTests extends ScriptTestCase {
|
||||||
"[foo] is of unknown type ["
|
"[foo] is of unknown type ["
|
||||||
+ UnknownArgTypeInArray.class.getName()
|
+ UnknownArgTypeInArray.class.getName()
|
||||||
+ ". Painless interfaces can only accept "
|
+ ". Painless interfaces can only accept "
|
||||||
+ "arguments that are of whitelisted types.",
|
+ "arguments that are of allowlisted types.",
|
||||||
e.getMessage()
|
e.getMessage()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ package org.opensearch.painless;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.opensearch.common.settings.Settings;
|
import org.opensearch.common.settings.Settings;
|
||||||
import org.opensearch.painless.spi.Whitelist;
|
import org.opensearch.painless.spi.Allowlist;
|
||||||
import org.opensearch.script.ScriptContext;
|
import org.opensearch.script.ScriptContext;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -51,8 +51,8 @@ public class BasicStatementTests extends ScriptTestCase {
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void beforeClass() {
|
public static void beforeClass() {
|
||||||
Map<ScriptContext<?>, List<Whitelist>> contexts = newDefaultContexts();
|
Map<ScriptContext<?>, List<Allowlist>> contexts = newDefaultContexts();
|
||||||
contexts.put(OneArg.CONTEXT, Whitelist.BASE_WHITELISTS);
|
contexts.put(OneArg.CONTEXT, Allowlist.BASE_ALLOWLISTS);
|
||||||
SCRIPT_ENGINE = new PainlessScriptEngine(Settings.EMPTY, contexts);
|
SCRIPT_ENGINE = new PainlessScriptEngine(Settings.EMPTY, contexts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,9 +35,9 @@ package org.opensearch.painless;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.opensearch.common.settings.Settings;
|
import org.opensearch.common.settings.Settings;
|
||||||
import org.opensearch.painless.spi.Whitelist;
|
import org.opensearch.painless.spi.Allowlist;
|
||||||
import org.opensearch.painless.spi.WhitelistInstanceBinding;
|
import org.opensearch.painless.spi.AllowlistInstanceBinding;
|
||||||
import org.opensearch.painless.spi.WhitelistLoader;
|
import org.opensearch.painless.spi.AllowlistLoader;
|
||||||
import org.opensearch.script.ScriptContext;
|
import org.opensearch.script.ScriptContext;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -50,12 +50,12 @@ public class BindingsTests extends ScriptTestCase {
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void beforeClass() {
|
public static void beforeClass() {
|
||||||
Map<ScriptContext<?>, List<Whitelist>> contexts = newDefaultContexts();
|
Map<ScriptContext<?>, List<Allowlist>> contexts = newDefaultContexts();
|
||||||
List<Whitelist> allowlists = new ArrayList<>(Whitelist.BASE_WHITELISTS);
|
List<Allowlist> allowlists = new ArrayList<>(Allowlist.BASE_ALLOWLISTS);
|
||||||
allowlists.add(WhitelistLoader.loadFromResourceFiles(Whitelist.class, "org.opensearch.painless.test"));
|
allowlists.add(AllowlistLoader.loadFromResourceFiles(Allowlist.class, "org.opensearch.painless.test"));
|
||||||
|
|
||||||
InstanceBindingTestClass instanceBindingTestClass = new InstanceBindingTestClass(1);
|
InstanceBindingTestClass instanceBindingTestClass = new InstanceBindingTestClass(1);
|
||||||
WhitelistInstanceBinding getter = new WhitelistInstanceBinding(
|
AllowlistInstanceBinding getter = new AllowlistInstanceBinding(
|
||||||
"test",
|
"test",
|
||||||
instanceBindingTestClass,
|
instanceBindingTestClass,
|
||||||
"setInstanceBindingValue",
|
"setInstanceBindingValue",
|
||||||
|
@ -63,7 +63,7 @@ public class BindingsTests extends ScriptTestCase {
|
||||||
Collections.singletonList("int"),
|
Collections.singletonList("int"),
|
||||||
Collections.emptyList()
|
Collections.emptyList()
|
||||||
);
|
);
|
||||||
WhitelistInstanceBinding setter = new WhitelistInstanceBinding(
|
AllowlistInstanceBinding setter = new AllowlistInstanceBinding(
|
||||||
"test",
|
"test",
|
||||||
instanceBindingTestClass,
|
instanceBindingTestClass,
|
||||||
"getInstanceBindingValue",
|
"getInstanceBindingValue",
|
||||||
|
@ -71,10 +71,10 @@ public class BindingsTests extends ScriptTestCase {
|
||||||
Collections.emptyList(),
|
Collections.emptyList(),
|
||||||
Collections.emptyList()
|
Collections.emptyList()
|
||||||
);
|
);
|
||||||
List<WhitelistInstanceBinding> instanceBindingsList = new ArrayList<>();
|
List<AllowlistInstanceBinding> instanceBindingsList = new ArrayList<>();
|
||||||
instanceBindingsList.add(getter);
|
instanceBindingsList.add(getter);
|
||||||
instanceBindingsList.add(setter);
|
instanceBindingsList.add(setter);
|
||||||
Whitelist instanceBindingsAllowlist = new Whitelist(
|
Allowlist instanceBindingsAllowlist = new Allowlist(
|
||||||
instanceBindingTestClass.getClass().getClassLoader(),
|
instanceBindingTestClass.getClass().getClassLoader(),
|
||||||
Collections.emptyList(),
|
Collections.emptyList(),
|
||||||
Collections.emptyList(),
|
Collections.emptyList(),
|
||||||
|
|
|
@ -37,7 +37,7 @@ import org.opensearch.common.io.stream.BytesStreamOutput;
|
||||||
import org.opensearch.common.io.stream.StreamInput;
|
import org.opensearch.common.io.stream.StreamInput;
|
||||||
import org.opensearch.painless.lookup.PainlessLookup;
|
import org.opensearch.painless.lookup.PainlessLookup;
|
||||||
import org.opensearch.painless.lookup.PainlessLookupBuilder;
|
import org.opensearch.painless.lookup.PainlessLookupBuilder;
|
||||||
import org.opensearch.painless.spi.Whitelist;
|
import org.opensearch.painless.spi.Allowlist;
|
||||||
import org.opensearch.script.ScriptException;
|
import org.opensearch.script.ScriptException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -50,7 +50,7 @@ import static org.hamcrest.Matchers.hasKey;
|
||||||
import static org.hamcrest.Matchers.not;
|
import static org.hamcrest.Matchers.not;
|
||||||
|
|
||||||
public class DebugTests extends ScriptTestCase {
|
public class DebugTests extends ScriptTestCase {
|
||||||
private final PainlessLookup painlessLookup = PainlessLookupBuilder.buildFromWhitelists(Whitelist.BASE_WHITELISTS);
|
private final PainlessLookup painlessLookup = PainlessLookupBuilder.buildFromAllowlists(Allowlist.BASE_ALLOWLISTS);
|
||||||
|
|
||||||
public void testExplain() {
|
public void testExplain() {
|
||||||
// Debug.explain can explain an object
|
// Debug.explain can explain an object
|
||||||
|
|
|
@ -35,7 +35,7 @@ package org.opensearch.painless;
|
||||||
import org.opensearch.painless.action.PainlessExecuteAction.PainlessTestScript;
|
import org.opensearch.painless.action.PainlessExecuteAction.PainlessTestScript;
|
||||||
import org.opensearch.painless.lookup.PainlessLookup;
|
import org.opensearch.painless.lookup.PainlessLookup;
|
||||||
import org.opensearch.painless.lookup.PainlessLookupBuilder;
|
import org.opensearch.painless.lookup.PainlessLookupBuilder;
|
||||||
import org.opensearch.painless.spi.Whitelist;
|
import org.opensearch.painless.spi.Allowlist;
|
||||||
import org.objectweb.asm.util.Textifier;
|
import org.objectweb.asm.util.Textifier;
|
||||||
|
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
@ -49,7 +49,7 @@ final class Debugger {
|
||||||
return toString(PainlessTestScript.class, source, new CompilerSettings());
|
return toString(PainlessTestScript.class, source, new CompilerSettings());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final PainlessLookup LOOKUP = PainlessLookupBuilder.buildFromWhitelists(Whitelist.BASE_WHITELISTS);
|
private static final PainlessLookup LOOKUP = PainlessLookupBuilder.buildFromAllowlists(Allowlist.BASE_ALLOWLISTS);
|
||||||
|
|
||||||
/** compiles to bytecode, and returns debugging output */
|
/** compiles to bytecode, and returns debugging output */
|
||||||
static String toString(Class<?> iface, String source, CompilerSettings settings) {
|
static String toString(Class<?> iface, String source, CompilerSettings settings) {
|
||||||
|
|
|
@ -34,7 +34,7 @@ package org.opensearch.painless;
|
||||||
|
|
||||||
import org.opensearch.painless.lookup.PainlessLookup;
|
import org.opensearch.painless.lookup.PainlessLookup;
|
||||||
import org.opensearch.painless.lookup.PainlessLookupBuilder;
|
import org.opensearch.painless.lookup.PainlessLookupBuilder;
|
||||||
import org.opensearch.painless.spi.Whitelist;
|
import org.opensearch.painless.spi.Allowlist;
|
||||||
import org.opensearch.painless.symbol.FunctionTable;
|
import org.opensearch.painless.symbol.FunctionTable;
|
||||||
import org.opensearch.test.OpenSearchTestCase;
|
import org.opensearch.test.OpenSearchTestCase;
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class DefBootstrapTests extends OpenSearchTestCase {
|
public class DefBootstrapTests extends OpenSearchTestCase {
|
||||||
private final PainlessLookup painlessLookup = PainlessLookupBuilder.buildFromWhitelists(Whitelist.BASE_WHITELISTS);
|
private final PainlessLookup painlessLookup = PainlessLookupBuilder.buildFromAllowlists(Allowlist.BASE_ALLOWLISTS);
|
||||||
|
|
||||||
/** calls toString() on integers, twice */
|
/** calls toString() on integers, twice */
|
||||||
public void testOneType() throws Throwable {
|
public void testOneType() throws Throwable {
|
||||||
|
|
|
@ -35,7 +35,7 @@ package org.opensearch.painless;
|
||||||
import org.opensearch.painless.Compiler.Loader;
|
import org.opensearch.painless.Compiler.Loader;
|
||||||
import org.opensearch.painless.lookup.PainlessLookup;
|
import org.opensearch.painless.lookup.PainlessLookup;
|
||||||
import org.opensearch.painless.lookup.PainlessLookupBuilder;
|
import org.opensearch.painless.lookup.PainlessLookupBuilder;
|
||||||
import org.opensearch.painless.spi.Whitelist;
|
import org.opensearch.painless.spi.Allowlist;
|
||||||
import org.opensearch.painless.symbol.ScriptScope;
|
import org.opensearch.painless.symbol.ScriptScope;
|
||||||
import org.opensearch.script.ScriptContext;
|
import org.opensearch.script.ScriptContext;
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class DocFieldsPhaseTests extends ScriptTestCase {
|
public class DocFieldsPhaseTests extends ScriptTestCase {
|
||||||
PainlessLookup lookup = PainlessLookupBuilder.buildFromWhitelists(Whitelist.BASE_WHITELISTS);
|
PainlessLookup lookup = PainlessLookupBuilder.buildFromAllowlists(Allowlist.BASE_ALLOWLISTS);
|
||||||
|
|
||||||
ScriptScope compile(String script) {
|
ScriptScope compile(String script) {
|
||||||
Compiler compiler = new Compiler(
|
Compiler compiler = new Compiler(
|
||||||
|
|
|
@ -35,7 +35,7 @@ package org.opensearch.painless;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.opensearch.common.settings.Settings;
|
import org.opensearch.common.settings.Settings;
|
||||||
import org.opensearch.painless.spi.Whitelist;
|
import org.opensearch.painless.spi.Allowlist;
|
||||||
import org.opensearch.script.ScriptContext;
|
import org.opensearch.script.ScriptContext;
|
||||||
import org.opensearch.script.ScriptException;
|
import org.opensearch.script.ScriptException;
|
||||||
import org.opensearch.script.ScriptFactory;
|
import org.opensearch.script.ScriptFactory;
|
||||||
|
@ -54,16 +54,16 @@ public class FactoryTests extends ScriptTestCase {
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void beforeClass() {
|
public static void beforeClass() {
|
||||||
Map<ScriptContext<?>, List<Whitelist>> contexts = newDefaultContexts();
|
Map<ScriptContext<?>, List<Allowlist>> contexts = newDefaultContexts();
|
||||||
contexts.put(StatefulFactoryTestScript.CONTEXT, Whitelist.BASE_WHITELISTS);
|
contexts.put(StatefulFactoryTestScript.CONTEXT, Allowlist.BASE_ALLOWLISTS);
|
||||||
contexts.put(FactoryTestScript.CONTEXT, Whitelist.BASE_WHITELISTS);
|
contexts.put(FactoryTestScript.CONTEXT, Allowlist.BASE_ALLOWLISTS);
|
||||||
contexts.put(DeterministicFactoryTestScript.CONTEXT, Whitelist.BASE_WHITELISTS);
|
contexts.put(DeterministicFactoryTestScript.CONTEXT, Allowlist.BASE_ALLOWLISTS);
|
||||||
contexts.put(EmptyTestScript.CONTEXT, Whitelist.BASE_WHITELISTS);
|
contexts.put(EmptyTestScript.CONTEXT, Allowlist.BASE_ALLOWLISTS);
|
||||||
contexts.put(TemplateScript.CONTEXT, Whitelist.BASE_WHITELISTS);
|
contexts.put(TemplateScript.CONTEXT, Allowlist.BASE_ALLOWLISTS);
|
||||||
contexts.put(VoidReturnTestScript.CONTEXT, Whitelist.BASE_WHITELISTS);
|
contexts.put(VoidReturnTestScript.CONTEXT, Allowlist.BASE_ALLOWLISTS);
|
||||||
contexts.put(FactoryTestConverterScript.CONTEXT, Whitelist.BASE_WHITELISTS);
|
contexts.put(FactoryTestConverterScript.CONTEXT, Allowlist.BASE_ALLOWLISTS);
|
||||||
contexts.put(FactoryTestConverterScriptBadDef.CONTEXT, Whitelist.BASE_WHITELISTS);
|
contexts.put(FactoryTestConverterScriptBadDef.CONTEXT, Allowlist.BASE_ALLOWLISTS);
|
||||||
contexts.put(DocFieldsTestScript.CONTEXT, Whitelist.BASE_WHITELISTS);
|
contexts.put(DocFieldsTestScript.CONTEXT, Allowlist.BASE_ALLOWLISTS);
|
||||||
SCRIPT_ENGINE = new PainlessScriptEngine(Settings.EMPTY, contexts);
|
SCRIPT_ENGINE = new PainlessScriptEngine(Settings.EMPTY, contexts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ package org.opensearch.painless;
|
||||||
import org.opensearch.common.settings.Settings;
|
import org.opensearch.common.settings.Settings;
|
||||||
import org.opensearch.index.IndexService;
|
import org.opensearch.index.IndexService;
|
||||||
import org.opensearch.index.query.QueryShardContext;
|
import org.opensearch.index.query.QueryShardContext;
|
||||||
import org.opensearch.painless.spi.Whitelist;
|
import org.opensearch.painless.spi.Allowlist;
|
||||||
import org.opensearch.script.NumberSortScript;
|
import org.opensearch.script.NumberSortScript;
|
||||||
import org.opensearch.script.ScriptContext;
|
import org.opensearch.script.ScriptContext;
|
||||||
import org.opensearch.test.OpenSearchSingleNodeTestCase;
|
import org.opensearch.test.OpenSearchSingleNodeTestCase;
|
||||||
|
@ -54,8 +54,8 @@ public class NeedsScoreTests extends OpenSearchSingleNodeTestCase {
|
||||||
public void testNeedsScores() {
|
public void testNeedsScores() {
|
||||||
IndexService index = createIndex("test", Settings.EMPTY, "type", "d", "type=double");
|
IndexService index = createIndex("test", Settings.EMPTY, "type", "d", "type=double");
|
||||||
|
|
||||||
Map<ScriptContext<?>, List<Whitelist>> contexts = new HashMap<>();
|
Map<ScriptContext<?>, List<Allowlist>> contexts = new HashMap<>();
|
||||||
contexts.put(NumberSortScript.CONTEXT, Whitelist.BASE_WHITELISTS);
|
contexts.put(NumberSortScript.CONTEXT, Allowlist.BASE_ALLOWLISTS);
|
||||||
PainlessScriptEngine service = new PainlessScriptEngine(Settings.EMPTY, contexts);
|
PainlessScriptEngine service = new PainlessScriptEngine(Settings.EMPTY, contexts);
|
||||||
|
|
||||||
QueryShardContext shardContext = index.newQueryShardContext(0, null, () -> 0, null);
|
QueryShardContext shardContext = index.newQueryShardContext(0, null, () -> 0, null);
|
||||||
|
|
|
@ -36,8 +36,8 @@ import junit.framework.AssertionFailedError;
|
||||||
|
|
||||||
import org.opensearch.common.settings.Settings;
|
import org.opensearch.common.settings.Settings;
|
||||||
import org.opensearch.painless.antlr.Walker;
|
import org.opensearch.painless.antlr.Walker;
|
||||||
import org.opensearch.painless.spi.Whitelist;
|
import org.opensearch.painless.spi.Allowlist;
|
||||||
import org.opensearch.painless.spi.WhitelistLoader;
|
import org.opensearch.painless.spi.AllowlistLoader;
|
||||||
import org.opensearch.script.ScriptContext;
|
import org.opensearch.script.ScriptContext;
|
||||||
import org.opensearch.script.ScriptException;
|
import org.opensearch.script.ScriptException;
|
||||||
import org.opensearch.test.OpenSearchTestCase;
|
import org.opensearch.test.OpenSearchTestCase;
|
||||||
|
@ -60,10 +60,10 @@ public abstract class ScriptTestCase extends OpenSearchTestCase {
|
||||||
private static final PainlessScriptEngine SCRIPT_ENGINE = new PainlessScriptEngine(Settings.EMPTY, newDefaultContexts());
|
private static final PainlessScriptEngine SCRIPT_ENGINE = new PainlessScriptEngine(Settings.EMPTY, newDefaultContexts());
|
||||||
|
|
||||||
/** Creates a new contexts map with PainlessTextScript = org.opensearch.painless.test */
|
/** Creates a new contexts map with PainlessTextScript = org.opensearch.painless.test */
|
||||||
protected static Map<ScriptContext<?>, List<Whitelist>> newDefaultContexts() {
|
protected static Map<ScriptContext<?>, List<Allowlist>> newDefaultContexts() {
|
||||||
Map<ScriptContext<?>, List<Whitelist>> contexts = new HashMap<>();
|
Map<ScriptContext<?>, List<Allowlist>> contexts = new HashMap<>();
|
||||||
List<Whitelist> allowlists = new ArrayList<>(Whitelist.BASE_WHITELISTS);
|
List<Allowlist> allowlists = new ArrayList<>(Allowlist.BASE_ALLOWLISTS);
|
||||||
allowlists.add(WhitelistLoader.loadFromResourceFiles(Whitelist.class, "org.opensearch.painless.test"));
|
allowlists.add(AllowlistLoader.loadFromResourceFiles(Allowlist.class, "org.opensearch.painless.test"));
|
||||||
contexts.put(PainlessTestScript.CONTEXT, allowlists);
|
contexts.put(PainlessTestScript.CONTEXT, allowlists);
|
||||||
return contexts;
|
return contexts;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ import org.apache.lucene.search.Scorable;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.opensearch.common.settings.Settings;
|
import org.opensearch.common.settings.Settings;
|
||||||
import org.opensearch.painless.spi.Whitelist;
|
import org.opensearch.painless.spi.Allowlist;
|
||||||
import org.opensearch.script.ScriptContext;
|
import org.opensearch.script.ScriptContext;
|
||||||
import org.opensearch.script.ScriptedMetricAggContexts;
|
import org.opensearch.script.ScriptedMetricAggContexts;
|
||||||
import org.opensearch.search.lookup.LeafSearchLookup;
|
import org.opensearch.search.lookup.LeafSearchLookup;
|
||||||
|
@ -60,11 +60,11 @@ public class ScriptedMetricAggContextsTests extends ScriptTestCase {
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void beforeClass() {
|
public static void beforeClass() {
|
||||||
Map<ScriptContext<?>, List<Whitelist>> contexts = new HashMap<>();
|
Map<ScriptContext<?>, List<Allowlist>> contexts = new HashMap<>();
|
||||||
contexts.put(ScriptedMetricAggContexts.InitScript.CONTEXT, Whitelist.BASE_WHITELISTS);
|
contexts.put(ScriptedMetricAggContexts.InitScript.CONTEXT, Allowlist.BASE_ALLOWLISTS);
|
||||||
contexts.put(ScriptedMetricAggContexts.MapScript.CONTEXT, Whitelist.BASE_WHITELISTS);
|
contexts.put(ScriptedMetricAggContexts.MapScript.CONTEXT, Allowlist.BASE_ALLOWLISTS);
|
||||||
contexts.put(ScriptedMetricAggContexts.CombineScript.CONTEXT, Whitelist.BASE_WHITELISTS);
|
contexts.put(ScriptedMetricAggContexts.CombineScript.CONTEXT, Allowlist.BASE_ALLOWLISTS);
|
||||||
contexts.put(ScriptedMetricAggContexts.ReduceScript.CONTEXT, Whitelist.BASE_WHITELISTS);
|
contexts.put(ScriptedMetricAggContexts.ReduceScript.CONTEXT, Allowlist.BASE_ALLOWLISTS);
|
||||||
SCRIPT_ENGINE = new PainlessScriptEngine(Settings.EMPTY, contexts);
|
SCRIPT_ENGINE = new PainlessScriptEngine(Settings.EMPTY, contexts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ import org.junit.AfterClass;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.opensearch.common.settings.Settings;
|
import org.opensearch.common.settings.Settings;
|
||||||
import org.opensearch.index.similarity.ScriptedSimilarity;
|
import org.opensearch.index.similarity.ScriptedSimilarity;
|
||||||
import org.opensearch.painless.spi.Whitelist;
|
import org.opensearch.painless.spi.Allowlist;
|
||||||
import org.opensearch.script.ScriptContext;
|
import org.opensearch.script.ScriptContext;
|
||||||
import org.opensearch.script.SimilarityScript;
|
import org.opensearch.script.SimilarityScript;
|
||||||
import org.opensearch.script.SimilarityWeightScript;
|
import org.opensearch.script.SimilarityWeightScript;
|
||||||
|
@ -69,9 +69,9 @@ public class SimilarityScriptTests extends ScriptTestCase {
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void beforeClass() {
|
public static void beforeClass() {
|
||||||
Map<ScriptContext<?>, List<Whitelist>> contexts = new HashMap<>();
|
Map<ScriptContext<?>, List<Allowlist>> contexts = new HashMap<>();
|
||||||
contexts.put(SimilarityScript.CONTEXT, Whitelist.BASE_WHITELISTS);
|
contexts.put(SimilarityScript.CONTEXT, Allowlist.BASE_ALLOWLISTS);
|
||||||
contexts.put(SimilarityWeightScript.CONTEXT, Whitelist.BASE_WHITELISTS);
|
contexts.put(SimilarityWeightScript.CONTEXT, Allowlist.BASE_ALLOWLISTS);
|
||||||
SCRIPT_ENGINE = new PainlessScriptEngine(Settings.EMPTY, contexts);
|
SCRIPT_ENGINE = new PainlessScriptEngine(Settings.EMPTY, contexts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,15 +50,15 @@ import static org.opensearch.index.reindex.ReindexValidator.checkRemoteAllowlist
|
||||||
/**
|
/**
|
||||||
* Tests the reindex-from-remote allowlist of remotes.
|
* Tests the reindex-from-remote allowlist of remotes.
|
||||||
*/
|
*/
|
||||||
public class ReindexFromRemoteWhitelistTests extends OpenSearchTestCase {
|
public class ReindexFromRemoteAllowlistTests extends OpenSearchTestCase {
|
||||||
|
|
||||||
private final BytesReference query = new BytesArray("{ \"foo\" : \"bar\" }");
|
private final BytesReference query = new BytesArray("{ \"foo\" : \"bar\" }");
|
||||||
|
|
||||||
public void testLocalRequestWithoutWhitelist() {
|
public void testLocalRequestWithoutAllowlist() {
|
||||||
checkRemoteAllowlist(buildRemoteAllowlist(emptyList()), null);
|
checkRemoteAllowlist(buildRemoteAllowlist(emptyList()), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testLocalRequestWithWhitelist() {
|
public void testLocalRequestWithAllowlist() {
|
||||||
checkRemoteAllowlist(buildRemoteAllowlist(randomAllowlist()), null);
|
checkRemoteAllowlist(buildRemoteAllowlist(randomAllowlist()), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ public class ReindexFromRemoteWhitelistTests extends OpenSearchTestCase {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWhitelistedRemote() {
|
public void testAllowlistedRemote() {
|
||||||
List<String> allowlist = randomAllowlist();
|
List<String> allowlist = randomAllowlist();
|
||||||
String[] inList = allowlist.iterator().next().split(":");
|
String[] inList = allowlist.iterator().next().split(":");
|
||||||
String host = inList[0];
|
String host = inList[0];
|
||||||
|
@ -88,7 +88,7 @@ public class ReindexFromRemoteWhitelistTests extends OpenSearchTestCase {
|
||||||
checkRemoteAllowlist(buildRemoteAllowlist(allowlist), newRemoteInfo(host, port));
|
checkRemoteAllowlist(buildRemoteAllowlist(allowlist), newRemoteInfo(host, port));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWhitelistedByPrefix() {
|
public void testAllowlistedByPrefix() {
|
||||||
checkRemoteAllowlist(
|
checkRemoteAllowlist(
|
||||||
buildRemoteAllowlist(singletonList("*.example.com:9200")),
|
buildRemoteAllowlist(singletonList("*.example.com:9200")),
|
||||||
new RemoteInfo(
|
new RemoteInfo(
|
||||||
|
@ -110,21 +110,21 @@ public class ReindexFromRemoteWhitelistTests extends OpenSearchTestCase {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWhitelistedBySuffix() {
|
public void testAllowlistedBySuffix() {
|
||||||
checkRemoteAllowlist(buildRemoteAllowlist(singletonList("es.example.com:*")), newRemoteInfo("es.example.com", 9200));
|
checkRemoteAllowlist(buildRemoteAllowlist(singletonList("es.example.com:*")), newRemoteInfo("es.example.com", 9200));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWhitelistedByInfix() {
|
public void testAllowlistedByInfix() {
|
||||||
checkRemoteAllowlist(buildRemoteAllowlist(singletonList("es*.example.com:9200")), newRemoteInfo("es1.example.com", 9200));
|
checkRemoteAllowlist(buildRemoteAllowlist(singletonList("es*.example.com:9200")), newRemoteInfo("es1.example.com", 9200));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testLoopbackInWhitelistRemote() throws UnknownHostException {
|
public void testLoopbackInAllowlistRemote() throws UnknownHostException {
|
||||||
List<String> allowlist = randomAllowlist();
|
List<String> allowlist = randomAllowlist();
|
||||||
allowlist.add("127.0.0.1:*");
|
allowlist.add("127.0.0.1:*");
|
||||||
checkRemoteAllowlist(buildRemoteAllowlist(allowlist), newRemoteInfo("127.0.0.1", 9200));
|
checkRemoteAllowlist(buildRemoteAllowlist(allowlist), newRemoteInfo("127.0.0.1", 9200));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testUnwhitelistedRemote() {
|
public void testUnallowlistedRemote() {
|
||||||
int port = between(1, Integer.MAX_VALUE);
|
int port = between(1, Integer.MAX_VALUE);
|
||||||
List<String> allowlist = randomBoolean() ? randomAllowlist() : emptyList();
|
List<String> allowlist = randomBoolean() ? randomAllowlist() : emptyList();
|
||||||
Exception e = expectThrows(
|
Exception e = expectThrows(
|
|
@ -68,7 +68,7 @@ public class URLRepositoryTests extends OpenSearchTestCase {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWhiteListingRepoURL() throws IOException {
|
public void testAllowListingRepoURL() throws IOException {
|
||||||
String repoPath = createTempDir().resolve("repository").toUri().toURL().toString();
|
String repoPath = createTempDir().resolve("repository").toUri().toURL().toString();
|
||||||
Settings baseSettings = Settings.builder()
|
Settings baseSettings = Settings.builder()
|
||||||
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString())
|
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString())
|
||||||
|
@ -84,7 +84,7 @@ public class URLRepositoryTests extends OpenSearchTestCase {
|
||||||
assertThat("blobContainer has to initialize blob store", repository.getBlobStore(), not(nullValue()));
|
assertThat("blobContainer has to initialize blob store", repository.getBlobStore(), not(nullValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testIfNotWhiteListedMustSetRepoURL() throws IOException {
|
public void testIfNotAllowListedMustSetRepoURL() throws IOException {
|
||||||
String repoPath = createTempDir().resolve("repository").toUri().toURL().toString();
|
String repoPath = createTempDir().resolve("repository").toUri().toURL().toString();
|
||||||
Settings baseSettings = Settings.builder()
|
Settings baseSettings = Settings.builder()
|
||||||
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString())
|
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString())
|
||||||
|
|
|
@ -28,7 +28,7 @@ gradle.projectsEvaluated {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
configure(project('painless-whitelist')) {
|
configure(project('painless-allowlist')) {
|
||||||
configurations.all {
|
configurations.all {
|
||||||
resolutionStrategy.dependencySubstitution {
|
resolutionStrategy.dependencySubstitution {
|
||||||
substitute module('org.opensearch.plugin:opensearch-scripting-painless-spi') with project(':modules:lang-painless:spi')
|
substitute module('org.opensearch.plugin:opensearch-scripting-painless-spi') with project(':modules:lang-painless:spi')
|
||||||
|
|
|
@ -31,9 +31,9 @@ apply plugin: 'opensearch.opensearchplugin'
|
||||||
apply plugin: 'opensearch.yaml-rest-test'
|
apply plugin: 'opensearch.yaml-rest-test'
|
||||||
|
|
||||||
opensearchplugin {
|
opensearchplugin {
|
||||||
name 'painless-whitelist'
|
name 'painless-allowlist'
|
||||||
description 'An example allowlisting additional classes and methods in painless'
|
description 'An example allowlisting additional classes and methods in painless'
|
||||||
classname 'org.opensearch.example.painlesswhitelist.MyWhitelistPlugin'
|
classname 'org.opensearch.example.painlessallowlist.MyAllowlistPlugin'
|
||||||
extendedPlugins = ['lang-painless']
|
extendedPlugins = ['lang-painless']
|
||||||
licenseFile rootProject.file('licenses/APACHE-LICENSE-2.0.txt')
|
licenseFile rootProject.file('licenses/APACHE-LICENSE-2.0.txt')
|
||||||
noticeFile rootProject.file('NOTICE.txt')
|
noticeFile rootProject.file('NOTICE.txt')
|
|
@ -30,17 +30,17 @@
|
||||||
* GitHub history for details.
|
* GitHub history for details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.opensearch.example.painlesswhitelist;
|
package org.opensearch.example.painlessallowlist;
|
||||||
|
|
||||||
import org.opensearch.painless.spi.annotation.WhitelistAnnotationParser;
|
import org.opensearch.painless.spi.annotation.AllowlistAnnotationParser;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class ExampleWhitelistAnnotationParser implements WhitelistAnnotationParser {
|
public class ExampleAllowlistAnnotationParser implements AllowlistAnnotationParser {
|
||||||
|
|
||||||
public static final ExampleWhitelistAnnotationParser INSTANCE = new ExampleWhitelistAnnotationParser();
|
public static final ExampleAllowlistAnnotationParser INSTANCE = new ExampleAllowlistAnnotationParser();
|
||||||
|
|
||||||
private ExampleWhitelistAnnotationParser() {
|
private ExampleAllowlistAnnotationParser() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,13 +30,13 @@
|
||||||
* GitHub history for details.
|
* GitHub history for details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.opensearch.example.painlesswhitelist;
|
package org.opensearch.example.painlessallowlist;
|
||||||
|
|
||||||
import org.opensearch.painless.spi.PainlessExtension;
|
import org.opensearch.painless.spi.PainlessExtension;
|
||||||
import org.opensearch.painless.spi.Whitelist;
|
import org.opensearch.painless.spi.Allowlist;
|
||||||
import org.opensearch.painless.spi.WhitelistInstanceBinding;
|
import org.opensearch.painless.spi.AllowlistInstanceBinding;
|
||||||
import org.opensearch.painless.spi.WhitelistLoader;
|
import org.opensearch.painless.spi.AllowlistLoader;
|
||||||
import org.opensearch.painless.spi.annotation.WhitelistAnnotationParser;
|
import org.opensearch.painless.spi.annotation.AllowlistAnnotationParser;
|
||||||
import org.opensearch.script.FieldScript;
|
import org.opensearch.script.FieldScript;
|
||||||
import org.opensearch.script.ScriptContext;
|
import org.opensearch.script.ScriptContext;
|
||||||
|
|
||||||
|
@ -47,16 +47,16 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/** An extension of painless which adds an allowlist. */
|
/** An extension of painless which adds an allowlist. */
|
||||||
public class ExampleWhitelistExtension implements PainlessExtension {
|
public class ExampleAllowlistExtension implements PainlessExtension {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<ScriptContext<?>, List<Whitelist>> getContextWhitelists() {
|
public Map<ScriptContext<?>, List<Allowlist>> getContextAllowlists() {
|
||||||
Map<String, WhitelistAnnotationParser> parsers = new HashMap<>(WhitelistAnnotationParser.BASE_ANNOTATION_PARSERS);
|
Map<String, AllowlistAnnotationParser> parsers = new HashMap<>(AllowlistAnnotationParser.BASE_ANNOTATION_PARSERS);
|
||||||
parsers.put(ExamplePainlessAnnotation.NAME, ExampleWhitelistAnnotationParser.INSTANCE);
|
parsers.put(ExamplePainlessAnnotation.NAME, ExampleAllowlistAnnotationParser.INSTANCE);
|
||||||
Whitelist classAllowlist = WhitelistLoader.loadFromResourceFiles(ExampleWhitelistExtension.class, parsers, "example_whitelist.txt");
|
Allowlist classAllowlist = AllowlistLoader.loadFromResourceFiles(ExampleAllowlistExtension.class, parsers, "example_allowlist.txt");
|
||||||
|
|
||||||
ExampleWhitelistedInstance eai = new ExampleWhitelistedInstance(1);
|
ExampleAllowlistedInstance eai = new ExampleAllowlistedInstance(1);
|
||||||
WhitelistInstanceBinding addValue = new WhitelistInstanceBinding(
|
AllowlistInstanceBinding addValue = new AllowlistInstanceBinding(
|
||||||
"example addValue",
|
"example addValue",
|
||||||
eai,
|
eai,
|
||||||
"addValue",
|
"addValue",
|
||||||
|
@ -64,7 +64,7 @@ public class ExampleWhitelistExtension implements PainlessExtension {
|
||||||
Collections.singletonList("int"),
|
Collections.singletonList("int"),
|
||||||
Collections.emptyList()
|
Collections.emptyList()
|
||||||
);
|
);
|
||||||
WhitelistInstanceBinding getValue = new WhitelistInstanceBinding(
|
AllowlistInstanceBinding getValue = new AllowlistInstanceBinding(
|
||||||
"example getValue",
|
"example getValue",
|
||||||
eai,
|
eai,
|
||||||
"getValue",
|
"getValue",
|
||||||
|
@ -72,7 +72,7 @@ public class ExampleWhitelistExtension implements PainlessExtension {
|
||||||
Collections.emptyList(),
|
Collections.emptyList(),
|
||||||
Collections.emptyList()
|
Collections.emptyList()
|
||||||
);
|
);
|
||||||
Whitelist instanceAllowlist = new Whitelist(
|
Allowlist instanceAllowlist = new Allowlist(
|
||||||
eai.getClass().getClassLoader(),
|
eai.getClass().getClassLoader(),
|
||||||
Collections.emptyList(),
|
Collections.emptyList(),
|
||||||
Collections.emptyList(),
|
Collections.emptyList(),
|
|
@ -30,15 +30,15 @@
|
||||||
* GitHub history for details.
|
* GitHub history for details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.opensearch.example.painlesswhitelist;
|
package org.opensearch.example.painlessallowlist;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An example of a class to be allowlisted for use by painless scripts
|
* An example of a class to be allowlisted for use by painless scripts
|
||||||
*
|
*
|
||||||
* Each of the members and methods below are allowlisted for use in search scripts.
|
* Each of the members and methods below are allowlisted for use in search scripts.
|
||||||
* See <a href="file:example_whitelist.txt">example_whitelist.txt</a>.
|
* See <a href="file:example_allowlist.txt">example_allowlist.txt</a>.
|
||||||
*/
|
*/
|
||||||
public class ExampleWhitelistedClass {
|
public class ExampleAllowlistedClass {
|
||||||
|
|
||||||
public static final int CONSTANT = 42;
|
public static final int CONSTANT = 42;
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ public class ExampleWhitelistedClass {
|
||||||
|
|
||||||
private int privateMember;
|
private int privateMember;
|
||||||
|
|
||||||
public ExampleWhitelistedClass(int publicMember, int privateMember) {
|
public ExampleAllowlistedClass(int publicMember, int privateMember) {
|
||||||
this.publicMember = publicMember;
|
this.publicMember = publicMember;
|
||||||
this.privateMember = privateMember;
|
this.privateMember = privateMember;
|
||||||
}
|
}
|
|
@ -30,12 +30,12 @@
|
||||||
* GitHub history for details.
|
* GitHub history for details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.opensearch.example.painlesswhitelist;
|
package org.opensearch.example.painlessallowlist;
|
||||||
|
|
||||||
public class ExampleWhitelistedInstance {
|
public class ExampleAllowlistedInstance {
|
||||||
private final int value;
|
private final int value;
|
||||||
|
|
||||||
public ExampleWhitelistedInstance(int value) {
|
public ExampleAllowlistedInstance(int value) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
* GitHub history for details.
|
* GitHub history for details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.opensearch.example.painlesswhitelist;
|
package org.opensearch.example.painlessallowlist;
|
||||||
|
|
||||||
public class ExamplePainlessAnnotation {
|
public class ExamplePainlessAnnotation {
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
* GitHub history for details.
|
* GitHub history for details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.opensearch.example.painlesswhitelist;
|
package org.opensearch.example.painlessallowlist;
|
||||||
|
|
||||||
public class ExampleStaticMethodClass {
|
public class ExampleStaticMethodClass {
|
||||||
public static int exampleAddInts(int x, int y) {
|
public static int exampleAddInts(int x, int y) {
|
|
@ -30,10 +30,10 @@
|
||||||
* GitHub history for details.
|
* GitHub history for details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.opensearch.example.painlesswhitelist;
|
package org.opensearch.example.painlessallowlist;
|
||||||
|
|
||||||
import org.opensearch.plugins.Plugin;
|
import org.opensearch.plugins.Plugin;
|
||||||
|
|
||||||
public class MyWhitelistPlugin extends Plugin {
|
public class MyAllowlistPlugin extends Plugin {
|
||||||
// we don't actually need anything here, since allowlists are extended through SPI
|
// we don't actually need anything here, since allowlists are extended through SPI
|
||||||
}
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
org.opensearch.example.painlessallowlist.ExampleAllowlistExtension
|
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
# This file contains an allowlist for an example class which may be access from painless
|
# This file contains an allowlist for an example class which may be access from painless
|
||||||
|
|
||||||
class org.opensearch.example.painlesswhitelist.ExampleWhitelistedClass {
|
class org.opensearch.example.painlessallowlist.ExampleAllowlistedClass {
|
||||||
# constructor
|
# constructor
|
||||||
(int, int)
|
(int, int)
|
||||||
|
|
||||||
|
@ -41,9 +41,9 @@ class org.opensearch.example.painlesswhitelist.ExampleWhitelistedClass {
|
||||||
class java.lang.String {
|
class java.lang.String {
|
||||||
# existing classes can be "augmented" to have additional methods, which take the object
|
# existing classes can be "augmented" to have additional methods, which take the object
|
||||||
# to operate on as the first argument to a static method
|
# to operate on as the first argument to a static method
|
||||||
int org.opensearch.example.painlesswhitelist.ExampleWhitelistedClass toInt()
|
int org.opensearch.example.painlessallowlist.ExampleAllowlistedClass toInt()
|
||||||
}
|
}
|
||||||
|
|
||||||
static_import {
|
static_import {
|
||||||
int exampleAddInts(int, int) from_class org.opensearch.example.painlesswhitelist.ExampleStaticMethodClass
|
int exampleAddInts(int, int) from_class org.opensearch.example.painlessallowlist.ExampleStaticMethodClass
|
||||||
}
|
}
|
|
@ -30,16 +30,16 @@
|
||||||
* GitHub history for details.
|
* GitHub history for details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.opensearch.example.painlesswhitelist;
|
package org.opensearch.example.painlessallowlist;
|
||||||
|
|
||||||
import com.carrotsearch.randomizedtesting.annotations.Name;
|
import com.carrotsearch.randomizedtesting.annotations.Name;
|
||||||
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
|
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
|
||||||
import org.opensearch.test.rest.yaml.ClientYamlTestCandidate;
|
import org.opensearch.test.rest.yaml.ClientYamlTestCandidate;
|
||||||
import org.opensearch.test.rest.yaml.OpenSearchClientYamlSuiteTestCase;
|
import org.opensearch.test.rest.yaml.OpenSearchClientYamlSuiteTestCase;
|
||||||
|
|
||||||
public class PainlessWhitelistClientYamlTestSuiteIT extends OpenSearchClientYamlSuiteTestCase {
|
public class PainlessAllowlistClientYamlTestSuiteIT extends OpenSearchClientYamlSuiteTestCase {
|
||||||
|
|
||||||
public PainlessWhitelistClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) {
|
public PainlessAllowlistClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) {
|
||||||
super(testCandidate);
|
super(testCandidate);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,4 +13,4 @@
|
||||||
- do:
|
- do:
|
||||||
nodes.info: {}
|
nodes.info: {}
|
||||||
|
|
||||||
- contains: { nodes.$cluster_manager.plugins: { name: painless-whitelist } }
|
- contains: { nodes.$cluster_manager.plugins: { name: painless-allowlist } }
|
|
@ -1,6 +1,6 @@
|
||||||
# Example test using allowlisted members and methods
|
# Example test using allowlisted members and methods
|
||||||
|
|
||||||
"Whitelisted custom class":
|
"Allowlisted custom class":
|
||||||
- do:
|
- do:
|
||||||
index:
|
index:
|
||||||
index: test
|
index: test
|
||||||
|
@ -19,7 +19,7 @@
|
||||||
script_fields:
|
script_fields:
|
||||||
sNum1:
|
sNum1:
|
||||||
script:
|
script:
|
||||||
source: "def e = new ExampleWhitelistedClass(6, 42); ExampleWhitelistedClass.staticMethod(); return e.publicMember + e.privateMemberAccessor + ExampleWhitelistedClass.CONSTANT + '2'.toInt()"
|
source: "def e = new ExampleAllowlistedClass(6, 42); ExampleAllowlistedClass.staticMethod(); return e.publicMember + e.privateMemberAccessor + ExampleAllowlistedClass.CONSTANT + '2'.toInt()"
|
||||||
lang: painless
|
lang: painless
|
||||||
|
|
||||||
- match: { hits.total: 1 }
|
- match: { hits.total: 1 }
|
|
@ -1 +0,0 @@
|
||||||
org.opensearch.example.painlesswhitelist.ExampleWhitelistExtension
|
|
|
@ -157,9 +157,9 @@ The runner is able to send and receive `application/yaml` and perform all assert
|
||||||
|
|
||||||
Asserts an array of object contains an object with a property set to a certain value. e.g:
|
Asserts an array of object contains an object with a property set to a certain value. e.g:
|
||||||
|
|
||||||
… contains: { nodes.$master.plugins: { name: painless-whitelist } } …
|
… contains: { nodes.$cluster_manager.plugins: { name: painless-allowlist } } …
|
||||||
|
|
||||||
Asserts the plugins array contains an object with a `name` property with the value `painless-whitelist`
|
Asserts the plugins array contains an object with a `name` property with the value `painless-allowlist`
|
||||||
|
|
||||||
## `transform_and_set`
|
## `transform_and_set`
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ import java.util.Arrays;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
|
||||||
public class MovFnWhitelistedFunctionTests extends OpenSearchTestCase {
|
public class MovFnAllowlistedFunctionTests extends OpenSearchTestCase {
|
||||||
|
|
||||||
public void testWindowMax() {
|
public void testWindowMax() {
|
||||||
int numValues = randomIntBetween(1, 100);
|
int numValues = randomIntBetween(1, 100);
|
Loading…
Reference in New Issue