starter配置方式启动跳板机

This commit is contained in:
xgc
2024-01-25 10:39:40 +08:00
parent 3f2e86be31
commit a4eead50a0
4 changed files with 20 additions and 0 deletions
@@ -1,9 +1,12 @@
package org.dromara.neutrinoproxy.client.starter.config;
import lombok.Data;
import org.dromara.neutrinoproxy.client.starter.ssh.SSHProxy;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import java.util.List;
/**
*
* @author: gc.x
@@ -14,9 +17,11 @@ import org.springframework.stereotype.Component;
@Component
public class SpringProxyConfig {
private Boolean enable=false;
private Boolean sshEnable=false;
private Protocol protocol;
private Tunnel tunnel;
private Client client;
private List<SSHProxy> sshProxys;
@Data
public static class Protocol {
@@ -5,6 +5,7 @@ import lombok.extern.slf4j.Slf4j;
import org.dromara.neutrinoproxy.client.sdk.config.ProxyConfig;
import org.dromara.neutrinoproxy.client.starter.config.ProxyConfiguration;
import org.dromara.neutrinoproxy.client.starter.config.SpringProxyConfig;
import org.dromara.neutrinoproxy.client.starter.ssh.SSHConnectionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
@@ -31,5 +32,11 @@ public class ProxyClientService implements ApplicationRunner {
proxyConfiguration.start(proxyConfig);
log.info("start success!");
}
if(springProxyConfig.getSshEnable()){
springProxyConfig.getSshProxys().forEach(sshProxy -> {
String sshId = SSHConnectionFactory.factory.addConnection(sshProxy);
SSHConnectionFactory.factory.openTunnel(sshId);
});
}
}
}
@@ -7,6 +7,7 @@ package org.dromara.neutrinoproxy.client.starter.ssh;
*/
public interface SSHConnectionService {
String addConnection(String host, String username, String password, int localPort, int remotePort,String remoteHost);
String addConnection(SSHProxy sshProxy);
void openTunnel(String sshId);
void closeTunnel(String sshId);
void closeAllTunnels();
@@ -32,6 +32,13 @@ public class SSHConnectionServiceImpl implements SSHConnectionService {
connections.put(connection.getSshId(), connection);
return sshId;
}
@Override
public String addConnection(SSHProxy sshProxy) {
String sshId = UUID.randomUUID().toString();
sshProxy.setSshId(sshId);
connections.put(sshProxy.getSshId(), sshProxy);
return sshId;
}
@Override
public void openTunnel(String sshId) {