Skip to content

Added support for local(Linux) proxy from env https_proxy #66

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 31, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
36 changes: 34 additions & 2 deletions test/unit/deploy_task_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ var deployTaskTest = {};

var awsSDKMock,
lambdaAPIMock,
defaultGruntConfig;
defaultGruntConfig,
proxyAgentMock;

deployTaskTest.setUp = function(done) {
mockery.enable({
Expand Down Expand Up @@ -81,13 +82,17 @@ deployTaskTest.setUp = function(done) {
return lambdaAPIMock;
}
};

proxyAgentMock = sinon.spy();

fsMock.reset();
mockery.registerMock('fs', fsMock);

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)')
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -468,4 +500,4 @@ deployTaskTest.testMultipleAliases = function(test) {
gruntMock.execute(deployTask.getHandler, harnessParams);
};

module.exports = deployTaskTest;
module.exports = deployTaskTest;
13 changes: 11 additions & 2 deletions utils/deploy_task.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ var dateFacade = require('./date_facade');

var deployTask = {};

var proxy = require('proxy-agent');

deployTask.getHandler = function (grunt) {

return function () {
Expand All @@ -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
Expand Down Expand Up @@ -264,4 +273,4 @@ deployTask.getHandler = function (grunt) {
};
};

module.exports = deployTask;
module.exports = deployTask;