From 8ce9044be128533496e58bffc4f36ebbfdb1d4e2 Mon Sep 17 00:00:00 2001 From: Kyle Rames Date: Fri, 15 Feb 2013 14:26:45 -0600 Subject: [PATCH] [rackspace|storage] added account model --- lib/fog/rackspace/models/storage/account.rb | 24 ++++++++++++++++ lib/fog/rackspace/storage.rb | 6 ++++ .../rackspace/models/storage/account_tests.rb | 28 +++++++++++++++++++ tests/rackspace/storage_tests.rb | 8 ++++++ 4 files changed, 66 insertions(+) create mode 100644 lib/fog/rackspace/models/storage/account.rb create mode 100644 tests/rackspace/models/storage/account_tests.rb create mode 100644 tests/rackspace/storage_tests.rb diff --git a/lib/fog/rackspace/models/storage/account.rb b/lib/fog/rackspace/models/storage/account.rb new file mode 100644 index 000000000..c98fac8f4 --- /dev/null +++ b/lib/fog/rackspace/models/storage/account.rb @@ -0,0 +1,24 @@ +require 'fog/core/model' + +module Fog + module Storage + class Rackspace + class Account < Fog::Model + attribute :meta_temp_url_key, :aliases => 'X-Account-Meta-Temp-Url-Key' + attribute :container_count, :aliases => 'X-Account-Container-Count', :type => :integer + attribute :bytes_used, :aliases => 'X-Account-Bytes-Used', :type => :integer + attribute :object_count, :aliases => 'X-Account-Object-Count', :type => :integer + + def save + service.post_set_meta_temp_url_key meta_temp_url_key + true + end + + def reload + response = service.head_containers + merge_attributes response.headers + end + end + end + end +end \ No newline at end of file diff --git a/lib/fog/rackspace/storage.rb b/lib/fog/rackspace/storage.rb index 0141c9630..46ef81d76 100644 --- a/lib/fog/rackspace/storage.rb +++ b/lib/fog/rackspace/storage.rb @@ -14,6 +14,7 @@ module Fog collection :directories model :file collection :files + model :account request_path 'fog/rackspace/requests/storage' request :copy_object @@ -97,6 +98,11 @@ module Fog Excon.defaults[:ssl_verify_peer] = false if options[:rackspace_servicenet] == true @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options) end + + def account + account = Fog::Storage::Rackspace::Account.new(:service => self) + account.reload + end def reload @connection.reset diff --git a/tests/rackspace/models/storage/account_tests.rb b/tests/rackspace/models/storage/account_tests.rb new file mode 100644 index 000000000..02d0e2a9d --- /dev/null +++ b/tests/rackspace/models/storage/account_tests.rb @@ -0,0 +1,28 @@ +Shindo.tests('Fog::Rackspace::Storage | account', ['rackspace']) do + + pending if Fog.mocking? + + @account = Fog::Storage[:rackspace].account + + tests('load') do + headers = @account.service.head_containers.headers + + returns(headers['X-Account-Meta-Temp-Url-Key']) { @account.meta_temp_url_key } + returns(headers['X-Account-Container-Count'].to_i) { @account.container_count } + returns(headers['X-Account-Bytes-Used'].to_i) { @account.bytes_used } + returns(headers['X-Account-Object-Count'].to_i) { @account.object_count } + end + + tests('reload') do + @account.reload + end + + tests('save') do + key = "testing-update-#{Time.now.to_i}" + @account.meta_temp_url_key = "testing-update-#{Time.now.to_i}" + @account.save + + headers = @account.service.head_containers.headers + returns(key) { headers['X-Account-Meta-Temp-Url-Key'] } + end +end \ No newline at end of file diff --git a/tests/rackspace/storage_tests.rb b/tests/rackspace/storage_tests.rb new file mode 100644 index 000000000..8f28b013b --- /dev/null +++ b/tests/rackspace/storage_tests.rb @@ -0,0 +1,8 @@ +Shindo.tests('Fog::Storage::Rackspace', ['rackspace']) do |variable| + + pending if Fog.mocking? + + tests('account').succeeds do + Fog::Storage[:rackspace].account + end +end \ No newline at end of file