1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[storage] provide http/https options for signed urls

closes #157
This commit is contained in:
geemus 2011-06-27 14:50:32 -07:00
parent 78dc50f1d5
commit 50cbeea302
10 changed files with 271 additions and 55 deletions

View file

@ -30,6 +30,8 @@ module Fog
request :get_object
request :get_object_acl
request :get_object_torrent
request :get_object_http_url
request :get_object_https_url
request :get_object_url
request :get_request_payment
request :get_service
@ -60,7 +62,22 @@ module Fog
)
end
def http_url(params, expires)
"http://" << host_path_query(params, expires)
end
def https_url(params, expires)
"https://" << host_path_query(params, expires)
end
def url(params, expires)
Formatador.display_line("[yellow][WARN] #{Fog::Storage::AWS} => #url is deprecated, use #https_url instead[/] [light_black](#{caller.first})[/]")
https_url(params, expires)
end
private
def host_path_query(params, expires)
params[:headers] ||= {}
params[:headers]['Date'] = expires.to_i
params[:path] = Fog::AWS.escape(params[:path]).gsub('%2F', '/')
@ -73,7 +90,7 @@ module Fog
query << "AWSAccessKeyId=#{@aws_access_key_id}"
query << "Signature=#{Fog::AWS.escape(signature(params))}"
query << "Expires=#{params[:headers]['Date']}"
"https://#{@host}/#{params[:path]}?#{query.join('&')}"
"#{@host}/#{params[:path]}?#{query.join('&')}"
end
end

View file

@ -20,6 +20,8 @@ module Fog
request :get_object
request :get_object_acl
request :get_object_torrent
request :get_object_http_url
request :get_object_https_url
request :get_object_url
request :get_service
request :head_object
@ -30,14 +32,30 @@ module Fog
module Utils
def http_url(params, expires)
"http://" << host_path_query(params, expires)
end
def https_url(params, expires)
"https://" << host_path_query(params, expires)
end
def url(params, expires)
Formatador.display_line("[yellow][WARN] Fog::Storage::Google => #url is deprecated, use #https_url instead[/] [light_black](#{caller.first})[/]")
https_url(params, expires)
end
private
def host_path_query(params, expires)
params[:headers]['Date'] = expires.to_i
params[:path] = CGI.escape(params[:path]).gsub('%2F', '/')
query = [params[:query]].compact
query << "GoogleAccessKeyId=#{@google_storage_access_key_id}"
query << "Signature=#{CGI.escape(signature(params))}"
query << "Expires=#{params[:headers]['Date']}"
"http://#{params[:host]}/#{params[:path]}?#{query.join('&')}"
"#{params[:host]}/#{params[:path]}?#{query.join('&')}"
end
end

View file

@ -6,6 +6,8 @@ module Fog
class AWS
class Files < Fog::Collection
extend Fog::Deprecation
deprecate :get_url, :get_https_url
attribute :common_prefixes, :aliases => 'CommonPrefixes'
attribute :delimiter, :aliases => 'Delimiter'
@ -76,9 +78,14 @@ module Fog
end
end
def get_url(key, expires)
def get_http_url(key, expires)
requires :directory
connection.get_object_url(directory.key, key, expires)
connection.get_object_http_url(directory.key, key, expires)
end
def get_https_url(key, expires)
requires :directory
connection.get_object_https_url(directory.key, key, expires)
end
def head(key, options = {})

View file

@ -6,6 +6,8 @@ module Fog
class Google
class Files < Fog::Collection
extend Fog::Deprecation
deprecate :get_url, :get_https_url
attribute :common_prefixes, :aliases => 'CommonPrefixes'
attribute :delimiter, :aliases => 'Delimiter'
@ -68,9 +70,14 @@ module Fog
nil
end
def get_url(key, expires)
def get_http_url(key, expires)
requires :directory
connection.get_object_url(directory.key, key, expires)
connection.get_object_http_url(directory.key, key, expires)
end
def get_https_url(key, expires)
requires :directory
connection.get_object_https_url(directory.key, key, expires)
end
def head(key, options = {})

View file

@ -0,0 +1,51 @@
module Fog
module Storage
class AWS
module GetObjectHttpUrl
def get_object_http_url(bucket_name, object_name, expires)
unless bucket_name
raise ArgumentError.new('bucket_name is required')
end
unless object_name
raise ArgumentError.new('object_name is required')
end
http_url({
:headers => {},
:host => @host,
:method => 'GET',
:path => "#{bucket_name}/#{object_name}"
}, expires)
end
end
class Real
# Get an expiring object http url from S3
#
# ==== Parameters
# * bucket_name<~String> - Name of bucket containing object
# * object_name<~String> - Name of object to get expiring url for
# * expires<~Time> - An expiry time for this url
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~String> - url for object
#
# ==== See Also
# http://docs.amazonwebservices.com/AmazonS3/latest/dev/S3_QSAuth.html
include GetObjectHttpUrl
end
class Mock # :nodoc:all
include GetObjectHttpUrl
end
end
end
end

View file

