Rework beacon auth file

This commit is contained in:
crschnick
2025-12-19 14:56:37 +00:00
parent 1ae9115b94
commit a24804e9a3
4 changed files with 20 additions and 7 deletions
@@ -3,6 +3,7 @@ package io.xpipe.app.beacon;
import io.xpipe.app.beacon.mcp.AppMcpServer;
import io.xpipe.app.issue.ErrorEventFactory;
import io.xpipe.app.issue.TrackEvent;
import io.xpipe.app.process.ShellTemp;
import io.xpipe.app.util.DocumentationLink;
import io.xpipe.beacon.BeaconConfig;
import io.xpipe.beacon.BeaconInterface;
@@ -120,6 +121,8 @@ public class AppBeaconServer {
}
private void initAuthSecret() throws IOException {
// Create temp dir and permissions for Linux
ShellTemp.getLocalTempDataDirectory(null);
var file = BeaconConfig.getLocalBeaconAuthFile();
var id = UUID.randomUUID().toString();
Files.writeString(file, id);
@@ -1,5 +1,7 @@
package io.xpipe.app.process;
import io.xpipe.app.core.AppInstallation;
import io.xpipe.app.core.AppNames;
import io.xpipe.app.core.AppProperties;
import io.xpipe.app.core.AppSystemInfo;
import io.xpipe.app.issue.ErrorEventFactory;
@@ -16,7 +18,7 @@ import java.nio.file.attribute.PosixFilePermissions;
public class ShellTemp {
public static Path getLocalTempDataDirectory(String sub) {
var temp = AppSystemInfo.ofCurrent().getTemp().resolve("xpipe");
var temp = AppSystemInfo.ofCurrent().getTemp().resolve(AppNames.ofCurrent().getKebapName());
// On Windows and macOS, we already have user specific temp directories
// Even on macOS as root we will have a unique directory (in contrast to shell controls)
if (OsType.ofLocal() == OsType.LINUX) {
@@ -27,8 +29,8 @@ public class ShellTemp {
ErrorEventFactory.fromThrowable(e).omit().expected().handle();
}
var user = System.getenv("USER");
temp = temp.resolve(user != null ? user : "user");
var user = AppSystemInfo.ofCurrent().getUser();
temp = temp.resolve(user);
}
return sub != null ? temp.resolve(sub) : temp;
@@ -40,7 +42,7 @@ public class ShellTemp {
// Even on macOS as root it is technically unique as only root will use /tmp
if (proc.getOsType() != OsType.WINDOWS && proc.getOsType() != OsType.MACOS) {
var temp = proc.getSystemTemporaryDirectory();
base = temp.join("xpipe");
base = temp.join(AppNames.ofCurrent().getKebapName());
proc.view().mkdir(base);
// We have to make sure that also other users can create files here
// This command should work in all shells
@@ -50,7 +52,7 @@ public class ShellTemp {
base = base.join(user);
} else {
var temp = proc.getSystemTemporaryDirectory();
base = temp.join("xpipe");
base = temp.join(AppNames.ofCurrent().getKebapName());
}
return sub != null ? base.join(sub) : base;
}
@@ -81,7 +81,8 @@ public class ZellijTerminalMultiplexer implements TerminalMultiplexer {
"zellij -s xpipe action write-chars -- " + escape(" " + firstCommand, true, true) + "\\;exit",
"zellij -s xpipe action write 10",
"zellij -s xpipe action clear",
"zellij -s xpipe action rename-tab \"" + escape(config.getColoredTitle(), false, true) + "\"",
"zellij -s xpipe action rename-tab \"" + escape(config.getColoredTitle(), false, true) + "\"",
"sleep 0.5",
"zellij -s xpipe action go-to-previous-tab",
"zellij -s xpipe action close-tab"));
@@ -1,5 +1,6 @@
package io.xpipe.beacon;
import io.xpipe.core.OsType;
import lombok.experimental.UtilityClass;
import java.nio.file.Path;
@@ -55,6 +56,12 @@ public class BeaconConfig {
var staging = Optional.ofNullable(System.getProperty("io.xpipe.app.staging"))
.map(Boolean::parseBoolean)
.orElse(false);
return Path.of(System.getProperty("java.io.tmpdir"), staging ? "xpipe_ptb_auth" : "xpipe_auth");
if (OsType.ofLocal() == OsType.LINUX) {
return Path.of(System.getProperty("java.io.tmpdir"), staging ? "xpipe-ptb" : "xpipe",
System.getProperty("user.name"), "beacon-auth");
} else {
return Path.of(System.getProperty("java.io.tmpdir"), staging ? "xpipe-ptb" : "xpipe",
"beacon-auth");
}
}
}