From 6f7385ab5f54da93c9460eebad8dc4c70322b62a Mon Sep 17 00:00:00 2001 From: Aleks Date: Wed, 17 Feb 2016 16:03:09 +0200 Subject: [PATCH 1/2] Added support for local(Linux) proxy from env https_proxy --- package.json | 1 + utils/deploy_task.js | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 54f19c1..64735b7 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "rimraf": "~2.2.8", "glob": "~4.3.0", "aws-sdk": "~2.2.32", + "proxy-agent": "latest", "npm": "^2.10.0", "q": "^1.4.1" }, diff --git a/utils/deploy_task.js b/utils/deploy_task.js index da028c7..1b1a867 100644 --- a/utils/deploy_task.js +++ b/utils/deploy_task.js @@ -17,6 +17,8 @@ var dateFacade = require('./date_facade'); var deployTask = {}; +var proxy = require('proxy-agent'); + deployTask.getHandler = function (grunt) { return function () { @@ -37,12 +39,19 @@ deployTask.getHandler = function (grunt) { aliases: null, enablePackageVersionAlias: false }); - + if (options.profile !== null) { var credentials = new AWS.SharedIniFileCredentials({profile: options.profile}); AWS.config.credentials = credentials; } + //Adding proxy if exists + if(process.env.https_proxy != "") { + AWS.config.update({ + httpOptions: { agent: proxy(process.env.https_proxy) } + }); + } + if (options.RoleArn !== null) { AWS.config.credentials = new AWS.EC2MetadataCredentials({ httpOptions: {timeout: 5000} // 5 second timeout @@ -264,4 +273,4 @@ deployTask.getHandler = function (grunt) { }; }; -module.exports = deployTask; \ No newline at end of file +module.exports = deployTask; From 407e4bf0fc77df377f2ee487e8ef39596a32bc6b Mon Sep 17 00:00:00 2001 From: Aleks Date: Thu, 18 Feb 2016 15:10:12 +0200 Subject: [PATCH 2/2] Added Readme and unittest for proxy --- README.md | 5 +++++ package.json | 2 +- test/unit/deploy_task_test.js | 36 +++++++++++++++++++++++++++++++++-- utils/deploy_task.js | 12 ++++++------ 4 files changed, 46 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index d2fc5b5..7ad4bad 100644 --- a/README.md +++ b/README.md @@ -291,6 +291,11 @@ Default value: None - Required (if you havn't specified an ARN) *This option is deprecated, use arn instead*. The name of your target Lambda function, ie. the name of the function in the AWS console. +##### Proxy +On Linux based hosts you can set proxy server for deploy task by specifying standard environment variable - https_proxy. +E.g: +env https_proxy=http://localhost:8080 grunt deploy + ##### package Type: `String` Default value: Package name set by package task of same target - see below. diff --git a/package.json b/package.json index 64735b7..c55108b 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "rimraf": "~2.2.8", "glob": "~4.3.0", "aws-sdk": "~2.2.32", - "proxy-agent": "latest", + "proxy-agent": "latest", "npm": "^2.10.0", "q": "^1.4.1" }, diff --git a/test/unit/deploy_task_test.js b/test/unit/deploy_task_test.js index a2bd084..8e4cdea 100644 --- a/test/unit/deploy_task_test.js +++ b/test/unit/deploy_task_test.js @@ -40,7 +40,8 @@ var deployTaskTest = {}; var awsSDKMock, lambdaAPIMock, - defaultGruntConfig; + defaultGruntConfig, + proxyAgentMock; deployTaskTest.setUp = function(done) { mockery.enable({ @@ -81,6 +82,8 @@ deployTaskTest.setUp = function(done) { return lambdaAPIMock; } }; + + proxyAgentMock = sinon.spy(); fsMock.reset(); mockery.registerMock('fs', fsMock); @@ -88,6 +91,8 @@ deployTaskTest.setUp = function(done) { fsMock.setFileContent('some-package.zip', 'abc123'); mockery.registerMock('aws-sdk', awsSDKMock); + + mockery.registerMock('proxy-agent', proxyAgentMock); var dateFacadeMock = { getHumanReadableTimestamp: sinon.stub().returns('Sat Feb 13 2016 21:46:15 GMT-0800 (PST)') @@ -132,6 +137,33 @@ deployTaskTest.testDeploySucceed = function(test) { gruntMock.execute(deployTask.getHandler, harnessParams); }; +deployTaskTest.testDeployUsingProxy = function(test) { + test.expect(6); + + var deployTask = require('../../utils/deploy_task'); + + + var proxy = 'http://localhost:8080'; + process.env.https_proxy = proxy; + + var harnessParams = { + options: {}, + config: defaultGruntConfig, + callback: function(harness) { + test.equal(harness.status, true); + test.equal(harness.output.length, 3); + test.equal(harness.output[0], 'Uploading...'); + test.equal(harness.output[1], 'Package deployed.'); + test.equal(harness.output[2], 'No config updates to make.'); + + test.ok(proxyAgentMock.calledWith(proxy)); + test.done(); + } + }; + + gruntMock.execute(deployTask.getHandler, harnessParams); +}; + deployTaskTest.testProfile = function(test) { test.expect(3); @@ -468,4 +500,4 @@ deployTaskTest.testMultipleAliases = function(test) { gruntMock.execute(deployTask.getHandler, harnessParams); }; -module.exports = deployTaskTest; \ No newline at end of file +module.exports = deployTaskTest; diff --git a/utils/deploy_task.js b/utils/deploy_task.js index 1b1a867..0b828f3 100644 --- a/utils/deploy_task.js +++ b/utils/deploy_task.js @@ -45,12 +45,12 @@ deployTask.getHandler = function (grunt) { AWS.config.credentials = credentials; } - //Adding proxy if exists - if(process.env.https_proxy != "") { - AWS.config.update({ - httpOptions: { agent: proxy(process.env.https_proxy) } - }); - } + //Adding proxy if exists + if(process.env.https_proxy !== "") { + AWS.config.update({ + httpOptions: { agent: proxy(process.env.https_proxy) } + }); + } if (options.RoleArn !== null) { AWS.config.credentials = new AWS.EC2MetadataCredentials({