WIP: ssh-agent support using jsch-agent-proxy
This commit is contained in:
@@ -7,5 +7,6 @@
|
||||
<factorypathentry kind="VARJAR" id="M2_REPO/org/checkerframework/checker-compat-qual/2.5.5/checker-compat-qual-2.5.5.jar" enabled="true" runInBatchMode="false"/>
|
||||
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/errorprone/error_prone_annotations/2.3.4/error_prone_annotations-2.3.4.jar" enabled="true" runInBatchMode="false"/>
|
||||
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/j2objc/j2objc-annotations/1.3/j2objc-annotations-1.3.jar" enabled="true" runInBatchMode="false"/>
|
||||
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/code/gson/gson/2.8.6/gson-2.8.6.jar" enabled="true" runInBatchMode="false"/>
|
||||
<factorypathentry kind="VARJAR" id="M2_REPO/org/projectlombok/lombok/1.18.16/lombok-1.18.16.jar" enabled="true" runInBatchMode="false"/>
|
||||
</factorypath>
|
||||
|
@@ -10,24 +10,24 @@ import java.io.IOException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Random;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.io.CharSource;
|
||||
import com.google.common.io.ByteStreams;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
import net.monarchpass.piecannon.util.ServerFactory;
|
||||
|
||||
import lombok.Setter;
|
||||
import lombok.Getter;
|
||||
|
||||
public class PieCannon {
|
||||
public List<Server> servers;
|
||||
public @Getter @Setter ServerFactory serverFactory = new ServerFactory();
|
||||
|
||||
public List<Server> loadServersFrom (final File serversJson) throws IOException {
|
||||
try (final InputStream in = new FileInputStream(serversJson)) {
|
||||
@@ -36,7 +36,6 @@ public class PieCannon {
|
||||
}
|
||||
|
||||
public List<Server> loadServersFrom (final InputStream in) throws IOException {
|
||||
final ServerFactory factory = new ServerFactory();
|
||||
final JsonParser parser = new JsonParser();
|
||||
final List<Server> loadedServers = new ArrayList<>();
|
||||
for (final JsonElement element : parser.parse(new InputStreamReader(in)).getAsJsonArray()) {
|
||||
@@ -44,7 +43,7 @@ public class PieCannon {
|
||||
continue;
|
||||
}
|
||||
|
||||
loadedServers.add(factory.apply((JsonObject)element));
|
||||
loadedServers.add(serverFactory.apply((JsonObject)element));
|
||||
}
|
||||
servers = loadedServers;
|
||||
return loadedServers;
|
||||
|
@@ -13,6 +13,7 @@ import com.jcraft.jsch.Channel;
|
||||
import com.jcraft.jsch.ChannelSftp;
|
||||
import com.jcraft.jsch.JSchException;
|
||||
import com.jcraft.jsch.SftpException;
|
||||
import com.jcraft.jsch.IdentityRepository;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@@ -25,12 +26,17 @@ public class SftpServer implements Server {
|
||||
private final String password;
|
||||
private final String path;
|
||||
private final URI uri;
|
||||
private final IdentityRepository identityRepository;
|
||||
|
||||
public URI upload (String name, ByteSource source) {
|
||||
try {
|
||||
final URI target = URI.create(uri.toString() + "/" + name.replace(" ", "%20"));
|
||||
|
||||
final JSch jsch = new JSch();
|
||||
if (identityRepository != null) {
|
||||
jsch.setIdentityRepository(identityRepository);
|
||||
}
|
||||
|
||||
final Session session = jsch.getSession(username, host, port);
|
||||
session.setPassword(password);
|
||||
session.setConfig("StrictHostKeyChecking", "no");
|
||||
|
@@ -5,10 +5,16 @@ import java.net.URI;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.jcraft.jsch.IdentityRepository;
|
||||
|
||||
import net.monarchpass.piecannon.Server;
|
||||
import net.monarchpass.piecannon.impl.SftpServer;
|
||||
|
||||
import lombok.Setter;
|
||||
|
||||
public class ServerFactory implements Function<JsonObject, Server> {
|
||||
private @Setter IdentityRepository identityRepository;
|
||||
|
||||
public Server apply (final JsonObject object) {
|
||||
return makeSftpServer(object);
|
||||
}
|
||||
@@ -24,7 +30,7 @@ public class ServerFactory implements Function<JsonObject, Server> {
|
||||
|
||||
return new SftpServer(
|
||||
label, host, port, username, password,
|
||||
path, URI.create(url)
|
||||
path, URI.create(url), identityRepository
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -22,7 +22,7 @@ public class SftpTest {
|
||||
final Server server = new SftpServer(
|
||||
"Test Server Instance", testServerHost, 22,
|
||||
testServerUser, testServerPassword, testServerPath,
|
||||
URI.create(testServerURL)
|
||||
URI.create(testServerURL), null
|
||||
);
|
||||
|
||||
assertThat(PieCannon.testServer(server)).isTrue();
|
||||
|
Reference in New Issue
Block a user