src/main/java/org/embulk/output/sftp/SftpUtils.java in embulk-output-sftp-0.1.8 vs src/main/java/org/embulk/output/sftp/SftpUtils.java in embulk-output-sftp-0.1.9
- old
+ new
@@ -33,10 +33,11 @@
{
private final Logger logger = Exec.getLogger(SftpUtils.class);
private final DefaultFileSystemManager manager;
private final FileSystemOptions fsOptions;
private final String userInfo;
+ private final String user;
private final String host;
private final int port;
private final int maxConnectionRetry;
private DefaultFileSystemManager initializeStandardFileSystemManager()
@@ -125,10 +126,11 @@
SftpUtils(PluginTask task)
{
this.manager = initializeStandardFileSystemManager();
this.userInfo = initializeUserInfo(task);
+ this.user = task.getUser();
this.fsOptions = initializeFsOptions(task);
this.host = task.getHost();
this.port = task.getPort();
this.maxConnectionRetry = task.getMaxConnectionRetry();
}
@@ -180,10 +182,13 @@
}
@Override
public boolean isRetryableException(Exception exception)
{
+ if (exception instanceof ConfigException) {
+ return false;
+ }
return true;
}
@Override
public void onRetry(Exception exception, int retryCount, int retryLimit, int retryWait) throws RetryGiveupException
@@ -262,17 +267,31 @@
catch (InterruptedException ex) {
throw Throwables.propagate(ex);
}
}
+ public void validateHost(PluginTask task)
+ {
+ if (task.getHost().contains("%s")) {
+ throw new ConfigException("'host' can't contain spaces");
+ }
+ getSftpFileUri("/");
+
+ if (task.getProxy().isPresent() && task.getProxy().get().getHost().isPresent()) {
+ if (task.getProxy().get().getHost().get().contains("%s")) {
+ throw new ConfigException("'proxy.host' can't contains spaces");
+ }
+ }
+ }
+
private URI getSftpFileUri(String remoteFilePath)
{
try {
return new URI("sftp", userInfo, host, port, remoteFilePath, null, null);
}
catch (URISyntaxException e) {
- logger.error(e.getMessage());
- throw new ConfigException(e);
+ String message = String.format("URISyntaxException was thrown: Illegal character in sftp://%s:******@%s:%s%s", user, host, port, remoteFilePath);
+ throw new ConfigException(message);
}
}
private FileObject newSftpFile(final URI sftpUri) throws FileSystemException
{