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

Aws cloudfront event schema #8250

Merged
merged 13 commits into from Sep 22, 2020

Conversation

thewizarodofoz
Copy link
Contributor

Closes: #8025

A few things I'm not sure of:

  1. Is the regex for pathPattern necessary? I derived it from this doc
  2. Should I add the full schema for origin? It will be quite verobse...
  3. Should I add the full schema for behavior? It will be quite verobse...
  4. Will the uri format work for origin?

Copy link
Contributor

@medikoo medikoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks you @thewizarodofoz ! It looks promising. Please see my comments

Is the regex for pathPattern necessary? I derived it from this doc

I think what you proposed looks good. I've just picked on few potential issues

Should I add the full schema for origin? It will be quite verobse

In general we define all config properties, and we did so for all events so far. So in this case I'd also ensure that we define them all.
There's a pretty good reference for it: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cloudfront-distribution-origin.html

Should I add the full schema for behavior? It will be quite verobse..

Yes I'd also follow with it. Here case is more complex as some properties are supported on its own in upper level (as pathPattern). In this case I'd allow to set only properties which are not handled in other scope (so no support for PathPattern at this level)

Will the uri format work for origin?

I think it's a great pick (btw I've just learned about format keyword`)

isDefaultOrigin: { type: 'boolean' },
includeBody: { type: 'boolean' },
behavior: { type: 'object' },
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add additionalProperties: false

type: 'string',
enum: ['viewer-request', 'origin-request', 'origin-response', 'viewer-response'],
},
pathPattern: { type: 'string', pattern: '^([A-Za-z0-9-_.*$/~"\'@:+]|&)+$' },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- char needs to be escaped (otherwise in [] it implies a range between characters.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved it to the end of the array like we do in other patterns

lib/plugins/aws/package/compile/events/cloudFront/index.js Outdated Show resolved Hide resolved
lib/plugins/aws/package/compile/events/cloudFront/index.js Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Sep 16, 2020

Codecov Report

Merging #8250 into master will decrease coverage by 0.08%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #8250      +/-   ##
==========================================
- Coverage   88.11%   88.02%   -0.09%     
==========================================
  Files         248      248              
  Lines        9388     9312      -76     
==========================================
- Hits         8272     8197      -75     
+ Misses       1116     1115       -1     
Impacted Files Coverage Δ
...ins/aws/package/compile/events/cloudFront/index.js 99.32% <100.00%> (ø)
.../package/compile/events/websockets/lib/validate.js 97.22% <0.00%> (-0.51%) ⬇️
lib/plugins/aws/package/compile/functions/index.js 97.03% <0.00%> (-0.22%) ⬇️
lib/configSchema.js 100.00% <0.00%> (ø)
lib/utils/getCommandSuggestion.js 100.00% <0.00%> (ø)
lib/plugins/aws/invokeLocal/index.js 69.66% <0.00%> (ø)
lib/plugins/aws/provider/awsProvider.js 93.11% <0.00%> (ø)
lib/plugins/interactiveCli/initializeService.js 100.00% <0.00%> (ø)
...ib/plugins/aws/package/compile/events/sns/index.js 100.00% <0.00%> (ø)
...ib/plugins/aws/package/compile/events/sqs/index.js 100.00% <0.00%> (ø)
... and 5 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 372ce54...f6476e2. Read the comment docs.

Copy link
Contributor

@medikoo medikoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @thewizarodofoz that looks outstanding! I've found few last issues, otherwise it looks as what we need

Comment on lines 38 to 39
HTTPPort: { type: 'integer' },
HTTPSPort: { type: 'integer' },
Copy link
Contributor

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 max 65535

HTTPSPort: { type: 'integer' },
OriginKeepaliveTimeout: { type: 'integer', miminum: 1, maximum: 60 },
OriginProtocolPolicy: {
type: 'string',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With enum, type is ineffective

OriginReadTimeout: { type: 'integer', miminum: 1, maximum: 60 },
OriginSSLProtocols: {
type: 'array',
items: { type: 'string', enum: ['SSLv3', 'TLSv1', 'TLSv1.1', 'TLSv1.2'] },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't seem to be addressed (we can remove type: 'string')

required: ['OriginProtocolPolicy'],
},
DomainName: { type: 'string' },
Id: { type: 'string' },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should not include Id, as we unconditionally generate it:

Id: naming.getCloudFrontOriginId(originObj),

Comment on lines 90 to 103
{ 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' },
],
},
Copy link
Contributor

Choose a reason for hiding this comment

The 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 AllowedMethods: ["GET"] will pass.

I believe we can achieve needed validation through { enum: [["GET", "HEAD"], [... ], [...]] }

Comment on lines 107 to 110
oneOf: [
{ type: 'array', items: [{ const: 'GET' }, { const: 'HEAD' }] },
{ type: 'array', items: [{ const: 'GET' }, { const: 'HEAD' }, { const: 'OPTIONS' }] },
],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

SmoothStreaming: { type: 'boolean' },
TrustedSigners: { type: 'array', items: { type: 'string' } },
ViewerProtocolPolicy: {
type: 'string',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for type

},
isDefaultOrigin: { type: 'boolean' },
includeBody: { type: 'boolean' },
behavior: behaviorObjectSchema,
Copy link
Contributor

Choose a reason for hiding this comment

The 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)

this.serverless.configSchemaHandler.defineFunctionEvent('aws', 'cloudFront', {
type: 'object',
properties: {
eventType: {
type: 'string',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove type here

Copy link
Contributor

@medikoo medikoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thewizarodofoz that looks great! There's just one style nit that left addressed, see my comment

OriginReadTimeout: { type: 'integer', miminum: 1, maximum: 60 },
OriginSSLProtocols: {
type: 'array',
items: { type: 'string', enum: ['SSLv3', 'TLSv1', 'TLSv1.1', 'TLSv1.2'] },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't seem to be addressed (we can remove type: 'string')

Copy link
Contributor

@medikoo medikoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @thewizarodofoz! That's outstanding!

@medikoo medikoo merged commit 8943693 into serverless:master Sep 22, 2020
@thewizarodofoz thewizarodofoz deleted the aws-cloudfront-event-schema branch September 22, 2020 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Config schema: Define AWS "cloudFront" function event properties
3 participants