Skip to content

Define SNS event schema validation#8112

Merged
medikoo merged 7 commits into
serverless:masterfrom
fredericbarthelet:sns-validation
Sep 1, 2020
Merged

Define SNS event schema validation#8112
medikoo merged 7 commits into
serverless:masterfrom
fredericbarthelet:sns-validation

Conversation

@fredericbarthelet

Copy link
Copy Markdown
Contributor

Closes: #8035

@medikoo medikoo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@fredericbarthelet thank you, that's outstanding!

This one seems a bit more challenging, due to more convoluted configuration options logic. Please see my comments and let me know what you think

Comment thread lib/configSchema.js Outdated
Comment thread lib/configSchema.js Outdated
Comment thread lib/plugins/aws/package/compile/events/sns/index.js Outdated
Comment thread lib/plugins/aws/package/compile/events/sns/index.js Outdated
Comment thread lib/plugins/aws/package/compile/events/sns/index.js
Comment thread lib/plugins/aws/package/compile/events/sns/index.js
Comment thread lib/plugins/aws/package/compile/events/sns/index.js Outdated
Comment thread lib/plugins/aws/package/compile/events/sns/index.js
@fredericbarthelet

Copy link
Copy Markdown
Contributor Author

@medikoo I updated my PR with your comments.

I still have 2 remaining questions regarding your comments where I need additional information from you. Could you help me with those :) ? Thanks

@codecov-commenter

codecov-commenter commented Aug 30, 2020

Copy link
Copy Markdown

Codecov Report

Merging #8112 into master will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #8112      +/-   ##
==========================================
+ Coverage   88.18%   88.21%   +0.02%     
==========================================
  Files         248      248              
  Lines        9444     9416      -28     
==========================================
- Hits         8328     8306      -22     
+ Misses       1116     1110       -6     
Impacted Files Coverage Δ
lib/plugins/aws/provider/awsProvider.js 92.85% <ø> (ø)
...ib/plugins/aws/package/compile/events/sns/index.js 100.00% <100.00%> (+6.52%) ⬆️

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 56aa5aa...435766b. Read the comment docs.

Comment thread lib/plugins/aws/provider/awsProvider.js
Comment thread lib/plugins/aws/provider/awsProvider.js
Comment on lines +21 to +23
arn: {
oneOf: [{ $ref: '#/definitions/awsArn' }, { $ref: '#/definitions/awsCfFunction' }],
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What do you think about renaming awsArn definition (in current form) to awsArnString, and introduce awsArn definition, that allows form as accepted by AWS, which then we can use here directly?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

What I don't like too much is that, while the current awsArn ensure we're talking about an ARN, there are no guarantee that value returned by any of the awsCfFunction are actually resolved to ARN. I could use a GetAtt to get Lambda current version and this will pass the new awsArn definition.

More largely, any value within a CF template can be replaced by an AWS function resolution.

What we could envision here, is whenever one value used in serverless.yaml will be passed as is to a CF template, this value can either be the expected primitive type of the CF template (string, number, boolean) as well as any combination of CF functions.

We could then have :

awsString: {
  oneOf: [{ type: 'string', minLength: 1}, { $ref: '#/definitions/awsCfFunction' }]
},
awsNumber: ...

WDYT ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

there are no guarantee that value returned by any of the awsCfFunction are actually resolved to ARN.

My idea for awsArn is that it's expected to be a valid ARN passed as is to AWS, which we validate just on surface, and it's AWS that eventually crashes with meaningful error, when nonsense instruction is passed.

I was thinking about keeping this as definition, as I believe we have many places where we propagate ARN down to a CF template supporting all instruction forms and without thoroughly validating it. Having that this definition could well serve all those place. (I think it's better to have reusable definition for that, instead being required to put oneOf combined instruction as above in all of them)

will be passed as is to a CF template, this value can either be the expected primitive type of the CF template

One problem of that approach is that we loose some sanity validation of string version, which could be nice to have

So I wonder whether it's not better to have dedicated definitions for types that are used frequently (like ARN) and in other cases use oneOf directly as you've proposed above.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

understood @medikoo , updated accordingly :)

Comment thread lib/plugins/aws/package/compile/events/sns/index.js

@medikoo medikoo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@fredericbarthelet thanks, it looks great in given form! I have just few minor remarks.

Comment thread lib/plugins/aws/package/compile/events/sns/index.js
Comment thread lib/plugins/aws/package/compile/events/sns/index.js
@fredericbarthelet

Copy link
Copy Markdown
Contributor Author

@medikoo I updated my PR with your latest comments

@medikoo medikoo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's outstanding! Thank you @fredericbarthelet

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 "sns" function event properties

3 participants