-
Notifications
You must be signed in to change notification settings - Fork 21
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
Add Smart CDN Signature Auth helper #71
Conversation
@kvz let me know if there's anything to review. |
Appreciate the offer! This would be ready for you now @rmehner! |
it "must call the create! method with the same parameters" do | ||
VCR.use_cassette "submit_assembly" do | ||
file = open("lib/transloadit/version.rb") | ||
mocker = Minitest::Mock.new | ||
mocker.expect :call, nil, [file] | ||
@assembly.stub :create!, mocker do | ||
@assembly.submit!(file) | ||
@assembly.create!(file) |
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.
IIRC this test ensured that the deprecated submit! method calls create!. By replacing the submit! call with a create! call, the test is now useless. Either we keep the test as is or we remove it entirely.
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.
Okay i see.
I thought the output was smelly, reverted this 👌
end | ||
|
||
it "requires input" do | ||
assert_raises ArgumentError, "input is required" do |
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.
Internally we have discusses use cases where customers might leave ${fields.input}
unset because they don't need it at all or prefer using named query parameters. When a customer wants to sign such a URL, should we require them to pass nil
and an explicit empty string to the signature method? I prefer an empty string, which would also work with this implementation.
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.
That's right, I now changed it to allow empty string input
s as well as empty string e.g. width
, which will show up in the URL
end | ||
|
||
it "allows overriding credentials" do | ||
url = @transloadit.signed_smart_cdn_url( |
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 wonder what the use case here is. AFAICT signed_smart_cdn_url
is not a static method but an instance method and thus a Transloadit
instance is always needed to call it. When would someone want to pass in other credentials to method instead of creating another Transloadit
instance?
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.
Removed this now with the exception of the reference implementation
lib/transloadit.rb
Outdated
next if value.nil? | ||
if value.is_a?(Array) | ||
value.each do |val| | ||
next if val.nil? || val.to_s.empty? |
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.
Does this filter out empty strings? While I don't have a use case, I also think we should not place unnecessary restrictions on the URL parameters. If a customer wants to have an empty parameter value, they can have it.
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 now changed it to allow empty string e.g. width
, which will show up in the URL
|
||
url = @transloadit.signed_smart_cdn_url(**params) | ||
node_url = run_node_script(params) | ||
assert_equal node_url, url |
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.
These test cases only check if the Ruby implementation matches the Node.js script in this repository. We should also compare the generated URLs against static strings here to ensure they are what we expect them to be:
assert_equal node_url, url | |
assert_equal node_url, url | |
assert_equal "https://....", url |
This makes the tests easier to understand since you directly see what the expected output is. In addition, we test the Node.js script to ensure it doesn't produce total garbage :)
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 changed it to have just one test file, that tests both against node as a hardcoded string
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.
Don't have enough time today, but @Acconut already did some good reviews there :)
lib/transloadit.rb
Outdated
raise ArgumentError, "workspace is required" if workspace.nil? | ||
raise ArgumentError, "template is required" if template.nil? | ||
raise ArgumentError, "input is required" if input.nil? |
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.
Do you want to guard explicitly against nil
being passed? Or is this to make sure that the argument is passed at all? If so, that's already taken care of by Ruby itself, since you don't define a default, making the keywords required.
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.
We want to allow empty strings, but not omitting or other falsey values
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 think we want to allow empty strings for workspace
and template
. They must always be set. Only input
could be an empty string.
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.
Implemented and rolled tests for this now too 👌
lib/transloadit.rb
Outdated
query_params["exp"] = [expire_at.to_s] | ||
|
||
# Sort parameters to ensure consistent ordering | ||
sorted_params = query_params.sort.map do |key, values| |
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.
Save some CPU cycles, use flat_map :D
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.
Perfect 🙏
Co-authored-by: Robin Mehner <robin@coding-robin.de>
Co-Authored-By: Robin Mehner <robin@coding-robin.de>
Co-Authored-By: Robin Mehner <robin@coding-robin.de>
I think I did all I could here, but I don't have access to cut a release on Rubygems, can you add me there @rmehner ? |
What's your rubygems.org username? |
@kvz also could you please add yourself here: https://github.com/transloadit/ruby-sdk/blob/main/transloadit.gemspec#L10-L11? |
✅ done!
Just signed up as |
Thank you!
If anything looks out the order to you please let me know :) |
You could draft a release here: https://github.com/transloadit/ruby-sdk/releases, so it shows up in the releases tab of this repo. |
Check, just did it. Would you say these steps are accurate? https://github.com/transloadit/ruby-sdk?tab=readme-ov-file#releasing-on-rubygems |
Yes, it's accurate. We could ease it a little bit with the help of gem-release, but since we don't do it so often and the steps are pretty well documented, I don't think it's worth the effort here. |
Allows you to generate signed URLs for Transloadit's Smart CDN.