fog 0.3.16 → 0.3.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. data/Gemfile.lock +1 -1
  2. data/README.rdoc +17 -12
  3. data/fog.gemspec +10 -5
  4. data/lib/fog.rb +1 -1
  5. data/lib/fog/aws/models/storage/directory.rb +22 -0
  6. data/lib/fog/aws/models/storage/file.rb +15 -0
  7. data/lib/fog/aws/storage.rb +8 -0
  8. data/lib/fog/core/collection.rb +9 -8
  9. data/lib/fog/core/compute.rb +1 -1
  10. data/lib/fog/google/models/storage/directory.rb +23 -1
  11. data/lib/fog/google/models/storage/file.rb +16 -1
  12. data/lib/fog/google/parsers/storage/access_control_list.rb +16 -14
  13. data/lib/fog/local/models/storage/directory.rb +8 -0
  14. data/lib/fog/local/models/storage/file.rb +4 -0
  15. data/lib/fog/rackspace/cdn.rb +3 -3
  16. data/lib/fog/rackspace/models/storage/directory.rb +18 -0
  17. data/lib/fog/rackspace/models/storage/file.rb +7 -0
  18. data/lib/fog/rackspace/requests/cdn/{get_cdn_containers.rb → get_containers.rb} +3 -3
  19. data/lib/fog/rackspace/requests/cdn/{head_cdn_container.rb → head_container.rb} +3 -3
  20. data/lib/fog/rackspace/requests/cdn/{put_cdn_container.rb → put_container.rb} +3 -3
  21. data/lib/fog/rackspace/storage.rb +10 -0
  22. data/lib/fog/vcloud.rb +32 -153
  23. data/lib/fog/vcloud/collection.rb +18 -0
  24. data/lib/fog/vcloud/mock_data_classes.rb +701 -0
  25. data/lib/fog/vcloud/requests/get_network.rb +8 -8
  26. data/lib/fog/vcloud/requests/get_organization.rb +10 -10
  27. data/lib/fog/vcloud/requests/get_vdc.rb +18 -18
  28. data/lib/fog/vcloud/requests/get_versions.rb +3 -3
  29. data/lib/fog/vcloud/requests/login.rb +2 -2
  30. data/lib/fog/vcloud/terremark/ecloud.rb +65 -109
  31. data/lib/fog/vcloud/terremark/ecloud/models/catalog.rb +1 -0
  32. data/lib/fog/vcloud/terremark/ecloud/models/firewall_acls.rb +1 -0
  33. data/lib/fog/vcloud/terremark/ecloud/models/internet_services.rb +1 -0
  34. data/lib/fog/vcloud/terremark/ecloud/models/ip.rb +1 -1
  35. data/lib/fog/vcloud/terremark/ecloud/models/ips.rb +1 -0
  36. data/lib/fog/vcloud/terremark/ecloud/models/network.rb +3 -2
  37. data/lib/fog/vcloud/terremark/ecloud/models/networks.rb +1 -0
  38. data/lib/fog/vcloud/terremark/ecloud/models/nodes.rb +1 -0
  39. data/lib/fog/vcloud/terremark/ecloud/models/public_ips.rb +1 -0
  40. data/lib/fog/vcloud/terremark/ecloud/models/server.rb +20 -8
  41. data/lib/fog/vcloud/terremark/ecloud/models/servers.rb +1 -0
  42. data/lib/fog/vcloud/terremark/ecloud/models/tasks.rb +1 -0
  43. data/lib/fog/vcloud/terremark/ecloud/models/vdcs.rb +2 -0
  44. data/lib/fog/vcloud/terremark/ecloud/requests/add_internet_service.rb +4 -8
  45. data/lib/fog/vcloud/terremark/ecloud/requests/add_node.rb +4 -7
  46. data/lib/fog/vcloud/terremark/ecloud/requests/configure_internet_service.rb +18 -20
  47. data/lib/fog/vcloud/terremark/ecloud/requests/configure_node.rb +6 -7
  48. data/lib/fog/vcloud/terremark/ecloud/requests/configure_vapp.rb +40 -9
  49. data/lib/fog/vcloud/terremark/ecloud/requests/delete_internet_service.rb +2 -10
  50. data/lib/fog/vcloud/terremark/ecloud/requests/delete_node.rb +2 -6
  51. data/lib/fog/vcloud/terremark/ecloud/requests/delete_vapp.rb +13 -1
  52. data/lib/fog/vcloud/terremark/ecloud/requests/get_catalog.rb +6 -6
  53. data/lib/fog/vcloud/terremark/ecloud/requests/get_catalog_item.rb +6 -7
  54. data/lib/fog/vcloud/terremark/ecloud/requests/get_internet_services.rb +34 -33
  55. data/lib/fog/vcloud/terremark/ecloud/requests/get_network.rb +23 -24
  56. data/lib/fog/vcloud/terremark/ecloud/requests/get_network_extensions.rb +10 -13
  57. data/lib/fog/vcloud/terremark/ecloud/requests/get_network_ip.rb +15 -19
  58. data/lib/fog/vcloud/terremark/ecloud/requests/get_network_ips.rb +20 -22
  59. data/lib/fog/vcloud/terremark/ecloud/requests/get_node.rb +12 -15
  60. data/lib/fog/vcloud/terremark/ecloud/requests/get_nodes.rb +11 -12
  61. data/lib/fog/vcloud/terremark/ecloud/requests/get_public_ip.rb +5 -4
  62. data/lib/fog/vcloud/terremark/ecloud/requests/get_public_ips.rb +9 -8
  63. data/lib/fog/vcloud/terremark/ecloud/requests/get_vapp.rb +33 -17
  64. data/lib/fog/vcloud/terremark/ecloud/requests/get_vdc.rb +54 -53
  65. data/lib/fog/vcloud/terremark/ecloud/requests/instantiate_vapp_template.rb +13 -19
  66. data/lib/fog/vcloud/terremark/ecloud/requests/power_off.rb +9 -2
  67. data/lib/fog/vcloud/terremark/ecloud/requests/power_on.rb +2 -4
  68. data/spec/vcloud/bin_spec.rb +3 -6
  69. data/spec/vcloud/models/vdc_spec.rb +8 -8
  70. data/spec/vcloud/requests/get_network_spec.rb +8 -8
  71. data/spec/vcloud/requests/get_organization_spec.rb +9 -9
  72. data/spec/vcloud/requests/get_vdc_spec.rb +7 -7
  73. data/spec/vcloud/requests/get_versions_spec.rb +1 -1
  74. data/spec/vcloud/requests/login_spec.rb +2 -2
  75. data/spec/vcloud/spec_helper.rb +45 -30
  76. data/spec/vcloud/terremark/ecloud/models/internet_service_spec.rb +10 -14
  77. data/spec/vcloud/terremark/ecloud/models/ip_spec.rb +5 -8
  78. data/spec/vcloud/terremark/ecloud/models/ips_spec.rb +2 -2
  79. data/spec/vcloud/terremark/ecloud/models/network_spec.rb +15 -16
  80. data/spec/vcloud/terremark/ecloud/models/node_spec.rb +7 -7
  81. data/spec/vcloud/terremark/ecloud/models/nodes_spec.rb +1 -1
  82. data/spec/vcloud/terremark/ecloud/models/public_ip_spec.rb +4 -8
  83. data/spec/vcloud/terremark/ecloud/models/server_spec.rb +42 -0
  84. data/spec/vcloud/terremark/ecloud/models/vdc_spec.rb +7 -7
  85. data/spec/vcloud/terremark/ecloud/models/vdcs_spec.rb +1 -1
  86. data/spec/vcloud/terremark/ecloud/requests/add_internet_service_spec.rb +13 -18
  87. data/spec/vcloud/terremark/ecloud/requests/add_node_spec.rb +9 -5
  88. data/spec/vcloud/terremark/ecloud/requests/configure_internet_service_spec.rb +5 -7
  89. data/spec/vcloud/terremark/ecloud/requests/configure_node_spec.rb +22 -28
  90. data/spec/vcloud/terremark/ecloud/requests/configure_vapp_spec.rb +71 -0
  91. data/spec/vcloud/terremark/ecloud/requests/delete_internet_service_spec.rb +7 -9
  92. data/spec/vcloud/terremark/ecloud/requests/delete_node_spec.rb +3 -7
  93. data/spec/vcloud/terremark/ecloud/requests/delete_vapp_spec.rb +83 -0
  94. data/spec/vcloud/terremark/ecloud/requests/get_catalog_item_spec.rb +6 -5
  95. data/spec/vcloud/terremark/ecloud/requests/get_catalog_spec.rb +2 -2
  96. data/spec/vcloud/terremark/ecloud/requests/get_internet_services_spec.rb +31 -42
  97. data/spec/vcloud/terremark/ecloud/requests/get_network_ip_spec.rb +4 -7
  98. data/spec/vcloud/terremark/ecloud/requests/get_network_ips_spec.rb +1 -1
  99. data/spec/vcloud/terremark/ecloud/requests/get_network_spec.rb +19 -11
  100. data/spec/vcloud/terremark/ecloud/requests/get_node_spec.rb +8 -8
  101. data/spec/vcloud/terremark/ecloud/requests/get_nodes_spec.rb +11 -11
  102. data/spec/vcloud/terremark/ecloud/requests/get_public_ip_spec.rb +4 -5
  103. data/spec/vcloud/terremark/ecloud/requests/get_public_ips_spec.rb +6 -6
  104. data/spec/vcloud/terremark/ecloud/requests/get_vapp_spec.rb +36 -19
  105. data/spec/vcloud/terremark/ecloud/requests/get_vdc_spec.rb +21 -18
  106. data/spec/vcloud/terremark/ecloud/requests/instantiate_vapp_template_spec.rb +27 -17
  107. data/spec/vcloud/terremark/ecloud/requests/power_off_spec.rb +34 -0
  108. data/spec/vcloud/terremark/ecloud/requests/power_on_spec.rb +3 -4
  109. data/spec/vcloud/vcloud_spec.rb +2 -2
  110. data/tests/helpers/storage/directory_tests.rb +8 -0
  111. data/tests/helpers/storage/file_tests.rb +4 -0
  112. metadata +11 -6
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fog (0.3.16)
4
+ fog (0.3.17)
5
5
  builder
6
6
  excon (>= 0.2.4)
7
7
  formatador (>= 0.0.15)
@@ -3,6 +3,7 @@ http://geemus.s3.amazonaws.com/fog.png
3
3
  fog is the Ruby cloud computing library.
4
4
 
5
5
  The quick and dirty, top to bottom:
6
+
6
7
  * Collections provide a simplified interface, making clouds easier to work with and switch between.
7
8
  * Requests allow power users to get the most out of the features of each individual cloud.
8
9
  * Mocks make testing and integrating a breeze.
@@ -25,16 +26,18 @@ Now just type 'fog' to trying stuff out, confident that fog should let you know
25
26
  == Collections
26
27
 
27
28
  A high level interface to each cloud is provided through collections, such as images and servers.
28
- You can see a list of available collections by calling #collections on the connection object.
29
- Some of these collections are shared across multiple providers.
30
- Shared collections for compute are: flavors, images and servers.
31
- Shared collections for storage are: directory and file.
29
+ You can see a list of available collections by calling #collections on the connection object. You can try it out using the `fog` command:
30
+
31
+ >> server = AWS.collections
32
+ [:addresses, :directories, :files, :flavors, :images, :key_pairs, :security_groups, :servers, :snapshots, :volumes]
32
33
 
33
- Some common methods for all of these collections are:
34
- * #all - fetch every object of that type from the provider.
35
- * #create initialize a new record locally and then persists it with the provider.
36
- * #get - fetch a single object by its identity from the provider.
37
- * #new - initialize a new record locally, but do not persist it to the provider.
34
+ Some of these collections are available across multiple providers. For example, all compute providers have +flavors+, +images+ and +servers+, and storage providers have +directory+ and +file+.
35
+
36
+ Collections share most of the basic CRUD type operations, such as:
37
+ * +#all+ - fetch every object of that type from the provider.
38
+ * +#create+ initialize a new record locally and then persists it with the provider.
39
+ * +#get+ - fetch a single object by its identity from the provider.
40
+ * +#new+ - initialize a new record locally, but do not persist it to the provider.
38
41
 
