Skip to content

Commit

Permalink
Merge branch 'master' into improve-login
Browse files Browse the repository at this point in the history
  • Loading branch information
nikgraf committed Sep 14, 2017
2 parents dae19d6 + 965ae8a commit 344a3b7
Show file tree
Hide file tree
Showing 17 changed files with 125 additions and 75 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Logs
*.log
npm-debug.log
npm-shrinkwrap.json

# Runtime data
pids
Expand Down
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# 1.22.0 (13.09.2017)
- [Serverless now fails if provided profile is not valid](https://github.com/serverless/serverless/pull/4245)
- [Removed escaping of double quotes around string values in Serverless Variables](https://github.com/serverless/serverless/pull/4224)
- [Added 4 new plugin commands](https://github.com/serverless/serverless/pull/4046)
- [Added aws-kotlin-jvm-marven template](https://github.com/serverless/serverless/pull/4220)
- [Added --update-config option to deploy function command](https://github.com/serverless/serverless/pull/4173)
- [Added description to CloudWatch Events](https://github.com/serverless/serverless/pull/4221)
- [Added support for aliasing commands](https://github.com/serverless/serverless/pull/4198)
- [Added --function option to deploy command](https://github.com/serverless/serverless/pull/4192)
- [Fixed a bug with Kinesis events](https://github.com/serverless/serverless/pull/4084)
- [Fixed a bug with packaging](https://github.com/serverless/serverless/pull/4189)


## Meta
- [Comparison since last release](https://github.com/serverless/serverless/compare/v1.21.1...v1.22.0)


# 1.21.1 (06.09.2017)
- [Preserve file encoding during packaging process](https://github.com/serverless/serverless/pull/4189)

Expand Down
14 changes: 7 additions & 7 deletions docs/providers/aws/cli-reference/deploy-function.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ The `sls deploy function` command deploys an individual function without AWS Clo
serverless deploy function -f functionName
```

**Note:** Because this command is only deploying the function code, function
properties such as environment variables and events will **not** be deployed.
Those properties are deployed via CloudFormation, which does not execute with
this command.
**Note:** This command **now** deploys both function configuration and code by
default. Just as before, this puts your function in an inconsistent state that
is out of sync with your CloudFormation stack. Use this for faster development
cycles and not production deployments

## Options
- `--function` or `-f` The name of the function which should be deployed
- `--stage` or `-s` The stage in your service that you want to deploy to.
- `--region` or `-r` The region in that stage that you want to deploy to.
- `--update-config` or `-u` Pushes Lambda-level configuration changes e.g. timeout or memorySize
- `--update-config` or `-u` Pushes ONLY Lambda-level configuration changes e.g. timeout or memorySize

## Examples

Expand All @@ -43,8 +43,8 @@ serverless deploy function --function helloWorld
serverless deploy function --function helloWorld --stage dev --region us-east-1
```

### Deployment with configuration change
### Deploy only configuration changes

```bash
serverless deploy function --function helloWorld --update-config
```
```
2 changes: 1 addition & 1 deletion docs/providers/aws/cli-reference/invoke.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ serverless invoke [local] --function functionName

# Invoke Local

Invokes a function locally for testing and logs the output. You can only invoke Node.js runtime locally at the moment. Keep in mind that we mock the `context` with simple mock data.
Invokes a function locally for testing and logs the output. Keep in mind that we mock the `context` with simple mock data.

```bash
serverless invoke local --function functionName
Expand Down
1 change: 1 addition & 0 deletions lib/classes/CLI.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ class CLI {
this.consoleLog(chalk.yellow.underline('Commands'));
this.consoleLog(chalk.dim('* You can run commands with "serverless" or the shortcut "sls"'));
this.consoleLog(chalk.dim('* Pass "--verbose" to this command to get in-depth plugin info'));
this.consoleLog(chalk.dim('* Pass "--no-color" to disable CLI colors'));
this.consoleLog(chalk.dim('* Pass "--help" after any <command> for contextual help'));

this.consoleLog('');
Expand Down
2 changes: 1 addition & 1 deletion lib/classes/Variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Variables {
this.cfRefSyntax = RegExp(/^cf:/g);
this.s3RefSyntax = RegExp(/^s3:(.+?)\/(.+)$/);
this.stringRefSynax = RegExp(/('.*')|(".*")/g);
this.ssmRefSyntax = RegExp(/^ssm:([a-zA-Z0-9_.-/]+)[~]?(true|false)?/);
this.ssmRefSyntax = RegExp(/^ssm:([a-zA-Z0-9_.\-/]+)[~]?(true|false)?/);
}

loadVariableSyntax() {
Expand Down
73 changes: 41 additions & 32 deletions lib/classes/Variables.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -946,21 +946,23 @@ describe('Variables', () => {
});

it('should get variable from Ssm using regular-style param', () => {
const param = 'Param-01_valid.chars';
const value = 'MockValue';
const awsResponseMock = {
Parameter: {
Value: 'MockValue',
Value: value,
},
};
const ssmStub = sinon.stub(awsProvider, 'request').resolves(awsResponseMock);

return serverless.variables.getValueFromSsm('ssm:param').then(value => {
expect(value).to.be.equal('MockValue');
return serverless.variables.getValueFromSsm(`ssm:${param}`).then(resolved => {
expect(resolved).to.be.equal(value);
expect(ssmStub.calledOnce).to.be.equal(true);
expect(ssmStub.calledWithExactly(
'SSM',
'getParameter',
{
Name: 'param',
Name: param,
WithDecryption: false,
},
serverless.variables.options.stage,
Expand All @@ -970,21 +972,23 @@ describe('Variables', () => {
});

it('should get variable from Ssm using path-style param', () => {
const param = '/path/to/Param-01_valid.chars';
const value = 'MockValue';
const awsResponseMock = {
Parameter: {
Value: 'MockValue',
Value: value,
},
};
const ssmStub = sinon.stub(awsProvider, 'request').resolves(awsResponseMock);

return serverless.variables.getValueFromSsm('ssm:/some/path/to/param').then(value => {
expect(value).to.be.equal('MockValue');
return serverless.variables.getValueFromSsm(`ssm:${param}`).then(resolved => {
expect(resolved).to.be.equal(value);
expect(ssmStub.calledOnce).to.be.equal(true);
expect(ssmStub.calledWithExactly(
'SSM',
'getParameter',
{
Name: '/some/path/to/param',
Name: param,
WithDecryption: false,
},
serverless.variables.options.stage,
Expand All @@ -994,21 +998,23 @@ describe('Variables', () => {
});

it('should get encrypted variable from Ssm using extended syntax', () => {
const param = '/path/to/Param-01_valid.chars';
const value = 'MockValue';
const awsResponseMock = {
Parameter: {
Value: 'MockValue',
Value: value,
},
};
const ssmStub = sinon.stub(awsProvider, 'request').resolves(awsResponseMock);

return serverless.variables.getValueFromSsm('ssm:/some/path/to/param~true').then(value => {
expect(value).to.be.equal('MockValue');
return serverless.variables.getValueFromSsm(`ssm:${param}~true`).then(resolved => {
expect(resolved).to.be.equal(value);
expect(ssmStub.calledOnce).to.be.equal(true);
expect(ssmStub.calledWithExactly(
'SSM',
'getParameter',
{
Name: '/some/path/to/param',
Name: param,
WithDecryption: true,
},
serverless.variables.options.stage,
Expand All @@ -1018,21 +1024,23 @@ describe('Variables', () => {
});

it('should get unencrypted variable from Ssm using extended syntax', () => {
const param = '/path/to/Param-01_valid.chars';
const value = 'MockValue';
const awsResponseMock = {
Parameter: {
Value: 'MockValue',
Value: value,
},
};
const ssmStub = sinon.stub(awsProvider, 'request').resolves(awsResponseMock);

return serverless.variables.getValueFromSsm('ssm:/some/path/to/param~false').then(value => {
expect(value).to.be.equal('MockValue');
return serverless.variables.getValueFromSsm(`ssm:${param}~false`).then(resolved => {
expect(resolved).to.be.equal(value);
expect(ssmStub.calledOnce).to.be.equal(true);
expect(ssmStub.calledWithExactly(
'SSM',
'getParameter',
{
Name: '/some/path/to/param',
Name: param,
WithDecryption: false,
},
serverless.variables.options.stage,
Expand All @@ -1042,28 +1050,29 @@ describe('Variables', () => {
});

it('should ignore bad values for extended syntax', () => {
const param = '/path/to/Param-01_valid.chars';
const value = 'MockValue';
const awsResponseMock = {
Parameter: {
Value: 'MockValue',
Value: value,
},
};
const ssmStub = sinon.stub(awsProvider, 'request').resolves(awsResponseMock);

return serverless.variables.getValueFromSsm('ssm:/some/path/to/param~badvalue')
.then(value => {
expect(value).to.be.equal('MockValue');
expect(ssmStub.calledOnce).to.be.equal(true);
expect(ssmStub.calledWithExactly(
'SSM',
'getParameter',
{
Name: '/some/path/to/param',
WithDecryption: false,
},
serverless.variables.options.stage,
serverless.variables.options.region
)).to.be.equal(true);
});
return serverless.variables.getValueFromSsm(`ssm:${param}~badvalue`).then(resolved => {
expect(resolved).to.be.equal(value);
expect(ssmStub.calledOnce).to.be.equal(true);
expect(ssmStub.calledWithExactly(
'SSM',
'getParameter',
{
Name: param,
WithDecryption: false,
},
serverless.variables.options.stage,
serverless.variables.options.region
)).to.be.equal(true);
});
});

it('should return undefined if SSM parameter does not exist', () => {
Expand Down
10 changes: 4 additions & 6 deletions lib/plugins/aws/deploy/lib/uploadArtifacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module.exports = {
}

return this.provider.request('S3',
'putObject',
'upload',
params,
this.options.stage,
this.options.region);
Expand Down Expand Up @@ -73,7 +73,7 @@ module.exports = {
}

return this.provider.request('S3',
'putObject',
'upload',
params,
this.options.stage,
this.options.region);
Expand All @@ -83,7 +83,7 @@ module.exports = {
let shouldUploadService = false;
this.serverless.cli.log('Uploading artifacts...');
const functionNames = this.serverless.service.getAllFunctions();
const uploadPromises = functionNames.map(name => {
return BbPromise.map(functionNames, (name) => {
const functionArtifactFileName = this.provider.naming.getFunctionArtifactName(name);
const functionObject = this.serverless.service.getFunction(name);
functionObject.package = functionObject.package || {};
Expand All @@ -100,9 +100,7 @@ module.exports = {
return BbPromise.resolve();
}
return this.uploadZipFile(artifactFilePath);
});

return BbPromise.all(uploadPromises).then(() => {
}, { concurrency: 3 }).then(() => {
if (shouldUploadService) {
const artifactFileName = this.provider.naming.getServiceArtifactName();
const artifactFilePath = path.join(this.packagePath, artifactFileName);
Expand Down
32 changes: 16 additions & 16 deletions lib/plugins/aws/deploy/lib/uploadArtifacts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ describe('uploadArtifacts', () => {

describe('#uploadCloudFormationFile()', () => {
let normalizeCloudFormationTemplateStub;
let putObjectStub;
let uploadStub;

beforeEach(() => {
normalizeCloudFormationTemplateStub = sinon
.stub(normalizeFiles, 'normalizeCloudFormationTemplate')
.returns();
putObjectStub = sinon
uploadStub = sinon
.stub(awsDeploy.provider, 'request')
.resolves();
});
Expand All @@ -91,10 +91,10 @@ describe('uploadArtifacts', () => {

return awsDeploy.uploadCloudFormationFile().then(() => {
expect(normalizeCloudFormationTemplateStub.calledOnce).to.equal(true);
expect(putObjectStub.calledOnce).to.equal(true);
expect(putObjectStub.calledWithExactly(
expect(uploadStub.calledOnce).to.equal(true);
expect(uploadStub.calledWithExactly(
'S3',
'putObject',
'upload',
{
Bucket: awsDeploy.bucketName,
Key: `${awsDeploy.serverless.service.package
Expand All @@ -121,10 +121,10 @@ describe('uploadArtifacts', () => {

return awsDeploy.uploadCloudFormationFile().then(() => {
expect(normalizeCloudFormationTemplateStub.calledOnce).to.equal(true);
expect(putObjectStub.calledOnce).to.be.equal(true);
expect(putObjectStub.calledWithExactly(
expect(uploadStub.calledOnce).to.be.equal(true);
expect(uploadStub.calledWithExactly(
'S3',
'putObject',
'upload',
{
Bucket: awsDeploy.bucketName,
Key: `${awsDeploy.serverless.service.package
Expand All @@ -147,13 +147,13 @@ describe('uploadArtifacts', () => {

describe('#uploadZipFile()', () => {
let readFileSyncStub;
let putObjectStub;
let uploadStub;

beforeEach(() => {
readFileSyncStub = sinon
.stub(fs, 'readFileSync')
.returns();
putObjectStub = sinon
uploadStub = sinon
.stub(awsDeploy.provider, 'request')
.resolves();
});
Expand All @@ -175,11 +175,11 @@ describe('uploadArtifacts', () => {
serverless.utils.writeFileSync(artifactFilePath, 'artifact.zip file content');

return awsDeploy.uploadZipFile(artifactFilePath).then(() => {
expect(putObjectStub.calledOnce).to.be.equal(true);
expect(uploadStub.calledOnce).to.be.equal(true);
expect(readFileSyncStub.calledOnce).to.equal(true);
expect(putObjectStub.calledWithExactly(
expect(uploadStub.calledWithExactly(
'S3',
'putObject',
'upload',
{
Bucket: awsDeploy.bucketName,
Key: `${awsDeploy.serverless.service.package.artifactDirectoryName}/artifact.zip`,
Expand Down Expand Up @@ -207,11 +207,11 @@ describe('uploadArtifacts', () => {
};

return awsDeploy.uploadZipFile(artifactFilePath).then(() => {
expect(putObjectStub.calledOnce).to.be.equal(true);
expect(uploadStub.calledOnce).to.be.equal(true);
expect(readFileSyncStub.calledOnce).to.equal(true);
expect(putObjectStub.calledWithExactly(
expect(uploadStub.calledWithExactly(
'S3',
'putObject',
'upload',
{
Bucket: awsDeploy.bucketName,
Key: `${awsDeploy.serverless.service.package.artifactDirectoryName}/artifact.zip`,
Expand Down
7 changes: 7 additions & 0 deletions lib/plugins/aws/provider/awsProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,14 @@ const impl = {
if (process.env.AWS_SHARED_CREDENTIALS_FILE) {
params.filename = process.env.AWS_SHARED_CREDENTIALS_FILE;
}

const profileCredentials = new AWS.SharedIniFileCredentials(params);
if (!(profileCredentials.accessKeyId
|| profileCredentials.sessionToken
|| profileCredentials.roleArn)) {
throw new Error(`Profile ${profile} does not exist`);
}

impl.addCredentials(results, profileCredentials);
}
},
Expand Down
Loading

0 comments on commit 344a3b7

Please sign in to comment.