mirror of
https://github.com/serverless/serverless.git
synced 2026-01-25 15:07:39 +00:00
refactored naming-js method naming
This commit is contained in:
parent
08156924d5
commit
fef9b68e5a
@ -18,7 +18,7 @@ module.exports = {
|
||||
}
|
||||
|
||||
const apiKeyLogicalId = this.provider.naming
|
||||
.getLogicalApiGatewayApiKeyName(apiKeyNumber);
|
||||
.getApiKeyLogicalId(apiKeyNumber);
|
||||
|
||||
_.merge(this.serverless.service.provider.compiledCloudFormationTemplate.Resources, {
|
||||
[apiKeyLogicalId]: {
|
||||
|
||||
@ -31,7 +31,7 @@ module.exports = {
|
||||
});
|
||||
}
|
||||
|
||||
const authorizerLogicalId = this.provider.naming.getLogicalAuthorizerName(authorizer.name);
|
||||
const authorizerLogicalId = this.provider.naming.getAuthorizerLogicalId(authorizer.name);
|
||||
|
||||
_.merge(this.serverless.service.provider.compiledCloudFormationTemplate.Resources, {
|
||||
[authorizerLogicalId]: {
|
||||
|
||||
@ -10,7 +10,7 @@ module.exports = {
|
||||
const resourceName = this.getResourceName(path);
|
||||
const resourceRef = this.getResourceId(path);
|
||||
const corsMethodLogicalId = this.provider.naming
|
||||
.getLogicalApiGatewayMethodName(resourceName, 'options');
|
||||
.getMethodLogicalId(resourceName, 'options');
|
||||
|
||||
const preflightHeaders = {
|
||||
'Access-Control-Allow-Origin': `'${config.origins.join(',')}'`,
|
||||
|
||||
@ -5,7 +5,8 @@ const BbPromise = require('bluebird');
|
||||
|
||||
module.exports = {
|
||||
compileDeployment() {
|
||||
this.apiGatewayDeploymentLogicalId = this.provider.naming.getApiGatewayDeploymentId();
|
||||
this.apiGatewayDeploymentLogicalId = this.provider.naming
|
||||
.generateApiGatewayDeploymentLogicalId();
|
||||
|
||||
_.merge(this.serverless.service.provider.compiledCloudFormationTemplate.Resources, {
|
||||
[this.apiGatewayDeploymentLogicalId]: {
|
||||
|
||||
@ -4,7 +4,7 @@ module.exports = {
|
||||
getMethodAuthorization(http) {
|
||||
if (http.authorizer) {
|
||||
const authorizerLogicalId = this.provider.naming
|
||||
.getLogicalAuthorizerName(http.authorizer.name);
|
||||
.getAuthorizerLogicalId(http.authorizer.name);
|
||||
|
||||
return {
|
||||
Properties: {
|
||||
|
||||
@ -34,7 +34,7 @@ module.exports = {
|
||||
);
|
||||
|
||||
const methodLogicalId = this.provider.naming
|
||||
.getLogicalApiGatewayMethodName(resourceName, event.http.method);
|
||||
.getMethodLogicalId(resourceName, event.http.method);
|
||||
|
||||
this.apiGatewayMethodLogicalIds.push(methodLogicalId);
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@ const _ = require('lodash');
|
||||
module.exports = {
|
||||
getMethodIntegration(http, functionName) {
|
||||
const lambdaLogicalId = this.provider.naming
|
||||
.getLogicalLambdaName(functionName);
|
||||
.getLambdaLogicalId(functionName);
|
||||
const integration = {
|
||||
IntegrationHttpMethod: 'POST',
|
||||
Type: http.integration,
|
||||
|
||||
@ -8,9 +8,9 @@ module.exports = {
|
||||
compilePermissions() {
|
||||
this.validated.events.forEach((event) => {
|
||||
const lambdaPermissionLogicalId = this.provider.naming
|
||||
.getLambdaApiGatewayPermissionName(event.functionName);
|
||||
.getLambdaApiGatewayPermissionLogicalId(event.functionName);
|
||||
const lambdaLogicalId = this.provider.naming
|
||||
.getLogicalLambdaName(event.functionName);
|
||||
.getLambdaLogicalId(event.functionName);
|
||||
|
||||
_.merge(this.serverless.service.provider.compiledCloudFormationTemplate.Resources, {
|
||||
[lambdaPermissionLogicalId]: {
|
||||
@ -28,7 +28,7 @@ module.exports = {
|
||||
if (event.http.authorizer) {
|
||||
const authorizer = event.http.authorizer;
|
||||
const authorizerPermissionLogicalId = this.provider.naming
|
||||
.getLambdaApiGatewayPermissionName(authorizer.name);
|
||||
.getLambdaApiGatewayPermissionLogicalId(authorizer.name);
|
||||
|
||||
_.merge(this.serverless.service.provider.compiledCloudFormationTemplate.Resources, {
|
||||
[authorizerPermissionLogicalId]: {
|
||||
|
||||
@ -14,8 +14,8 @@ module.exports = {
|
||||
// ['users', 'users/create', 'users/create/something']
|
||||
resourcePaths.forEach(path => {
|
||||
const pathArray = path.split('/');
|
||||
const resourceName = this.provider.naming.getNormalizedApiGatewayResourceName(path);
|
||||
const resourceLogicalId = this.provider.naming.getLogicalApiGatewayResourceName(path);
|
||||
const resourceName = this.provider.naming.normalizePath(path);
|
||||
const resourceLogicalId = this.provider.naming.getResourceLogicalId(path);
|
||||
const pathPart = pathArray.pop();
|
||||
const parentPath = pathArray.join('/');
|
||||
const parentRef = this.getResourceId(parentPath);
|
||||
|
||||
@ -5,7 +5,7 @@ const BbPromise = require('bluebird');
|
||||
|
||||
module.exports = {
|
||||
compileRestApi() {
|
||||
this.apiGatewayRestApiLogicalId = this.provider.naming.getLogicalApiGatewayName();
|
||||
this.apiGatewayRestApiLogicalId = this.provider.naming.getRestApiLogicalId();
|
||||
|
||||
_.merge(this.serverless.service.provider.compiledCloudFormationTemplate.Resources, {
|
||||
[this.apiGatewayRestApiLogicalId]: {
|
||||
|
||||
@ -375,7 +375,7 @@ module.exports = {
|
||||
|
||||
getLambdaArn(name) {
|
||||
this.serverless.service.getFunction(name);
|
||||
const lambdaLogicalId = this.provider.naming.getLogicalLambdaName(name);
|
||||
const lambdaLogicalId = this.provider.naming.getLambdaLogicalId(name);
|
||||
return { 'Fn::GetAtt': [lambdaLogicalId, 'Arn'] };
|
||||
},
|
||||
|
||||
|
||||
@ -79,7 +79,7 @@ class AwsCompileS3Events {
|
||||
}
|
||||
|
||||
const lambdaLogicalId = this.provider.naming
|
||||
.getLogicalLambdaName(functionName);
|
||||
.getLambdaLogicalId(functionName);
|
||||
|
||||
// check if the bucket already defined
|
||||
// in another S3 event in the service
|
||||
@ -139,7 +139,7 @@ class AwsCompileS3Events {
|
||||
};
|
||||
|
||||
const bucketLogicalId = this.provider.naming
|
||||
.getLogicalBucketName(bucketName);
|
||||
.getBucketLogicalId(bucketName);
|
||||
const bucketCFResource = {
|
||||
[bucketLogicalId]: bucketTemplate,
|
||||
};
|
||||
@ -152,7 +152,7 @@ class AwsCompileS3Events {
|
||||
// by adding Lambda::Permission resource for each
|
||||
s3EnabledFunctions.forEach(functionName => {
|
||||
const lambdaLogicalId = this.provider.naming
|
||||
.getLogicalLambdaName(functionName);
|
||||
.getLambdaLogicalId(functionName);
|
||||
const permissionTemplate = {
|
||||
Type: 'AWS::Lambda::Permission',
|
||||
Properties: {
|
||||
@ -167,7 +167,7 @@ class AwsCompileS3Events {
|
||||
},
|
||||
};
|
||||
const lambdaPermissionLogicalId = this.provider.naming
|
||||
.getLambdaS3PermissionName(functionName);
|
||||
.getLambdaS3PermissionLogicalId(functionName);
|
||||
const permissionCFResource = {
|
||||
[lambdaPermissionLogicalId]: permissionTemplate,
|
||||
};
|
||||
|
||||
@ -75,12 +75,12 @@ class AwsCompileScheduledEvents {
|
||||
}
|
||||
|
||||
const lambdaLogicalId = this.provider.naming
|
||||
.getLogicalLambdaName(functionName);
|
||||
.getLambdaLogicalId(functionName);
|
||||
const scheduleLogicalId = this.provider.naming
|
||||
.getCloudWatchEventName(functionName, scheduleNumberInFunction);
|
||||
.getScheduleLogicalId(functionName, scheduleNumberInFunction);
|
||||
const lambdaPermissionLogicalId = this.provider.naming
|
||||
.getLambdaCloudWatchEventPermissionName(functionName, scheduleNumberInFunction);
|
||||
const scheduleId = this.provider.naming.getCloudWatchEventId(functionName);
|
||||
.getLambdaSchedulePermissionLogicalId(functionName, scheduleNumberInFunction);
|
||||
const scheduleId = this.provider.naming.getScheduleId(functionName);
|
||||
|
||||
const scheduleTemplate = `
|
||||
{
|
||||
|
||||
@ -51,11 +51,11 @@ class AwsCompileSNSEvents {
|
||||
}
|
||||
|
||||
const lambdaLogicalId = this.provider.naming
|
||||
.getLogicalLambdaName(functionName);
|
||||
.getLambdaLogicalId(functionName);
|
||||
const topicLogicalId = this.provider.naming
|
||||
.getLogicalSnsTopicName(topicName);
|
||||
.getTopicLogicalId(topicName);
|
||||
const lambdaPermissionLogicalId = this.provider.naming
|
||||
.getLambdaSnsTopicPermissionName(functionName, topicName);
|
||||
.getLambdaSnsPermissionLogicalId(functionName, topicName);
|
||||
|
||||
const snsTemplate = `
|
||||
{
|
||||
|
||||
@ -61,7 +61,7 @@ class AwsCompileStreamEvents {
|
||||
const streamName = EventSourceArn.split('/')[1];
|
||||
|
||||
const lambdaLogicalId = this.provider.naming
|
||||
.getLogicalLambdaName(functionName);
|
||||
.getLambdaLogicalId(functionName);
|
||||
const streamLogicalId = this.provider.naming
|
||||
.getStreamLogicalId(functionName, streamType, streamName);
|
||||
|
||||
|
||||
@ -104,9 +104,9 @@ class AwsCompileFunctions {
|
||||
}
|
||||
|
||||
const functionLogicalId = this.provider.naming
|
||||
.getLogicalLambdaName(functionName);
|
||||
.getLambdaLogicalId(functionName);
|
||||
const functionOutputLogicalId = this.provider.naming
|
||||
.getLogicalLambdaArnName(functionName);
|
||||
.getLambdaOutputLogicalId(functionName);
|
||||
const newFunctionObject = {
|
||||
[functionLogicalId]: newFunction,
|
||||
};
|
||||
|
||||
@ -80,7 +80,7 @@ module.exports = {
|
||||
this.serverless.service.getAllFunctions().forEach((functionName) => {
|
||||
const functionObject = this.serverless.service.getFunction(functionName);
|
||||
const logGroupLogicalId = this.provider.naming
|
||||
.getLogicalLogGroupName(functionName);
|
||||
.getLogGroupLogicalId(functionName);
|
||||
const logGroupTemplate = `
|
||||
{
|
||||
"${logGroupLogicalId}": {
|
||||
|
||||
@ -55,7 +55,7 @@ class AwsInfo {
|
||||
outputs = result.Stacks[0].Outputs;
|
||||
|
||||
const lambdaArnOutputRegex = this.provider.naming
|
||||
.getLogicalLambdaArnNameRegex();
|
||||
.getLambdaOutputLogicalIdRegex();
|
||||
|
||||
const serviceEndpointOutputRegex = this.provider.naming
|
||||
.getServiceEndpointRegex();
|
||||
|
||||
@ -3,16 +3,15 @@
|
||||
const _ = require('lodash');
|
||||
|
||||
module.exports = {
|
||||
/*
|
||||
* General Name Normalization
|
||||
*/
|
||||
|
||||
// General
|
||||
normalizeName(name) {
|
||||
return `${_.upperFirst(name)}`;
|
||||
},
|
||||
normalizeNameToAlphaNumericOnly(name) {
|
||||
return this.normalizeName(name.replace(/[^0-9A-Za-z]/g, ''));
|
||||
},
|
||||
normalizePathtoCapitalAlphaNumbericOnlyWithReplacement(path) {
|
||||
normalizePathPart(path) {
|
||||
return this.normalizeNameToAlphaNumericOnly(
|
||||
path.replace(/-/g, 'Dash')
|
||||
.replace(/\{(.*)\}/g, '$1Var'));
|
||||
@ -22,21 +21,17 @@ module.exports = {
|
||||
return /^ServiceEndpoint/;
|
||||
},
|
||||
|
||||
/*
|
||||
* Stack Naming
|
||||
*/
|
||||
// Stack
|
||||
getStackName() {
|
||||
return `${this.sdk.serverless.service.service}-${this.sdk.getStage()}`;
|
||||
},
|
||||
|
||||
getLogicalLogGroupName(functionName) {
|
||||
return `${this.getNormalizedLambdaName(functionName)}LogGroup`;
|
||||
getLogGroupLogicalId(functionName) {
|
||||
return `${this.getNormalizedFunctionName(functionName)}LogGroup`;
|
||||
},
|
||||
|
||||
/*
|
||||
* Lambda Function Naming
|
||||
*/
|
||||
getNormalizedLambdaName(functionName) {
|
||||
// Lambda
|
||||
getNormalizedFunctionName(functionName) {
|
||||
return this.normalizeName(functionName);
|
||||
},
|
||||
extractLambdaNameFromArn(functionArn) {
|
||||
@ -49,126 +44,108 @@ module.exports = {
|
||||
const splitName = splitArn[splitArn.length - 1].split('-');
|
||||
return splitName[splitName.length - 1];
|
||||
},
|
||||
getLogicalLambdaName(functionName) {
|
||||
return `${this.getNormalizedLambdaName(functionName)}LambdaFunction`;
|
||||
getLambdaLogicalId(functionName) {
|
||||
return `${this.getNormalizedFunctionName(functionName)}LambdaFunction`;
|
||||
},
|
||||
getLogicalLambdaNameRegex() {
|
||||
getLambdaLogicalIdRegex() {
|
||||
return /LambdaFunction$/;
|
||||
},
|
||||
getLogicalLambdaArnName(functionName) {
|
||||
return `${this.getLogicalLambdaName(functionName)}Arn`;
|
||||
getLambdaOutputLogicalId(functionName) {
|
||||
return `${this.getLambdaLogicalId(functionName)}Arn`;
|
||||
},
|
||||
getLogicalLambdaArnNameRegex() {
|
||||
getLambdaOutputLogicalIdRegex() {
|
||||
return /LambdaFunctionArn$/;
|
||||
},
|
||||
|
||||
/*
|
||||
* ApiGateway Authorizer Lambda & Method Naming
|
||||
*/
|
||||
getApiGatewayName() {
|
||||
return `${this.sdk.getStage()}-${this.sdk.serverless.service.service}`;
|
||||
},
|
||||
getApiGatewayDeploymentId() {
|
||||
// API Gateway
|
||||
generateApiGatewayDeploymentLogicalId() {
|
||||
return `ApiGatewayDeployment${(new Date()).getTime().toString()}`;
|
||||
},
|
||||
getLogicalApiGatewayName() {
|
||||
getRestApiLogicalId() {
|
||||
return 'ApiGatewayRestApi';
|
||||
},
|
||||
getNormalizedAuthorizerName(functionName) {
|
||||
return this.getNormalizedLambdaName(functionName);
|
||||
return this.getNormalizedFunctionName(functionName);
|
||||
},
|
||||
getLogicalAuthorizerName(functionName) {
|
||||
getAuthorizerLogicalId(functionName) {
|
||||
return `${this.getNormalizedAuthorizerName(functionName)}ApiGatewayAuthorizer`;
|
||||
},
|
||||
getLogicalAuthorizerArnName(functionName) {
|
||||
return `${this.getLogicalAuthorizerName(functionName)}Arn`;
|
||||
},
|
||||
getNormalizedApiGatewayResourceName(resourcePath) {
|
||||
normalizePath(resourcePath) {
|
||||
return resourcePath.split('/').map(
|
||||
this.normalizePathtoCapitalAlphaNumbericOnlyWithReplacement.bind(this)
|
||||
this.normalizePathPart.bind(this)
|
||||
).join('');
|
||||
},
|
||||
getLogicalApiGatewayResourceName(resourcePath) {
|
||||
return `ApiGatewayResource${this.getNormalizedApiGatewayResourceName(resourcePath)}`;
|
||||
getResourceLogicalId(resourcePath) {
|
||||
return `ApiGatewayResource${this.normalizePath(resourcePath)}`;
|
||||
},
|
||||
extractResourceId(logicalApiGatewayResourceName) {
|
||||
return logicalApiGatewayResourceName.match(/ApiGatewayResource(.*)/)[1];
|
||||
extractResourceId(resourceLogicalId) {
|
||||
return resourceLogicalId.match(/ApiGatewayResource(.*)/)[1];
|
||||
},
|
||||
getNormalizedApiGatewayMethodName(methodName) {
|
||||
normalizeMethodName(methodName) {
|
||||
return this.normalizeName(methodName.toLowerCase());
|
||||
},
|
||||
getLogicalApiGatewayMethodName(resourceId, methodName) {
|
||||
return `ApiGatewayMethod${resourceId}${this.getNormalizedApiGatewayMethodName(methodName)}`;
|
||||
getMethodLogicalId(resourceId, methodName) {
|
||||
return `ApiGatewayMethod${resourceId}${this.normalizeMethodName(methodName)}`;
|
||||
},
|
||||
getLogicalApiGatewayApiKeyName(apiKeyNumber) {
|
||||
getApiKeyLogicalId(apiKeyNumber) {
|
||||
return `ApiGatewayApiKey${apiKeyNumber}`;
|
||||
},
|
||||
getLogicalApiGatewayApiKeyRegex() {
|
||||
getApiKeyLogicalIdRegex() {
|
||||
return /^ApiGatewayApiKey/;
|
||||
},
|
||||
|
||||
/*
|
||||
* S3 Bucket Naming
|
||||
*/
|
||||
getLogicalDeploymentBucketName() {
|
||||
// S3
|
||||
getDeploymentBucketLogicalId() {
|
||||
return 'ServerlessDeploymentBucket';
|
||||
},
|
||||
getLogicalDeploymentBucketOutputVariableName() {
|
||||
getDeploymentBucketOutputLogicalId() {
|
||||
return 'ServerlessDeploymentBucketName';
|
||||
},
|
||||
getNormalizedBucketName(bucketName) {
|
||||
normalizeBucketName(bucketName) {
|
||||
return this.normalizeNameToAlphaNumericOnly(bucketName);
|
||||
},
|
||||
getLogicalBucketName(bucketName) {
|
||||
return `S3Bucket${this.getNormalizedBucketName(bucketName)}`;
|
||||
getBucketLogicalId(bucketName) {
|
||||
return `S3Bucket${this.normalizeBucketName(bucketName)}`;
|
||||
},
|
||||
|
||||
/*
|
||||
* SNS Topic Naming
|
||||
*/
|
||||
getNormalizedSnsTopicName(topicName) {
|
||||
// SNS
|
||||
normalizeTopicName(topicName) {
|
||||
return this.normalizeNameToAlphaNumericOnly(topicName);
|
||||
},
|
||||
getLogicalSnsTopicName(topicName) {
|
||||
return `SNSTopic${this.getNormalizedSnsTopicName(topicName)}`;
|
||||
getTopicLogicalId(topicName) {
|
||||
return `SNSTopic${this.normalizeTopicName(topicName)}`;
|
||||
},
|
||||
|
||||
/*
|
||||
* CloudWatch Event Naming
|
||||
*/
|
||||
getCloudWatchEventId(functionName) {
|
||||
// Schedule
|
||||
getScheduleId(functionName) {
|
||||
return `${functionName}Schedule`;
|
||||
},
|
||||
getCloudWatchEventName(functionName, scheduleIndex) {
|
||||
return `${this.getNormalizedLambdaName(functionName)}EventsRuleSchedule${scheduleIndex}`;
|
||||
getScheduleLogicalId(functionName, scheduleIndex) {
|
||||
return `${this.getNormalizedFunctionName(functionName)}EventsRuleSchedule${scheduleIndex}`;
|
||||
},
|
||||
|
||||
/*
|
||||
* Stream Event Naming
|
||||
*/
|
||||
// Stream
|
||||
getStreamLogicalId(functionName, streamType, streamName) {
|
||||
return `${
|
||||
this.getNormalizedLambdaName(functionName)
|
||||
this.getNormalizedFunctionName(functionName)
|
||||
}EventSourceMapping${
|
||||
this.normalizeName(streamType)
|
||||
}${this.normalizeNameToAlphaNumericOnly(streamName)}`;
|
||||
},
|
||||
|
||||
/*
|
||||
* Lambda to S3 Bucket/SNS Topic/CloudWatch Event/ApiGateway Permissions Naming
|
||||
*/
|
||||
getLambdaS3PermissionName(functionName) {
|
||||
return `${this.getNormalizedLambdaName(functionName)}LambdaPermissionS3`;
|
||||
// Permissions
|
||||
getLambdaS3PermissionLogicalId(functionName) {
|
||||
return `${this.getNormalizedFunctionName(functionName)}LambdaPermissionS3`;
|
||||
},
|
||||
getLambdaSnsTopicPermissionName(functionName, topicName) {
|
||||
return `${this.getNormalizedLambdaName(functionName)}LambdaPermission${
|
||||
this.getNormalizedSnsTopicName(topicName)}`;
|
||||
getLambdaSnsPermissionLogicalId(functionName, topicName) {
|
||||
return `${this.getNormalizedFunctionName(functionName)}LambdaPermission${
|
||||
this.normalizeTopicName(topicName)}`;
|
||||
},
|
||||
getLambdaCloudWatchEventPermissionName(functionName, scheduleIndex) {
|
||||
return `${this.getNormalizedLambdaName(functionName)}LambdaPermissionEventsRuleSchedule${
|
||||
getLambdaSchedulePermissionLogicalId(functionName, scheduleIndex) {
|
||||
return `${this.getNormalizedFunctionName(functionName)}LambdaPermissionEventsRuleSchedule${
|
||||
scheduleIndex}`;
|
||||
},
|
||||
getLambdaApiGatewayPermissionName(functionName) {
|
||||
return `${this.getNormalizedLambdaName(functionName)}LambdaPermissionApiGateway`;
|
||||
getLambdaApiGatewayPermissionLogicalId(functionName) {
|
||||
return `${this.getNormalizedFunctionName(functionName)}LambdaPermissionApiGateway`;
|
||||
},
|
||||
};
|
||||
|
||||
@ -5,7 +5,7 @@ const BbPromise = require('bluebird');
|
||||
const HttpsProxyAgent = require('https-proxy-agent');
|
||||
const url = require('url');
|
||||
|
||||
const Naming = require('../lib/naming.js');
|
||||
const naming = require('../lib/naming.js');
|
||||
|
||||
const constants = {
|
||||
providerName: 'aws',
|
||||
@ -89,7 +89,7 @@ class AwsProvider {
|
||||
this.sdk = AWS;
|
||||
this.serverless.setProvider(constants.providerName, this);
|
||||
|
||||
Object.assign(this.naming, Naming);
|
||||
Object.assign(this.naming, naming);
|
||||
|
||||
// Use HTTPS Proxy (Optional)
|
||||
const proxy = process.env.proxy
|
||||
@ -145,7 +145,7 @@ class AwsProvider {
|
||||
const errorMessage = [
|
||||
'AWS provider credentials not found.',
|
||||
' You can find more info on how to set up provider',
|
||||
' credentials in our docs here: https://git.io/viZAC',
|
||||
' credentials in our docs here: https://git.io/vXsdd',
|
||||
].join('');
|
||||
err.message = errorMessage;
|
||||
}
|
||||
@ -164,7 +164,7 @@ class AwsProvider {
|
||||
* @returns {{region: *}}
|
||||
*/
|
||||
getCredentials() {
|
||||
const ret = { region: this.getRegion() };
|
||||
const returnValue = { region: this.getRegion() };
|
||||
const credentials = {};
|
||||
const stageUpper = this.getStage() ? this.getStage().toUpperCase() : null;
|
||||
|
||||
@ -177,21 +177,21 @@ class AwsProvider {
|
||||
impl.addEnvironmentProfile(credentials, `AWS_${stageUpper}`);
|
||||
|
||||
if (Object.keys(credentials).length) {
|
||||
ret.credentials = credentials;
|
||||
returnValue.credentials = credentials;
|
||||
}
|
||||
return ret;
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
getRegion() {
|
||||
let ret = 'us-east-1';
|
||||
let returnValue = 'us-east-1';
|
||||
if (this.options && this.options.region) {
|
||||
ret = this.options.region;
|
||||
returnValue = this.options.region;
|
||||
} else if (this.serverless.config.region) {
|
||||
ret = this.serverless.config.region;
|
||||
returnValue = this.serverless.config.region;
|
||||
} else if (this.serverless.service.provider.region) {
|
||||
ret = this.serverless.service.provider.region;
|
||||
returnValue = this.serverless.service.provider.region;
|
||||
}
|
||||
return ret;
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
getServerlessDeploymentBucketName() {
|
||||
@ -202,21 +202,21 @@ class AwsProvider {
|
||||
'describeStackResource',
|
||||
{
|
||||
StackName: this.naming.getStackName(),
|
||||
LogicalResourceId: this.naming.getLogicalDeploymentBucketName(),
|
||||
LogicalResourceId: this.naming.getDeploymentBucketLogicalId(),
|
||||
}
|
||||
).then((result) => result.StackResourceDetail.PhysicalResourceId);
|
||||
}
|
||||
|
||||
getStage() {
|
||||
let ret = 'dev';
|
||||
let returnValue = 'dev';
|
||||
if (this.options && this.options.stage) {
|
||||
ret = this.options.stage;
|
||||
returnValue = this.options.stage;
|
||||
} else if (this.serverless.config.stage) {
|
||||
ret = this.serverless.config.stage;
|
||||
returnValue = this.serverless.config.stage;
|
||||
} else if (this.serverless.service.provider.stage) {
|
||||
ret = this.serverless.service.provider.stage;
|
||||
returnValue = this.serverless.service.provider.stage;
|
||||
}
|
||||
return ret;
|
||||
return returnValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -183,7 +183,7 @@ describe('AwsProvider', () => {
|
||||
awsProvider.request('S3', 'error', {})
|
||||
.then(() => done('Should not succeed'))
|
||||
.catch((err) => {
|
||||
expect(err.message).to.contain('https://git.io/viZAC');
|
||||
expect(err.message).to.contain('https://git.io/vXsdd');
|
||||
done();
|
||||
})
|
||||
.catch(done);
|
||||
@ -353,7 +353,7 @@ describe('AwsProvider', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getRegion', () => {
|
||||
describe('#getRegion()', () => {
|
||||
let newAwsProvider;
|
||||
|
||||
it('should prefer options over config or provider', () => {
|
||||
@ -369,6 +369,7 @@ describe('AwsProvider', () => {
|
||||
|
||||
expect(newAwsProvider.getRegion()).to.equal(newOptions.region);
|
||||
});
|
||||
|
||||
it('should prefer config over provider in lieu of options', () => {
|
||||
const newOptions = {};
|
||||
const config = {
|
||||
@ -380,6 +381,7 @@ describe('AwsProvider', () => {
|
||||
|
||||
expect(newAwsProvider.getRegion()).to.equal(config.region);
|
||||
});
|
||||
|
||||
it('should use provider in lieu of options and config', () => {
|
||||
const newOptions = {};
|
||||
const config = {};
|
||||
@ -389,6 +391,7 @@ describe('AwsProvider', () => {
|
||||
|
||||
expect(newAwsProvider.getRegion()).to.equal(serverless.service.provider.region);
|
||||
});
|
||||
|
||||
it('should use the default us-east-1 in lieu of options, config, and provider', () => {
|
||||
const newOptions = {};
|
||||
const config = {};
|
||||
@ -399,7 +402,7 @@ describe('AwsProvider', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getServerlessDeploymentBucketName', () => {
|
||||
describe('#getServerlessDeploymentBucketName()', () => {
|
||||
it('should return the name of the serverless deployment bucket', () => {
|
||||
const describeStackResourcesStub = sinon
|
||||
.stub(awsProvider, 'request')
|
||||
@ -444,7 +447,7 @@ describe('AwsProvider', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getStage', () => {
|
||||
describe('#getStage()', () => {
|
||||
it('should prefer options over config or provider', () => {
|
||||
const newOptions = {
|
||||
stage: 'optionsStage',
|
||||
|
||||
@ -41,27 +41,27 @@ describe('#naming()', () => {
|
||||
});
|
||||
describe('#normalizeNameToCapitalAlphaNumbericOnly()', () => {
|
||||
it('converts `-` to `Dash`', () => {
|
||||
expect(sdk.naming.normalizePathtoCapitalAlphaNumbericOnlyWithReplacement(
|
||||
expect(sdk.naming.normalizePathPart(
|
||||
'a-path'
|
||||
)).to.equal('ADashpath');
|
||||
});
|
||||
it('converts variable declarations (`${var}`) to `VariableVar`', () => {
|
||||
expect(sdk.naming.normalizePathtoCapitalAlphaNumbericOnlyWithReplacement(
|
||||
expect(sdk.naming.normalizePathPart(
|
||||
'${variable}'
|
||||
)).to.equal('VariableVar');
|
||||
});
|
||||
it('converts variable declarations prefixes to `VariableVarPath`', () => {
|
||||
expect(sdk.naming.normalizePathtoCapitalAlphaNumbericOnlyWithReplacement(
|
||||
expect(sdk.naming.normalizePathPart(
|
||||
'${variable}Path'
|
||||
)).to.equal('VariableVarPath');
|
||||
});
|
||||
it('converts variable declarations suffixes to `PathvariableVar`', () => {
|
||||
expect(sdk.naming.normalizePathtoCapitalAlphaNumbericOnlyWithReplacement(
|
||||
expect(sdk.naming.normalizePathPart(
|
||||
'path${variable}'
|
||||
)).to.equal('PathvariableVar');
|
||||
});
|
||||
it('converts variable declarations in center to `PathvariableVarDir`', () => {
|
||||
expect(sdk.naming.normalizePathtoCapitalAlphaNumbericOnlyWithReplacement(
|
||||
expect(sdk.naming.normalizePathPart(
|
||||
'path${variable}Dir'
|
||||
)).to.equal('PathvariableVarDir');
|
||||
});
|
||||
@ -86,9 +86,9 @@ describe('#naming()', () => {
|
||||
expect(sdk.naming.getStackName()).to.equal(`${serverless.service.service}-${options.stage}`);
|
||||
});
|
||||
});
|
||||
describe('#getNormalizedLambdaName()', () => {
|
||||
describe('#getNormalizedFunctionName()', () => {
|
||||
it('should normalize the given functionName', () => {
|
||||
expect(sdk.naming.getNormalizedLambdaName('functionName'))
|
||||
expect(sdk.naming.getNormalizedFunctionName('functionName'))
|
||||
.to.equal('FunctionName');
|
||||
});
|
||||
});
|
||||
@ -104,65 +104,59 @@ describe('#naming()', () => {
|
||||
expect(sdk.naming.extractLambdaNameFromArn(arn)).to.equal('my-dev-lambda');
|
||||
});
|
||||
});
|
||||
describe('#getLogicalLambdaName()', () => {
|
||||
describe('#getLambdaLogicalId()', () => {
|
||||
it('should normalize the function name and add the logical suffix', () => {
|
||||
expect(sdk.naming.getLogicalLambdaName('functionName'))
|
||||
expect(sdk.naming.getLambdaLogicalId('functionName'))
|
||||
.to.equal('FunctionNameLambdaFunction');
|
||||
});
|
||||
});
|
||||
describe('#getLogicalLambdaNameRegex()', () => {
|
||||
describe('#getLambdaLogicalIdRegex()', () => {
|
||||
it('should match the suffix', () => {
|
||||
expect(sdk.naming.getLogicalLambdaNameRegex()
|
||||
expect(sdk.naming.getLambdaLogicalIdRegex()
|
||||
.test('LambdaFunction')).to.equal(true);
|
||||
});
|
||||
it('should not match a name without the suffix', () => {
|
||||
expect(sdk.naming.getLogicalLambdaNameRegex()
|
||||
expect(sdk.naming.getLambdaLogicalIdRegex()
|
||||
.test('LambdaFunctionNotTheSuffix')).to.equal(false);
|
||||
});
|
||||
it('should match a name with the suffix', () => {
|
||||
expect(sdk.naming.getLogicalLambdaNameRegex()
|
||||
expect(sdk.naming.getLambdaLogicalIdRegex()
|
||||
.test('AFunctionNameLambdaFunction')).to.equal(true);
|
||||
});
|
||||
});
|
||||
describe('#getLogicalLambdaArnName()', () => {
|
||||
describe('#getLambdaOutputLogicalId()', () => {
|
||||
it('should normalize the function name and add the logical arn suffix', () => {
|
||||
expect(
|
||||
sdk.naming.getLogicalLambdaArnName('functionName')
|
||||
sdk.naming.getLambdaOutputLogicalId('functionName')
|
||||
).to.equal('FunctionNameLambdaFunctionArn');
|
||||
});
|
||||
});
|
||||
describe('#getLogicalLambdaArnNameRegex()', () => {
|
||||
describe('#getLambdaOutputLogicalIdRegex()', () => {
|
||||
it('should match the suffix', () => {
|
||||
expect(sdk.naming.getLogicalLambdaArnNameRegex()
|
||||
expect(sdk.naming.getLambdaOutputLogicalIdRegex()
|
||||
.test('aLambdaFunctionArn')).to.equal(true);
|
||||
});
|
||||
it('should not match a name without the suffix', () => {
|
||||
expect(sdk.naming.getLogicalLambdaArnNameRegex()
|
||||
expect(sdk.naming.getLambdaOutputLogicalIdRegex()
|
||||
.test('LambdaFunctionArnNotTheSuffix'))
|
||||
.to.equal(false);
|
||||
});
|
||||
it('should match a name with the suffix', () => {
|
||||
expect(sdk.naming.getLogicalLambdaArnNameRegex()
|
||||
expect(sdk.naming.getLambdaOutputLogicalIdRegex()
|
||||
.test('AFunctionArnNameLambdaFunctionArn'))
|
||||
.to.equal(true);
|
||||
});
|
||||
});
|
||||
describe('#getApiGatewayName()', () => {
|
||||
it('should return the composition of stage and service name', () => {
|
||||
serverless.service.service = 'myService';
|
||||
expect(sdk.naming.getApiGatewayName())
|
||||
.to.equal(`dev-${serverless.service.service}`);
|
||||
});
|
||||
});
|
||||
describe('#getApiGatewayDeploymentId()', () => {
|
||||
describe('#generateApiGatewayDeploymentLogicalId()', () => {
|
||||
it('should return ApiGatewayDeployment with a date based suffix', () => {
|
||||
expect(sdk.naming.getApiGatewayDeploymentId().match(/ApiGatewayDeployment(.*)/).length)
|
||||
expect(sdk.naming.generateApiGatewayDeploymentLogicalId()
|
||||
.match(/ApiGatewayDeployment(.*)/).length)
|
||||
.to.be.greaterThan(1);
|
||||
});
|
||||
});
|
||||
describe('#getLogicalApiGatewayName()', () => {
|
||||
describe('#getRestApiLogicalId()', () => {
|
||||
it('should return ApiGatewayRestApi', () => {
|
||||
expect(sdk.naming.getLogicalApiGatewayName()).to.equal('ApiGatewayRestApi');
|
||||
expect(sdk.naming.getRestApiLogicalId()).to.equal('ApiGatewayRestApi');
|
||||
});
|
||||
});
|
||||
describe('#getNormalizedAuthorizerName()', () => {
|
||||
@ -171,9 +165,9 @@ describe('#naming()', () => {
|
||||
.to.equal('AuthorizerName');
|
||||
});
|
||||
});
|
||||
describe('#getLogicalAuthorizerName()', () => {
|
||||
describe('#getAuthorizerLogicalId()', () => {
|
||||
it('should normalize the authorizer name and add the standard suffix', () => {
|
||||
expect(sdk.naming.getLogicalAuthorizerName('authorizerName'))
|
||||
expect(sdk.naming.getAuthorizerLogicalId('authorizerName'))
|
||||
.to.equal('AuthorizerNameApiGatewayAuthorizer');
|
||||
});
|
||||
});
|
||||
@ -183,23 +177,17 @@ describe('#naming()', () => {
|
||||
expect(sdk.naming.extractAuthorizerNameFromArn(arn)).to.equal('lambda');
|
||||
});
|
||||
});
|
||||
describe('#getLogicalAuthorizerArnName()', () => {
|
||||
it('should normalize the authorizer name and add the standard arn suffix', () => {
|
||||
expect(sdk.naming.getLogicalAuthorizerArnName('authorizerName'))
|
||||
.to.equal('AuthorizerNameApiGatewayAuthorizerArn');
|
||||
});
|
||||
});
|
||||
describe('#getNormalizedApiGatewayResourceName()', () => {
|
||||
describe('#normalizePath()', () => {
|
||||
it('should normalize each part of the resource path and remove non-alpha-numeric characters',
|
||||
() => {
|
||||
expect(sdk.naming.getNormalizedApiGatewayResourceName(
|
||||
expect(sdk.naming.normalizePath(
|
||||
'my/path/to/a-${var}-resource'
|
||||
)).to.equal('MyPathToADashvarVarDashresource');
|
||||
});
|
||||
});
|
||||
describe('#getLogicalApiGatewayResourceName()', () => {
|
||||
describe('#getResourceLogicalId()', () => {
|
||||
it('should normalize the resource and add the standard suffix', () => {
|
||||
expect(sdk.naming.getLogicalApiGatewayResourceName(
|
||||
expect(sdk.naming.getResourceLogicalId(
|
||||
'my/path/to/a-${var}-resource'
|
||||
)).to.equal('ApiGatewayResourceMyPathToADashvarVarDashresource');
|
||||
});
|
||||
@ -211,98 +199,98 @@ describe('#naming()', () => {
|
||||
)).to.equal('MyPathToADashvarVarDashResource');
|
||||
});
|
||||
});
|
||||
describe('#getNormalizedApiGatewayMethodName()', () => {
|
||||
describe('#normalizeMethodName()', () => {
|
||||
it('should capitalize the first letter and lowercase any other characters', () => {
|
||||
expect(sdk.naming.getNormalizedApiGatewayMethodName('gET')).to.equal('Get');
|
||||
expect(sdk.naming.normalizeMethodName('gET')).to.equal('Get');
|
||||
});
|
||||
});
|
||||
describe('#getLogicalApiGatewayMethodName()', () => {
|
||||
describe('#getMethodLogicalId()', () => {
|
||||
it('', () => {
|
||||
expect(sdk.naming.getLogicalApiGatewayMethodName(
|
||||
expect(sdk.naming.getMethodLogicalId(
|
||||
'ResourceId', 'get'
|
||||
)).to.equal('ApiGatewayMethodResourceIdGet');
|
||||
});
|
||||
});
|
||||
describe('#getLogicalApiGatewayApiKeyRegex()', () => {
|
||||
describe('#getApiKeyLogicalIdRegex()', () => {
|
||||
it('should match the prefix', () => {
|
||||
expect(sdk.naming.getLogicalApiGatewayApiKeyRegex()
|
||||
expect(sdk.naming.getApiKeyLogicalIdRegex()
|
||||
.test('ApiGatewayApiKey')).to.equal(true);
|
||||
});
|
||||
it('should not match a name without the prefix', () => {
|
||||
expect(sdk.naming.getLogicalApiGatewayApiKeyRegex()
|
||||
expect(sdk.naming.getApiKeyLogicalIdRegex()
|
||||
.test('NotThePrefixApiGatewayApiKey')).to.equal(false);
|
||||
});
|
||||
it('should match a name with the prefix', () => {
|
||||
expect(sdk.naming.getLogicalApiGatewayApiKeyRegex()
|
||||
expect(sdk.naming.getApiKeyLogicalIdRegex()
|
||||
.test('ApiGatewayApiKeySuffix')).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getLogicalDeploymentBucketName()', () => {
|
||||
describe('#getDeploymentBucketLogicalId()', () => {
|
||||
it('should return "ServerlessDeploymentBucket"', () => {
|
||||
expect(sdk.naming.getLogicalDeploymentBucketName()).to.equal('ServerlessDeploymentBucket');
|
||||
expect(sdk.naming.getDeploymentBucketLogicalId()).to.equal('ServerlessDeploymentBucket');
|
||||
});
|
||||
});
|
||||
describe('#getLogicalDeploymentBucketOutputVariableName()', () => {
|
||||
describe('#getDeploymentBucketOutputLogicalId()', () => {
|
||||
it('should return "ServerlessDeploymentBucketName"', () => {
|
||||
expect(sdk.naming.getLogicalDeploymentBucketOutputVariableName())
|
||||
expect(sdk.naming.getDeploymentBucketOutputLogicalId())
|
||||
.to.equal('ServerlessDeploymentBucketName');
|
||||
});
|
||||
});
|
||||
describe('#getNormalizedBucketName()', () => {
|
||||
describe('#normalizeBucketName()', () => {
|
||||
it('should remove all non-alpha-numeric characters and capitalize the first letter', () => {
|
||||
expect(sdk.naming.getNormalizedBucketName('b!u@c#k$e%t^N&a*m(e')).to.equal('BucketName');
|
||||
expect(sdk.naming.normalizeBucketName('b!u@c#k$e%t^N&a*m(e')).to.equal('BucketName');
|
||||
});
|
||||
});
|
||||
describe('#getLogicalBucketName()', () => {
|
||||
describe('#getBucketLogicalId()', () => {
|
||||
it('should normalize the bucket name and add the standard prefix', () => {
|
||||
expect(sdk.naming.getLogicalBucketName('b!u@c#k$e%t^N&a*m(e')).to.equal('S3BucketBucketName');
|
||||
expect(sdk.naming.getBucketLogicalId('b!u@c#k$e%t^N&a*m(e')).to.equal('S3BucketBucketName');
|
||||
});
|
||||
});
|
||||
describe('#getNormalizedSnsTopicName()', () => {
|
||||
describe('#normalizeTopicName()', () => {
|
||||
it('should remove all non-alpha-numeric characters and capitalize the first letter', () => {
|
||||
expect(sdk.naming.getNormalizedSnsTopicName('t!o@p#i$c%N^a&m*e')).to.equal('TopicName');
|
||||
expect(sdk.naming.normalizeTopicName('t!o@p#i$c%N^a&m*e')).to.equal('TopicName');
|
||||
});
|
||||
});
|
||||
describe('#getLogicalSnsTopicName()', () => {
|
||||
describe('#getTopicLogicalId()', () => {
|
||||
it('should remove all non-alpha-numeric characters and capitalize the first letter', () => {
|
||||
expect(sdk.naming.getLogicalSnsTopicName('t!o@p#i$c%N^a&m*e')).to.equal('SNSTopicTopicName');
|
||||
expect(sdk.naming.getTopicLogicalId('t!o@p#i$c%N^a&m*e')).to.equal('SNSTopicTopicName');
|
||||
});
|
||||
});
|
||||
describe('#getCloudWatchEventId()', () => {
|
||||
describe('#getScheduleId()', () => {
|
||||
it('should add the standard suffix', () => {
|
||||
expect(sdk.naming.getCloudWatchEventId('functionName')).to.equal('functionNameSchedule');
|
||||
expect(sdk.naming.getScheduleId('functionName')).to.equal('functionNameSchedule');
|
||||
});
|
||||
});
|
||||
describe('#getCloudWatchEventName()', () => {
|
||||
describe('#getScheduleLogicalId()', () => {
|
||||
it('should normalize the function name and add the standard suffix including the index', () => {
|
||||
expect(sdk.naming.getCloudWatchEventName('functionName', 0))
|
||||
expect(sdk.naming.getScheduleLogicalId('functionName', 0))
|
||||
.to.equal('FunctionNameEventsRuleSchedule0');
|
||||
});
|
||||
});
|
||||
describe('#getLambdaS3PermissionName()', () => {
|
||||
describe('#getLambdaS3PermissionLogicalId()', () => {
|
||||
it('should normalize the function name and add the standard suffix', () => {
|
||||
expect(sdk.naming.getLambdaS3PermissionName('functionName'))
|
||||
expect(sdk.naming.getLambdaS3PermissionLogicalId('functionName'))
|
||||
.to.equal('FunctionNameLambdaPermissionS3');
|
||||
});
|
||||
});
|
||||
describe('#getLambdaSnsTopicPermissionName()', () => {
|
||||
describe('#getLambdaSnsPermissionLogicalId()', () => {
|
||||
it('should normalize the function and topic names and add them as prefix and suffix to the ' +
|
||||
'standard permission center', () => {
|
||||
expect(sdk.naming.getLambdaSnsTopicPermissionName('functionName', 'topicName'))
|
||||
expect(sdk.naming.getLambdaSnsPermissionLogicalId('functionName', 'topicName'))
|
||||
.to.equal('FunctionNameLambdaPermissionTopicName');
|
||||
});
|
||||
});
|
||||
describe('#getLambdaCloudWatchEventPermissionName()', () => {
|
||||
describe('#getLambdaSchedulePermissionLogicalId()', () => {
|
||||
it('should normalize the function name and add the standard suffix including event index',
|
||||
() => {
|
||||
expect(sdk.naming.getLambdaCloudWatchEventPermissionName('functionName', 0))
|
||||
expect(sdk.naming.getLambdaSchedulePermissionLogicalId('functionName', 0))
|
||||
.to.equal('FunctionNameLambdaPermissionEventsRuleSchedule0');
|
||||
});
|
||||
});
|
||||
describe('#getLambdaApiGatewayPermissionName()', () => {
|
||||
describe('#getLambdaApiGatewayPermissionLogicalId()', () => {
|
||||
it('should normalize the function name and append the standard suffix', () => {
|
||||
expect(sdk.naming.getLambdaApiGatewayPermissionName('functionName'))
|
||||
expect(sdk.naming.getLambdaApiGatewayPermissionLogicalId('functionName'))
|
||||
.to.equal('FunctionNameLambdaPermissionApiGateway');
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user