Apply WireGuard peers to VPS safely
This commit is contained in:
@@ -44,4 +44,25 @@ public class WireGuardVpsService {
|
||||
|
||||
return ips;
|
||||
}
|
||||
|
||||
public WireGuardPeerApplyResult applyPeer(String publicKey, String allowedIps) {
|
||||
|
||||
String command = """
|
||||
sudo /usr/local/sbin/lr-wg-add-peer '%s' '%s'
|
||||
""".formatted(publicKey, allowedIps);
|
||||
|
||||
SshCommandResult result = sshService.executeOnConfiguredVps(command);
|
||||
|
||||
if (result.exitCode() != 0) {
|
||||
throw new SshCommandException(
|
||||
"Failed to apply WireGuard peer: " + result.stderr()
|
||||
);
|
||||
}
|
||||
|
||||
return new WireGuardPeerApplyResult(
|
||||
publicKey,
|
||||
allowedIps,
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user