Initialization class as argument to EntitlementAgent (#127815)

Preliminary step for test entitlement initialization, extracted from #127814
This commit is contained in:
Lorenzo Dematté 2025-05-08 10:22:02 +02:00 committed by GitHub
parent 7d06f815f3
commit 2d9fc30f62
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 3 deletions

View File

@ -25,10 +25,16 @@ import java.lang.reflect.Method;
*/
public class EntitlementAgent {
/**
* The agent main method
* @param agentArgs arguments passed to the agent.For our agent, this is the class to load and use for Entitlement Initialization.
* See e.g. {@code EntitlementsBootstrap#loadAgent}
* @param inst The {@link Instrumentation} instance to use for injecting Entitlements checks
*/
public static void agentmain(String agentArgs, Instrumentation inst) {
final Class<?> initClazz;
try {
initClazz = Class.forName("org.elasticsearch.entitlement.initialization.EntitlementInitialization");
initClazz = Class.forName(agentArgs);
} catch (ClassNotFoundException e) {
throw new AssertionError("entitlement agent does could not find EntitlementInitialization", e);
}

View File

@ -138,7 +138,7 @@ public class EntitlementBootstrap {
try {
VirtualMachine vm = VirtualMachine.attach(Long.toString(ProcessHandle.current().pid()));
try {
vm.loadAgent(agentPath);
vm.loadAgent(agentPath, EntitlementInitialization.class.getName());
} finally {
vm.detach();
}
@ -154,7 +154,7 @@ public class EntitlementBootstrap {
EntitlementInitialization.class.getModule().addExports(initPkg, unnamedModule);
}
private static String findAgentJar() {
public static String findAgentJar() {
String propertyName = "es.entitlement.agentJar";
String propertyValue = System.getProperty(propertyName);
if (propertyValue != null) {