mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-11-21 23:20:23 +00:00
Add enable api setting
This commit is contained in:
parent
44ba765e30
commit
a8e8c13f18
15 changed files with 71 additions and 1 deletions
|
@ -39,6 +39,10 @@ public class BeaconRequestHandler<T> implements HttpHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (beaconInterface.requiresEnabledApi() && !AppPrefs.get().enableHttpApi().get()) {
|
||||||
|
throw ErrorEvent.expected(new IllegalStateException("HTTP API is not enabled in the settings menu"));
|
||||||
|
}
|
||||||
|
|
||||||
if (!AppPrefs.get().disableApiAuthentication().get() && beaconInterface.requiresAuthentication()) {
|
if (!AppPrefs.get().disableApiAuthentication().get() && beaconInterface.requiresAuthentication()) {
|
||||||
var auth = exchange.getRequestHeaders().getFirst("Authorization");
|
var auth = exchange.getRequestHeaders().getFirst("Authorization");
|
||||||
if (auth == null) {
|
if (auth == null) {
|
||||||
|
|
|
@ -36,4 +36,9 @@ public class AskpassExchangeImpl extends AskpassExchange {
|
||||||
}
|
}
|
||||||
return Response.builder().value(secret.inPlace()).build();
|
return Response.builder().value(secret.inPlace()).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean requiresEnabledApi() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,4 +12,9 @@ public class DaemonFocusExchangeImpl extends DaemonFocusExchange {
|
||||||
OperationMode.switchUp(OperationMode.map(msg.getMode()));
|
OperationMode.switchUp(OperationMode.map(msg.getMode()));
|
||||||
return Response.builder().build();
|
return Response.builder().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean requiresEnabledApi() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,4 +25,9 @@ public class DaemonModeExchangeImpl extends DaemonModeExchange {
|
||||||
.usedMode(OperationMode.map(OperationMode.get()))
|
.usedMode(OperationMode.map(OperationMode.get()))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean requiresEnabledApi() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,4 +21,9 @@ public class DaemonOpenExchangeImpl extends DaemonOpenExchange {
|
||||||
LauncherInput.handle(msg.getArguments());
|
LauncherInput.handle(msg.getArguments());
|
||||||
return Response.builder().build();
|
return Response.builder().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean requiresEnabledApi() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,4 +23,9 @@ public class DaemonStatusExchangeImpl extends DaemonStatusExchange {
|
||||||
|
|
||||||
return Response.builder().mode(mode).build();
|
return Response.builder().mode(mode).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean requiresEnabledApi() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,4 +21,9 @@ public class DaemonStopExchangeImpl extends DaemonStopExchange {
|
||||||
});
|
});
|
||||||
return Response.builder().success(true).build();
|
return Response.builder().success(true).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean requiresEnabledApi() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,4 +31,9 @@ public class DaemonVersionExchangeImpl extends DaemonVersionExchange {
|
||||||
.pro(pro)
|
.pro(pro)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean requiresEnabledApi() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,4 +42,9 @@ public class HandshakeExchangeImpl extends HandshakeExchange {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean requiresEnabledApi() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package io.xpipe.app.beacon.impl;
|
||||||
|
|
||||||
import com.sun.net.httpserver.HttpExchange;
|
import com.sun.net.httpserver.HttpExchange;
|
||||||
import io.xpipe.app.util.TerminalLauncherManager;
|
import io.xpipe.app.util.TerminalLauncherManager;
|
||||||
import io.xpipe.beacon.BeaconClientException;
|
|
||||||
import io.xpipe.beacon.api.SshLaunchExchange;
|
import io.xpipe.beacon.api.SshLaunchExchange;
|
||||||
import io.xpipe.core.process.ProcessControlProvider;
|
import io.xpipe.core.process.ProcessControlProvider;
|
||||||
import io.xpipe.core.process.ShellDialects;
|
import io.xpipe.core.process.ShellDialects;
|
||||||
|
@ -35,4 +34,9 @@ public class SshLaunchExchangeImpl extends SshLaunchExchange {
|
||||||
.buildBaseParts(null);
|
.buildBaseParts(null);
|
||||||
return Response.builder().command(c).build();
|
return Response.builder().command(c).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean requiresEnabledApi() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,4 +12,9 @@ public class TerminalLaunchExchangeImpl extends TerminalLaunchExchange {
|
||||||
var r = TerminalLauncherManager.performLaunch(msg.getRequest());
|
var r = TerminalLauncherManager.performLaunch(msg.getRequest());
|
||||||
return Response.builder().targetFile(r).build();
|
return Response.builder().targetFile(r).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean requiresEnabledApi() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,4 +13,9 @@ public class TerminalWaitExchangeImpl extends TerminalWaitExchange {
|
||||||
TerminalLauncherManager.waitForCompletion(msg.getRequest());
|
TerminalLauncherManager.waitForCompletion(msg.getRequest());
|
||||||
return Response.builder().build();
|
return Response.builder().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean requiresEnabledApi() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,8 @@ public class AppPrefs {
|
||||||
private static AppPrefs INSTANCE;
|
private static AppPrefs INSTANCE;
|
||||||
private final List<Mapping<?>> mapping = new ArrayList<>();
|
private final List<Mapping<?>> mapping = new ArrayList<>();
|
||||||
|
|
||||||
|
final BooleanProperty enableHttpApi =
|
||||||
|
mapVaultSpecific(new SimpleBooleanProperty(false), "enableHttpApi", Boolean.class);
|
||||||
final BooleanProperty dontAutomaticallyStartVmSshServer =
|
final BooleanProperty dontAutomaticallyStartVmSshServer =
|
||||||
mapVaultSpecific(new SimpleBooleanProperty(false), "dontAutomaticallyStartVmSshServer", Boolean.class);
|
mapVaultSpecific(new SimpleBooleanProperty(false), "dontAutomaticallyStartVmSshServer", Boolean.class);
|
||||||
final BooleanProperty dontAcceptNewHostKeys =
|
final BooleanProperty dontAcceptNewHostKeys =
|
||||||
|
@ -144,6 +146,10 @@ public class AppPrefs {
|
||||||
return disableApiAuthentication;
|
return disableApiAuthentication;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ObservableBooleanValue enableHttpApi() {
|
||||||
|
return enableHttpApi;
|
||||||
|
}
|
||||||
|
|
||||||
private final IntegerProperty editorReloadTimeout =
|
private final IntegerProperty editorReloadTimeout =
|
||||||
map(new SimpleIntegerProperty(1000), "editorReloadTimeout", Integer.class);
|
map(new SimpleIntegerProperty(1000), "editorReloadTimeout", Integer.class);
|
||||||
private final BooleanProperty confirmDeletions =
|
private final BooleanProperty confirmDeletions =
|
||||||
|
|
|
@ -16,6 +16,8 @@ public class HttpApiCategory extends AppPrefsCategory {
|
||||||
return new OptionsBuilder()
|
return new OptionsBuilder()
|
||||||
.addTitle("httpServerConfiguration")
|
.addTitle("httpServerConfiguration")
|
||||||
.sub(new OptionsBuilder()
|
.sub(new OptionsBuilder()
|
||||||
|
.nameAndDescription("enableHttpApi")
|
||||||
|
.addToggle(prefs.enableHttpApi)
|
||||||
.nameAndDescription("apiKey")
|
.nameAndDescription("apiKey")
|
||||||
.addString(prefs.apiKey)
|
.addString(prefs.apiKey)
|
||||||
.nameAndDescription("disableApiAuthentication")
|
.nameAndDescription("disableApiAuthentication")
|
||||||
|
|
|
@ -83,4 +83,8 @@ public abstract class BeaconInterface<T> {
|
||||||
public boolean readRawRequestBody() {
|
public boolean readRawRequestBody() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean requiresEnabledApi() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue