Rails, Rackspace Cloud Files, Referrer ACLs

I am using Rackspace Cloud Files as the file storage server for my application. Files downloaded by users must be authorized from my application, and then from the controller it is redirected to the correct CDN URL of the Rackspace cloud files. I am trying to do authorization using the Rackspace Cloud Files referral ACL.

So let me add a very simple snippet to clarify what I'm trying to accomplish.

class FilesController < ApplicationController
  def download
    redirect_to(some_url_to_a_file_on_cloud_files_url)
  end
end

The URL that the user would access this download action would be:

http://a-subdomain.domain.com/projects/:project_id/files/:file_id/download

So, with the CloudFiles stone, I set up a Referrer ACL regex that should work.

http\:\/\/.+\.domain\.com\/projects\/\d+\/files\/\d+\/download

-, URL-, URL- Rackspace.

, , , ( http-). , , , "" HTTP- URL- , , URL:

http\:\/\/.+\.domain\.com\/projects\/\d+\/files

, , "", FilesController.

HTTP Referrer ACL Rackspace :

http\:\/\/.+\.domain\.com\/projects\/\d+\/files

, . , , , , firebug html .

, , : - , , , - /? , , , , , , URL, .

?

class FilesController < ApplicationController
  def download
    # Dynamically set a HTTP Referrer here before
    # redirecting the user to the actual file on cloud files
    # so the user is authorized to download the file?
    redirect_to(some_url_to_a_file_on_cloud_files_url)
  end
end

, !

!

+3
2

Micahel , , S3 , HTTP Rackspace, HTTP-

class DownloadsController < ApplicationController
   def download
     send_data HTTParty.get(some_url_to_a_file_on_cloud_files_url, :headers => {"x-special-headers" => "AWESOME" }), :file_name => "myfile.something"
   end
end

, , .

0

"Referer" - , temp urls ( URL-) Rackspace CloudFiles.

Rackspace.

require "openssl"
 unless ARGV.length == 4
 puts "Syntax: <method> <url> <seconds> <key>"
 puts ("Example: GET https://storage101.dfw1.clouddrive.com/v1/" +
 "MossoCloudFS_12345678-9abc-def0-1234-56789abcdef0/" +
 "container/path/to/object.file 60 my_shared_secret_key")
 else
 method, url, seconds, key = ARGV
 method = method.upcase
 base_url, object_path = url.split(/\/v1\//)
 object_path = '/v1/' + object_path
 seconds = seconds.to_i
 expires = (Time.now + seconds).to_i
 hmac_body = "#{method}\n#{expires}\n#{object_path}"
 sig = OpenSSL::HMAC.hexdigest("sha1", key, hmac_body)
 puts ("#{base_url}#{object_path}?" +
 "temp_url_sig=#{sig}&temp_url_expires=#{expires}")
 end
0

Source: https://habr.com/ru/post/1771419/


All Articles