From 2b8aa685b0a1ba87ce9e2c0dfbfa1424b6d4450f Mon Sep 17 00:00:00 2001 From: litoral05 Date: Tue, 5 May 2026 11:57:54 +0100 Subject: [PATCH] Externalize OpenVPN tools path configuration --- .../openvpn/LrOpenvpnBackendApplication.java | 6 +++++- .../openvpn/openvpn/OpenVpnProperties.java | 17 +++++++++++++++++ .../openvpn/openvpn/OpenVpnService.java | 7 ++++--- src/main/resources/application.yaml | 5 ++++- 4 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/litoralregas/openvpn/openvpn/OpenVpnProperties.java diff --git a/src/main/java/com/litoralregas/openvpn/LrOpenvpnBackendApplication.java b/src/main/java/com/litoralregas/openvpn/LrOpenvpnBackendApplication.java index 277f0d7..9fc2848 100644 --- a/src/main/java/com/litoralregas/openvpn/LrOpenvpnBackendApplication.java +++ b/src/main/java/com/litoralregas/openvpn/LrOpenvpnBackendApplication.java @@ -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) { diff --git a/src/main/java/com/litoralregas/openvpn/openvpn/OpenVpnProperties.java b/src/main/java/com/litoralregas/openvpn/openvpn/OpenVpnProperties.java new file mode 100644 index 0000000..9b8245f --- /dev/null +++ b/src/main/java/com/litoralregas/openvpn/openvpn/OpenVpnProperties.java @@ -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; + } +} \ No newline at end of file diff --git a/src/main/java/com/litoralregas/openvpn/openvpn/OpenVpnService.java b/src/main/java/com/litoralregas/openvpn/openvpn/OpenVpnService.java index 9b8e666..f9c8a5c 100644 --- a/src/main/java/com/litoralregas/openvpn/openvpn/OpenVpnService.java +++ b/src/main/java/com/litoralregas/openvpn/openvpn/OpenVpnService.java @@ -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 listClients() { var result = sshService.executeOnConfiguredVps( - TOOLS_PATH + "/list-clients.sh" + properties.getToolsPath() + "/list-clients.sh" ); if (result.exitCode() != 0) { diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 3352c58..88c4dc5 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -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} \ No newline at end of file + password: ${LR_VPS_SSH_PASSWORD} + + openvpn: + tools-path: ${LR_OPENVPN_TOOLS_PATH:/var/litoral_regas_openvpn/tools} \ No newline at end of file