Skip to content

Commit

Permalink
fix review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
anh-bolt committed Aug 21, 2024
1 parent be2aae0 commit 851affc
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.axonivy.connector.sftp.demo;

public class Constants {
public static final String DUMMY = "dummy";
public static final String TEST_SFTP_SERVER_NAME = "dummy";

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
SftpClientDemoData #class
com.axonivy.connector.sftp.demo.SftpClientDemo #namespace
sftpName String #field
sftpName PERSISTENT #fieldModifier
sftpServerName String #field
sftpServerName PERSISTENT #fieldModifier
clientHost String #field
clientHost PERSISTENT #fieldModifier
clientPort Number #field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
"import com.axonivy.connector.sftp.service.SftpClientService;",
"import com.axonivy.connector.sftp.demo.Constants;",
"",
"in.sftpName = new String(Constants.DUMMY);",
"in.clientHost = SftpClientService.getClientHost(in.sftpName);",
"in.clientPort = Integer.parseInt(SftpClientService.getPort(in.sftpName));",
"in.clientUsername = SftpClientService.getUsername(in.sftpName);"
"in.sftpServerName = Constants.TEST_SFTP_SERVER_NAME;",
"in.clientHost = SftpClientService.getClientHost(in.sftpServerName);",
"in.clientPort = Integer.parseInt(SftpClientService.getPort(in.sftpServerName));",
"in.clientUsername = SftpClientService.getUsername(in.sftpServerName);"
]
}
},
Expand Down Expand Up @@ -84,8 +84,7 @@
"output" : {
"map" : {
"out" : "in",
"out.isFileUploaded" : "result.isSuccess",
"out.sftpName" : "in.sftpName"
"out.isFileUploaded" : "result.isSuccess"
}
},
"call" : {
Expand All @@ -95,7 +94,7 @@
{ "name" : "fileName", "type" : "String" }
],
"map" : {
"param.sftpName" : "in.sftpName",
"param.sftpName" : "in.sftpServerName",
"param.fileToBeUploaded" : "in.uploadedFile.getInputStream()",
"param.fileName" : "in.uploadedFile.getFileName()"
}
Expand Down Expand Up @@ -130,7 +129,7 @@
{ "name" : "remoteFileName", "type" : "String" }
],
"map" : {
"param.sftpName" : "in.sftpName",
"param.sftpName" : "in.sftpServerName",
"param.remoteFileName" : "in.fileToDownload.name"
}
}
Expand Down Expand Up @@ -212,7 +211,7 @@
{ "name" : "remoteDirectory", "type" : "String" }
],
"map" : {
"param.sftpName" : "in.sftpName",
"param.sftpName" : "in.sftpServerName",
"param.remoteDirectory" : "\".\""
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class SftpProcessTest {
private static final BpmProcess TEST_UPLOAD_FILE_PROCESS = BpmProcess.path("Sftp/SftpUploadFile");
private static final BpmProcess TEST_DOWNLOAD_FILE_PROCESS = BpmProcess.path("Sftp/SftpDownloadFile");

private static final String TEST_SFTP_NAME = "dummy";
private static final String TEST_SFTP_SERVER_NAME = "dummy";
private static final String TEST_FILE_NAME = "market_market_connector_sftp.pdf";
private static final long TEST_FILE_SIZE = 207569L;

Expand All @@ -53,7 +53,7 @@ public void callOpenConnection(BpmClient bpmClient) {

SubProcessCallResult result = bpmClient.start()
.subProcess(startable)
.execute(TEST_SFTP_NAME) // Callable sub process input arguments
.execute(TEST_SFTP_SERVER_NAME) // Callable sub process input arguments
.subResult();

SftpClientService sftpClient = result.param("sftpClient", SftpClientService.class);
Expand All @@ -70,7 +70,7 @@ public void callUploadFile(BpmClient bpmClient) {

SubProcessCallResult result = bpmClient.start()
.subProcess(startable)
.execute(TEST_SFTP_NAME, fileToBeUploaded, TEST_FILE_NAME) // Callable sub process input arguments
.execute(TEST_SFTP_SERVER_NAME, fileToBeUploaded, TEST_FILE_NAME) // Callable sub process input arguments
.subResult();

Boolean isSuccess = result.param("isSuccess", Boolean.class);
Expand All @@ -91,7 +91,7 @@ public void callUploadIvyFile(BpmClient bpmClient) throws IOException {

SubProcessCallResult result = bpmClient.start()
.subProcess(startable)
.execute(TEST_SFTP_NAME, ivyFile) // Callable sub process input arguments
.execute(TEST_SFTP_SERVER_NAME, ivyFile) // Callable sub process input arguments
.subResult();

Boolean isSuccess = result.param("isSuccess", Boolean.class);
Expand All @@ -105,7 +105,7 @@ public void callListAllFiles(BpmClient bpmClient) {

SubProcessCallResult result = bpmClient.start()
.subProcess(startable)
.execute(TEST_SFTP_NAME, ".") // Callable sub process input arguments
.execute(TEST_SFTP_SERVER_NAME, ".") // Callable sub process input arguments
.subResult();
List<FileData> listFiles = result.param("listFiles", List.class);
assertThat(listFiles.size()).isGreaterThanOrEqualTo(1);
Expand All @@ -119,7 +119,7 @@ public void callDownloadFile(BpmClient bpmClient) {

SubProcessCallResult result = bpmClient.start()
.subProcess(startable)
.execute(TEST_SFTP_NAME, TEST_FILE_NAME) // Callable sub process input arguments
.execute(TEST_SFTP_SERVER_NAME, TEST_FILE_NAME) // Callable sub process input arguments
.subResult();
java.io.File downloadedFile = result.param("toFile", java.io.File.class);
assertThat(downloadedFile.length()).isEqualTo(TEST_FILE_SIZE);
Expand Down
3 changes: 2 additions & 1 deletion sftp-connector/config/variables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ Variables:
# The username to the SFTP server
username: 'usr'

# Auth type to the SFPT server: password OR ssh
# Auth type to the SFPT server
# [enum: password, ssh]
auth: 'password'

# The password to the SFTP server
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.axonivy.connector.sftp.enums;

/**
* Enumeration types of authentication method used in SFTP client
*/
public enum AuthMethod {
PASSWORD,
SSH,

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Properties;

import org.apache.commons.lang3.StringUtils;
import ch.ivyteam.log.Logger;
Expand All @@ -19,9 +18,9 @@
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import com.jcraft.jsch.SftpException;

import ch.ivyteam.ivy.environment.Ivy;

import static com.axonivy.connector.sftp.enums.AuthMethod.PASSWORD;
/**
* Service class for file transfer to/from the SFTP server. The service class is
* used to decouple the SFTP implementation.
Expand All @@ -41,7 +40,6 @@ public class SftpClientService implements AutoCloseable {
private static final String AUTH_VAR = "auth";
private static final String PASSWORD_VAR = "password";
private static final String USERNAME_VAR = "username";
private static final String PASSWORD = "password";

/**
* A Session represents a connection to an SSH server.
Expand Down Expand Up @@ -79,7 +77,7 @@ public SftpClientService(String sftpName) throws IOException {
JSch jsch = new JSch();

session = jsch.getSession(username, host, port);
if (StringUtils.isEmpty(auth) || PASSWORD.equalsIgnoreCase(auth)) {
if (StringUtils.isEmpty(auth) || PASSWORD.name().equalsIgnoreCase(auth)) {
session.setPassword(password);
} else {
session.setConfig("PreferredAuthentications", "publickey");
Expand Down

0 comments on commit 851affc

Please sign in to comment.