Implement full OpenVPN lifecycle: provisioning, removal, IP allocation, and SSH integration

This commit is contained in:
litoral05
2026-05-05 15:12:51 +01:00
parent 40ae52f00e
commit 78cb539508
2 changed files with 40 additions and 12 deletions
@@ -113,4 +113,28 @@ public class OpenVpnService {
public boolean isDryRun() {
return properties.isProvisionDryRun();
}
public String buildRemoveCommand(String clientName, String lanSubnet) {
validateShellSafe(clientName);
validateShellSafe(lanSubnet);
return properties.getToolsPath()
+ "/remove-client.sh "
+ clientName + " "
+ lanSubnet;
}
public SshCommandResult removeClient(String clientName, String lanSubnet) {
String command = buildRemoveCommand(clientName, lanSubnet);
if (properties.isProvisionDryRun()) {
return new SshCommandResult(
0,
"DRY RUN ONLY. Would execute: " + command,
""
);
}
return sshService.executeOnConfiguredVps(command);
}
}
@@ -45,13 +45,6 @@ public class RouterController {
return service.findById(id);
}
@PatchMapping("/{id}/status")
public Router updateStatus(
@PathVariable UUID id,
@Valid @RequestBody UpdateRouterStatusRequest request
) {
return service.updateStatus(id, request);
}
@DeleteMapping("/{id}")
public void delete(@PathVariable UUID id) {
@@ -122,21 +115,32 @@ public class RouterController {
var deployment = deploymentService.startDeployment(router, DeploymentAction.REMOVE);
try {
service.forceStatus(id, RouterStatus.PROVISIONING); // or REMOVING if you want later
service.forceStatus(id, RouterStatus.REMOVING);
var result = sshService.executeOnConfiguredVps(
"echo 'Removing router: " + router.getName() + "' && whoami && hostname"
var allocation = ipAllocationService.findByRouterId(id);
var result = openVpnService.removeClient(
allocation.getClientName(),
allocation.getLanSubnet()
);
if (result.exitCode() != 0) {
throw new IllegalStateException(result.stderr());
throw new IllegalStateException(
"Remove failed. stdout: " + result.stdout()
+ " stderr: " + result.stderr()
);
}
var finished = deploymentService.finishSuccess(
deployment,
result.stdout()
);
if (openVpnService.isDryRun()) {
service.forceStatus(id, RouterStatus.PROVISIONED);
} else {
service.forceStatus(id, RouterStatus.REMOVED);
}
return DeploymentResponse.from(finished);
} catch (Exception e) {