Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,16 @@
*/
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making the arguments just be the name of the class, rather than some kind of option flags, doesn't allow much evolution in the future, but then, we are in control of all of this code and change it in the future if need be, just like we did this time, so it doesn't actually matter much.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had exactly the same conversation in my head :D wondering if I should do that, and thinking we can change this any time anyway, so I decided to let it like this for now. Unless you or someone else feels strongly about this.

} catch (ClassNotFoundException e) {
throw new AssertionError("entitlement agent does could not find EntitlementInitialization", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ private static void loadAgent(String agentPath) {
try {
VirtualMachine vm = VirtualMachine.attach(Long.toString(ProcessHandle.current().pid()));
try {
vm.loadAgent(agentPath);
vm.loadAgent(agentPath, EntitlementInitialization.class.getName());
} finally {
vm.detach();
}
Expand All @@ -154,7 +154,7 @@ private static void exportInitializationToAgent() {
EntitlementInitialization.class.getModule().addExports(initPkg, unnamedModule);
}

private static String findAgentJar() {
public static String findAgentJar() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why this became public, but I presume that will become clear in an upcoming PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be package private, right? The TestEntitlementBootstrap can be in the same entitlement bootstrap package (split packages are ok when using the classpath)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes sorry this change slipped in (see the linked PR).
If split packages are OK for tests (as we use the classpath) I will change them the package of TestEntitlementBootstrap etc. and make this (and other method/classes) package-private then.

String propertyName = "es.entitlement.agentJar";
String propertyValue = System.getProperty(propertyName);
if (propertyValue != null) {
Expand Down