Skip to content

Commit 4551df7

Browse files
committed
Merge pull request #66 from alekstr/feature/add-proxy-support-for-deploy
Added support for local(Linux) proxy from env https_proxy
2 parents 8fadb77 + 407e4bf commit 4551df7

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,11 @@ Default value: None - Required (if you havn't specified an ARN)
291291

292292
*This option is deprecated, use arn instead*. The name of your target Lambda function, ie. the name of the function in the AWS console.
293293

294+
##### Proxy
295+
On Linux based hosts you can set proxy server for deploy task by specifying standard environment variable - https_proxy.
296+
E.g:
297+
env https_proxy=http://localhost:8080 grunt deploy
298+
294299
##### package
295300
Type: `String`
296301
Default value: Package name set by package task of same target - see below.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"rimraf": "~2.2.8",
3434
"glob": "~4.3.0",
3535
"aws-sdk": "~2.2.32",
36+
"proxy-agent": "latest",
3637
"npm": "^2.10.0",
3738
"q": "^1.4.1"
3839
},

test/unit/deploy_task_test.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ var deployTaskTest = {};
4040

4141
var awsSDKMock,
4242
lambdaAPIMock,
43-
defaultGruntConfig;
43+
defaultGruntConfig,
44+
proxyAgentMock;
4445

4546
deployTaskTest.setUp = function(done) {
4647
mockery.enable({
@@ -81,13 +82,17 @@ deployTaskTest.setUp = function(done) {
8182
return lambdaAPIMock;
8283
}
8384
};
85+
86+
proxyAgentMock = sinon.spy();
8487

8588
fsMock.reset();
8689
mockery.registerMock('fs', fsMock);
8790

8891
fsMock.setFileContent('some-package.zip', 'abc123');
8992

9093
mockery.registerMock('aws-sdk', awsSDKMock);
94+
95+
mockery.registerMock('proxy-agent', proxyAgentMock);
9196

9297
var dateFacadeMock = {
9398
getHumanReadableTimestamp: sinon.stub().returns('Sat Feb 13 2016 21:46:15 GMT-0800 (PST)')
@@ -132,6 +137,33 @@ deployTaskTest.testDeploySucceed = function(test) {
132137
gruntMock.execute(deployTask.getHandler, harnessParams);
133138
};
134139

140+
deployTaskTest.testDeployUsingProxy = function(test) {
141+
test.expect(6);
142+
143+
var deployTask = require('../../utils/deploy_task');
144+
145+
146+
var proxy = 'http://localhost:8080';
147+
process.env.https_proxy = proxy;
148+
149+
var harnessParams = {
150+
options: {},
151+
config: defaultGruntConfig,
152+
callback: function(harness) {
153+
test.equal(harness.status, true);
154+
test.equal(harness.output.length, 3);
155+
test.equal(harness.output[0], 'Uploading...');
156+
test.equal(harness.output[1], 'Package deployed.');
157+
test.equal(harness.output[2], 'No config updates to make.');
158+
159+
test.ok(proxyAgentMock.calledWith(proxy));
160+
test.done();
161+
}
162+
};
163+
164+
gruntMock.execute(deployTask.getHandler, harnessParams);
165+
};
166+
135167
deployTaskTest.testProfile = function(test) {
136168
test.expect(3);
137169

utils/deploy_task.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ var dateFacade = require('./date_facade');
1717

1818
var deployTask = {};
1919

20+
var proxy = require('proxy-agent');
21+
2022
deployTask.getHandler = function (grunt) {
2123

2224
return function () {
@@ -39,12 +41,19 @@ deployTask.getHandler = function (grunt) {
3941
subnetIds: null,
4042
securityGroupIds: null
4143
});
42-
44+
4345
if (options.profile !== null) {
4446
var credentials = new AWS.SharedIniFileCredentials({profile: options.profile});
4547
AWS.config.credentials = credentials;
4648
}
4749

50+
//Adding proxy if exists
51+
if(process.env.https_proxy !== "") {
52+
AWS.config.update({
53+
httpOptions: { agent: proxy(process.env.https_proxy) }
54+
});
55+
}
56+
4857
if (options.RoleArn !== null) {
4958
AWS.config.credentials = new AWS.EC2MetadataCredentials({
5059
httpOptions: {timeout: 5000} // 5 second timeout

0 commit comments

Comments
 (0)