Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -747,18 +747,6 @@ private String activeTunnelID(String username, String tunnelName, Logger logger)

protected abstract String getCurrentVersion();

/**
* Returns the arguments to be used to launch Sauce Connect
*
* @param args the initial Sauce Connect command line args
* @param username name of the user which launched Sauce Connect
* @param apiKey the access key for the Sauce user
* @param options command line args specified by the user
* @return String array representing the command line args to be used to launch Sauce Connect
*/
protected abstract String[] generateSauceConnectArgs(
String[] args, String username, String apiKey, String options);

protected abstract String[] addExtraInfo(String[] args);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,43 +140,29 @@ public String getDefaultSauceConnectLogDirectory() {
private static final String SAUCE_CONNECT_PREFIX = "sauce-connect-";
public static final String SAUCE_CONNECT = SAUCE_CONNECT_PREFIX + CURRENT_SC_VERSION;

private static final int DEFAULT_API_PORT = 9000;
private int apiPort;

/** Constructs a new instance with quiet mode disabled. */
public SauceConnectManager() {
this(false);
}

/**
* Constructs a new instance with quiet mode disabled.
*
* @param runner System which runs SauceConnect, this info is added to '--metadata runner=' argument
*/
public SauceConnectManager(String runner) {
this(false, runner, DEFAULT_API_PORT);
}

/**
* Constructs a new instance.
*
* @param quietMode indicates whether Sauce Connect output should be suppressed
*/
public SauceConnectManager(boolean quietMode) {
this(quietMode, "jenkins", DEFAULT_API_PORT);
this(quietMode, "jenkins");
}

/**
* Constructs a new instance.
*
* @param quietMode indicates whether Sauce Connect output should be suppressed
* @param runner System which runs SauceConnect, this info is added to '--metadata runner=' argument
* @param apiPort Port the Sauce Connect process will listen on
*/
public SauceConnectManager(boolean quietMode, String runner, int apiPort) {
public SauceConnectManager(boolean quietMode, String runner) {
super(quietMode);
this.runner = runner;
this.apiPort = apiPort;
}

/**
Expand Down Expand Up @@ -241,17 +227,13 @@ protected Process prepAndCreateProcess(
}
}

if ( apiPort != 0 ) {
this.apiPort = apiPort;
}

// although we are setting the working directory, we need to specify the full path to the exe
String[] args = {sauceConnectBinary.getPath()};
if (legacy) {
args = generateSauceConnectArgsLegacy(args, username, accessKey, options);
args = generateSauceConnectArgsLegacy(args, username, accessKey, apiPort, options);
args = addExtraInfoLegacy(args);
} else {
args = generateSauceConnectArgs(args, username, accessKey, options);
args = generateSauceConnectArgs(args, username, accessKey, apiPort, options);
args = addExtraInfo(args);
}

Expand Down Expand Up @@ -342,13 +324,14 @@ public static String getLatestSauceConnectVersion() {
* @param args the initial Sauce Connect command line args
* @param username name of the user which launched Sauce Connect
* @param accessKey the access key for the Sauce user
* @param apiPort specify the port the Sauce Connect API will listen on
* @param options command line args specified by the user
* @return String array representing the command line args to be used to launch Sauce Connect
*/
protected String[] generateSauceConnectArgs(
String[] args, String username, String accessKey, String options) {
String[] args, String username, String accessKey, int apiPort, String options) {
String[] result =
joinArgs(args, "run", "--username", username.trim(), "--access-key", accessKey.trim(), "--api-address", ":" + String.valueOf(this.apiPort));
joinArgs(args, "run", "--username", username.trim(), "--access-key", accessKey.trim(), "--api-address", ":" + String.valueOf(apiPort));
result = addElement(result, options);
return result;
}
Expand All @@ -362,15 +345,16 @@ protected String[] addExtraInfo(String[] args) {
* @param args the initial Sauce Connect command line args
* @param username name of the user which launched Sauce Connect
* @param accessKey the access key for the Sauce user
* @param apiPort specify the port the Sauce Connect API will listen on
* @param options command line args specified by the user
* @return String array representing the command line args to be used to launch Sauce Connect
*/
@Deprecated
protected String[] generateSauceConnectArgsLegacy(
String[] args, String username, String accessKey, String options) {
String[] args, String username, String accessKey, int apiPort, String options) {
String[] result;

result = joinArgs(args, "legacy", "--user", username.trim(), "--api-key", accessKey.trim(), "--status-address", "0.0.0.0:" + String.valueOf(this.apiPort));
result = joinArgs(args, "legacy", "--user", username.trim(), "--api-key", accessKey.trim(), "--status-address", "0.0.0.0:" + String.valueOf(apiPort));
result = addElement(result, options);
return result;
}
Expand Down Expand Up @@ -441,22 +425,6 @@ private File getUnzipDir(File workingDirectory, OperatingSystem operatingSystem)
return new File(workingDirectory, operatingSystem.getDirectory(useLatestSauceConnect));
}

protected boolean isConnected() {
HttpClient client = HttpClient.newHttpClient();

HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(String.format("http://localhost:%d", this.apiPort)))
.GET()
.build();

try {
HttpResponse<Void> response = client.send(request, HttpResponse.BodyHandlers.discarding());
return response.statusCode() == 200;
} catch (IOException | InterruptedException e) {
return false;
}
}

@Override
protected String getCurrentVersion() {
return getVersion(useLatestSauceConnect);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ void testSauceConnectSecretsCoveredWithStars() {
args,
"username",
"apikey",
9000,
"--access-key apiKey");
String result = manager.hideSauceConnectCommandlineSecrets(args);

Expand All @@ -263,6 +264,7 @@ void testSauceConnectLegacySecretsCoveredWithStars() {
args,
"username",
"apikey",
9000,
"--api-key apiKey");
String result = manager.hideSauceConnectCommandlineSecrets(args);

Expand All @@ -282,6 +284,7 @@ void testSauceConnectAuthSecretsCoveredWithStars() {
args,
"username",
"apikey",
9000,
"--auth foo:bar@host:8080");
String result = manager.hideSauceConnectCommandlineSecrets(args);

Expand All @@ -295,6 +298,7 @@ void testSauceConnectAuthSecretsCoveredWithStars() {
args,
"username",
"apikey",
9000,
"-a foo:bar@host:8080");
result = manager.hideSauceConnectCommandlineSecrets(args);

Expand All @@ -308,6 +312,7 @@ void testSauceConnectAuthSecretsCoveredWithStars() {
args,
"username",
"apikey",
9000,
"-a foo:bar@host:8080 -a user:pwd@host1:1234 --auth root:pass@host2:9999 --auth uucp:pass@host3:8080");
result = manager.hideSauceConnectCommandlineSecrets(args);

Expand All @@ -327,6 +332,7 @@ void testSauceConnectProxySecretsCoveredWithStars() {
args,
"username",
"apikey",
9000,
"--proxy user:pwd@host:8080");
String result = manager.hideSauceConnectCommandlineSecrets(args);

Expand All @@ -340,6 +346,7 @@ void testSauceConnectProxySecretsCoveredWithStars() {
args,
"username",
"apikey",
9000,
"--proxy user@host:8080");
result = manager.hideSauceConnectCommandlineSecrets(args);

Expand All @@ -353,6 +360,7 @@ void testSauceConnectProxySecretsCoveredWithStars() {
args,
"username",
"apikey",
9000,
"-x user@host:8080");
result = manager.hideSauceConnectCommandlineSecrets(args);

Expand All @@ -366,6 +374,7 @@ void testSauceConnectProxySecretsCoveredWithStars() {
args,
"username",
"apikey",
9000,
"--proxy-sauce user@host:8080");
result = manager.hideSauceConnectCommandlineSecrets(args);

Expand All @@ -385,6 +394,7 @@ void testSauceConnectAPIBasicAuthSecretsCoveredWithStars() {
args,
"username",
"apiKey",
9000,
"--api-basic-auth user:pwd");
String result = manager.hideSauceConnectCommandlineSecrets(args);

Expand All @@ -398,6 +408,7 @@ void testSauceConnectAPIBasicAuthSecretsCoveredWithStars() {
args,
"username",
"apiKey",
9000,
"--api-basic-auth user");
result = manager.hideSauceConnectCommandlineSecrets(args);

Expand Down