39
42
  As an example, we'll try initializing and persisting a Rackspace Cloud server:
40
43
 
@@ -60,12 +63,14 @@ As an example, we'll try initializing and persisting a Rackspace Cloud server:
60
63
  == Models
61
64
 
62
65
  Many of the collection methods return individual objects, which also provide some common methods:
63
- * #destroy - will destroy the persisted object from the provider
64
- * #save - persist the object to the provider
65
- * #wait_for - takes a block and waits for either the block to return true for the object or for a timeout (defaults to 10 minutes)
66
+ * +#destroy+ - will destroy the persisted object from the provider
67
+ * +#save+ - persist the object to the provider
68
+ * +#wait_for+ - takes a block and waits for either the block to return true for the object or for a timeout (defaults to 10 minutes)
66
69
 
67
70
  == Mocks
68
71
 
72
+ As you might imagine, testing code using Fog could be feasibly slow and expensive to constantly be turning and and shutting down instances. Fortunately, fog includes support for mocking itself out.
73
+
69
74
  Mocking provides an in memory representation of the state of cloud resources as you make requests.
70
75
  Mocked calls to mimic the behavior of each provider while eliminating the cost and time needed to actually use cloud resources.
71
76
  Enabling mocking easy to use, before you run any other commands run:
@@ -7,8 +7,8 @@ Gem::Specification.new do |s|
7
7
  ## If your rubyforge_project name is different, then edit it and comment out
