Added proxy support for azure agent and github runner

This commit is contained in:
Thomas VAILLIER
2020-03-11 22:43:44 +01:00
committed by Artur
parent e1e31a379b
commit a2f365cab2
34 changed files with 256 additions and 180 deletions

View File

@@ -1,7 +1,8 @@
import * as fs from 'fs'
import * as path from 'path'
import * as urlApi from 'url'
import { v4 as uuidv4 } from 'uuid';
import { v4 as uuidv4 } from 'uuid'
import * as core from '@actions/core'
import * as exe from '@actions/exec'
@@ -11,6 +12,10 @@ import * as toolCache from '@actions/tool-cache'
import { injectable } from 'inversify'
import { IBuildAgent, IExecResult } from '../../core/models'
import {
IRequestOptions,
IProxyConfiguration
} from 'typed-rest-client/Interfaces'
@injectable()
class BuildAgent implements IBuildAgent {
@@ -22,6 +27,57 @@ class BuildAgent implements IBuildAgent {
return toolCache.find(toolName, versionSpec, arch)
}
public proxyConfiguration(url: string): IRequestOptions {
return {
proxy: this.getProxyConfiguration(url),
cert: undefined,
ignoreSslError: undefined
}
}
private getProxyConfiguration(requestedUrl: string): IProxyConfiguration {
let noProxy = process.env.NO_PROXY || process.env.no_proxy || null
let allowedHostsWithoutProxy
let dontUseProxy = false
if (noProxy) {
if (noProxy === '*') {
dontUseProxy = true
} else {
allowedHostsWithoutProxy = noProxy.split(',')
if (requestedUrl) {
allowedHostsWithoutProxy.forEach(host => {
if (new RegExp(host, 'i').test(requestedUrl)) {
dontUseProxy = true
}
})
}
}
}
if (dontUseProxy) {
return undefined
}
let proxyURL =
process.env.HTTP_PROXY ||
process.env.http_proxy ||
process.env.HTTPS_PROXY ||
process.env.https_proxy ||
null
if (proxyURL) {
let url = new urlApi.URL(requestedUrl)
return {
proxyUrl: `${url.protocol}//${url.hostname}:${url.port}`,
proxyUsername: url.username,
proxyPassword: url.password,
proxyBypassHosts: allowedHostsWithoutProxy
}
}
return undefined
}
public cacheDir(
sourceDir: string,
tool: string,