예제 #1
0
    def configure_proxy(self):
        """Check whether the machine is configured to use an http(s) proxy
        and if it does - propagate the environment proxy settings to Jenkins."""
        env_proxy = (os.environ['HTTP_PROXY'] or os.environ['HTTPS_PROXY']
                     or os.environ['http_proxy'] or os.environ['https_proxy'])

        if not env_proxy:
            hookenv.log("There are no environment proxy settings")
            return

        hookenv.log("There are environment proxy settings")
        url = urlparse(env_proxy)

        noproxy = os.environ['NO_PROXY'] or os.environ['no_proxy']
        if noproxy:
            noproxy = ' '.join(
                [re.sub("^\.", '*.', x.strip()) for x in noproxy.split(',')])

        api = Api()
        api.configure_proxy(url.hostname, url.port, url.username, url.password,
                            noproxy)