Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions JenkinsTestfile
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,15 @@ pipeline {
if(!cfg.proxies)cfg.proxies={};

// HTTP Proxy
if(process.env.HTTP_PROXY_ADDRESS && process.env.HTTP_PROXY_ADDRESS.trim()!==""){
if(process.env.HTTP_PROXY_HOST && process.env.HTTP_PROXY_HOST.trim()!==""){
cfg.credentials.proxyCredentials={};
cfg.credentials.proxyCredentials.username=process.env.HTTP_PROXY_USER||"";
cfg.credentials.proxyCredentials.password=process.env.HTTP_PROXY_PASS||"";

cfg.proxies.default={
agentType: process.env.HTTP_AGENT_TYPE || "http",
address: process.env.HTTP_PROXY_ADDRESS.trim(),
host: process.env.HTTP_PROXY_HOST.trim(),
port: process.env.HTTP_PROXY_PORT,
credential: "proxyCredentials",
options: {
timeout: 30000,
Expand All @@ -116,10 +117,11 @@ pipeline {
}

// SOCKS Proxy
if(process.env.SOCKS_PROXY_ADDRESS && process.env.SOCKS_PROXY_ADDRESS.trim()!==""){
if(process.env.SOCKS_PROXY_HOST && process.env.SOCKS_PROXY_HOST.trim()!==""){
cfg.proxies.socksproxy={
agentType: process.env.SOCKS_AGENT_TYPE || "socks",
address: process.env.SOCKS_PROXY_ADDRESS.trim(),
host: process.env.SOCKS_PROXY_HOST.trim(),
port: process.env.SOCKS_PROXY_PORT,
credential: null,
options: {
timeout: 30000,
Expand Down Expand Up @@ -195,13 +197,15 @@ pipeline {
env.TARGET_GW_PASS = params.VAR_target_gateway_password ?: ''

// Map Proxy Variables
env.HTTP_AGENT_TYPE = params.VAR_http_agent_type ?: 'httpproxy'
env.HTTP_PROXY_ADDRESS = (params.VAR_http_proxy_address ?: '').trim()
env.HTTP_AGENT_TYPE = params.VAR_http_agent_type ?: 'http'
env.HTTP_PROXY_HOST = (params.VAR_http_proxy_host ?: '').trim()
env.HTTP_PROXY_PORT = params.VAR_http_proxy_port ? : '3128'
env.HTTP_PROXY_USER = params.VAR_http_proxy_username ?: 'root'
env.HTTP_PROXY_PASS = params.VAR_http_password ?: ''

env.SOCKS_AGENT_TYPE = params.VAR_socks_agent_type ?: 'socksproxy'
env.SOCKS_AGENT_TYPE = params.VAR_socks_agent_type ?: 'socks'
env.SOCKS_PROXY_ADDRESS = (params.VAR_socks_proxy_address ?: '').trim()
env.SOCKS_PROXY_PORT = params.VAR_socks_proxy_port ? : '1080'
env.SOCKS_PROXY_USER = params.VAR_socks_proxy_username ?: 'root'
env.SOCKS_PROXY_PASS = params.VAR_socks_password ?: ''

Expand Down
3 changes: 2 additions & 1 deletion graphman.configuration
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"proxies": {
"default": {
"agentType": "http",
"address": "http://localhost:3128",
"host": "localhost",
"port": 3128
"credential": null,
"options" : {
"timeout": 30000,
Expand Down
45 changes: 9 additions & 36 deletions modules/graphman-extension-http-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ module.exports = {
*/
apply: function (input, context) {

if(input.agentType === "socks") {
if(input.agentType?.startsWith("socks")) {
return createSocksProxyAgent(input, context);
} else {
} else {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation is disturbed. revert this change.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed

return createHttpProxyAgent(input, context);
}
}
Expand All @@ -25,7 +25,7 @@ function createSocksProxyAgent(input, context) {

try {
const { SocksProxyAgent } = require("socks-proxy-agent");
agent = new SocksProxyAgent(proxyConfig.url || new URL(input.address), proxyConfig);
agent = new SocksProxyAgent(proxyConfig.url , proxyConfig);
} catch (e) {
throw "failed to configure socks proxy agent" + e.message;
}
Expand All @@ -36,30 +36,17 @@ function createHttpProxyAgent(input, context) {
let agent = null;
const isHttps = context.gateway["address"].startsWith('https://');
const proxyConfig = createProxyConfig(input);
const proxyUrlLower = input.address.toLowerCase();
const isProxyHttps = proxyUrlLower.startsWith('https://');

if (isProxyHttps) {
// If proxy URL uses https://, ensure TLS options are configured if needed
if (!proxyConfig.tls) {
proxyConfig.tls = {};
}
// If rejectUnauthorized is not explicitly set for proxy TLS, default to false for compatibility
if (proxyConfig.tls.rejectUnauthorized === undefined) {
proxyConfig.tls.rejectUnauthorized = false;
}
}

try {
// Use https-proxy-agent for HTTPS targets, http-proxy-agent for HTTP targets
// Note: The agent type is based on TARGET protocol, not proxy URL protocol

if (isHttps) {
const { HttpsProxyAgent } = require("https-proxy-agent")
agent = new HttpsProxyAgent(input.address, proxyConfig);
agent = new HttpsProxyAgent(proxyConfig.url, proxyConfig);
} else {
const { HttpProxyAgent } = require("http-proxy-agent")
agent = new HttpProxyAgent(input.address, proxyConfig);
agent = new HttpProxyAgent(proxyConfig.url, proxyConfig);
}

} catch (e) {
Expand All @@ -72,31 +59,17 @@ function createHttpProxyAgent(input, context) {
function createProxyConfig(obj) {
const proxy = {};
const cred = obj.credentialRef;
let auth;
const url = new URL(`${obj.agentType}://${obj.host}:${obj.port}`);

if (cred) {
if (obj.agentType === "socks") {
const url = new URL(obj.address);
url.username = cred.username;
url.password = cred.password;

proxy.url = url;
} else {
auth = `Basic ${Buffer.from(`${cred.username}:${cred.password}`).toString('base64')}`;
}
url.username = cred.username;
url.password = cred.password;
}

Object.keys(obj.options).forEach(key => {
proxy[key] = obj.options[key];
});

if (!proxy.headers) {
proxy.headers = {};
}

if (auth) {
proxy.headers["Proxy-Authorization"] = auth;
}

proxy.url = url;
return proxy;
}
20 changes: 20 additions & 0 deletions modules/graphman.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,26 @@ function makeCredentials(credentials) {
}

function makeProxies(proxies) {
//populate default proxy if no proxy profiles are defined
if (!Object.keys(proxies).length) {
proxies['default'] = {
"agentType": "http",
"host": "localhost",
"port": 3128,
"credential": null,
"options" : {
"timeout": 30000,
"keepAlive": true,
"maxSockets": 10,
"rejectUnauthorized": false
}
};
}

// define entry for default proxy for error reporting
if (!proxies['default']) {
proxies['default'] = {};
}
// No hard default; just ensure each proxy knows its name if useful
Object.entries(proxies).forEach(([key, item]) => item['name'] = key);
return proxies;
Expand Down