serverless-step-functions
Advanced tools
Comparing version 1.3.0 to 1.4.0
@@ -21,2 +21,3 @@ 'use strict'; | ||
AuthorizationType: 'NONE', | ||
ApiKeyRequired: Boolean(event.http.private), | ||
ResourceId: resourceId, | ||
@@ -23,0 +24,0 @@ RestApiId: { Ref: this.apiGatewayRestApiLogicalId }, |
@@ -31,4 +31,6 @@ 'use strict'; | ||
= { 'foo/bar': 'apiGatewayResourceLogicalId' }; | ||
serverlessStepFunctions.apiGatewayResourceNames | ||
= { 'foo/bar': 'apiGatewayResourceNames' }; | ||
serverlessStepFunctions.apiGatewayResourceNames = { | ||
'foo/bar1': 'apiGatewayResourceNamesFirst', | ||
'foo/bar2': 'apiGatewayResourceNamesSecond', | ||
}; | ||
serverlessStepFunctions.pluginhttpValidated = { | ||
@@ -39,6 +41,14 @@ events: [ | ||
http: { | ||
path: 'foo/bar', | ||
path: 'foo/bar1', | ||
method: 'post', | ||
}, | ||
}, | ||
{ | ||
stateMachineName: 'first', | ||
http: { | ||
path: 'foo/bar2', | ||
method: 'post', | ||
private: true, | ||
}, | ||
}, | ||
], | ||
@@ -53,5 +63,18 @@ }; | ||
.Resources) | ||
.to.have.property('ApiGatewayMethodapiGatewayResourceNamesPost'); | ||
.to.have.property('ApiGatewayMethodapiGatewayResourceNamesFirstPost'); | ||
}) | ||
); | ||
it('should verify if http private parameter is correctly passed to resource', | ||
() => serverlessStepFunctions | ||
.compileMethods().then(() => { | ||
const resources = serverlessStepFunctions | ||
.serverless.service.provider.compiledCloudFormationTemplate.Resources; | ||
expect(resources.ApiGatewayMethodapiGatewayResourceNamesFirstPost | ||
.Properties.ApiKeyRequired).to.eql(false); | ||
expect(resources.ApiGatewayMethodapiGatewayResourceNamesSecondPost | ||
.Properties.ApiKeyRequired).to.eql(true); | ||
}) | ||
); | ||
}); | ||
@@ -58,0 +81,0 @@ |
@@ -11,2 +11,5 @@ 'use strict'; | ||
const httpCors = require('./deploy/events/apiGateway/cors'); | ||
const httpApiKeys = require('./deploy/events/apiGateway/apiKeys'); | ||
const httpUsagePlan = require('./deploy/events/apiGateway/usagePlan'); | ||
const httpUsagePlanKeys = require('./deploy/events/apiGateway/usagePlanKeys'); | ||
const httpIamRole = require('./deploy/events/apiGateway/iamRole'); | ||
@@ -42,2 +45,5 @@ const httpDeployment = require('./deploy/events/apiGateway/deployment'); | ||
httpCors, | ||
httpApiKeys, | ||
httpUsagePlan, | ||
httpUsagePlanKeys, | ||
httpIamRole, | ||
@@ -112,3 +118,6 @@ httpDeployment, | ||
.then(this.compileHttpIamRole) | ||
.then(this.compileDeployment); | ||
.then(this.compileDeployment) | ||
.then(this.compileApiKeys) | ||
.then(this.compileUsagePlan) | ||
.then(this.compileUsagePlanKeys); | ||
} | ||
@@ -144,2 +153,3 @@ ), | ||
let message = ''; | ||
let stateMachineMessages = ''; | ||
@@ -149,2 +159,3 @@ const endpointInfo = this.endpointInfo; | ||
message += `${chalk.yellow('endpoints:')}`; | ||
if (this.isStateMachines()) { | ||
@@ -167,3 +178,3 @@ _.forEach(this.getAllStateMachines(), (stateMachineName) => { | ||
path = path !== '/' ? `/${path.split('/').filter(p => p !== '').join('/')}` : ''; | ||
message += `\n ${method} - ${endpointInfo}${path}`; | ||
stateMachineMessages += `\n ${method} - ${endpointInfo}${path}`; | ||
} | ||
@@ -174,4 +185,12 @@ }); | ||
} | ||
if (_.isEmpty(stateMachineMessages)) { | ||
return ''; | ||
} | ||
message += stateMachineMessages; | ||
message += '\n'; | ||
this.serverless.cli.consoleLog(message); | ||
return message; | ||
@@ -178,0 +197,0 @@ } |
@@ -110,2 +110,8 @@ 'use strict'; | ||
.stub(serverlessStepFunctions, 'compileDeployment').returns(BbPromise.resolve()); | ||
const compileApiKeysStub = sinon | ||
.stub(serverlessStepFunctions, 'compileApiKeys').returns(BbPromise.resolve()); | ||
const compileUsagePlanStub = sinon | ||
.stub(serverlessStepFunctions, 'compileUsagePlan').returns(BbPromise.resolve()); | ||
const compileUsagePlanKeysStub = sinon | ||
.stub(serverlessStepFunctions, 'compileUsagePlanKeys').returns(BbPromise.resolve()); | ||
return serverlessStepFunctions.hooks['package:compileEvents']() | ||
@@ -121,2 +127,5 @@ .then(() => { | ||
expect(compileDeploymentStub.notCalled).to.be.equal(true); | ||
expect(compileApiKeysStub.notCalled).to.be.equal(true); | ||
expect(compileUsagePlanStub.notCalled).to.be.equal(true); | ||
expect(compileUsagePlanKeysStub.notCalled).to.be.equal(true); | ||
serverlessStepFunctions.compileScheduledEvents.restore(); | ||
@@ -130,2 +139,5 @@ serverlessStepFunctions.httpValidate.restore(); | ||
serverlessStepFunctions.compileDeployment.restore(); | ||
serverlessStepFunctions.compileApiKeys.restore(); | ||
serverlessStepFunctions.compileUsagePlan.restore(); | ||
serverlessStepFunctions.compileUsagePlanKeys.restore(); | ||
}); | ||
@@ -152,2 +164,8 @@ }); | ||
.stub(serverlessStepFunctions, 'compileDeployment').returns(BbPromise.resolve()); | ||
const compileApiKeysStub = sinon | ||
.stub(serverlessStepFunctions, 'compileApiKeys').returns(BbPromise.resolve()); | ||
const compileUsagePlanStub = sinon | ||
.stub(serverlessStepFunctions, 'compileUsagePlan').returns(BbPromise.resolve()); | ||
const compileUsagePlanKeysStub = sinon | ||
.stub(serverlessStepFunctions, 'compileUsagePlanKeys').returns(BbPromise.resolve()); | ||
return serverlessStepFunctions.hooks['package:compileEvents']() | ||
@@ -163,2 +181,5 @@ .then(() => { | ||
expect(compileDeploymentStub.calledAfter(compileHttpIamRoleStub)).to.be.equal(true); | ||
expect(compileApiKeysStub.calledAfter(compileDeploymentStub)).to.be.equal(true); | ||
expect(compileUsagePlanStub.calledAfter(compileApiKeysStub)).to.be.equal(true); | ||
expect(compileUsagePlanKeysStub.calledAfter(compileUsagePlanStub)).to.be.equal(true); | ||
@@ -172,2 +193,5 @@ serverlessStepFunctions.compileScheduledEvents.restore(); | ||
serverlessStepFunctions.compileDeployment.restore(); | ||
serverlessStepFunctions.compileApiKeys.restore(); | ||
serverlessStepFunctions.compileUsagePlan.restore(); | ||
serverlessStepFunctions.compileUsagePlanKeys.restore(); | ||
}); | ||
@@ -256,8 +280,5 @@ }); | ||
serverlessStepFunctions.serverless.service.stepFunctions = {}; | ||
let expectedMessage = ''; | ||
expectedMessage += `${chalk.yellow.underline('Serverless StepFunctions OutPuts')}\n`; | ||
expectedMessage += `${chalk.yellow('endpoints:')}`; | ||
expectedMessage += '\n'; | ||
const expectedMessage = ''; | ||
const message = serverlessStepFunctions.display(); | ||
expect(consoleLogStub.calledOnce).to.equal(true); | ||
expect(consoleLogStub.calledOnce).to.equal(false); | ||
expect(message).to.equal(expectedMessage); | ||
@@ -347,8 +368,5 @@ }); | ||
}; | ||
let expectedMessage = ''; | ||
expectedMessage += `${chalk.yellow.underline('Serverless StepFunctions OutPuts')}\n`; | ||
expectedMessage += `${chalk.yellow('endpoints:')}`; | ||
expectedMessage += '\n'; | ||
const expectedMessage = ''; | ||
const message = serverlessStepFunctions.display(); | ||
expect(consoleLogStub.calledOnce).to.equal(true); | ||
expect(consoleLogStub.calledOnce).to.equal(false); | ||
expect(message).to.equal(expectedMessage); | ||
@@ -370,8 +388,5 @@ }); | ||
}; | ||
let expectedMessage = ''; | ||
expectedMessage += `${chalk.yellow.underline('Serverless StepFunctions OutPuts')}\n`; | ||
expectedMessage += `${chalk.yellow('endpoints:')}`; | ||
expectedMessage += '\n'; | ||
const expectedMessage = ''; | ||
const message = serverlessStepFunctions.display(); | ||
expect(consoleLogStub.calledOnce).to.equal(true); | ||
expect(consoleLogStub.calledOnce).to.equal(false); | ||
expect(message).to.equal(expectedMessage); | ||
@@ -378,0 +393,0 @@ }); |
@@ -38,2 +38,36 @@ 'use strict'; | ||
it('should default to dev when stage and provider are not defined', () => { | ||
serverlessStepFunctions.serverless.pluginManager.cliOptions.stage = null; | ||
serverlessStepFunctions.serverless.service.provider = null; | ||
serverlessStepFunctions.yamlParse() | ||
.then(() => { | ||
expect(serverless.pluginManager.cliOptions.stage).to.be.equal('dev'); | ||
}); | ||
}); | ||
it('should default to us-east-1 when region and provider are not defined', () => { | ||
serverlessStepFunctions.serverless.pluginManager.cliOptions.region = null; | ||
serverlessStepFunctions.serverless.service.provider = null; | ||
serverlessStepFunctions.yamlParse() | ||
.then(() => { | ||
expect(serverless.pluginManager.cliOptions.region).to.be.equal('us-east-1'); | ||
}); | ||
}); | ||
it('should not default to dev when stage is defined', () => { | ||
serverlessStepFunctions.serverless.pluginManager.cliOptions.stage = 'my-stage'; | ||
serverlessStepFunctions.yamlParse() | ||
.then(() => { | ||
expect(serverless.pluginManager.cliOptions.stage).to.be.equal('my-stage'); | ||
}); | ||
}); | ||
it('should not default to us-east-1 when region is defined', () => { | ||
serverlessStepFunctions.serverless.pluginManager.cliOptions.region = 'my-region'; | ||
serverlessStepFunctions.yamlParse() | ||
.then(() => { | ||
expect(serverless.pluginManager.cliOptions.region).to.be.equal('my-region'); | ||
}); | ||
}); | ||
it('should throw error if servicePath is not given', () => { | ||
@@ -40,0 +74,0 @@ serverlessStepFunctions.serverless.config.servicePath = null; |
{ | ||
"name": "serverless-step-functions", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "The module is AWS Step Functions plugin for Serverless Framework", | ||
@@ -30,3 +30,3 @@ "main": "lib/index.js", | ||
"eslint-plugin-react": "^6.1.1", | ||
"serverless": "^1.4.0", | ||
"serverless": "^1.26.1", | ||
"istanbul": "^0.4.4", | ||
@@ -33,0 +33,0 @@ "mocha": "^3.0.2", |
@@ -195,2 +195,56 @@ [![serverless](http://public.serverless.com/badges/v3.svg)](http://www.serverless.com) [![Build Status](https://travis-ci.org/horike37/serverless-step-functions.svg?branch=master)](https://travis-ci.org/horike37/serverless-step-functions) [![npm version](https://badge.fury.io/js/serverless-step-functions.svg)](https://badge.fury.io/js/serverless-step-functions) [![Coverage Status](https://coveralls.io/repos/github/horike37/serverless-step-functions/badge.svg?branch=master)](https://coveralls.io/github/horike37/serverless-step-functions?branch=master) [![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE) | ||
``` | ||
#### Setting API keys for your Rest API | ||
You can specify a list of API keys to be used by your service Rest API by adding an apiKeys array property to the provider object in serverless.yml. You'll also need to explicitly specify which endpoints are private and require one of the api keys to be included in the request by adding a private boolean property to the http event object you want to set as private. API Keys are created globally, so if you want to deploy your service to different stages make sure your API key contains a stage variable as defined below. When using API keys, you can optionally define usage plan quota and throttle, using usagePlan object. | ||
Here's an example configuration for setting API keys for your service Rest API: | ||
```yml | ||
service: my-service | ||
provider: | ||
name: aws | ||
apiKeys: | ||
- myFirstKey | ||
- ${opt:stage}-myFirstKey | ||
- ${env:MY_API_KEY} # you can hide it in a serverless variable | ||
usagePlan: | ||
quota: | ||
limit: 5000 | ||
offset: 2 | ||
period: MONTH | ||
throttle: | ||
burstLimit: 200 | ||
rateLimit: 100 | ||
functions: | ||
hello: | ||
handler: handler.hello | ||
stepFunctions: | ||
stateMachines: | ||
statemachine1: | ||
name: ${self:service}-${opt:stage}-statemachine1 | ||
events: | ||
- http: | ||
path: /hello | ||
method: post | ||
private: true | ||
definition: | ||
Comment: "A Hello World example of the Amazon States Language using an AWS Lambda Function" | ||
StartAt: HelloWorld1 | ||
States: | ||
HelloWorld1: | ||
Type: Task | ||
Resource: arn:aws:lambda:#{AWS::Region}:#{AWS::AccountId}:function:${self:service}-${opt:stage}-hello | ||
End: true | ||
plugins: | ||
- serverless-step-functions | ||
- serverless-pseudo-parameters | ||
``` | ||
Please note that those are the API keys names, not the actual values. Once you deploy your service, the value of those API keys will be auto generated by AWS and printed on the screen for you to use. The values can be concealed from the output with the --conceal deploy option. | ||
Clients connecting to this Rest API will then need to set any of these API keys values in the x-api-key header of their request. This is only necessary for functions where the private property is set to true. | ||
### Schedule | ||
@@ -197,0 +251,0 @@ The following config will attach a schedule event and causes the stateMachine `crawl` to be called every 2 hours. The configuration allows you to attach multiple schedules to the same stateMachine. You can either use the `rate` or `cron` syntax. Take a look at the [AWS schedule syntax documentation](http://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html) for more details. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
198343
49
4693
578