Skip to content

Commit 13dcba5

Browse files
committed
Make proxy-agent require enabling via yml
1 parent e01e949 commit 13dcba5

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

.circleci/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: 2
22
jobs:
33
lint:
44
docker:
5-
- image: circleci/node:16
5+
- image: circleci/node:18
66

77
working_directory: ~/repo
88

@@ -25,7 +25,7 @@ jobs:
2525

2626
test:
2727
docker:
28-
- image: circleci/node:16
28+
- image: circleci/node:18
2929

3030
working_directory: ~/repo
3131

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,13 @@ __Be careful when introducing any customizations to default config. Many kind of
9494
### Force Migration
9595

9696
Custom migrations can specify `{ force: true }` to force the migration of an existing resource in to a new stack. BE CAREFUL. This will cause a resource to be deleted and recreated. It may not even work if CloudFormation tries to create the new one before deleting the old one and they have a name or some other unique property that cannot have two resources existing at the same time. It can also mean a small window of downtime during this period, for example as an `AWS::Lambda::Permission` is deleted/recreated calls may be denied until IAM sorts things out.
97+
98+
## Proxy Support
99+
100+
This plugin makes use of the `proxy-agent` library, which reads environmental varaibles for configuration. To avoid conflicts with existing deployments, it is not used automatically, but instead needs to be enabled via serverless config:
101+
102+
```yml
103+
custom:
104+
splitStacks:
105+
proxyAgent: true
106+
```

__tests__/utils/bucket-endpoint.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const originalRequest = https.request;
99
test.beforeEach(t => {
1010
https.request = originalRequest;
1111
t.context = Object.assign(
12-
{},
12+
{ config: {} },
1313
{ serverless: { service: { provider: {} } } }
1414
);
1515
});

lib/deployment-bucket-endpoint.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const { endpoint } = require('aws-info');
44
const { ProxyAgent } = require('proxy-agent');
55
const https = require('https');
66

7-
function getOptions(cli, bucket, endpoint) {
7+
function getOptions(cli, bucket, endpoint, useProxy) {
88
const method = 'HEAD';
99
const proxyAgent = new ProxyAgent();
1010

@@ -18,19 +18,21 @@ function getOptions(cli, bucket, endpoint) {
1818
method,
1919
hostname: endpoint,
2020
path: `/${bucket}`,
21-
agent: proxyAgent
21+
agent: useProxy ? proxyAgent : undefined
2222
};
2323
}
2424

2525
return {
2626
method,
2727
hostname: `${bucket}.${endpoint}`,
2828
path: '/',
29-
agent: proxyAgent
29+
agent: useProxy ? proxyAgent : undefined
3030
};
3131
}
3232

3333
module.exports = function setDeploymentBucketEndpoint() {
34+
const useProxy = !!this.config.proxyAgent
35+
3436
return new Promise((resolve, reject) => {
3537
const { service: { provider } } = this.serverless;
3638
const { deploymentBucket } = provider;
@@ -43,7 +45,7 @@ module.exports = function setDeploymentBucketEndpoint() {
4345
? deploymentBucket.name
4446
: deploymentBucket;
4547

46-
const options = getOptions(this.serverless.cli, bucket, s3Endpoint);
48+
const options = getOptions(this.serverless.cli, bucket, s3Endpoint, useProxy);
4749
const request = https.request(options);
4850

4951
request.on('response', response => {

0 commit comments

Comments
 (0)