Skip to content
Permalink
Browse files

JENKINS-7828 Added ability to use authentication information in ~/.sa…

…uce-ondemand file
  • Loading branch information
rossrowe committed Jan 26, 2012
1 parent ef69d92 commit 313e7156a5be90f28d6849b0ae18862a33249031
@@ -42,9 +42,7 @@
import org.kohsuke.stapler.bind.JavaScriptMethod;

import javax.servlet.ServletException;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;

/**
* Persists the access credential to Sauce OnDemand.
@@ -65,6 +63,8 @@
* Password for Sauce OnDemand.
*/
private Secret apiKey;

private boolean reuseSauceAuth;

public String getUsername() {
return username;
@@ -93,6 +93,7 @@ public void setCredential(String username, String apiKey) throws IOException {

@Override
public void configure(StaplerRequest req, JSONObject formData) throws IOException, ServletException, Descriptor.FormException {
reuseSauceAuth = formData.getBoolean("reuseSauceAuth");
username = formData.getString("username");
apiKey = Secret.fromString(formData.getString("apiKey"));
save();
@@ -106,16 +107,21 @@ public static PluginImpl get() {
return Hudson.getInstance().getPlugin(PluginImpl.class);
}

public boolean isReuseSauceAuth() {
return reuseSauceAuth;
}

@Extension
public static final class DescriptorImpl extends Descriptor<PluginImpl> {
@Override
public String getDisplayName() {
return "Sauce OnDemand";
}

public FormValidation doValidate(@QueryParameter String username, @QueryParameter String apiKey) {
public FormValidation doValidate(@QueryParameter String username, @QueryParameter String apiKey, @QueryParameter boolean reuseSauceAuth) {
try {
new SauceTunnelFactory(new Credential(username, Secret.toString(Secret.fromString(apiKey)))).list();
Credential credential = reuseSauceAuth ? new Credential() : new Credential(username, Secret.toString(Secret.fromString(apiKey)));
new SauceTunnelFactory(credential).list();
return FormValidation.ok("Success");
} catch (IOException e) {
return FormValidation.error(e, "Failed to connect to Sauce OnDemand");
@@ -112,7 +112,6 @@ private String getHostName() {
}



private String getStartingURL() {
if (getSeleniumInformation() != null) {
return getSeleniumInformation().getStartingURL();
@@ -242,21 +241,27 @@ public void close(TaskListener listener) {
private File sauceConnectJar;
private int port;

public SauceConnectStarter(String buildName, BuildListener listener, int port) {
public SauceConnectStarter(String buildName, BuildListener listener, int port) throws IOException {
if (getCredentials() != null) {
this.username = getCredentials().getUsername();
this.key = getCredentials().getApiKey();
} else {
PluginImpl p = PluginImpl.get();
this.username = p.getUsername();
this.key = Secret.toString(p.getApiKey());
if (p.isReuseSauceAuth()) {
com.saucelabs.rest.Credential storedCredentials = new com.saucelabs.rest.Credential();
this.username = storedCredentials.getUsername();
this.key = storedCredentials.getKey();
} else {
this.username = p.getUsername();
this.key = Secret.toString(p.getApiKey());
}
}
this.buildName = buildName;
this.listener = listener;
this.port = port;
}

public SauceConnectStarter(String buildName, BuildListener listener, int port, File sauceConnectJar) {
public SauceConnectStarter(String buildName, BuildListener listener, int port, File sauceConnectJar) throws IOException {
this(buildName, listener, port);
this.sauceConnectJar = sauceConnectJar;

@@ -1,29 +1,49 @@
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<f:section title="Sauce OnDemand">
<j:scope>
<j:set var="instance" value="${it}" />
<j:set var="descriptor" value="${instance.descriptor}" />
<f:entry title="${%Username}" field="username">
<f:textbox />
</f:entry>
<f:entry title="${%API Access Key}" field="apiKey">
<f:password />
</f:entry>
<f:entry help="/descriptor/hudson.plugins.sauce_ondemand.PluginImpl/help/updates">
<div id="progress" style="display:none;">
<img src="${imagesURL}/spinner.gif" />
</div>
<div id="msg"></div>
<script>
var plugin = <st:bind value="${it}"/>
plugin.checkForUpdates(function(t) {
document.getElementById('msg').innerHTML = t.responseObject();
})
</script>
</f:entry>
<f:block>
<f:validateButton title="${%Test Connection}" with="username,apiKey" method="validate"/>
</f:block>
</j:scope>
</f:section>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout"
xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<script LANGUAGE="JavaScript">
function enableDisable() {

if(document.getElementById('reuseSauceAuthCheckBox').checked)
{
document.getElementById('userBox').disabled=true;
document.getElementById('apiKeyBox').disabled=true;
}
else
{
document.getElementById('userBox').disabled=false;
document.getElementById('apiKeyBox').disabled=false;
}
}
</script>
<f:section title="Sauce OnDemand">
<j:scope>
<j:set var="instance" value="${it}"/>
<j:set var="descriptor" value="${instance.descriptor}"/>
<f:entry title="${%Username}" field="username">
<f:textbox id="userBox"/>
</f:entry>
<f:entry title="${%API Access Key}" field="apiKey">
<f:password id="apiKeyBox"/>
</f:entry>
<f:entry field="reuseSauceAuth">
<f:checkbox id="reuseSauceAuthCheckBox" onclick="debugger;enableDisable();" title="${%Use authentication details in ~/.sauce-ondemand?}"/>
</f:entry>
<f:entry help="/descriptor/hudson.plugins.sauce_ondemand.PluginImpl/help/updates">
<div id="progress" style="display:none;">
<img src="${imagesURL}/spinner.gif"/>
</div>
<div id="msg"></div>
<script>
var plugin =
<st:bind value="${it}"/>
plugin.checkForUpdates(function(t) {
document.getElementById('msg').innerHTML = t.responseObject();
})
</script>
</f:entry>
<f:block>
<f:validateButton title="${%Test Connection}" with="username,apiKey,reuseSauceAuth" method="validate"/>
</f:block>
</j:scope>
</f:section>
</j:jelly>

0 comments on commit 313e715

Please sign in to comment.
You can’t perform that action at this time.