Skip to content
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

feat(AJV): Add missing provider level schema properties #8297

Merged
merged 22 commits into from Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
99b386d
Add missing provider level properties name in schema definition
fredericbarthelet Sep 28, 2020
c87addb
Add logRetentionInDays
fredericbarthelet Sep 28, 2020
070df62
Add region
fredericbarthelet Sep 28, 2020
1d7ceb2
Add profile and notificationArns
fredericbarthelet Sep 28, 2020
b98f473
Add rolePermissionsBoundary and rollbackConfiguration
fredericbarthelet Sep 28, 2020
377db54
Add stage and stackName
fredericbarthelet Sep 28, 2020
49c8b64
Add stackParameters
fredericbarthelet Sep 28, 2020
9adffa7
Add stackPolicy
fredericbarthelet Sep 28, 2020
48b3245
Add stackTagss
fredericbarthelet Sep 28, 2020
e9c7323
Add deploymentBucket
fredericbarthelet Sep 28, 2020
74b149d
Add deploymentPrefix, iamManagedPolicies and iamRoleStatements
fredericbarthelet Sep 28, 2020
e32b965
Add missing GovCloud regions
fredericbarthelet Sep 28, 2020
b45f5b9
Remove unused mergeIamTemplates testss
fredericbarthelet Sep 28, 2020
41fefb2
Add required fields for awsIamPolicyStatements definition
fredericbarthelet Sep 30, 2020
e599ab0
Update bucket options definition
fredericbarthelet Sep 30, 2020
d8f8c89
Add china regions
fredericbarthelet Sep 30, 2020
47e1e40
Add frameworkLambda definition
fredericbarthelet Sep 30, 2020
8e8a185
Use { const: '*' }
fredericbarthelet Sep 30, 2020
e355552
Update deploymentBucket to deny additional properties
fredericbarthelet Sep 30, 2020
1729ed2
Add AWS statement grammar reference
fredericbarthelet Sep 30, 2020
e50b273
Add missing Service Principal for iam policy
fredericbarthelet Sep 30, 2020
f764377
Add pattern source for awsS3BucketName in comment
fredericbarthelet Sep 30, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/plugins/aws/deploy/lib/createStack.js
Expand Up @@ -11,7 +11,7 @@ module.exports = {
let stackTags = { STAGE: this.provider.getStage() };

// Merge additional stack tags
if (typeof this.serverless.service.provider.stackTags === 'object') {
if (this.serverless.service.provider.stackTags) {
const customKeys = Object.keys(this.serverless.service.provider.stackTags);
const collisions = Object.keys(stackTags).filter(defaultKey =>
customKeys.some(key => defaultKey.toLowerCase() === key.toLowerCase())
Expand Down
4 changes: 2 additions & 2 deletions lib/plugins/aws/lib/updateStack.js
Expand Up @@ -17,7 +17,7 @@ module.exports = {
const templateUrl = `https://${s3Endpoint}/${this.bucketName}/${this.serverless.service.package.artifactDirectoryName}/${compiledTemplateFileName}`;

// Merge additional stack tags
if (typeof this.serverless.service.provider.stackTags === 'object') {
if (this.serverless.service.provider.stackTags) {
const customKeys = Object.keys(this.serverless.service.provider.stackTags);
const collisions = Object.keys(stackTags).filter(defaultKey =>
customKeys.some(key => defaultKey.toLowerCase() === key.toLowerCase())
Expand Down Expand Up @@ -74,7 +74,7 @@ module.exports = {
let stackTags = { STAGE: this.provider.getStage() };

// Merge additional stack tags
if (typeof this.serverless.service.provider.stackTags === 'object') {
if (this.serverless.service.provider.stackTags) {
const customKeys = Object.keys(this.serverless.service.provider.stackTags);
const collisions = Object.keys(stackTags).filter(defaultKey =>
customKeys.some(key => defaultKey.toLowerCase() === key.toLowerCase())
Expand Down
45 changes: 0 additions & 45 deletions lib/plugins/aws/lib/validateS3BucketName.js

This file was deleted.

114 changes: 0 additions & 114 deletions lib/plugins/aws/lib/validateS3BucketName.test.js

This file was deleted.

38 changes: 16 additions & 22 deletions lib/plugins/aws/package/lib/generateCoreTemplate.js
Expand Up @@ -4,12 +4,8 @@ const BbPromise = require('bluebird');
const path = require('path');
const _ = require('lodash');

const validateS3BucketName = require('../../lib/validateS3BucketName');

module.exports = {
generateCoreTemplate() {
Object.assign(this, validateS3BucketName);

this.serverless.service.provider.compiledCloudFormationTemplate = this.serverless.utils.readFileSync(
path.join(
this.serverless.config.serverlessPath,
Expand Down Expand Up @@ -47,7 +43,7 @@ module.exports = {
}

// enable S3 block public access for deployment bucket
if (deploymentBucketObject.blockPublicAccess === true) {
if (deploymentBucketObject.blockPublicAccess) {
Object.assign(
this.serverless.service.provider.compiledCloudFormationTemplate.Resources[
deploymentBucketLogicalId
Expand Down Expand Up @@ -76,23 +72,21 @@ module.exports = {
}

if (bucketName) {
return BbPromise.bind(this)
.then(() => this.validateS3BucketName(bucketName))
.then(() => {
if (isS3TransferAccelerationEnabled) {
const warningMessage =
'Warning: S3 Transfer Acceleration will not be enabled on deploymentBucket.';
this.serverless.cli.log(warningMessage);
}
this.bucketName = bucketName;
this.serverless.service.package.deploymentBucket = bucketName;
this.serverless.service.provider.compiledCloudFormationTemplate.Outputs.ServerlessDeploymentBucketName.Value = bucketName;

delete this.serverless.service.provider.compiledCloudFormationTemplate.Resources
.ServerlessDeploymentBucket;
delete this.serverless.service.provider.compiledCloudFormationTemplate.Resources
.ServerlessDeploymentBucketPolicy;
});
return BbPromise.bind(this).then(() => {
if (isS3TransferAccelerationEnabled) {
const warningMessage =
'Warning: S3 Transfer Acceleration will not be enabled on deploymentBucket.';
this.serverless.cli.log(warningMessage);
}
this.bucketName = bucketName;
this.serverless.service.package.deploymentBucket = bucketName;
this.serverless.service.provider.compiledCloudFormationTemplate.Outputs.ServerlessDeploymentBucketName.Value = bucketName;

delete this.serverless.service.provider.compiledCloudFormationTemplate.Resources
.ServerlessDeploymentBucket;
delete this.serverless.service.provider.compiledCloudFormationTemplate.Resources
.ServerlessDeploymentBucketPolicy;
});
}

if (isS3TransferAccelerationEnabled && isS3TransferAccelerationSupported) {
Expand Down
54 changes: 0 additions & 54 deletions lib/plugins/aws/package/lib/mergeIamTemplates.js
Expand Up @@ -6,12 +6,6 @@ const path = require('path');

module.exports = {
mergeIamTemplates() {
this.validateStatements(this.serverless.service.provider.iamRoleStatements);
this.validateManagedPolicies(this.serverless.service.provider.iamManagedPolicies);
return this.merge();
},

merge() {
// resolve early if no functions are provided
if (!this.serverless.service.getAllFunctions().length) {
return BbPromise.resolve();
Expand Down Expand Up @@ -188,52 +182,4 @@ module.exports = {
}
resource.ManagedPolicyArns = resource.ManagedPolicyArns.concat(managedPolicies);
},

validateStatements(statements) {
// Verify that iamRoleStatements (if present) is an array of { Effect: ...,
// Action: ..., Resource: ... } objects.
if (!statements) {
return;
}
let violationsFound;
if (!Array.isArray(statements)) {
violationsFound = 'it is not an array';
} else {
const descriptions = statements.map((statement, i) => {
const missing = [
['Effect'],
['Action', 'NotAction'],
['Resource', 'NotResource'],
].filter(props => props.every(prop => !statement[prop]));
return missing.length === 0
? null
: `statement ${i} is missing the following properties: ${missing
.map(m => m.join(' / '))
.join(', ')}`;
});
const flawed = descriptions.filter(curr => curr);
if (flawed.length) {
violationsFound = flawed.join('; ');
}
}

if (violationsFound) {
const errorMessage = [
'iamRoleStatements should be an array of objects,',
' where each object has Effect, Action / NotAction, Resource / NotResource fields.',
` Specifically, ${violationsFound}`,
].join('');
throw new this.serverless.classes.Error(errorMessage);
}
},

validateManagedPolicies(iamManagedPolicies) {
// Verify that iamManagedPolicies (if present) is an array
if (!iamManagedPolicies) {
return;
}
if (!Array.isArray(iamManagedPolicies)) {
throw new this.serverless.classes.Error('iamManagedPolicies should be an array of arns');
}
},
};