anynines website

Categories

Series

Julian Weber

Published at 04.07.2013

How-To’s & Tutorials

Ruby Fog Gem HP Provider Now With Openstack Swift Temp URL Support

The Fog HP storage provider is currently the most stable and recommended way to access Swift using Ruby as the HP storage implementation is more reliable than the OpenStack provider.

So while you should use OpenStack::Identity for tenant and user management, Swift access is rather done using HP::Storage of the HP provider.

During the creation of the anynines OpenStack Swift file storage service a pull request to the Ruby fog gem has been made.

The pull request enhances the HP Fog provider to create temporary URLs for files stored on OpenStack Swift.
Here HP goes a different way calculating the required signature to request a temporary url. Both strategies: HP and OpenStack are now supported.

In order to enable the OpenStack strategy the only thing you have to do is to pass the :os_account_meta_temp_url_key attribute to the HP::Storage.new() method.

Example:

[code language=”ruby”]
credentials = {
:provider => ‘HP’,
:hp_access_key => "username",
:hp_secret_key => "password",
:hp_tenant_id => "tenant_id",
:hp_auth_uri => "authentication_uri",
:hp_use_upass_auth_style => true,
:hp_avl_zone => "nova",
:hp_auth_version => :v2,
:os_account_meta_temp_url_key => "your_os_account_meta_temp_url_key"
}
[/code]

Then create a storage instance, create a directory, upload a file and there you go:

[code language=”ruby”]
storage = Fog::Storage.new(credentials)
dirname = "fog-swift-test-#{Time.now.to_i}"
directory = storage.directories.create(:key => dirname)
file = directory.files.create(:key => "picture.jpg", :body => File.open("picture.jpg"))
my_temp_url = file.temp_signed_url(240, "GET")
[/code]

Note:

Please be aware that at the time of this writing the above code is in the Fog master branch on Github but not released, yet. So look for any version > 1.12.1 or use the bleeding edge Fog in your Gemfile like this:

[code language=”ruby”]
gem ‘fog’, :git => ‘git@github.com:fog/fog.git’
[/code]

© anynines GmbH 2024

Imprint

Privacy Policy

About

© anynines GmbH 2024