Skip to content

Commit

Permalink
Add access-filter file with fixed path
Browse files Browse the repository at this point in the history
  • Loading branch information
dnestoro committed Sep 3, 2024
1 parent 9e9703c commit ef4b536
Showing 1 changed file with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ public AgentConfiguration(Collection<String> callerFilterFiles,
AgentMode agentMode) {
this.callerFilterFiles = callerFilterFiles;
this.accessFilterFiles = accessFilterFiles;
addDefaultAccessFilter();
this.builtinCallerFilter = builtinCallerFilter;
this.builtinHeuristicFilter = builtinHeuristicFilter;
this.experimentalPredefinedClasses = experimentalPredefinedClasses;
Expand All @@ -97,6 +96,7 @@ public AgentConfiguration(Collection<String> callerFilterFiles,
}

public List<String> getAgentCommandLine() {
addDefaultAccessFilter();
List<String> cmdLine = new ArrayList<>(agentMode.getAgentCommandLine());
appendOptionToValues("caller-filter-file=", callerFilterFiles, cmdLine);
appendOptionToValues("access-filter-file=", accessFilterFiles, cmdLine);
Expand Down Expand Up @@ -137,11 +137,27 @@ private void addToCmd(String option, Boolean value, List<String> cmdLine) {
}

private void addDefaultAccessFilter() {
if (accessFilterFiles == null) {
// this could only happen if we instantiated disabled agent configuration
return;
}

String tempDir = System.getProperty("java.io.tmpdir");
Path agentDir = Path.of(tempDir).resolve("agent-config");
Path accessFilterFile = agentDir.resolve("access-filter.json");
if (Files.exists(accessFilterFile)) {
accessFilterFiles.add(accessFilterFile.toString());
return;
}

try(InputStream accessFilter = AgentConfiguration.class.getResourceAsStream(DEFAULT_ACCESS_FILTER_FILE)) {
if (accessFilter != null) {
Path accessFilterPath = Files.createTempFile("access-filter", ".json");
Files.copy(accessFilter, accessFilterPath, StandardCopyOption.REPLACE_EXISTING);
accessFilterFiles.add(accessFilterPath.toString());
if (!Files.exists(agentDir)) {
Files.createDirectory(agentDir);
}

Files.copy(accessFilter, accessFilterFile, StandardCopyOption.REPLACE_EXISTING);
accessFilterFiles.add(accessFilterFile.toString());
} else {
throw new IOException("Cannot find access-filter.json on default location: " + DEFAULT_ACCESS_FILTER_FILE);
}
Expand Down

0 comments on commit ef4b536

Please sign in to comment.