All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.saucelabs.bamboo.sod.util.BambooSauceFactory Maven / Gradle / Ivy

The newest version!
package com.saucelabs.bamboo.sod.util;

import com.atlassian.bamboo.configuration.AdministrationConfiguration;
import com.atlassian.bamboo.configuration.AdministrationConfigurationAccessor;
import com.saucelabs.bamboo.sod.config.SODKeys;
import com.saucelabs.ci.SauceFactory;
import org.apache.commons.lang.StringUtils;

import java.net.Authenticator;
import java.net.PasswordAuthentication;

/**
 * Delegates requests to the Sauce API.
 *
 * @author Ross Rowe
 */
public class BambooSauceFactory extends SauceFactory {

    public void setupProxy(AdministrationConfigurationAccessor administrationConfigurationManager) {
        AdministrationConfiguration adminConfig = administrationConfigurationManager.getAdministrationConfiguration();
        String proxyHost = adminConfig.getSystemProperty(SODKeys.PROXY_HOST_KEY);
        String proxyPort = adminConfig.getSystemProperty(SODKeys.PROXY_PORT_KEY);
        final String proxyUsername = adminConfig.getSystemProperty(SODKeys.PROXY_USERNAME_KEY);
        final String proxyPassword = adminConfig.getSystemProperty(SODKeys.PROXY_PASSWORD_KEY);
        setupProxy(proxyHost, proxyPort, proxyUsername, proxyPassword);

        if (StringUtils.isNotBlank(proxyUsername) && StringUtils.isNotBlank(proxyPassword)) {
            Authenticator.setDefault(
                    new Authenticator() {
                        public PasswordAuthentication getPasswordAuthentication() {
                            return new PasswordAuthentication(
                                    proxyUsername, proxyPassword.toCharArray());
                        }
                    }
            );
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy