cloudfiles 1.4.15 → 1.4.16

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -3,3 +3,4 @@ coverage/*
3
3
  doc/*
4
4
  pkg/*
5
5
  *.gem
6
+ .idea
data/CHANGELOG CHANGED
@@ -1,3 +1,10 @@
1
+ ================================================================================
2
+ 1.4.16 (2011/03/17)
3
+ ================================================================================
4
+ o Bugfix on CDN purging. (CvX)
5
+ o Better OpenStack Swift support with regards to handling the lack of
6
+ available CDN. (Topper Bowers)
7
+
1
8
  ================================================================================
2
9
  1.4.15 (2011/03/09)
3
10
  ================================================================================
@@ -27,3 +27,5 @@ drue
27
27
  mkcode
28
28
  megaphone
29
29
  Nugroho Herucahyono
30
+ CvX
31
+ Topper Bowers
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.4.15
1
+ 1.4.16
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{cloudfiles}
8
- s.version = "1.4.15"
8
+ s.version = "1.4.16"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["H. Wade Minter", "Rackspace Hosting"]
12
- s.date = %q{2011-03-10}
12
+ s.date = %q{2011-03-17}
13
13
  s.description = %q{A Ruby version of the Rackspace Cloud Files API.}
14
14
  s.email = %q{minter@lunenburg.org}
15
15
  s.extra_rdoc_files = [
@@ -27,6 +27,7 @@ module CloudFiles
27
27
  response = server.get(path, hdrhash)
28
28
  if (response.code =~ /^20./)
29
29
  if response["x-cdn-management-url"]
30
+ connection.cdn_available = true
30
31
  connection.cdnmgmthost = URI.parse(response["x-cdn-management-url"]).host
31
32
  connection.cdnmgmtpath = URI.parse(response["x-cdn-management-url"]).path
32
33
  connection.cdnmgmtport = URI.parse(response["x-cdn-management-url"]).port
@@ -15,6 +15,10 @@ module CloudFiles
15
15
  # API host to authenticate to
16
16
  attr_reader :auth_url
17
17
 
18
+ # Set at auth to see if a CDN is available for use
19
+ attr_accessor :cdn_available
20
+ alias :cdn_available? :cdn_available
21
+
18
22
  # Hostname of the CDN management server
19
23
  attr_accessor :cdnmgmthost
20
24
 
@@ -20,10 +20,12 @@ module CloudFiles
20
20
  @storagepath = self.connection.storagepath + "/" + CloudFiles.escape(@name)
21
21
  @storageport = self.connection.storageport
22
22
  @storagescheme = self.connection.storagescheme
23
- @cdnmgmthost = self.connection.cdnmgmthost
24
- @cdnmgmtpath = self.connection.cdnmgmtpath + "/" + CloudFiles.escape(@name) if self.connection.cdnmgmtpath
25
- @cdnmgmtport = self.connection.cdnmgmtport
26
- @cdnmgmtscheme = self.connection.cdnmgmtscheme
23
+ if self.connection.cdn_available?
24
+ @cdnmgmthost = self.connection.cdnmgmthost
25
+ @cdnmgmtpath = self.connection.cdnmgmtpath + "/" + CloudFiles.escape(@name) if self.connection.cdnmgmtpath
26
+ @cdnmgmtport = self.connection.cdnmgmtport
27
+ @cdnmgmtscheme = self.connection.cdnmgmtscheme
28
+ end
27
29
  # Load the metadata now, so we'll get a CloudFiles::Exception::NoSuchContainer exception should the container
28
30
  # not exist.
29
31
  self.metadata
@@ -57,19 +59,24 @@ module CloudFiles
57
59
 
58
60
  # Retrieves CDN-Enabled Meta Data
59
61
  def cdn_metadata
60
- @cdn_metadata ||= (
61
- response = self.connection.cfreq("HEAD", @cdnmgmthost, @cdnmgmtpath, @cdnmgmtport, @cdnmgmtscheme)
62
- cdn_enabled = ((response["x-cdn-enabled"] || "").downcase == "true") ? true : false
63
- {
64
- :cdn_enabled => cdn_enabled,
65
- :cdn_ttl => cdn_enabled ? response["x-ttl"].to_i : nil,
66
- :cdn_url => cdn_enabled ? response["x-cdn-uri"] : nil,
67
- :cdn_ssl_url => cdn_enabled ? response["x-cdn-ssl-uri"] : nil,
68
- :user_agent_acl => response["x-user-agent-acl"],
69
- :referrer_acl => response["x-referrer-acl"],
70
- :cdn_log => (cdn_enabled and response["x-log-retention"] == "True") ? true : false
71
- }
72
- )
62
+ return @cdn_metadata if @cdn_metadata
63
+ if cdn_available?
64
+ @cdn_metadata = (
65
+ response = self.connection.cfreq("HEAD", @cdnmgmthost, @cdnmgmtpath, @cdnmgmtport, @cdnmgmtscheme)
66
+ cdn_enabled = ((response["x-cdn-enabled"] || "").downcase == "true") ? true : false
67
+ {
68
+ :cdn_enabled => cdn_enabled,
69
+ :cdn_ttl => cdn_enabled ? response["x-ttl"].to_i : nil,
70
+ :cdn_url => cdn_enabled ? response["x-cdn-uri"] : nil,
71
+ :cdn_ssl_url => cdn_enabled ? response["x-cdn-ssl-uri"] : nil,
72
+ :user_agent_acl => response["x-user-agent-acl"],
73
+ :referrer_acl => response["x-referrer-acl"],
74
+ :cdn_log => (cdn_enabled and response["x-log-retention"] == "True") ? true : false
75
+ }
76
+ )
77
+ else
78
+ @cdn_metadata = {}
79
+ end
73
80
  end
74
81
 
75
82
  # Size of the container (in bytes)
@@ -92,7 +99,7 @@ module CloudFiles
92
99
  # private_container.public?
93
100
  # => false
94
101
  def cdn_enabled
95
- self.cdn_metadata[:cdn_enabled]
102
+ cdn_available? && self.cdn_metadata[:cdn_enabled]
96
103
  end
97
104
  alias :cdn_enabled? :cdn_enabled
98
105
  alias :public? :cdn_enabled
@@ -134,6 +141,7 @@ module CloudFiles
134
141
  # These logs will be periodically (at unpredictable intervals) compressed and uploaded
135
142
  # to a “.CDN_ACCESS_LOGS” container in the form of “container_name.YYYYMMDDHH-XXXX.gz”.
136
143
  def log_retention=(value)
144
+ raise Exception::CDNNotAvailable unless cdn_available?
137
145
  response = self.connection.cfreq("POST", @cdnmgmthost, @cdnmgmtpath, @cdnmgmtport, @cdnmgmtscheme, {"x-log-retention" => value.to_s.capitalize})
138
146
  raise CloudFiles::Exception::InvalidResponse, "Invalid response code #{response.code}" unless (response.code == "201" or response.code == "202")
139
147
  return true
@@ -289,6 +297,7 @@ module CloudFiles
289
297
  # container.make_public(:ttl => 8900, :user_agent_acl => "/Mozilla/", :referrer_acl => "/^http://rackspace.com")
290
298
  # => true
291
299
  def make_public(options = {:ttl => 86400})
300
+ raise Exception::CDNNotAvailable unless cdn_available?
292
301
  if options.is_a?(Fixnum)
293
302
  print "DEPRECATED: make_public takes a hash of options now, instead of a TTL number"
294
303
  ttl = options
@@ -315,6 +324,7 @@ module CloudFiles
315
324
  # container.make_private
316
325
  # => true
317
326
  def make_private
327
+ raise Exception::CDNNotAvailable unless cdn_available?
318
328
  headers = { "X-CDN-Enabled" => "False" }
319
329
  response = self.connection.cfreq("POST", @cdnmgmthost, @cdnmgmtpath, @cdnmgmtport, @cdnmgmtscheme, headers)
320
330
  raise CloudFiles::Exception::NoSuchContainer, "Container #{@name} does not exist" unless (response.code == "201" || response.code == "202")
@@ -340,21 +350,26 @@ module CloudFiles
340
350
  # container.purge_from_cdn("User@domain.com, User2@domain.com")
341
351
  # => true
342
352
  def purge_from_cdn(email=nil)
343
- if email
344
- headers = {"X-Purge-Email" => email}
345
- response = self.connection.cfreq("DELETE", @cdnmgmthost, @cdnmgmtpath, @cdnmgmtport, @cdnmgmtscheme, headers)
346
- raise CloudFiles::Exception::Connection, "Error Unable to Purge Container: #{@name}" unless (response.code > "200" && response.code < "299")
347
- else
348
- response = self.connection.cfreq("DELETE", @cdnmgmthost, @cdnmgmtpath, @cdnmgmtport, @cdnmgmtscheme)
349
- raise CloudFiles::Exception::Connection, "Error Unable to Purge Container: #{@name}" unless (response.code > "200" && response.code < "299")
350
- true
351
- end
353
+ raise Exception::CDNNotAvailable unless cdn_available?
354
+ if email
355
+ headers = {"X-Purge-Email" => email}
356
+ response = self.connection.cfreq("DELETE", @cdnmgmthost, @cdnmgmtpath, @cdnmgmtport, @cdnmgmtscheme, headers)
357
+ raise CloudFiles::Exception::Connection, "Error Unable to Purge Container: #{@name}" unless (response.code > "200" && response.code < "299")
358
+ else
359
+ response = self.connection.cfreq("DELETE", @cdnmgmthost, @cdnmgmtpath, @cdnmgmtport, @cdnmgmtscheme)
360
+ raise CloudFiles::Exception::Connection, "Error Unable to Purge Container: #{@name}" unless (response.code > "200" && response.code < "299")
361
+ true
362
+ end
352
363
  end
353
364
 
354
365
  def to_s # :nodoc:
355
366
  @name
356
367
  end
357
368
 
369
+ def cdn_available?
370
+ self.connection.cdn_available?
371
+ end
372
+
358
373
  end
359
374
 
360
375
  end
@@ -58,7 +58,8 @@ module CloudFiles
58
58
  end
59
59
  class ExpiredAuthToken < ExpiredAuthTokenException # :nodoc:
60
60
  end
61
+ class CDNNotAvailable < StandardError
62
+ end
61
63
 
62
64
  end
63
65
  end
64
-
@@ -24,10 +24,12 @@ module CloudFiles
24
24
  @storagepath = self.container.connection.storagepath + "/#{CloudFiles.escape @containername}/#{CloudFiles.escape @name, '/'}"
25
25
  @storageport = self.container.connection.storageport
26
26
  @storagescheme = self.container.connection.storagescheme
27
- @cdnmgmthost = self.container.connection.cdnmgmthost
28
- @cdnmgmtpath = self.container.connection.cdnmgmtpath + "/#{CloudFiles.escape @containername}/#{CloudFiles.escape @name, '/'}"
29
- @cdnmgmtport = self.container.connection.cdnmgmtport
30
- @cdnmgmtscheme = self.container.connection.cdnmgmtscheme
27
+ if self.container.connection.cdn_available?
28
+ @cdnmgmthost = self.container.connection.cdnmgmthost
29
+ @cdnmgmtpath = self.container.connection.cdnmgmtpath + "/#{CloudFiles.escape @containername}/#{CloudFiles.escape @name, '/'}"
30
+ @cdnmgmtport = self.container.connection.cdnmgmtport
31
+ @cdnmgmtscheme = self.container.connection.cdnmgmtscheme
32
+ end
31
33
  if force_exists
32
34
  raise CloudFiles::Exception::NoSuchObject, "Object #{@name} does not exist" unless container.object_exists?(objectname)
33
35
  end
@@ -210,16 +212,17 @@ module CloudFiles
210
212
  #
211
213
  # obj.purge_from_cdn("User@domain.com, User2@domain.com")
212
214
  # => true
213
- def purge_from_cdn(email=nil)
214
- if email
215
- headers = {"X-Purge-Email" => email}
216
- response = self.container.connection.cfreq("DELETE", @cdnmgmthost, @cdnmgmtpath, @cdnmgmtport, @cdnmgmtscheme, headers)
217
- raise CloudFiles::Exception::Connection, "Error Unable to Purge Object: #{@name}" unless (response.code.to_s =~ /^20.$/)
218
- else
219
- response = self.container..connection.cfreq("DELETE", @cdnmgmthost, @cdnmgmtpath, @cdnmgmtport, @cdnmgmtscheme)
220
- raise CloudFiles::Exception::Connection, "Error Unable to Purge Object: #{@name}" unless (response.code.to_s =~ /^20.$/)
221
- end
222
- true
215
+ def purge_from_cdn(email=nil)
216
+ raise Exception::CDNNotAvailable unless cdn_available?
217
+ if email
218
+ headers = {"X-Purge-Email" => email}
219
+ response = self.container.connection.cfreq("DELETE", @cdnmgmthost, @cdnmgmtpath, @cdnmgmtport, @cdnmgmtscheme, headers)
220
+ raise CloudFiles::Exception::Connection, "Error Unable to Purge Object: #{@name}" unless (response.code.to_s =~ /^20.$/)
221
+ else
222
+ response = self.container.connection.cfreq("DELETE", @cdnmgmthost, @cdnmgmtpath, @cdnmgmtport, @cdnmgmtscheme)
223
+ raise CloudFiles::Exception::Connection, "Error Unable to Purge Object: #{@name}" unless (response.code.to_s =~ /^20.$/)
224
+ end
225
+ true
223
226
  end
224
227
 
225
228
  # A convenience method to stream data into an object from a local file (or anything that can be loaded by Ruby's open method)
@@ -344,6 +347,10 @@ module CloudFiles
344
347
 
345
348
  private
346
349
 
350
+ def cdn_available?
351
+ @cdn_available ||= self.container.connection.cdn_available?
352
+ end
353
+
347
354
  def make_path(path) # :nodoc:
348
355
  if path == "." || path == "/"
349
356
  return
@@ -10,7 +10,7 @@ class CloudfilesAuthenticationTest < Test::Unit::TestCase
10
10
  server = mock(:use_ssl= => true, :verify_mode= => true, :start => true, :finish => true)
11
11
  server.stubs(:get).returns(response)
12
12
  CloudFiles::Authentication.any_instance.stubs(:get_server).returns(server)
13
- @connection = stub(:authuser => 'dummy_user', :authkey => 'dummy_key', :cdnmgmthost= => true, :cdnmgmtpath= => true, :cdnmgmtport= => true, :cdnmgmtscheme= => true, :storagehost= => true, :storagepath= => true, :storageport= => true, :storagescheme= => true, :authtoken= => true, :authok= => true, :snet? => false, :auth_url => 'https://auth.api.rackspacecloud.com/v1.0')
13
+ @connection = stub(:authuser => 'dummy_user', :authkey => 'dummy_key', :cdnmgmthost= => true, :cdnmgmtpath= => true, :cdnmgmtport= => true, :cdnmgmtscheme= => true, :storagehost= => true, :storagepath= => true, :storageport= => true, :storagescheme= => true, :authtoken= => true, :authok= => true, :snet? => false, :auth_url => 'https://auth.api.rackspacecloud.com/v1.0', :cdn_available? => true, :cdn_available= => true)
14
14
  result = CloudFiles::Authentication.new(@connection)
15
15
  assert_equal result.class, CloudFiles::Authentication
16
16
  end
@@ -21,7 +21,7 @@ class CloudfilesAuthenticationTest < Test::Unit::TestCase
21
21
  server = mock(:use_ssl= => true, :verify_mode= => true, :start => true, :finish => true)
22
22
  server.stubs(:get).returns(response)
23
23
  CloudFiles::Authentication.any_instance.stubs(:get_server).returns(server)
24
- @connection = stub(:authuser => 'dummy_user', :authkey => 'dummy_key', :cdnmgmthost= => true, :cdnmgmtpath= => true, :cdnmgmtport= => true, :cdnmgmtscheme= => true, :storagehost= => true, :storagepath= => true, :storageport= => true, :storagescheme= => true, :authtoken= => true, :authok= => true, :snet? => true, :auth_url => 'https://auth.api.rackspacecloud.com/v1.0')
24
+ @connection = stub(:authuser => 'dummy_user', :authkey => 'dummy_key', :cdnmgmthost= => true, :cdnmgmtpath= => true, :cdnmgmtport= => true, :cdnmgmtscheme= => true, :storagehost= => true, :storagepath= => true, :storageport= => true, :storagescheme= => true, :authtoken= => true, :authok= => true, :snet? => true, :auth_url => 'https://auth.api.rackspacecloud.com/v1.0', :cdn_available? => true, :cdn_available= => true)
25
25
  result = CloudFiles::Authentication.new(@connection)
26
26
  assert_equal result.class, CloudFiles::Authentication
27
27
  end
@@ -32,7 +32,7 @@ class CloudfilesAuthenticationTest < Test::Unit::TestCase
32
32
  server = mock(:use_ssl= => true, :verify_mode= => true, :start => true)
33
33
  server.stubs(:get).returns(response)
34
34
  CloudFiles::Authentication.any_instance.stubs(:get_server).returns(server)
35
- @connection = stub(:authuser => 'bad_user', :authkey => 'bad_key', :authok= => true, :authtoken= => true, :auth_url => 'https://auth.api.rackspacecloud.com/v1.0')
35
+ @connection = stub(:authuser => 'bad_user', :authkey => 'bad_key', :authok= => true, :authtoken= => true, :auth_url => 'https://auth.api.rackspacecloud.com/v1.0', :cdn_available? => true)
36
36
  assert_raises(CloudFiles::Exception::Authentication) do
37
37
  result = CloudFiles::Authentication.new(@connection)
38
38
  end
@@ -40,7 +40,7 @@ class CloudfilesAuthenticationTest < Test::Unit::TestCase
40
40
 
41
41
  def test_bad_hostname
42
42
  Net::HTTP.stubs(:new).raises(CloudFiles::Exception::Connection)
43
- @connection = stub(:proxy_host => nil, :proxy_port => nil, :authuser => 'bad_user', :authkey => 'bad_key', :authok= => true, :authtoken= => true, :auth_url => 'https://auth.api.rackspacecloud.com/v1.0')
43
+ @connection = stub(:proxy_host => nil, :proxy_port => nil, :authuser => 'bad_user', :authkey => 'bad_key', :authok= => true, :authtoken= => true, :auth_url => 'https://auth.api.rackspacecloud.com/v1.0', :cdn_available? => true)
44
44
  assert_raises(CloudFiles::Exception::Connection) do
45
45
  result = CloudFiles::Authentication.new(@connection)
46
46
  end
@@ -4,7 +4,7 @@ require 'test_helper'
4
4
  class CloudfilesContainerTest < Test::Unit::TestCase
5
5
 
6
6
  def test_object_creation
7
- connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https')
7
+ connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true)
8
8
  response = {'x-container-bytes-used' => '42', 'x-container-object-count' => '5'}
9
9
  response.stubs(:code).returns('204')
10
10
  connection.stubs(:cfreq => response)
@@ -15,9 +15,20 @@ class CloudfilesContainerTest < Test::Unit::TestCase
15
15
  assert_equal @container.cdn_url, nil
16
16
  assert_equal @container.cdn_ttl, nil
17
17
  end
18
+
19
+ def test_object_creation_with_no_cdn_available
20
+ connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => false)
21
+ response = {'x-container-bytes-used' => '42', 'x-container-object-count' => '5'}
22
+ response.stubs(:code).returns('204')
23
+ connection.stubs(:cfreq => response)
24
+ @container = CloudFiles::Container.new(connection, 'test_container')
25
+ assert_equal 'test_container', @container.name
26
+ assert_equal CloudFiles::Container, @container.class
27
+ assert_equal false, @container.public?
28
+ end
18
29
 
19
30
  def test_object_creation_no_such_container
20
- connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https')
31
+ connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true)
21
32
  response = {'x-container-bytes-used' => '42', 'x-container-object-count' => '5'}
22
33
  response.stubs(:code).returns('999')
23
34
  connection.stubs(:cfreq => response)
@@ -27,7 +38,7 @@ class CloudfilesContainerTest < Test::Unit::TestCase
27
38
  end
28
39
 
29
40
  def test_object_creation_with_cdn
30
- connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https')
41
+ connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true)
31
42
  response = {'x-container-bytes-used' => '42', 'x-container-object-count' => '5', 'x-cdn-enabled' => 'True', 'x-cdn-uri' => 'http://cdn.test.example/container', 'x-ttl' => '86400'}
32
43
  response.stubs(:code).returns('204')
33
44
  connection.stubs(:cfreq => response)
@@ -73,7 +84,7 @@ class CloudfilesContainerTest < Test::Unit::TestCase
73
84
  end
74
85
 
75
86
  def test_empty_is_false
76
- connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https')
87
+ connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true)
77
88
  response = {'x-container-bytes-used' => '42', 'x-container-object-count' => '5'}
78
89
  response.stubs(:code).returns('204')
79
90
  connection.stubs(:cfreq => response)
@@ -82,7 +93,7 @@ class CloudfilesContainerTest < Test::Unit::TestCase
82
93
  end
83
94
 
84
95
  def test_empty_is_true
85
- connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https')
96
+ connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true)
86
97
  response = {'x-container-bytes-used' => '0', 'x-container-object-count' => '0'}
87
98
  response.stubs(:code).returns('204')
88
99
  connection.stubs(:cfreq => response)
@@ -91,7 +102,7 @@ class CloudfilesContainerTest < Test::Unit::TestCase
91
102
  end
92
103
 
93
104
  def test_log_retention_is_true
94
- connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https')
105
+ connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true)
95
106
  response = {'x-container-bytes-used' => '0', 'x-container-object-count' => '0', 'x-cdn-enabled' => 'True', 'x-log-retention' => 'True'}
96
107
  response.stubs(:code).returns('204')
97
108
  connection.stubs(:cfreq => response)
@@ -240,12 +251,20 @@ class CloudfilesContainerTest < Test::Unit::TestCase
240
251
  assert(@container.log_retention='false')
241
252
  end
242
253
 
254
+ def test_purge_from_cdn_succeeds
255
+ build_net_http_object
256
+ assert_nothing_raised do
257
+ @container.purge_from_cdn
258
+ @container.purge_from_cdn("small.fox@hole.org")
259
+ end
260
+ end
261
+
243
262
  private
244
263
 
245
264
  def build_net_http_object(args={:code => '204' }, cfreq_expectations={})
246
265
  CloudFiles::Container.any_instance.stubs(:populate).returns(true)
247
266
  CloudFiles::Container.any_instance.stubs(:metadata).returns({})
248
- connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https')
267
+ connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true)
249
268
  args[:response] = {} unless args[:response]
250
269
  response = {'x-cdn-management-url' => 'http://cdn.example.com/path', 'x-storage-url' => 'http://cdn.example.com/storage', 'authtoken' => 'dummy_token', 'last-modified' => Time.now.to_s}.merge(args[:response])
251
270
  response.stubs(:code).returns(args[:code])
@@ -4,7 +4,19 @@ require 'test_helper'
4
4
  class CloudfilesStorageObjectTest < Test::Unit::TestCase
5
5
 
6
6
  def test_object_creation
7
- connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https')
7
+ connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true)
8
+ response = {'x-container-bytes-used' => '42', 'x-container-object-count' => '5', 'last-modified' => Time.now.to_s}
9
+ response.stubs(:code).returns('204')
10
+ connection.stubs(:cfreq => response)
11
+ container = CloudFiles::Container.new(connection, 'test_container')
12
+ @object = CloudFiles::StorageObject.new(container, 'test_object')
13
+ assert_equal @object.name, 'test_object'
14
+ assert_equal @object.class, CloudFiles::StorageObject
15
+ assert_equal @object.to_s, 'test_object'
16
+ end
17
+
18
+ def test_object_creation_with_no_cdn_available
19
+ connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => false)
8
20
  response = {'x-container-bytes-used' => '42', 'x-container-object-count' => '5', 'last-modified' => Time.now.to_s}
9
21
  response.stubs(:code).returns('204')
10
22
  connection.stubs(:cfreq => response)
@@ -16,7 +28,7 @@ class CloudfilesStorageObjectTest < Test::Unit::TestCase
16
28
  end
17
29
 
18
30
  def test_object_creation_with_invalid_name
19
- connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https')
31
+ connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true)
20
32
  response = {'x-container-bytes-used' => '42', 'x-container-object-count' => '5', 'last-modified' => Time.now.to_s}
21
33
  response.stubs(:code).returns('204')
22
34
  connection.stubs(:cfreq => response)
@@ -108,7 +120,7 @@ class CloudfilesStorageObjectTest < Test::Unit::TestCase
108
120
  end
109
121
 
110
122
  def test_read_metadata_succeeds
111
- connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https')
123
+ connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true)
112
124
  response = {'x-container-bytes-used' => '42', 'x-container-object-count' => '5', 'x-object-meta-foo' => 'Bar', 'last-modified' => Time.now.to_s}
113
125
  response.stubs(:code).returns('204')
114
126
  connection.stubs(:cfreq => response)
@@ -127,7 +139,7 @@ class CloudfilesStorageObjectTest < Test::Unit::TestCase
127
139
  end
128
140
 
129
141
  def test_write_with_make_path
130
- connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https')
142
+ connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true)
131
143
  response = {'x-container-bytes-used' => '42', 'x-container-object-count' => '5', 'last-modified' => Time.now.to_s}
132
144
  response.stubs(:code).returns('204').then.returns('204').then.returns('201').then.returns('204')
133
145
  connection.stubs(:cfreq => response)
@@ -161,6 +173,14 @@ class CloudfilesStorageObjectTest < Test::Unit::TestCase
161
173
  end
162
174
  end
163
175
 
176
+ def test_purge_from_cdn_succeeds
177
+ build_net_http_object
178
+ assert_nothing_raised do
179
+ @object.purge_from_cdn
180
+ @object.purge_from_cdn("small.fox@hole.org")
181
+ end
182
+ end
183
+
164
184
  def test_write_with_no_data_dies
165
185
  build_net_http_object
166
186
  assert_raise(CloudFiles::Exception::Syntax) do
@@ -194,7 +214,7 @@ class CloudfilesStorageObjectTest < Test::Unit::TestCase
194
214
  def build_net_http_object(args={:code => '204' })
195
215
  CloudFiles::Container.any_instance.stubs(:metadata).returns({})
196
216
  CloudFiles::Container.any_instance.stubs(:populate).returns(true)
197
- connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https')
217
+ connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true)
198
218
  args[:response] = {} unless args[:response]
199
219
  response = {'x-cdn-management-url' => 'http://cdn.example.com/path', 'x-storage-url' => 'http://cdn.example.com/storage', 'authtoken' => 'dummy_token', 'last-modified' => Time.now.to_s}.merge(args[:response])
200
220
  response.stubs(:code).returns(args[:code])
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudfiles
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 39
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 4
9
- - 15
10
- version: 1.4.15
9
+ - 16
10
+ version: 1.4.16
11
11
  platform: ruby
12
12
  authors:
13
13
  - H. Wade Minter
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-03-10 00:00:00 -05:00
19
+ date: 2011-03-17 00:00:00 -04:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency