@@ -17,6 +17,8 @@ const deepCopy = require('lodash.clonedeep')
17
17
const aioLogger = require ( '@adobe/aio-lib-core-logging' ) ( '@adobe/aio-lib-runtime:RuntimeAPI' , { provider : 'debug' , level : process . env . LOG_LEVEL } )
18
18
const LogForwarding = require ( './LogForwarding' )
19
19
const LogForwardingLocalDestinationsProvider = require ( './LogForwardingLocalDestinationsProvider' )
20
+ const { patchOWForTunnelingIssue } = require ( './openwhisk-patch' )
21
+ const { getProxyAgent } = require ( './utils' )
20
22
21
23
require ( './types.jsdoc' ) // for VS Code autocomplete
22
24
/* global OpenwhiskOptions, OpenwhiskClient */ // for linter
@@ -35,8 +37,14 @@ class RuntimeAPI {
35
37
*/
36
38
async init ( options ) {
37
39
aioLogger . debug ( `init options: ${ JSON . stringify ( options , null , 2 ) } ` )
40
+
38
41
const clonedOptions = deepCopy ( options )
39
42
43
+ clonedOptions . use_proxy_from_env_var = false // default, unless env var is set
44
+ if ( process . env . NEEDLE_USE_PROXY_FROM_ENV_VAR === 'true' ) { // legacy support
45
+ clonedOptions . use_proxy_from_env_var = true
46
+ }
47
+
40
48
const initErrors = [ ]
41
49
if ( ! clonedOptions || ! clonedOptions . api_key ) {
42
50
initErrors . push ( 'api_key' )
@@ -53,7 +61,13 @@ class RuntimeAPI {
53
61
const proxyUrl = getProxyForUrl ( clonedOptions . apihost )
54
62
if ( proxyUrl ) {
55
63
aioLogger . debug ( `using proxy url: ${ proxyUrl } ` )
56
- clonedOptions . proxy = proxyUrl
64
+ if ( clonedOptions . use_proxy_from_env_var !== false ) {
65
+ clonedOptions . proxy = proxyUrl
66
+ clonedOptions . agent = null
67
+ } else {
68
+ clonedOptions . proxy = null
69
+ clonedOptions . agent = getProxyAgent ( clonedOptions . apihost , proxyUrl )
70
+ }
57
71
} else {
58
72
aioLogger . debug ( 'proxy settings not found' )
59
73
}
@@ -67,7 +81,7 @@ class RuntimeAPI {
67
81
const shouldIgnoreCerts = process . env . NODE_TLS_REJECT_UNAUTHORIZED === '0'
68
82
clonedOptions . ignore_certs = clonedOptions . ignore_certs || shouldIgnoreCerts
69
83
70
- this . ow = ow ( clonedOptions )
84
+ this . ow = patchOWForTunnelingIssue ( ow ( clonedOptions ) , clonedOptions . use_proxy_from_env_var )
71
85
const self = this
72
86
73
87
return {
0 commit comments