Skip to content

Commit

Permalink
Revert "[Ruby] force users to specify the temp folder path to address…
Browse files Browse the repository at this point in the history
… security concerns (#8730)" (#8807)

This reverts commit 18a6f5a.
  • Loading branch information
wing328 authored Feb 23, 2021
1 parent a7c6ecc commit c653051
Show file tree
Hide file tree
Showing 7 changed files with 3 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,6 @@ module {{moduleName}}
{{/isFaraday}}
{{#isFaraday}}
if return_type == 'File'
# throw an exception if the temp folder path is not defined
# to avoid using the default temp directory which can be read by anyone
if @config.temp_folder_path.nil?
raise "@config.temp_folder_path must be setup first (e.g. ENV[\"HOME\"], ENV[\"HOMEPATH\"]) " +
"to avoid dowloading the file to a location readable by everyone."
end

content_disposition = response.headers['Content-Disposition']
if content_disposition && content_disposition =~ /filename=/i
filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@

{{#hasAuthMethods}}
update_params_for_auth! header_params, query_params, opts[:auth_names]

{{/hasAuthMethods}}

# set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
_verify_ssl_host = @config.verify_ssl_host ? 2 : 0

Expand Down Expand Up @@ -122,13 +122,6 @@
#
# @see Configuration#temp_folder_path
def download_file(request)
# throw an exception if the temp folder path is not defined
# to avoid using the default temp directory which can be read by anyone
if @config.temp_folder_path.nil?
raise "@config.temp_folder_path must be setup first (e.g. ENV[\"HOME\"], ENV[\"HOMEPATH\"])" +
"to avoid dowloading the file to a location readable by everyone."
end

tempfile = nil
encoding = nil
request.on_headers do |response|
Expand All @@ -144,12 +137,10 @@
tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
@tempfile = tempfile
end

request.on_body do |chunk|
chunk.force_encoding(encoding)
tempfile.write(chunk)
end

request.on_complete do |response|
if tempfile
tempfile.close
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,6 @@ def deserialize(response, return_type)
# handle file downloading - return the File instance processed in request callbacks
# note that response body is empty when the file is written in chunks in request on_body callback
if return_type == 'File'
# throw an exception if the temp folder path is not defined
# to avoid using the default temp directory which can be read by anyone
if @config.temp_folder_path.nil?
raise "@config.temp_folder_path must be setup first (e.g. ENV[\"HOME\"], ENV[\"HOMEPATH\"]) " +
"to avoid dowloading the file to a location readable by everyone."
end

content_disposition = response.headers['Content-Disposition']
if content_disposition && content_disposition =~ /filename=/i
filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
Expand Down
9 changes: 0 additions & 9 deletions samples/client/petstore/ruby/lib/petstore/api_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,6 @@ def build_request_body(header_params, form_params, body)
#
# @see Configuration#temp_folder_path
def download_file(request)
# throw an exception if the temp folder path is not defined
# to avoid using the default temp directory which can be read by anyone
if @config.temp_folder_path.nil?
raise "@config.temp_folder_path must be setup first (e.g. ENV[\"HOME\"], ENV[\"HOMEPATH\"])" +
"to avoid dowloading the file to a location readable by everyone."
end

tempfile = nil
encoding = nil
request.on_headers do |response|
Expand All @@ -186,12 +179,10 @@ def download_file(request)
tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
@tempfile = tempfile
end

request.on_body do |chunk|
chunk.force_encoding(encoding)
tempfile.write(chunk)
end

request.on_complete do |response|
if tempfile
tempfile.close
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,6 @@ def build_request_body(header_params, form_params, body)
#
# @see Configuration#temp_folder_path
def download_file(request)
# throw an exception if the temp folder path is not defined
# to avoid using the default temp directory which can be read by anyone
if @config.temp_folder_path.nil?
raise "@config.temp_folder_path must be setup first (e.g. ENV[\"HOME\"], ENV[\"HOMEPATH\"])" +
"to avoid dowloading the file to a location readable by everyone."
end

tempfile = nil
encoding = nil
request.on_headers do |response|
Expand All @@ -186,12 +179,10 @@ def download_file(request)
tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
@tempfile = tempfile
end

request.on_body do |chunk|
chunk.force_encoding(encoding)
tempfile.write(chunk)
end

request.on_complete do |response|
if tempfile
tempfile.close
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def build_request(http_method, path, opts = {})
query_params = opts[:query_params] || {}
form_params = opts[:form_params] || {}


# set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
_verify_ssl_host = @config.verify_ssl_host ? 2 : 0

Expand Down Expand Up @@ -162,13 +163,6 @@ def build_request_body(header_params, form_params, body)
#
# @see Configuration#temp_folder_path
def download_file(request)
# throw an exception if the temp folder path is not defined
# to avoid using the default temp directory which can be read by anyone
if @config.temp_folder_path.nil?
raise "@config.temp_folder_path must be setup first (e.g. ENV[\"HOME\"], ENV[\"HOMEPATH\"])" +
"to avoid dowloading the file to a location readable by everyone."
end

tempfile = nil
encoding = nil
request.on_headers do |response|
Expand All @@ -184,12 +178,10 @@ def download_file(request)
tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
@tempfile = tempfile
end

request.on_body do |chunk|
chunk.force_encoding(encoding)
tempfile.write(chunk)
end

request.on_complete do |response|
if tempfile
tempfile.close
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def build_request(http_method, path, opts = {})
query_params = opts[:query_params] || {}
form_params = opts[:form_params] || {}


# set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
_verify_ssl_host = @config.verify_ssl_host ? 2 : 0

Expand Down Expand Up @@ -162,13 +163,6 @@ def build_request_body(header_params, form_params, body)
#
# @see Configuration#temp_folder_path
def download_file(request)
# throw an exception if the temp folder path is not defined
# to avoid using the default temp directory which can be read by anyone
if @config.temp_folder_path.nil?
raise "@config.temp_folder_path must be setup first (e.g. ENV[\"HOME\"], ENV[\"HOMEPATH\"])" +
"to avoid dowloading the file to a location readable by everyone."
end

tempfile = nil
encoding = nil
request.on_headers do |response|
Expand All @@ -184,12 +178,10 @@ def download_file(request)
tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
@tempfile = tempfile
end

request.on_body do |chunk|
chunk.force_encoding(encoding)
tempfile.write(chunk)
end

request.on_complete do |response|
if tempfile
tempfile.close
Expand Down

0 comments on commit c653051

Please sign in to comment.