Skip to content

Commit 3d478ca

Browse files
authored
fix(cli): cannot use CA bundle and proxy at the same time (#17990)
fixes #5804 This is reworked solution I proposed 30.11.2021 in PR #16704 on current master. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 9b6e237 commit 3d478ca

File tree

2 files changed

+14
-22
lines changed

2 files changed

+14
-22
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ coverage/
2323
*.sw[a-z]
2424
*~
2525
.idea
26+
*.iml
2627
junit.xml
2728

2829
# We don't want tsconfig at the root

packages/aws-cdk/lib/api/aws-auth/sdk-provider.ts

+13-22
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as https from 'https';
21
import * as os from 'os';
32
import * as path from 'path';
43
import * as cxapi from '@aws-cdk/cx-api';
@@ -375,31 +374,23 @@ function parseHttpOptions(options: SdkHttpOptions) {
375374
config.customUserAgent = userAgent;
376375

377376
const caBundlePath = options.caBundlePath || caBundlePathFromEnvironment();
378-
379-
if (options.proxyAddress && caBundlePath) {
380-
throw new Error(`At the moment, cannot specify Proxy (${options.proxyAddress}) and CA Bundle (${caBundlePath}) at the same time. See https://github.com/aws/aws-cdk/issues/5804`);
381-
// Maybe it's possible after all, but I've been staring at
382-
// https://github.com/TooTallNate/node-proxy-agent/blob/master/index.js#L79
383-
// a while now trying to figure out what to pass in so that the underlying Agent
384-
// object will get the 'ca' argument. It's not trivial and I don't want to risk it.
385-
}
386-
387377
if (caBundlePath) {
388378
debug('Using CA bundle path: %s', caBundlePath);
389-
config.httpOptions.agent = new https.Agent({
390-
ca: readIfPossible(caBundlePath),
391-
keepAlive: true,
392-
});
393-
} else {
394-
// Configure the proxy agent. By default, this will use HTTPS?_PROXY and
395-
// NO_PROXY environment variables to determine which proxy to use for each
396-
// request.
397-
//
398-
// eslint-disable-next-line @typescript-eslint/no-require-imports
399-
const ProxyAgent: any = require('proxy-agent');
400-
config.httpOptions.agent = new ProxyAgent();
379+
(config.httpOptions as any).ca = readIfPossible(caBundlePath);
401380
}
402381

382+
if (options.proxyAddress) {
383+
debug('Proxy server from command-line arguments: %s', options.proxyAddress);
384+
}
385+
386+
// Configure the proxy agent. By default, this will use HTTPS?_PROXY and
387+
// NO_PROXY environment variables to determine which proxy to use for each
388+
// request.
389+
//
390+
// eslint-disable-next-line @typescript-eslint/no-require-imports
391+
const ProxyAgent = require('proxy-agent');
392+
config.httpOptions.agent = new ProxyAgent(options.proxyAddress);
393+
403394
return config;
404395
}
405396

0 commit comments

Comments
 (0)