From 4168dc1f303148012f2027b6fbcbd686749a9357 Mon Sep 17 00:00:00 2001 From: Oz Weiss Date: Thu, 1 Oct 2020 18:39:51 +0300 Subject: [PATCH] feat(Config Schema): Schema for `layers` (#8299) --- docs/providers/aws/guide/plugins.md | 11 +++++ lib/classes/ConfigSchemaHandler/index.js | 2 +- lib/configSchema.js | 3 -- .../aws/package/compile/layers/index.js | 9 +--- .../aws/package/compile/layers/index.test.js | 2 +- lib/plugins/aws/provider/awsProvider.js | 42 +++++++++++++++++++ 6 files changed, 57 insertions(+), 12 deletions(-) diff --git a/docs/providers/aws/guide/plugins.md b/docs/providers/aws/guide/plugins.md index 2b495301e0c..0f16ed5ec0b 100644 --- a/docs/providers/aws/guide/plugins.md +++ b/docs/providers/aws/guide/plugins.md @@ -562,6 +562,17 @@ class NewProviderPlugin { // ... }, }, + + // Definition for eventual top level "layers" section + layers: { + type: 'object', + additionalProperties: { + type: 'object', + properties: { + // ... + }, + }, + }, }); } } diff --git a/lib/classes/ConfigSchemaHandler/index.js b/lib/classes/ConfigSchemaHandler/index.js index b42925cc7a4..3f89d39a87a 100644 --- a/lib/classes/ConfigSchemaHandler/index.js +++ b/lib/classes/ConfigSchemaHandler/index.js @@ -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) { @@ -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 diff --git a/lib/configSchema.js b/lib/configSchema.js index fd063bc1bdf..c8d32f32b2c 100644 --- a/lib/configSchema.js +++ b/lib/configSchema.js @@ -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 diff --git a/lib/plugins/aws/package/compile/layers/index.js b/lib/plugins/aws/package/compile/layers/index.js index 80e3043d906..132e3a046de 100644 --- a/lib/plugins/aws/package/compile/layers/index.js +++ b/lib/plugins/aws/package/compile/layers/index.js @@ -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; diff --git a/lib/plugins/aws/package/compile/layers/index.test.js b/lib/plugins/aws/package/compile/layers/index.test.js index 42ff1ef4e2e..5679e5e4fc3 100644 --- a/lib/plugins/aws/package/compile/layers/index.test.js +++ b/lib/plugins/aws/package/compile/layers/index.test.js @@ -390,7 +390,7 @@ describe('AwsCompileLayers', () => { awsCompileLayers.serverless.service.layers = { test: { path: 'layer', - allowedAccounts: [1111111, '2222222'], + allowedAccounts: ['1111111', '2222222'], }, }; const compiledLayer = { diff --git a/lib/plugins/aws/provider/awsProvider.js b/lib/plugins/aws/provider/awsProvider.js index 34fb45409b2..e7296b943cd 100644 --- a/lib/plugins/aws/provider/awsProvider.js +++ b/lib/plugins/aws/provider/awsProvider.js @@ -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: {