-
Notifications
You must be signed in to change notification settings - Fork 13
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
added webhook verification to mux_ruby + helper-func infrastructure #46
base: master
Are you sure you want to change the base?
Conversation
…we nuke the /lib dir on build for reasons)
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.
Reviewing this took me way back, but I think this looks good to me! I had a couple of questions mostly about naming, but functionally this lgtm.
# @param [Array<Symbol>] header_schemes the list of accepted header schemes for this verifier | ||
def initialize(secret: nil, tolerance: DEFAULT_TOLERANCE, header_schemes: [:v1]) | ||
raise "secret '#{secret.inspect}' must be a String" unless secret.is_a?(String) | ||
raise "tolerance '#{tolerance.inspect}' must be a positive number." \ |
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.
I'm not sure we use tolerance
anywhere else, typically it's expiration
. Why the change here?
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.
It's tolerance in the node SDK.
# @param [String] header the Mux-Signature header | ||
# @param [Time] current_timestamp (for test purposes) the current time expected for this webhook (defaults to `Time.utc`) | ||
# @return [Boolean] true if webhook is verified; false otherwise | ||
def verify(request_body:, header:, current_timestamp: Time.now.getutc) |
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.
I don't remember this from Ruby land circa 2013, but is arg:,
just specifying a nullish default value?
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.
It specifies a named argument rather than a positional argument. I think they're clearer.
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.
@mmcc this must have come after your Ruby time (it was right near the end of my Ruby time) -- keyword args, which are a fantastic language feature:
https://thoughtbot.com/blog/ruby-2-keyword-arguments
In this case calling verify
without request_body:
and header:
args would cause a runtime error.
In the past we would sometimes use an options hash and then have conditionals inside method to check for things that were passed into the options hash.
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.
Yeah, this just replaces the options hash.
@dylanjha , I didn't know you were a Ruby guy. Oh, do I have code for you to review...!
Just dropping in here to note that we have wanted this for so long. Thanks @eropple for coming up with a pattern to pull in ad-hoc helper functionality into generated SDKs ❤️ |
Thanks, @dylanjha . I got more of these to do. We'll get there. 😎 |
lib-manual
tolib
on build (has to be done this way because OAS won't remove old files for renamed/deleted modules, so we have to deletelib
every build)