Skip to content

Commit

Permalink
feat(Config Schema): Schema for layers (#8299)
Browse files Browse the repository at this point in the history
  • Loading branch information
Oz Weiss committed Oct 1, 2020
1 parent a6ff964 commit 4168dc1
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 12 deletions.
11 changes: 11 additions & 0 deletions docs/providers/aws/guide/plugins.md
Expand Up @@ -562,6 +562,17 @@ class NewProviderPlugin {
// ...
},
},

// Definition for eventual top level "layers" section
layers: {
type: 'object',
additionalProperties: {
type: 'object',
properties: {
// ...
},
},
},
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/classes/ConfigSchemaHandler/index.js
Expand Up @@ -51,7 +51,6 @@ class ConfigSchemaHandler {
Object.freeze(this.schema.properties.service.name);
deepFreeze(this.schema.properties.plugins);
deepFreeze(this.schema.properties.package);
Object.freeze(this.schema.properties.layers);
}

validateConfig(userConfig) {
Expand Down Expand Up @@ -171,6 +170,7 @@ class ConfigSchemaHandler {
}

if (options.resources) this.schema.properties.resources = options.resources;
if (options.layers) this.schema.properties.layers = options.layers;

// In case provider implementers do not set stage or variableSyntax options,
// then they are set here. The framework internally sets these options in
Expand Down
3 changes: 0 additions & 3 deletions lib/configSchema.js
Expand Up @@ -108,9 +108,6 @@ const schema = {
additionalProperties: false,
},

// TODO: Complete schema, see https://github.com/serverless/serverless/issues/8015
layers: { type: 'object' },

/*
* Modes for config validation:
* - error: the error is thrown
Expand Down
9 changes: 2 additions & 7 deletions lib/plugins/aws/package/compile/layers/index.js
Expand Up @@ -72,17 +72,12 @@ class AwsCompileLayers {

if (layerObject.allowedAccounts) {
layerObject.allowedAccounts.map(account => {
let parsedAccount = account;
// cast to string if account is number
if (typeof account === 'number' && !isNaN(account)) {
parsedAccount = `${account}`;
}
const newPermission = this.cfLambdaLayerPermissionTemplate();
newPermission.Properties.LayerVersionArn = { Ref: layerLogicalId };
newPermission.Properties.Principal = parsedAccount;
newPermission.Properties.Principal = account;
const layerPermLogicalId = this.provider.naming.getLambdaLayerPermissionLogicalId(
layerName,
parsedAccount
account
);
newLayerObject[layerPermLogicalId] = newPermission;
return newPermission;
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/aws/package/compile/layers/index.test.js
Expand Up @@ -390,7 +390,7 @@ describe('AwsCompileLayers', () => {
awsCompileLayers.serverless.service.layers = {
test: {
path: 'layer',
allowedAccounts: [1111111, '2222222'],
allowedAccounts: ['1111111', '2222222'],
},
};
const compiledLayer = {
Expand Down
42 changes: 42 additions & 0 deletions lib/plugins/aws/provider/awsProvider.js
Expand Up @@ -722,6 +722,48 @@ class AwsProvider {
},
additionalProperties: false,
},
layers: {
type: 'object',
additionalProperties: {
type: 'object',
properties: {
allowedAccounts: {
type: 'array',
items: {
type: 'string',
pattern: '^(\\d{12}|\\*|arn:(aws[a-zA-Z-]*):iam::\\d{12}:root)$',
},
},
compatibleRuntimes: {
type: 'array',
items: { $ref: '#/definitions/awsLambdaRuntime' },
maxItems: 5,
},
description: { type: 'string', maxLength: 256 },
licenseInfo: { type: 'string', maxLength: 512 },
name: {
type: 'string',
minLength: 1,
maxLength: 140,
pattern:
'^((arn:[a-zA-Z0-9-]+:lambda:[a-zA-Z0-9-]+:\\d{12}:layer:[a-zA-Z0-9-_]+)|[a-zA-Z0-9-_]+)$',
},
package: {
type: 'object',
properties: {
artifact: { type: 'string' },
exclude: { type: 'array', items: { type: 'string' } },
include: { type: 'array', items: { type: 'string' } },
},
additionalProperties: false,
},
path: { type: 'string' },
retain: { type: 'boolean' },
},
required: ['path'],
additionalProperties: false,
},
},
resources: {
properties: {
AWSTemplateFormatVersion: {
Expand Down

0 comments on commit 4168dc1

Please sign in to comment.