added webhook verification to mux_ruby + helper-func infrastructure#46
added webhook verification to mux_ruby + helper-func infrastructure#46
Conversation
…we nuke the /lib dir on build for reasons)
mmcc
left a comment
There was a problem hiding this comment.
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.
I'm not sure we use tolerance anywhere else, typically it's expiration. Why the change here?
There was a problem hiding this comment.
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.
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.
It specifies a named argument rather than a positional argument. I think they're clearer.
There was a problem hiding this comment.
@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.
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-manualtolibon build (has to be done this way because OAS won't remove old files for renamed/deleted modules, so we have to deletelibevery build)