starter配置方式启动跳板机
This commit is contained in:
+5
@@ -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 {
|
||||
|
||||
+7
@@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -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();
|
||||
|
||||
+7
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user