From 4dd1cb178d219959972031a4e59bac6c33d1bebe Mon Sep 17 00:00:00 2001 From: Julian Weber Date: Thu, 30 Oct 2014 13:08:47 +0100 Subject: [PATCH] implements the public_url feature for openstack storage --- lib/fog/openstack/models/storage/directory.rb | 12 +++++-- .../openstack/requests/storage/public_url.rb | 32 +++++++++++++++++++ lib/fog/openstack/storage.rb | 1 + 3 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 lib/fog/openstack/requests/storage/public_url.rb diff --git a/lib/fog/openstack/models/storage/directory.rb b/lib/fog/openstack/models/storage/directory.rb index 58164a48a..11b65f3fe 100644 --- a/lib/fog/openstack/models/storage/directory.rb +++ b/lib/fog/openstack/models/storage/directory.rb @@ -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 diff --git a/lib/fog/openstack/requests/storage/public_url.rb b/lib/fog/openstack/requests/storage/public_url.rb new file mode 100644 index 000000000..6a5085aa9 --- /dev/null +++ b/lib/fog/openstack/requests/storage/public_url.rb @@ -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 diff --git a/lib/fog/openstack/storage.rb b/lib/fog/openstack/storage.rb index e72eb5d45..b67462b54 100644 --- a/lib/fog/openstack/storage.rb +++ b/lib/fog/openstack/storage.rb @@ -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