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

implements the public_url feature for openstack storage

This commit is contained in:
Julian Weber 2014-10-30 13:08:47 +01:00
parent c2978a2365
commit 4dd1cb178d
3 changed files with 43 additions and 2 deletions

View file

@ -9,7 +9,7 @@ module Fog
attribute :bytes, :aliases => 'X-Container-Bytes-Used'
attribute :count, :aliases => 'X-Container-Object-Count'
attr_writer :public
def destroy
@ -30,7 +30,15 @@ module Fog
end
def public_url
raise NotImplementedError
requires :key
@public_url ||= begin
begin response = service.head_container(key)
# escape the key to cover for special char. in container names
url = service.public_url(key)
rescue Fog::Storage::OpenStack::NotFound => err
nil
end
end
end
def save

View file

@ -0,0 +1,32 @@
module Fog
module Storage
class OpenStack
class Real
def url
"#{@scheme}://#{@host}:#{@port}#{@path}"
end
# Get public_url for an object
#
# ==== Parameters
# * container<~String> - Name of container to look in
# * object<~String> - Name of object to look for
#
def public_url(container=nil, object=nil)
public_url = nil
unless container.nil?
if object.nil?
# return container public url
public_url = "#{url}/#{Fog::OpenStack.escape(container)}"
else
# return object public url
public_url = "#{url}/#{Fog::OpenStack.escape(container)}/#{Fog::OpenStack.escape(object)}"
end
end
public_url
end
end
end
end
end

View file

@ -36,6 +36,7 @@ module Fog
request :put_dynamic_obj_manifest
request :put_static_obj_manifest
request :post_set_meta_temp_url_key
request :public_url
class Mock
def self.data