Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* The MIT License
*
* Copyright (c) 2010, InfraDNA, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package hudson.plugins.sauce_ondemand;
import com.saucelabs.rest.Credential;
import com.saucelabs.rest.SauceTunnelFactory;
import hudson.Extension;
import hudson.Plugin;
import hudson.model.Describable;
import hudson.model.Descriptor;
import hudson.model.Descriptor.FormException;
import hudson.model.Hudson;
import hudson.model.Items;
import hudson.util.FormValidation;
import hudson.util.Secret;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.WebApp;
import javax.servlet.ServletException;
import java.io.IOException;
import java.util.Map;
/**
* Persists the access credential to Sauce OnDemand.
*
* @author Kohsuke Kawaguchi
*/
@Extension
public class PluginImpl extends Plugin implements Describable {
/**
* User name to access Sauce OnDemand.
*/
private String username;
/**
* Password for Sauce OnDemand.
*/
private Secret apiKey;
/**
* Download video and reports.
*/
public transient final DownloadQueue download = new DownloadQueue();
public String getUsername() {
return username;
}
public Secret getApiKey() {
return apiKey;
}
@Override
public void start() throws Exception {
// backward compatibility with the legacy class name
Items.XSTREAM.alias("hudson.plugins.sauce_ondemand.SoDBuildWrapper",SauceOnDemandBuildWrapper.class);
Items.XSTREAM.alias("hudson.plugins.sauce__ondemand.SoDBuildWrapper",SauceOnDemandBuildWrapper.class);
// the real name must be registered at the end
Items.XSTREAM.alias("hudson.plugins.sauce_ondemand.SauceOnDemandBuildWrapper",SauceOnDemandBuildWrapper.class);
Map mimeTypes = WebApp.get(Hudson.getInstance().servletContext).mimeTypes;
if (!mimeTypes.containsKey("flv")) mimeTypes.put("flv","video/x-flv");
load();
}
public void setCredential(String username, String apiKey) throws IOException {
this.username = username;
this.apiKey = Secret.fromString(apiKey);
save();
}
@Override
public void configure(StaplerRequest req, JSONObject formData) throws IOException, ServletException, FormException {
username = formData.getString("username");
apiKey = Secret.fromString(formData.getString("apiKey"));
save();
}
public DescriptorImpl getDescriptor() {
return (DescriptorImpl)Hudson.getInstance().getDescriptorOrDie(getClass());
}
public static PluginImpl get() {
return Hudson.getInstance().getPlugin(PluginImpl.class);
}
@Extension
public static final class DescriptorImpl extends Descriptor {
@Override
public String getDisplayName() {
return "Sauce OnDemand";
}
public FormValidation doValidate(@QueryParameter String username, @QueryParameter String apiKey) {
try {
new SauceTunnelFactory(new Credential(username,Secret.toString(Secret.fromString(apiKey)))).list();
return FormValidation.ok("Success");
} catch (IOException e) {
return FormValidation.error(e,"Failed to connect to Sauce OnDemand");
}
}
}
}