1414import com .sun .tools .attach .AttachNotSupportedException ;
1515import com .sun .tools .attach .VirtualMachine ;
1616
17- import org .elasticsearch .core .Nullable ;
1817import org .elasticsearch .core .PathUtils ;
1918import org .elasticsearch .core .SuppressForbidden ;
2019import org .elasticsearch .entitlement .initialization .EntitlementInitialization ;
2120import org .elasticsearch .entitlement .runtime .policy .PathLookup ;
22- import org .elasticsearch .entitlement .runtime .policy .PathLookupImpl ;
2321import org .elasticsearch .entitlement .runtime .policy .Policy ;
2422import org .elasticsearch .entitlement .runtime .policy .PolicyManager ;
2523import org .elasticsearch .logging .LogManager ;
3028import java .nio .file .Path ;
3129import java .util .Map ;
3230import java .util .Set ;
33- import java .util .function .Function ;
34- import java .util .stream .Stream ;
3531
3632import static java .util .Objects .requireNonNull ;
3733
4238 */
4339public class EntitlementBootstrap {
4440
41+ /**
42+ * A place to stash objects that the agent will need during its initialization
43+ */
4544 public record BootstrapArgs (
46- @ Nullable Policy serverPolicyPatch ,
45+ PolicyManager policyManager ,
4746 Map <String , Policy > pluginPolicies ,
48- Function <Class <?>, PolicyManager .PolicyScope > scopeResolver ,
4947 PathLookup pathLookup ,
50- Map <String , Path > sourcePaths ,
5148 Set <Package > suppressFailureLogPackages
5249 ) {
5350 public BootstrapArgs {
51+ requireNonNull (policyManager );
5452 requireNonNull (pluginPolicies );
55- requireNonNull (scopeResolver );
5653 requireNonNull (pathLookup );
57- requireNonNull (sourcePaths );
5854 requireNonNull (suppressFailureLogPackages );
5955 }
6056 }
@@ -71,68 +67,27 @@ public static BootstrapArgs bootstrapArgs() {
7167 * <p>
7268 * (Note: when we reference Elasticsearch "plugins" here, we generally also include Elasticsearch "modules".)
7369 *
74- * @param serverPolicyPatch a policy with additional entitlements to patch the embedded server layer policy
75- * @param pluginPolicies a map holding policies for plugins, by plugin name.
76- * @param scopeResolver a functor to map a Java Class to the component and module it belongs to.
77- * @param settingResolver a functor to resolve a setting name pattern for one or more Elasticsearch settings.
78- * @param dataDirs data directories for Elasticsearch
79- * @param sharedRepoDirs shared repository directories for Elasticsearch
80- * @param configDir the config directory for Elasticsearch
81- * @param libDir the lib directory for Elasticsearch
82- * @param modulesDir the directory where Elasticsearch modules are
83- * @param pluginsDir the directory where plugins are installed for Elasticsearch
84- * @param sourcePaths a map holding the path to each plugin or module jars, by plugin name.
85- * @param tempDir the temp directory for Elasticsearch
86- * @param logsDir the log directory for Elasticsearch
87- * @param pidFile path to a pid file for Elasticsearch, or {@code null} if one was not specified
88- * @param suppressFailureLogPackages packages for which we do not need or want to log Entitlements failures
70+ * @param policyManager
71+ * @param pluginPolicies a map holding policies for plugins, by plugin name.
72+ * @param pathLookup
73+ * @param suppressFailureLogPackages packages for which we do not need or want to log Entitlements failures
8974 */
9075 public static void bootstrap (
91- Policy serverPolicyPatch ,
76+ PolicyManager policyManager ,
9277 Map <String , Policy > pluginPolicies ,
93- Function <Class <?>, PolicyManager .PolicyScope > scopeResolver ,
94- Function <String , Stream <String >> settingResolver ,
95- Path [] dataDirs ,
96- Path [] sharedRepoDirs ,
97- Path configDir ,
98- Path libDir ,
99- Path modulesDir ,
100- Path pluginsDir ,
101- Map <String , Path > sourcePaths ,
102- Path logsDir ,
103- Path tempDir ,
104- Path pidFile ,
78+ PathLookup pathLookup ,
10579 Set <Package > suppressFailureLogPackages
10680 ) {
10781 logger .debug ("Loading entitlement agent" );
10882 if (EntitlementBootstrap .bootstrapArgs != null ) {
10983 throw new IllegalStateException ("plugin data is already set" );
11084 }
111- EntitlementBootstrap .bootstrapArgs = new BootstrapArgs (
112- serverPolicyPatch ,
113- pluginPolicies ,
114- scopeResolver ,
115- new PathLookupImpl (
116- getUserHome (),
117- configDir ,
118- dataDirs ,
119- sharedRepoDirs ,
120- libDir ,
121- modulesDir ,
122- pluginsDir ,
123- logsDir ,
124- tempDir ,
125- pidFile ,
126- settingResolver
127- ),
128- sourcePaths ,
129- suppressFailureLogPackages
130- );
85+ EntitlementBootstrap .bootstrapArgs = new BootstrapArgs (policyManager , pluginPolicies , pathLookup , suppressFailureLogPackages );
13186 exportInitializationToAgent ();
13287 loadAgent (findAgentJar ());
13388 }
13489
135- private static Path getUserHome () {
90+ public static Path getUserHome () {
13691 String userHome = System .getProperty ("user.home" );
13792 if (userHome == null ) {
13893 throw new IllegalStateException ("user.home system property is required" );
0 commit comments