Configure VPS SSH connection from environment variables
This commit is contained in:
@@ -3,6 +3,7 @@ package com.litoralregas.openvpn.router;
|
||||
import com.litoralregas.openvpn.deployment.DeploymentAction;
|
||||
import com.litoralregas.openvpn.deployment.DeploymentResponse;
|
||||
import com.litoralregas.openvpn.deployment.DeploymentService;
|
||||
import com.litoralregas.openvpn.ssh.SshService;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -15,10 +16,12 @@ public class RouterController {
|
||||
|
||||
private final RouterService service;
|
||||
private final DeploymentService deploymentService;
|
||||
private final SshService sshService;
|
||||
|
||||
public RouterController(RouterService service, DeploymentService deploymentService) {
|
||||
public RouterController(RouterService service, DeploymentService deploymentService, SshService sshService) {
|
||||
this.service = service;
|
||||
this.deploymentService = deploymentService;
|
||||
this.sshService = sshService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@@ -58,24 +61,22 @@ public class RouterController {
|
||||
try {
|
||||
service.forceStatus(id, RouterStatus.PROVISIONING);
|
||||
|
||||
// Simulated provisioning for now.
|
||||
var finishedDeployment = deploymentService.finishSuccess(
|
||||
deployment,
|
||||
"Provision completed successfully"
|
||||
);
|
||||
var result = sshService.executeOnConfiguredVps("whoami && hostname");
|
||||
|
||||
service.forceStatus(id, RouterStatus.PROVISIONED);
|
||||
|
||||
return DeploymentResponse.from(finishedDeployment);
|
||||
} catch (Exception exception) {
|
||||
var failedDeployment = deploymentService.finishFailure(
|
||||
deployment,
|
||||
exception.getMessage()
|
||||
);
|
||||
if (result.exitCode() == 0) {
|
||||
var finished = deploymentService.finishSuccess(deployment, result.stdout());
|
||||
service.forceStatus(id, RouterStatus.PROVISIONED);
|
||||
return DeploymentResponse.from(finished);
|
||||
} else {
|
||||
var failed = deploymentService.finishFailure(deployment, result.stderr());
|
||||
service.forceStatus(id, RouterStatus.FAILED);
|
||||
return DeploymentResponse.from(failed);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
var failed = deploymentService.finishFailure(deployment, e.getMessage());
|
||||
service.forceStatus(id, RouterStatus.FAILED);
|
||||
|
||||
return DeploymentResponse.from(failedDeployment);
|
||||
return DeploymentResponse.from(failed);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user