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

Fail lambda if shouldFail flag provided #233

Merged
merged 4 commits into from
Sep 19, 2018

Conversation

sdomagala
Copy link
Contributor

Hello,
It seemed to me that checking if each secret is available at start of lambda function is a bit too much if you are in situation where missing secrets mean there is no point for lambda to run.

@@ -487,6 +487,7 @@ For each secret, you also provide the name under which its value should be added
- `secrets` (object) : Map of secrets to fetch from Secrets Manager, where the key is the destination, and value is secret name in Secrets Manager.
Example: `{secrets: {RDS_LOGIN: 'dev/rds_login'}}`
- `awsSdkOptions` (object) (optional): Options to pass to AWS.SecretsManager class constructor.
- `shouldFail` (boolean) (optional): Defaults to `false`. Set it to `true` if you want your lambda to fail in case call to AWS Secrets Manager fails (secrets don't exist or internal error)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe name it more explicitly to better convey the intent?

Like throwOnMissingParam or ignoreMissingParams

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I couldn't think of any good name, your proposal doesn't cover errors other than missing param in store - how about throwOnFailedCall?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, agree, doesn't cover throttling errors etc, so another thing I can think of is to borrow bail name from jest

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, I think throw would be more descriptive here, bail is not so common

Copy link
Contributor

@vladholubiev vladholubiev left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the valuable contribution @sdomagala! Might worth a look by @theburningmonk

@sdomagala
Copy link
Contributor Author

Thanks @vladgolubev for quick review!

@@ -57,6 +58,9 @@ module.exports = opts => {
// if we already have a cached secrets, then reset the timestamp so we don't
// keep retrying on every invocation which can cause performance problems
// when there's temporary problems with Secrets Manager
if (options.throwOnFailedCall) {
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 only throw on the first request, if you have a cached value already you can continue with execution still. If we want to be smarter then we can build in some mechanism for the app developer to flush the cache - for example, by adding a function to the context object to flushCachedSecrets, but let's not do it in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @theburningmonk,
I didn't thought of it, it's fixed now, lambda will fail only if first call didn't succeed

@codecov
Copy link

codecov bot commented Sep 18, 2018

Codecov Report

Merging #233 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #233   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          19     19           
  Lines         492    494    +2     
  Branches      100    101    +1     
=====================================
+ Hits          492    494    +2
Impacted Files Coverage Δ
src/middlewares/secretsManager.js 100% <100%> (ø) ⬆️

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 76f66fd...d199f48. Read the comment docs.

2 similar comments
@codecov
Copy link

codecov bot commented Sep 18, 2018

Codecov Report

Merging #233 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #233   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          19     19           
  Lines         492    494    +2     
  Branches      100    101    +1     
=====================================
+ Hits          492    494    +2
Impacted Files Coverage Δ
src/middlewares/secretsManager.js 100% <100%> (ø) ⬆️

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 76f66fd...d199f48. Read the comment docs.

@codecov
Copy link

codecov bot commented Sep 18, 2018

Codecov Report

Merging #233 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #233   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          19     19           
  Lines         492    494    +2     
  Branches      100    101    +1     
=====================================
+ Hits          492    494    +2
Impacted Files Coverage Δ
src/middlewares/secretsManager.js 100% <100%> (ø) ⬆️

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 76f66fd...d199f48. Read the comment docs.

@theburningmonk
Copy link
Contributor

@sdomagala thanks for making the change, LGTM!

@lmammino
Copy link
Member

Hey Guys, sorry I have been a bit absent these days. Thanks for taking care of this and doing such a thorough review.

I'll version bump and get this merged.

@lmammino
Copy link
Member

@sdomagala, thanks for proposing this change. I tried to version bump (to version 0.18.0) in your branch but it doesn't let me push. can you update package.json and package-lock.json and change the version to 0.18.0 so that we can get this merged and let the CI pipeline release the new version?

Thanks again :)

@lmammino lmammino self-requested a review September 19, 2018 20:12
@sdomagala
Copy link
Contributor Author

Hey @lmammino, sure, on it!

@sdomagala
Copy link
Contributor Author

@lmammino, could you update package-lock yourself? I'm using yarn exclusively and get a lot of checksum errors when going the npm way, which then result in dependencies refresh.
I'll give you write access to this repo

@lmammino
Copy link
Member

sure, I can update both. I already have the commit ready, i just can't push :P

@sdomagala
Copy link
Contributor Author

Looks like you have to accept being a collabolator, invite should be available here: https://github.com/sdomagala/middy/invitations

@lmammino lmammino merged commit 9850fb9 into middyjs:master Sep 19, 2018
@lmammino lmammino deleted the feature/secrets-manager-handler branch September 19, 2018 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

4 participants