Externalize OpenVPN tools path configuration

This commit is contained in:
litoral05
2026-05-05 11:57:54 +01:00
parent ea0b002af1
commit 2b8aa685b0
4 changed files with 30 additions and 5 deletions
@@ -1,12 +1,16 @@
package com.litoralregas.openvpn;
import com.litoralregas.openvpn.openvpn.OpenVpnProperties;
import com.litoralregas.openvpn.ssh.VpsSshProperties;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@SpringBootApplication
@EnableConfigurationProperties(VpsSshProperties.class)
@EnableConfigurationProperties({
VpsSshProperties.class,
OpenVpnProperties.class
})
public class LrOpenvpnBackendApplication {
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
public class OpenVpnService {
private static final String TOOLS_PATH = "/var/litoral_regas_openvpn/tools";
private final OpenVpnProperties properties;
private final SshService sshService;
public OpenVpnService(SshService sshService) {
public OpenVpnService(SshService sshService, OpenVpnProperties properties) {
this.sshService = sshService;
this.properties = properties;
}
public List<OpenVpnClientResponse> listClients() {
var result = sshService.executeOnConfiguredVps(
TOOLS_PATH + "/list-clients.sh"
properties.getToolsPath() + "/list-clients.sh"
);
if (result.exitCode() != 0) {
+4 -1
View File
@@ -30,4 +30,7 @@ lr:
host: ${LR_VPS_SSH_HOST}
port: ${LR_VPS_SSH_PORT:22}
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}