8
8
  ## the sub! line in the Rakefile
9
9
  s.name = 'fog'
10
- s.version = '0.3.16'
11
- s.date = '2010-11-04'
10
+ s.version = '0.3.17'
11
+ s.date = '2010-11-05'
12
12
  s.rubyforge_project = 'fog'
13
13
 
14
14
  ## Make sure your summary is short. The description may be as long
@@ -374,9 +374,9 @@ Gem::Specification.new do |s|
374
374
  lib/fog/rackspace/models/storage/directory.rb
375
375
  lib/fog/rackspace/models/storage/file.rb
376
376
  lib/fog/rackspace/models/storage/files.rb
377
- lib/fog/rackspace/requests/cdn/get_cdn_containers.rb
378
- lib/fog/rackspace/requests/cdn/head_cdn_container.rb
379
- lib/fog/rackspace/requests/cdn/put_cdn_container.rb
377
+ lib/fog/rackspace/requests/cdn/get_containers.rb
378
+ lib/fog/rackspace/requests/cdn/head_container.rb
379
+ lib/fog/rackspace/requests/cdn/put_container.rb
380
380
  lib/fog/rackspace/requests/compute/create_image.rb
381
381
  lib/fog/rackspace/requests/compute/create_server.rb
382
382
  lib/fog/rackspace/requests/compute/delete_image.rb
@@ -500,6 +500,7 @@ Gem::Specification.new do |s|
500
500
  lib/fog/vcloud/bin.rb
501
501
  lib/fog/vcloud/collection.rb
502
502
  lib/fog/vcloud/generators.rb
503
+ lib/fog/vcloud/mock_data_classes.rb
503
504
  lib/fog/vcloud/model.rb
504
505
  lib/fog/vcloud/models/vdc.rb
505
506
  lib/fog/vcloud/models/vdcs.rb
@@ -631,14 +632,17 @@ Gem::Specification.new do |s|
631
632
  spec/vcloud/terremark/ecloud/models/nodes_spec.rb
632
633
  spec/vcloud/terremark/ecloud/models/public_ip_spec.rb
633
634
  spec/vcloud/terremark/ecloud/models/public_ips_spec.rb
635
+ spec/vcloud/terremark/ecloud/models/server_spec.rb
634
636
  spec/vcloud/terremark/ecloud/models/vdc_spec.rb
635
637
  spec/vcloud/terremark/ecloud/models/vdcs_spec.rb
636
638
  spec/vcloud/terremark/ecloud/requests/add_internet_service_spec.rb
637
639
  spec/vcloud/terremark/ecloud/requests/add_node_spec.rb
638
640
  spec/vcloud/terremark/ecloud/requests/configure_internet_service_spec.rb
639
641
  spec/vcloud/terremark/ecloud/requests/configure_node_spec.rb
642
+ spec/vcloud/terremark/ecloud/requests/configure_vapp_spec.rb
640
643
  spec/vcloud/terremark/ecloud/requests/delete_internet_service_spec.rb
641
644
  spec/vcloud/terremark/ecloud/requests/delete_node_spec.rb
645
+ spec/vcloud/terremark/ecloud/requests/delete_vapp_spec.rb
642
646
  spec/vcloud/terremark/ecloud/requests/get_catalog_item_spec.rb
643
647
  spec/vcloud/terremark/ecloud/requests/get_catalog_spec.rb
