Add safe OpenVPN preflight and dry-run provisioning

This commit is contained in:
litoral05
2026-05-05 14:05:21 +01:00
parent 6f70cbfe67
commit 40ae52f00e
4 changed files with 64 additions and 6 deletions
@@ -69,20 +69,38 @@ public class RouterController {
var allocation = ipAllocationService.findByRouterId(id);
String command = openVpnService.buildProvisionCommand(
var preflight = openVpnService.runPreflightCheck();
if (preflight.exitCode() != 0) {
throw new IllegalStateException(
"Preflight failed. stdout: " + preflight.stdout()
+ " stderr: " + preflight.stderr()
);
}
var result = openVpnService.provisionClient(
allocation.getClientName(),
allocation.getLanSubnet(),
allocation.getVpnIp()
);
if (result.exitCode() != 0) {
throw new IllegalStateException(
"Provision failed. stdout: " + result.stdout()
+ " stderr: " + result.stderr()
);
}
var finishedDeployment = deploymentService.finishSuccess(
deployment,
"DRY RUN ONLY. Would execute: " + command
result.stdout()
);
// Keep this as PROVISIONING? No — dry run succeeded but real provision did not happen.
// So we should NOT mark as PROVISIONED yet.
service.forceStatus(id, RouterStatus.PENDING);
if (openVpnService.isDryRun()) {
service.forceStatus(id, RouterStatus.PENDING);
} else {
service.forceStatus(id, RouterStatus.PROVISIONED);
}
return DeploymentResponse.from(finishedDeployment);
} catch (Exception exception) {