use of org.opensearch.painless.spi.WhitelistConstructor in project OpenSearch by opensearch-project.
the class PainlessLookupBuilder method buildFromWhitelists.
public static PainlessLookup buildFromWhitelists(List<Whitelist> allowlists) {
PainlessLookupBuilder painlessLookupBuilder = new PainlessLookupBuilder();
String origin = "internal error";
try {
for (Whitelist allowlist : allowlists) {
for (WhitelistClass allowlistClass : allowlist.whitelistClasses) {
origin = allowlistClass.origin;
painlessLookupBuilder.addPainlessClass(allowlist.classLoader, allowlistClass.javaClassName, allowlistClass.painlessAnnotations.containsKey(NoImportAnnotation.class) == false);
}
}
for (Whitelist allowlist : allowlists) {
for (WhitelistClass allowlistClass : allowlist.whitelistClasses) {
String targetCanonicalClassName = allowlistClass.javaClassName.replace('$', '.');
for (WhitelistConstructor allowlistConstructor : allowlistClass.whitelistConstructors) {
origin = allowlistConstructor.origin;
painlessLookupBuilder.addPainlessConstructor(targetCanonicalClassName, allowlistConstructor.canonicalTypeNameParameters, allowlistConstructor.painlessAnnotations);
}
for (WhitelistMethod allowlistMethod : allowlistClass.whitelistMethods) {
origin = allowlistMethod.origin;
painlessLookupBuilder.addPainlessMethod(allowlist.classLoader, targetCanonicalClassName, allowlistMethod.augmentedCanonicalClassName, allowlistMethod.methodName, allowlistMethod.returnCanonicalTypeName, allowlistMethod.canonicalTypeNameParameters, allowlistMethod.painlessAnnotations);
}
for (WhitelistField allowlistField : allowlistClass.whitelistFields) {
origin = allowlistField.origin;
painlessLookupBuilder.addPainlessField(targetCanonicalClassName, allowlistField.fieldName, allowlistField.canonicalTypeNameParameter);
}
}
for (WhitelistMethod allowlistStatic : allowlist.whitelistImportedMethods) {
origin = allowlistStatic.origin;
painlessLookupBuilder.addImportedPainlessMethod(allowlist.classLoader, allowlistStatic.augmentedCanonicalClassName, allowlistStatic.methodName, allowlistStatic.returnCanonicalTypeName, allowlistStatic.canonicalTypeNameParameters, allowlistStatic.painlessAnnotations);
}
for (WhitelistClassBinding allowlistClassBinding : allowlist.whitelistClassBindings) {
origin = allowlistClassBinding.origin;
painlessLookupBuilder.addPainlessClassBinding(allowlist.classLoader, allowlistClassBinding.targetJavaClassName, allowlistClassBinding.methodName, allowlistClassBinding.returnCanonicalTypeName, allowlistClassBinding.canonicalTypeNameParameters, allowlistClassBinding.painlessAnnotations);
}
for (WhitelistInstanceBinding allowlistInstanceBinding : allowlist.whitelistInstanceBindings) {
origin = allowlistInstanceBinding.origin;
painlessLookupBuilder.addPainlessInstanceBinding(allowlistInstanceBinding.targetInstance, allowlistInstanceBinding.methodName, allowlistInstanceBinding.returnCanonicalTypeName, allowlistInstanceBinding.canonicalTypeNameParameters);
}
}
} catch (Exception exception) {
throw new IllegalArgumentException("error loading allowlist(s) " + origin, exception);
}
return painlessLookupBuilder.build();
}
Aggregations