644
648
  spec/vcloud/terremark/ecloud/requests/get_customization_options_spec.rb
@@ -654,6 +658,7 @@ Gem::Specification.new do |s|
654
658
  spec/vcloud/terremark/ecloud/requests/get_vdc_spec.rb
655
659
  spec/vcloud/terremark/ecloud/requests/instantiate_vapp_template_spec.rb
656
660
  spec/vcloud/terremark/ecloud/requests/login_spec.rb
661
+ spec/vcloud/terremark/ecloud/requests/power_off_spec.rb
657
662
  spec/vcloud/terremark/ecloud/requests/power_on_spec.rb
658
663
  spec/vcloud/vcloud_spec.rb
659
664
  tests/aws/helper.rb
data/lib/fog.rb CHANGED
@@ -18,7 +18,7 @@ module Fog
18
18
  @mocking = false
19
19
 
20
20
  unless const_defined?(:VERSION)
21
- VERSION = '0.3.16'
21
+ VERSION = '0.3.17'
22
22
  end
23
23
 
24
24
  module Mock
@@ -61,6 +61,28 @@ module Fog
61
61
  @payer = new_payer
62
62
  end
63
63
 
64
+ def public=(new_public)
65
+ if new_public
66
+ @acl = 'public-read'
67
+ else
68
+ @acl = 'private'
69
+ end
70
+ new_public
71
+ end
72
+
73
+ def public_url
74
+ requires :key
75
+ if connection.get_bucket_acl(key).body['AccessControlList'].detect {|grant| grant['Grantee']['URI'] == 'http://acs.amazonaws.com/groups/global/AllUsers' && grant['Permission'] == 'READ'}
76
+ if key.to_s =~ /^(?:[a-z]|\d(?!\d{0,2}(?:\.\d{1,3}){3}$))(?:[a-z0-9]|\.(?![\.\-])|\-(?![\.])){1,61}[a-z0-9]$/
77
+ "https://#{key}.s3.amazonaws.com"
78
+ else
79
+ "https://s3.amazonaws.com/#{key}"
80
+ end
81
+ else
82
+ nil
83
+ end
84
+ end
85
+
64
86
  def save
65
87
  requires :key
66
88
  options = {}
@@ -60,6 +60,21 @@ module Fog
60
60
  end
61
61
  end
62
62
 
63
+ def public_url
64
+ requires :directory, :key
65
+ if directory.public_url
66
+ "#{directory.public_url}/#{key}"
67
+ elsif connection.get_object_acl(directory.key, key).body['AccessControlList'].detect {|grant| grant['Grantee']['URI'] == 'http://acs.amazonaws.com/groups/global/AllUsers' && grant['Permission'] == 'READ'}
68
+ if directory.key.to_s =~ /^(?:[a-z]|\d(?!\d{0,2}(?:\.\d{1,3}){3}$))(?:[a-z0-9]|\.(?![\.\-])|\-(?![\.])){1,61}[a-z0-9]$/
69
+ "https://#{directory.key}.s3.amazonaws.com/#{key}"
70
+ else
71
+ "https://s3.amazonaws.com/#{directory.key}/#{key}"
72
+ end
73
+ else
74
+ nil
75
+ end
76
+ end
77
+
63
78
  def save(options = {})
64
79
  requires :body, :directory, :key
65
80
  if options != {}
@@ -38,6 +38,13 @@ module Fog
38
38
 
39
39
  module Utils
40
40
 
41
+ def cdn
42
+ @cdn ||= Fog::AWS::CDN.new(
43
+ :aws_access_key_id => @aws_access_key_id,
44
+ :aws_secret_access_key => @aws_secret_access_key
45
+ )
46
+ end
47
+
41
48
  def parse_data(data)