@ -0,0 +1,51 @@
module Fog
module Storage
class AWS
module GetObjectHttpsUrl
def get_object_https_url(bucket_name, object_name, expires)
unless bucket_name
raise ArgumentError.new('bucket_name is required')
end
unless object_name
raise ArgumentError.new('object_name is required')
end
https_url({
:headers => {},
:host => @host,
:method => 'GET',
:path => "#{bucket_name}/#{object_name}"
}, expires)
end
end
class Real
# Get an expiring object https url from S3
#
# ==== Parameters
# * bucket_name<~String> - Name of bucket containing object
# * object_name<~String> - Name of object to get expiring url for
# * expires<~Time> - An expiry time for this url
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~String> - url for object
#
# ==== See Also
# http://docs.amazonwebservices.com/AmazonS3/latest/dev/S3_QSAuth.html
include GetObjectHttpsUrl
end
class Mock # :nodoc:all
include GetObjectHttpsUrl
end
end
end
end

View file

@ -18,18 +18,8 @@ module Fog
# http://docs.amazonwebservices.com/AmazonS3/latest/dev/S3_QSAuth.html
def get_object_url(bucket_name, object_name, expires)
unless bucket_name
raise ArgumentError.new('bucket_name is required')
end
unless object_name
raise ArgumentError.new('object_name is required')
end
url({
:headers => {},
:host => @host,
:method => 'GET',
:path => "#{bucket_name}/#{object_name}"
}, expires)
Formatador.display_line("[yellow][WARN] Fog::Storage::AWS => ##{get_object_url} is deprecated, use ##{get_object_https_url} instead[/] [light_black](#{caller.first})[/]")
get_object_https_url(bucket_name, object_name, expires)
end
end
@ -37,18 +27,8 @@ module Fog
class Mock # :nodoc:all
def get_object_url(bucket_name, object_name, expires)
unless bucket_name
raise ArgumentError.new('bucket_name is required')
end
unless object_name
raise ArgumentError.new('object_name is required')
end
url({
:headers => {},
:host => @host,
:method => 'GET',
:path => "#{bucket_name}/#{object_name}"
}, expires)
Formatador.display_line("[yellow][WARN] Fog::Storage::AWS => ##{get_object_url} is deprecated, use ##{get_object_https_url} instead[/] [light_black](#{caller.first})[/]")
get_object_https_url(bucket_name, object_name, expires)
end
end

View file

@ -0,0 +1,51 @@
module Fog
module Storage
class Google
module GetObjectHttpUrl
def get_object_http_url(bucket_name, object_name, expires)
unless bucket_name
raise ArgumentError.new('bucket_name is required')
end
unless object_name
raise ArgumentError.new('object_name is required')
end
http_url({
:headers => {},
:host => @host,
:method => 'GET',
:path => "#{bucket_name}/#{object_name}"
}, expires)
end
end
class Real
# Get an expiring object http url from S3
#
# ==== Parameters
# * bucket_name<~String> - Name of bucket containing object
# * object_name<~String> - Name of object to get expiring url for
# * expires<~Time> - An expiry time for this url
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~String> - url for object
#
# ==== See Also
# http://docs.amazonwebservices.com/AmazonS3/latest/dev/S3_QSAuth.html
include GetObjectHttpUrl
end
class Mock # :nodoc:all
include GetObjectHttpUrl
end
end
end
end

View file

@ -0,0 +1,51 @@
module Fog
module Storage
class AWS
module GetObjectHttpsUrl
def get_object_https_url(bucket_name, object_name, expires)
unless bucket_name
raise ArgumentError.new('bucket_name is required')
end
unless object_name
raise ArgumentError.new('object_name is required')
end
https_url({
:headers => {},
:host => @host,
:method => 'GET',
:path => "#{bucket_name}/#{object_name}"
}, expires)
end
end
class Real
# Get an expiring object https url from Google Storage
#
# ==== Parameters
# * bucket_name<~String> - Name of bucket containing object
# * object_name<~String> - Name of object to get expiring url for
# * expires<~Time> - An expiry time for this url
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~String> - url for object
#
# ==== See Also
# http://docs.amazonwebservices.com/AmazonS3/latest/dev/S3_QSAuth.html
include GetObjectHttpsUrl
end
class Mock # :nodoc:all
include GetObjectHttpsUrl
end
end
end
end

View file

@ -14,38 +14,21 @@ module Fog
# * response<~Excon::Response>:
# * body<~String> - url for object
#
# ==== See Also
# http://docs.amazonwebservices.com/AmazonS3/latest/dev/S3_QSAuth.html
def get_object_url(bucket_name, object_name, expires)
unless bucket_name
raise ArgumentError.new('bucket_name is required')
end
unless object_name
raise ArgumentError.new('object_name is required')
end
url({
:headers => {},
:host => @host,
:method => 'GET',
:path => "#{bucket_name}/#{object_name}"
}, expires)
Formatador.display_line("[yellow][WARN] Fog::Storage::Google => ##{get_object_url} is deprecated, use ##{get_object_https_url} instead[/] [light_black](#{caller.first})[/]")
get_object_https_url(bucket_name, object_name, expires)
end
end
class Mock
class Mock # :nodoc:all
def get_object_url(bucket_name, object_name, expires)
unless bucket_name
raise ArgumentError.new('bucket_name is required')
end
unless object_name
raise ArgumentError.new('object_name is required')
end
url({
:headers => {},
:host => @host,
:method => 'GET',
:path => "#{bucket_name}/#{object_name}"
}, expires)
Formatador.display_line("[yellow][WARN] Fog::Storage::Google => ##{get_object_url} is deprecated, use ##{get_object_https_url} instead[/] [light_black](#{caller.first})[/]")
get_object_https_url(bucket_name, object_name, expires)
end
end