Externalize OpenVPN tools path configuration
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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}
|
||||
Reference in New Issue
Block a user