42
49
  metadata = {
43
50
  :body => nil,
@@ -93,6 +100,7 @@ module Fog
93
100
  def initialize(options={})
94
101
  require 'mime/types'
95
102
  @aws_access_key_id = options[:aws_access_key_id]
103
+ @aws_secret_access_key = options[:aws_secret_access_key]
96
104
  options[:region] ||= 'us-east-1'
97
105
  @host = options[:host] || case options[:region]
98
106
  when 'eu-west-1'
@@ -5,19 +5,20 @@ module Fog
5
5
  include Fog::Attributes::InstanceMethods
6
6
 
7
7
  Array.public_instance_methods(false).each do |method|
8
- class_eval <<-RUBY
9
- def #{method}(*args)
10
- unless @loaded
11
- lazy_load
8
+ unless [:reject, :select].include?(method.to_sym)
9
+ class_eval <<-RUBY
10
+ def #{method}(*args)
11
+ unless @loaded
12
+ lazy_load
13
+ end
14
+ super
12
15
  end
13
- super
14
- end
15
- RUBY
16
+ RUBY
17
+ end
16
18
  end
17
19
 
18
20
  %w[reject select].each do |method|
19
21
  class_eval <<-RUBY
20
- # remove_method :#{method}
21
22
  def #{method}(*args)
22
23
  unless @loaded
23
24
  lazy_load
@@ -2,7 +2,7 @@ module Fog
2
2
  class Storage
3
3
 
4
4
  def self.new(attributes)
5
- case attributes.delete(:provider)
5
+ case provider = attributes.delete(:provider)
6
6
  when 'AWS'
7
7
  require 'fog/aws'
8
8
  Fog::AWS::Compute.new(attributes)
@@ -39,11 +39,33 @@ module Fog
39
39
  end
40
40
  end
41
41
 
42
+ def public=(new_public)
43
+ if new_public
44
+ @acl = 'public-read'
45
+ else
46
+ @acl = 'private'
47
+ end
48
+ new_public
49
+ end
50
+
51
+ def public_url
52
+ requires :key
53
+ if connection.get_bucket_acl(key).body['AccessControlList'].detect {|entry| entry['Scope']['type'] == 'AllUsers' && entry['Permission'] == 'READ'}
54
+ if key.to_s =~ /^(?:[a-z]|\d(?!\d{0,2}(?:\.\d{1,3}){3}$))(?:[a-z0-9]|\.(?![\.\-])|\-(?![\.])){1,61}[a-z0-9]$/
55
+ "https://#{key}.commondatastorage.googleapis.com"
56
+ else
57
+ "https://commondatastorage.googleapis.com/#{key}"
58
+ end
59
+ else
60
+ nil
61
+ end
62
+ end
63
+
42
64
  def save
43
65
  requires :key
44
66
  options = {}
45
67
  if @acl
46
- options['x-amz-acl'] = @acl
68
+ options['x-goog-acl'] = @acl
47
69
  end
48
70
  if @location
49
71
  options['LocationConstraint'] = @location
@@ -63,13 +63,28 @@ module Fog
63
63
  end
64
64
  end
65
65
 
66
+ def public_url
67
+ requires :directory, :key
68
+ if directory.public_url
69
+ "#{directory.public_url}/#{key}"
70
+ elsif connection.get_object_acl(directory.key, key).body['AccessControlList'].detect {|entry| entry['Scope']['type'] == 'AllUsers' && entry['Permission'] == 'READ'}
71
+ if directory.key.to_s =~ /^(?:[a-z]|\d(?!\d{0,2}(?:\.\d{1,3}){3}$))(?:[a-z0-9]|\.(?![\.\-])|\-(?![\.])){1,61}[a-z0-9]$/
72
+ "https://#{directory.key}.commondatastorage.googleapis/#{key}"
73
+ else
74
+ "https://commondatastorage.googleapis.com/#{directory.key}/#{key}"
75
+ end
76
+ else
77
+ nil
78
+ end
79
+ end
80
+
66
81
  def save(options = {})
67
82
  requires :body, :directory, :key
68
83
  if options != {}
69
84
  Formatador.display_line("[yellow][WARN] options param is deprecated, use acl= instead[/] [light_black](#{caller.first})[/]")
70
85
  end
71
86
  if @acl
72
- options['x-amz-acl'] ||= @acl
87
+ options['x-goog-acl'] ||= @acl
73
88
  end
74
89
  if content_type
75
90
  options['Content-Type'] = content_type
@@ -6,35 +6,37 @@ module Fog
6
6
  class AccessControlList < Fog::Parsers::Base
7
7
 
8
8
  def reset
9
- @in_access_control_list = false
10
- @grant = { 'Grantee' => {} }
9
+ @in_entries = false
10
+ @entry = { 'Scope' => {} }
11
11
  @response = { 'Owner' => {}, 'AccessControlList' => [] }
12
12
  end
13
13
 
14
14
  def start_element(name, attrs = [])
15
15
  super
16
- if name == 'AccessControlList'
17
- @in_access_control_list = true
16
+ case name
17
+ when 'Entries'
18
+ @in_entries = true
19
+ when 'Scope'
20
+ key, value = attrs
21
+ @entry['Scope'][key] = value
18
22
  end
19
23
  end
20
24
 
21
25
  def end_element(name)
22
26
  case name
23
- when 'AccessControlList'
24
- @in_access_control_list = false
25
- when 'Grant'
26
- @response['AccessControlList'] << @grant
27
- @grant = { 'Grantee' => {} }
27
+ when 'Entries'
28
+ @in_entries = false
29
+ when 'Entry'
30
+ @response['AccessControlList'] << @entry
31
+ @entry = { 'Scope' => {} }
28
32
  when 'DisplayName', 'ID'
29
- if @in_access_control_list
30
- @grant['Grantee'][name] = @value
33
+ if @in_entries
34
+ @entry['Scope'][name] = @value
31
35
  else
32
36
  @response['Owner'][name] = @value
33
37
  end
34
38
  when 'Permission'
35
- @grant[name] = @value
36
- when 'URI'
37
- @grant['Grantee'][name] = @value
39
+ @entry[name] = @value
38
40
  end
39
41
  end
40
42
 
@@ -32,6 +32,14 @@ module Fog
32
32
  end
33
33
  end
34
34
 
35
+ def public=(new_public)
36
+ new_public
37
+ end
38
+
39
+ def public_url
40
+ nil
41
+ end
42
+
35
43
  def save
36
44
  requires :key
37
45
 
@@ -31,6 +31,10 @@ module Fog
31
31
  true
32
32
  end
33
33
 
34
+ def public_url
35
+ nil
36
+ end
37
+
34
38
  def save(options = {})
35
39
  requires :body, :directory, :key
36
40
  file = ::File.new(path, 'w')
@@ -7,9 +7,9 @@ module Fog
7
7
  model_path 'fog/rackspace/models/cdn'
8
8
 
9
9
  request_path 'fog/rackspace/requests/cdn'
10
- request :get_cdn_containers
11
- request :head_cdn_container
12
- request :put_cdn_container
10
+ request :get_containers
11
+ request :head_container
12
+ request :put_container
13
13
 
14
14
  class Mock
15
15
 
@@ -32,9 +32,27 @@ module Fog
32
32
  end
33
33
  end
34
34
 
35
+ def public=(new_public)
36
+ @public = new_public
37
+ end
38
+
39
+ def public_url
40
+ requires :key
41
+ @public_url ||= begin
42
+ begin response = connection.cdn.head_container(key)
43
+ response.headers['X-CDN-URI']
44
+ rescue Fog::Service::NotFound
45
+ nil
46
+ end
47
+ end
48
+ end
49
+
35
50
  def save
36
51
  requires :key
37
52
  connection.put_container(key)
53
+ if @public
54
+ @public_url = connection.cdn.put_container(key).headers['X-CDN-URI']
55
+ end
38
56
  true
39
57
  end
40
58
 
@@ -41,6 +41,13 @@ module Fog
41
41
  end
42
42
  end
43
43
 
44
+ def public_url
45
+ requires :directory, :key
46
+ if @directory.public_url
47
+ "#{@directory.public_url}/#{key}"
48
+ end
49
+ end
50
+
44
51
  def save(options = {})
45
52
  requires :body, :directory, :key
46
53
  data = connection.put_object(directory.key, @key, @body, options)
@@ -1,6 +1,6 @@
1
1
  module Fog
2
2
  module Rackspace
3
- class Storage
3
+ class CDN
4
4
  class Real
5
5
 
6
6
  # List existing cdn-enabled storage containers
@@ -15,7 +15,7 @@ module Fog
15
15
  # * response<~Excon::Response>:
16
16
  # * body<~Array>:
17
17
  # * container<~String>: Name of container
18
- def get_cdn_containers(options = {})
18
+ def get_containers(options = {})
19
19
  response = request(
20
20
  :expects => [200, 204],
21
21
  :method => 'GET',
@@ -29,7 +29,7 @@ module Fog
29
29
 
30
30
  class Mock
31
31
 
32
- def get_cdn_containers(options = {})
32
+ def get_containers(options = {})
33
33
  Fog::Mock.not_implemented
34
34
  end
35
35