Skip to content

Commit 50b51e7

Browse files
authored
Merge pull request #267 from katalon-studio/add-prop
Add exclude proxy properties
2 parents 6406acd + c662b5e commit 50b51e7

File tree

8 files changed

+75
-12
lines changed

8 files changed

+75
-12
lines changed

Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ ENV SERVER_URL='https://testops.katalon.io'
4545
ENV KATALON_API_KEY=''
4646
ENV ORGANIZATION_ID=''
4747
ENV PROXY=''
48+
ENV PROXY_EXCLUDE_LIST=''
4849
ENV LOG_LEVEL='INFO'
4950
ENV XVFB_RUN=''
5051
ENV X11_DISPLAY=''

cli.js

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ program
3030
.option('-a, --agent-name <value>', 'Agent name')
3131
.option('-c, --config <value>', 'Configuration file path')
3232
.option('-x, --proxy <value>', 'HTTTP/HTTPS Proxy')
33+
.option('--proxy-exclude-list <value>', 'Proxy excluded URLs')
3334
.option('--log-level <value>', 'Log level (ALL < TRACE < DEBUG < INFO < WARN < ERROR < FATAL < MARK < OFF)')
3435
.option('--xvfb-run <value>', 'xvfb-run options')
3536
.option('--x11-display <value>', 'x11 DISPLAY environment variable')
@@ -44,6 +45,7 @@ program
4445
agentName: command.agentName,
4546
configPath: command.config,
4647
proxy: command.proxy,
48+
proxyExcludeList: command.proxyExcludeList,
4749
logLevel: command.logLevel,
4850
xvfbRun: command.xvfbRun,
4951
x11Display: command.x11Display,
@@ -62,6 +64,7 @@ program
6264
.option('-a, --agent-name <value>', 'Agent name')
6365
.option('-c, --config <value>', 'Configuration file path')
6466
.option('-x, --proxy <value>', 'HTTTP/HTTPS Proxy')
67+
.option('--proxy-exclude-list <value>', 'Proxy excluded URLs')
6568
.option('--ci', 'CI mode')
6669
.action((command) => {
6770
const options = {
@@ -72,6 +75,7 @@ program
7275
agentName: command.agentName,
7376
configPath: command.config,
7477
proxy: command.proxy,
78+
proxyExcludeList: command.proxyExcludeList,
7579
};
7680
if (process.platform === 'win32') {
7781
readline

docker/entrypoint.sh

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,16 @@ set -xe
44

55
echo "Entrypoint"
66

7-
if [ "$AUTO_UPGRADE_ENVIRONMENT" = true ]; then
7+
if [[ "$AUTO_UPGRADE_ENVIRONMENT" = true ]]; then
88
/katalon/scripts/upgrade_environment.sh || true
99
fi
10+
11+
echo "Setup proxy"
12+
#[ -f /etc/machine-id ] || echo $RANDOM | md5sum | fold -w 32 | head -n 1 > /etc/machine-id
13+
if [[ -n "${PROXY}" ]]; then
14+
git config --global http.proxy ${PROXY}
15+
fi
16+
1017
if [ -z "$KATALON_USER_ID" ]; then
1118
exec "$@"
1219
else

docker/scripts/agent.sh

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ cd $KATALON_AGENT_DIR
1515
--organizationid "$ORGANIZATION_ID" \
1616
--agent-name "$AGENT_NAME" \
1717
--proxy "$PROXY" \
18+
--proxy-exclude-list "$PROXY_EXCLUDE_LIST" \
1819
--log-level "$LOG_LEVEL" \
1920
--xvfb-run "$XVFB_RUN" \
2021
--x11-display "$X11_DISPLAY" \

package-lock.json

+19-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"ini": "^4.1.2",
4040
"ip": "^2.0.1",
4141
"lodash": "^4.17.21",
42+
"match-url-wildcard": "0.0.5",
4243
"log4js": "^6.9.1",
4344
"moment": "^2.30.1",
4445
"progress": "^2.0.3",

src/core/api/http.js

+24-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ const axios = require('axios').default;
22
const fs = require('fs');
33
const path = require('path');
44
const ProgressBar = require('progress');
5+
// const wildcard = require('wildcard');
56
const { FILTERED_ERROR_CODE } = require('./constants');
67
const logger = require('../../config/logger');
78
const { getProxy, getDefaultHttpsAgent } = require('./proxy');
9+
// const config = require('../config');
810

911
const PROGRESS_RENDER_THROTTLE = 5000;
1012

@@ -43,6 +45,27 @@ axios.interceptors.response.use(
4345
},
4446
);
4547

48+
// axios.interceptors.request.use((config1) => {
49+
// const { proxy, proxyExcludedUrls } = config;
50+
// const httpAgent = new HttpProxyAgent(proxy, { rejectUnauthorized: false, keepAlive: true });
51+
// const httpsAgent = new HttpsProxyAgent(proxy, { rejectUnauthorized: false, keepAlive: true });
52+
// const { url } = config1;
53+
// if (proxyExcludedUrls) {
54+
// const excludedUrls = proxyExcludedUrls.split(',');
55+
// const isExcluded = excludedUrls.some((excludedUrl) => wildcard(excludedUrl, url));
56+
// if (isExcluded) {
57+
// return config1;
58+
// }
59+
// }
60+
// // Set the proxy agents for non-excluded URLs
61+
// if (url.startsWith('http://')) {
62+
// config1.httpAgent = httpAgent;
63+
// } else if (url.startsWith('https://')) {
64+
// config1.httpsAgent = httpsAgent;
65+
// }
66+
// return config1;
67+
// });
68+
4669
module.exports = {
4770
get(urlParam, headers) {
4871
return this.request('get', urlParam, null, headers);
@@ -127,7 +150,7 @@ module.exports = {
127150
params: urlParam.params,
128151
data,
129152
headers,
130-
proxy: getProxy(),
153+
proxy: getProxy(urlParam.url),
131154
...overrideOpts,
132155
httpsAgent: getDefaultHttpsAgent(),
133156
});

src/core/api/proxy.js

+17-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
const https = require('https');
2+
const matchUrl = require('match-url-wildcard');
23
const config = require('../config');
34
const logger = require('../../config/logger');
45

5-
function getProxy() {
6-
const { proxy } = config;
6+
const agent = new https.Agent({
7+
rejectUnauthorized: false,
8+
keepAlive: true,
9+
});
10+
11+
function getProxy(url) {
12+
const { proxy, proxyExcludeList } = config;
713
if (!proxy) {
8-
return null;
14+
return false;
15+
}
16+
if (proxyExcludeList) {
17+
const excludedUrls = proxyExcludeList.split(',');
18+
const isExcluded = excludedUrls.some((excludedUrl) => matchUrl(url, excludedUrl));
19+
if (isExcluded) {
20+
return false;
21+
}
922
}
1023
try {
1124
const { protocol, hostname: host, port, username, password } = new URL(proxy);
@@ -25,7 +38,7 @@ function getProxy() {
2538
return proxyInfo;
2639
} catch (e) {
2740
logger.error('Unable to setup proxy:', e);
28-
return null;
41+
return false;
2942
}
3043
}
3144

@@ -37,10 +50,6 @@ function getIgnoreSsl() {
3750
}
3851

3952
function getDefaultHttpsAgent() {
40-
const agent = new https.Agent({
41-
rejectUnauthorized: false,
42-
keepAlive: true,
43-
});
4453
return agent;
4554
}
4655

0 commit comments

Comments
 (0)