-
Notifications
You must be signed in to change notification settings - Fork 145
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
Support query parameters in GET requests #409
Conversation
:host => @host, | ||
:method => "GET", | ||
:path => "#{bucket_name}/#{object_name}" | ||
}), expires) |
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.
Layout/IndentHash: Indent the right brace the same as the first position after the preceding left parenthesis.
}, expires) | ||
|
||
https_url(options.merge({ | ||
:headers => {}, |
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.
Layout/IndentHash: Use 2 spaces for indentation in a hash, relative to the first position after the preceding left parenthesis.
:path => "#{bucket_name}/#{object_name}" | ||
}, expires) | ||
|
||
https_url(options.merge({ |
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.
Style/BracesAroundHashParameters: Redundant curly braces around a hash parameter.
lib/fog/storage/google_xml/utils.rb
Outdated
query = [params[:query]].compact | ||
query = if params[:query] | ||
params[:query].compact.map { |k, v| [k.to_s, CGI.escape(v)].join("=") } | ||
else |
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.
Layout/ElseAlignment: Align else with if.
lib/fog/storage/google_xml/utils.rb
Outdated
@@ -31,7 +31,12 @@ def url(params, expires) | |||
def host_path_query(params, expires) | |||
params[:headers]["Date"] = expires.to_i | |||
params[:path] = Fog::Google.escape(params[:path]).gsub("%2F", "/") | |||
query = [params[:query]].compact | |||
query = if params[:query] |
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.
Style/ConditionalAssignment: Assign variables inside of conditionals
raise ArgumentError.new("bucket_name is required") unless bucket_name | ||
raise ArgumentError.new("object_name is required") unless object_name | ||
https_url({ | ||
|
||
https_url(options.merge({ |
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.
Style/BracesAroundHashParameters: Redundant curly braces around a hash parameter.
:headers => {}, | ||
:host => @host, | ||
:method => "GET", | ||
:path => "#{bucket_name}/#{object_name}" | ||
}, expires) | ||
}), expires) |
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.
Layout/IndentHash: Indent the right brace the same as the first position after the preceding left parenthesis.
raise ArgumentError.new("bucket_name is required") unless bucket_name | ||
raise ArgumentError.new("object_name is required") unless object_name | ||
|
||
https_url({ | ||
https_url(options.merge({ |
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.
Style/BracesAroundHashParameters: Redundant curly braces around a hash parameter.
:headers => {}, | ||
:host => @host, | ||
:method => "GET", | ||
:path => "#{bucket_name}/#{object_name}" | ||
}, expires) | ||
}), expires) |
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.
Layout/IndentHash: Indent the right brace the same as the first position after the preceding left parenthesis.
raise ArgumentError.new("bucket_name is required") unless bucket_name | ||
raise ArgumentError.new("object_name is required") unless object_name | ||
http_url({ | ||
http_url(options.merge({ |
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.
Style/BracesAroundHashParameters: Redundant curly braces around a hash parameter.
9a8831a
to
78840c4
Compare
url = @client.get_object_url("bucket", | ||
"just some file.json", | ||
Time.now + 2 * 60, | ||
{ query: { "Response-Content-Disposition" => 'inline; filename="test.json"' } }) |
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.
Style/BracesAroundHashParameters: Redundant curly braces around a hash parameter.
c677d00
to
af6301e
Compare
@Temikus Would you mind taking a look at this? This is affecting lots of people trying to use GitLab with Google Cloud Storage (https://gitlab.com/gitlab-org/gitlab-ce/issues/49957#note_95023022). |
Codecov Report
@@ Coverage Diff @@
## master #409 +/- ##
==========================================
- Coverage 84.14% 84.11% -0.04%
==========================================
Files 339 339
Lines 5766 5771 +5
==========================================
+ Hits 4852 4854 +2
- Misses 914 917 +3
Continue to review full report at Codecov.
|
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.
Overall looks good, please, check the escape method though. If I'm missing something - just let me know!
lib/fog/storage/google_json/utils.rb
Outdated
|
||
if params[:query] | ||
filtered = params[:query].reject { |k, v| k.nil? || v.nil? } | ||
query = filtered.map { |k, v| [k.to_s, CGI.escape(v)].join("=") } |
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.
Be aware that CGI.escape inserts +
instead of %20
when escaping whitespaces which breaks certain behaviours.
If you plan on whitespace being in the query - check if you need to use Fog::Google.escape instead.
See #357
lib/fog/storage/google_xml/utils.rb
Outdated
|
||
if params[:query] | ||
filtered = params[:query].reject { |k, v| k.nil? || v.nil? } | ||
query = filtered.map { |k, v| [k.to_s, CGI.escape(v)].join("=") } |
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.
Ditto
Be aware that CGI.escape inserts +
instead of %20
when escaping whitespaces which breaks certain behaviours.
If you plan on whitespace being in the query - check if you need to use Fog::Google.escape instead.
See #357
@@ -12,6 +12,16 @@ def teardown | |||
Fog.unmock! | |||
end | |||
|
|||
def test_get_url_path_has_query_params |
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.
Thank you for the tests ❤️
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 had an equivalent test for the JSON request API, but I saw this error:
NoMethodError: NoMethodError: undefined method `issuer' for nil:NilClass
/Users/stanhu/github/fog-google/lib/fog/storage/google_json/utils.rb:30:in `host_path_query'
/Users/stanhu/github/fog-google/lib/fog/storage/google_json/utils.rb:10:in `https_url'
/Users/stanhu/github/fog-google/lib/fog/storage/google_json/requests/get_object_https_url.rb:9:in `get_object_https_url'
/Users/stanhu/github/fog-google/lib/fog/storage/google_json/requests/get_object_url.rb:16:in `get_object_url'
/Users/stanhu/github/fog-google/test/unit/storage/test_json_requests.rb:18:in `test_get_url_path_has_query_params'
I assume client.issuer
comes from Google::Auth::ServiceAccountCredentials#make_creds
, but I punted on further investigation.
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.
Actually, @client
is nil
in the test. Not sure where that's supposed to come from.
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.
Ok, I did some simple mocking. Not sure if it's ideal. Take a look.
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.
Our mocking is not ideal either as I've just started redoing unit tests after 1.0 upgrade, so no worries :)
Thank you for the tests, I'll refactor the client into something more idiomatic as a part 2.0 refactor.
raise ArgumentError.new("bucket_name is required") unless bucket_name | ||
raise ArgumentError.new("object_name is required") unless object_name | ||
|
||
https_url({ | ||
https_url(options.merge({ |
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.
Nit: Make this consistent with the other options.merge
@stanhu And I do see you're blocked on this so I'm willing to work with you to push a release right away. |
3cb2bd1
to
588fb5c
Compare
@Temikus Good catch. I'm not sure why in my end-to-end testing the escaping of the |
This makes it possible to send some extra headers (e.g. response-content-disposition): * https://cloud.google.com/storage/docs/xml-api/reference-headers * https://cloud.google.com/storage/docs/json_api/v1/objects/get
588fb5c
to
574dce1
Compare
def initialize(options = {}) | ||
shared_initialize(options[:google_project], GOOGLE_STORAGE_JSON_API_VERSION, GOOGLE_STORAGE_JSON_BASE_URL) | ||
@client = MockClient.new('test') |
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.
Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
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.
LGTM, thank you!
Merging this in, I'll prep a release by EOD tomorrow (Sydney time) |
This is needed to support query parameters in `Fog::Storage::Google`. See fog/fog-google#409. Relates to https://gitlab.com/gitlab-org/gitlab-ce/issues/49957
This makes it possible to send some extra headers (e.g. response-content-disposition):
https://cloud.google.com/storage/docs/xml-api/reference-headers