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
Aws cloudfront event schema #8250
Changes from 5 commits
7b7a2a9
2282c44
a3d1b8f
5703ee4
2f5524c
e8ab079
f1356df
fb32776
283fb6c
0c343c3
20b58cf
7502dd4
f6476e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -27,9 +27,118 @@ class AwsCompileCloudFrontEvents { | |||
'before:remove:remove': this.logRemoveReminder.bind(this), | ||||
}; | ||||
|
||||
// TODO: Complete schema, see https://github.com/serverless/serverless/issues/8025 | ||||
const originObjectSchema = { | ||||
type: 'object', | ||||
properties: { | ||||
ConnectionAttempts: { type: 'integer', miminum: 1, maximum: 3 }, | ||||
ConnectionTimeout: { type: 'integer', miminum: 1, maximum: 10 }, | ||||
CustomOriginConfig: { | ||||
type: 'object', | ||||
properties: { | ||||
HTTPPort: { type: 'integer' }, | ||||
HTTPSPort: { type: 'integer' }, | ||||
OriginKeepaliveTimeout: { type: 'integer', miminum: 1, maximum: 60 }, | ||||
OriginProtocolPolicy: { | ||||
type: 'string', | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With |
||||
enum: ['http-only', 'match-viewer', 'https-only'], | ||||
}, | ||||
OriginReadTimeout: { type: 'integer', miminum: 1, maximum: 60 }, | ||||
OriginSSLProtocols: { | ||||
type: 'array', | ||||
items: { type: 'string', enum: ['SSLv3', 'TLSv1', 'TLSv1.1', 'TLSv1.2'] }, | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't seem to be addressed (we can remove |
||||
}, | ||||
}, | ||||
additionalProperties: false, | ||||
required: ['OriginProtocolPolicy'], | ||||
}, | ||||
DomainName: { type: 'string' }, | ||||
Id: { type: 'string' }, | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should not include
|
||||
OriginCustomHeaders: { | ||||
type: 'array', | ||||
items: { | ||||
type: 'object', | ||||
properties: { | ||||
HeaderName: { type: 'string' }, | ||||
HeaderValue: { type: 'string' }, | ||||
}, | ||||
additionalProperties: false, | ||||
required: ['HeaderName', 'HeaderValue'], | ||||
}, | ||||
}, | ||||
OriginPath: { type: 'string' }, | ||||
S3OriginConfig: { | ||||
type: 'object', | ||||
properties: { | ||||
OriginAccessIdentity: { | ||||
type: 'string', | ||||
pattern: '^origin-access-identity/cloudfront/.+', | ||||
}, | ||||
}, | ||||
additionalProperties: false, | ||||
}, | ||||
}, | ||||
additionalProperties: false, | ||||
required: ['DomainName', 'Id'], | ||||
oneOf: [{ required: ['CustomOriginConfig'] }, { required: ['S3OriginConfig'] }], | ||||
}; | ||||
|
||||
const behaviorObjectSchema = { | ||||
type: 'object', | ||||
properties: { | ||||
AllowedMethods: { | ||||
oneOf: [ | ||||
{ type: 'array', items: [{ const: 'GET' }, { const: 'HEAD' }] }, | ||||
{ type: 'array', items: [{ const: 'GET' }, { const: 'HEAD' }, { const: 'OPTIONS' }] }, | ||||
{ | ||||
type: 'array', | ||||
items: [ | ||||
{ const: 'GET' }, | ||||
{ const: 'HEAD' }, | ||||
{ const: 'OPTIONS' }, | ||||
{ const: 'PUT' }, | ||||
{ const: 'PATCH' }, | ||||
{ const: 'POST' }, | ||||
{ const: 'DELETE' }, | ||||
], | ||||
}, | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If understand we allow three exact collections. If it's the case then above doesn't meet that, as I believe we can achieve needed validation through |
||||
], | ||||
}, | ||||
CachedMethods: { | ||||
oneOf: [ | ||||
{ type: 'array', items: [{ const: 'GET' }, { const: 'HEAD' }] }, | ||||
{ type: 'array', items: [{ const: 'GET' }, { const: 'HEAD' }, { const: 'OPTIONS' }] }, | ||||
], | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||||
}, | ||||
CachePolicyId: { type: 'string' }, | ||||
Compress: { type: 'boolean' }, | ||||
FieldLevelEncryptionId: { type: 'string' }, | ||||
OriginRequestPolicyId: { type: 'string' }, | ||||
SmoothStreaming: { type: 'boolean' }, | ||||
TrustedSigners: { type: 'array', items: { type: 'string' } }, | ||||
ViewerProtocolPolicy: { | ||||
type: 'string', | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for |
||||
enum: ['allow-all', 'redirect-to-https', 'https-only'], | ||||
}, | ||||
}, | ||||
additionalProperties: false, | ||||
}; | ||||
|
||||
this.serverless.configSchemaHandler.defineFunctionEvent('aws', 'cloudFront', { | ||||
type: 'object', | ||||
properties: { | ||||
eventType: { | ||||
type: 'string', | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's remove |
||||
enum: ['viewer-request', 'origin-request', 'origin-response', 'viewer-response'], | ||||
}, | ||||
pathPattern: { type: 'string', pattern: '^([A-Za-z0-9_.*$/~"\'@:+-]|&)+$' }, | ||||
origin: { | ||||
oneOf: [{ type: 'string', format: 'uri' }, originObjectSchema], | ||||
}, | ||||
isDefaultOrigin: { type: 'boolean' }, | ||||
includeBody: { type: 'boolean' }, | ||||
behavior: behaviorObjectSchema, | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's ensure alphabetical order (when there's larger count of properties, it's then easier to find one) |
||||
}, | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add |
||||
additionalProperties: false, | ||||
}); | ||||
} | ||||
|
||||
|
@@ -156,10 +265,6 @@ class AwsCompileCloudFrontEvents { | |||
if (functionObj.events) { | ||||
functionObj.events.forEach(event => { | ||||
if (event.cloudFront) { | ||||
if (!_.isObject(event.cloudFront)) { | ||||
throw new Error('cloudFront event has to be an object'); | ||||
} | ||||
|
||||
const lambdaFunctionLogicalId = Object.keys(Resources).find( | ||||
key => | ||||
Resources[key].Type === 'AWS::Lambda::Function' && | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's maybe set min
0
and max65535