Externalize OpenVPN tools path configuration
This commit is contained in:
@@ -1,12 +1,16 @@
|
|||||||
package com.litoralregas.openvpn;
|
package com.litoralregas.openvpn;
|
||||||
|
|
||||||
|
import com.litoralregas.openvpn.openvpn.OpenVpnProperties;
|
||||||
import com.litoralregas.openvpn.ssh.VpsSshProperties;
|
import com.litoralregas.openvpn.ssh.VpsSshProperties;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@EnableConfigurationProperties(VpsSshProperties.class)
|
@EnableConfigurationProperties({
|
||||||
|
VpsSshProperties.class,
|
||||||
|
OpenVpnProperties.class
|
||||||
|
})
|
||||||
public class LrOpenvpnBackendApplication {
|
public class LrOpenvpnBackendApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package com.litoralregas.openvpn.openvpn;
|
||||||
|
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
|
||||||
|
@ConfigurationProperties(prefix = "lr.openvpn")
|
||||||
|
public class OpenVpnProperties {
|
||||||
|
|
||||||
|
private String toolsPath;
|
||||||
|
|
||||||
|
public String getToolsPath() {
|
||||||
|
return toolsPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setToolsPath(String toolsPath) {
|
||||||
|
this.toolsPath = toolsPath;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,17 +9,18 @@ import java.util.List;
|
|||||||
@Service
|
@Service
|
||||||
public class OpenVpnService {
|
public class OpenVpnService {
|
||||||
|
|
||||||
private static final String TOOLS_PATH = "/var/litoral_regas_openvpn/tools";
|
private final OpenVpnProperties properties;
|
||||||
|
|
||||||
private final SshService sshService;
|
private final SshService sshService;
|
||||||
|
|
||||||
public OpenVpnService(SshService sshService) {
|
public OpenVpnService(SshService sshService, OpenVpnProperties properties) {
|
||||||
this.sshService = sshService;
|
this.sshService = sshService;
|
||||||
|
this.properties = properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<OpenVpnClientResponse> listClients() {
|
public List<OpenVpnClientResponse> listClients() {
|
||||||
var result = sshService.executeOnConfiguredVps(
|
var result = sshService.executeOnConfiguredVps(
|
||||||
TOOLS_PATH + "/list-clients.sh"
|
properties.getToolsPath() + "/list-clients.sh"
|
||||||
);
|
);
|
||||||
|
|
||||||
if (result.exitCode() != 0) {
|
if (result.exitCode() != 0) {
|
||||||
|
|||||||
@@ -31,3 +31,6 @@ lr:
|
|||||||
port: ${LR_VPS_SSH_PORT:22}
|
port: ${LR_VPS_SSH_PORT:22}
|
||||||
username: ${LR_VPS_SSH_USER}
|
username: ${LR_VPS_SSH_USER}
|
||||||
password: ${LR_VPS_SSH_PASSWORD}
|
password: ${LR_VPS_SSH_PASSWORD}
|
||||||
|
|
||||||
|
openvpn:
|
||||||
|
tools-path: ${LR_OPENVPN_TOOLS_PATH:/var/litoral_regas_openvpn/tools}
|
||||||
Reference in New Issue
Block a user