package org.embulk.output.sftp; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonValue; import com.google.common.base.Optional; import org.apache.commons.vfs2.FileSystemOptions; import org.apache.commons.vfs2.provider.sftp.SftpFileSystemConfigBuilder; import org.embulk.config.Config; import org.embulk.config.ConfigDefault; import org.embulk.config.ConfigException; import org.embulk.config.Task; import java.util.Locale; interface ProxyTask extends Task { @Config("type") public ProxyType getType(); @Config("host") public Optional getHost(); @Config("user") @ConfigDefault("null") public Optional getUser(); @Config("password") @ConfigDefault("null") public Optional getPassword(); @Config("port") @ConfigDefault("22") public int getPort(); @Config("command") @ConfigDefault("null") public Optional getCommand(); public enum ProxyType { HTTP, SOCKS, STREAM; @JsonValue @Override public String toString() { return name().toLowerCase(Locale.ENGLISH); } @JsonCreator public static ProxyType fromString(String value) { switch (value) { case "http": return HTTP; case "socks": return SOCKS; case "stream": return STREAM; default: throw new ConfigException(String.format("Unknown proxy type '%s'. Supported proxy types are http, socks, stream", value)); } } public static SftpFileSystemConfigBuilder setProxyType(SftpFileSystemConfigBuilder builder, FileSystemOptions fsOptions, ProxyTask.ProxyType type) { SftpFileSystemConfigBuilder.ProxyType setType = null; switch (type) { case HTTP: setType = SftpFileSystemConfigBuilder.PROXY_HTTP; break; case SOCKS: setType = SftpFileSystemConfigBuilder.PROXY_SOCKS5; break; case STREAM: setType = SftpFileSystemConfigBuilder.PROXY_STREAM; } builder.setProxyType(fsOptions, setType); return builder; } } }