fog 1.12.1 → 1.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (194) hide show
  1. data/.travis.yml +1 -1
  2. data/Gemfile +5 -0
  3. data/Rakefile +14 -4
  4. data/bin/fog +22 -0
  5. data/changelog.txt +262 -0
  6. data/fog.gemspec +8 -4
  7. data/lib/fog/aws.rb +11 -0
  8. data/lib/fog/aws/auto_scaling.rb +15 -18
  9. data/lib/fog/aws/beanstalk.rb +8 -10
  10. data/lib/fog/aws/cloud_formation.rb +9 -12
  11. data/lib/fog/aws/compute.rb +8 -10
  12. data/lib/fog/aws/credential_fetcher.rb +6 -6
  13. data/lib/fog/aws/elasticache.rb +13 -17
  14. data/lib/fog/aws/elb.rb +29 -31
  15. data/lib/fog/aws/iam.rb +10 -13
  16. data/lib/fog/aws/models/auto_scaling/group.rb +6 -3
  17. data/lib/fog/aws/models/compute/spot_request.rb +1 -11
  18. data/lib/fog/aws/models/rds/log_file.rb +26 -0
  19. data/lib/fog/aws/models/rds/log_files.rb +50 -0
  20. data/lib/fog/aws/models/rds/server.rb +3 -1
  21. data/lib/fog/aws/models/rds/snapshot.rb +1 -0
  22. data/lib/fog/aws/models/rds/snapshots.rb +20 -13
  23. data/lib/fog/aws/parsers/rds/db_parser.rb +1 -1
  24. data/lib/fog/aws/parsers/rds/describe_db_log_files.rb +44 -0
  25. data/lib/fog/aws/parsers/rds/download_db_logfile_portion.rb +26 -0
  26. data/lib/fog/aws/parsers/ses/verify_domain_identity.rb +26 -0
  27. data/lib/fog/aws/parsers/storage/complete_multipart_upload.rb +1 -1
  28. data/lib/fog/aws/parsers/sts/assume_role.rb +30 -0
  29. data/lib/fog/aws/rds.rb +27 -14
  30. data/lib/fog/aws/requests/auto_scaling/create_auto_scaling_group.rb +8 -0
  31. data/lib/fog/aws/requests/auto_scaling/update_auto_scaling_group.rb +8 -1
  32. data/lib/fog/aws/requests/compute/create_volume.rb +3 -3
  33. data/lib/fog/aws/requests/rds/create_db_instance.rb +3 -1
  34. data/lib/fog/aws/requests/rds/describe_db_log_files.rb +67 -0
  35. data/lib/fog/aws/requests/rds/download_db_logfile_portion.rb +63 -0
  36. data/lib/fog/aws/requests/ses/send_raw_email.rb +1 -1
  37. data/lib/fog/aws/requests/ses/verify_domain_identity.rb +30 -0
  38. data/lib/fog/aws/requests/storage/complete_multipart_upload.rb +6 -2
  39. data/lib/fog/aws/requests/storage/get_object.rb +1 -1
  40. data/lib/fog/aws/requests/sts/assume_role.rb +46 -0
  41. data/lib/fog/aws/ses.rb +26 -9
  42. data/lib/fog/aws/storage.rb +2 -1
  43. data/lib/fog/aws/sts.rb +31 -21
  44. data/lib/fog/bin.rb +0 -1
  45. data/lib/fog/bin/openstack.rb +5 -0
  46. data/lib/fog/brightbox/compute.rb +20 -212
  47. data/lib/fog/brightbox/compute/shared.rb +232 -0
  48. data/lib/fog/brightbox/models/compute/collaboration.rb +43 -0
  49. data/lib/fog/brightbox/models/compute/collaborations.rb +23 -0
  50. data/lib/fog/brightbox/models/compute/user_collaboration.rb +29 -0
  51. data/lib/fog/brightbox/models/compute/user_collaborations.rb +23 -0
  52. data/lib/fog/brightbox/requests/compute/accept_user_collaboration.rb +21 -0
  53. data/lib/fog/brightbox/requests/compute/create_collaboration.rb +23 -0
  54. data/lib/fog/brightbox/requests/compute/delete_collaboration.rb +28 -0
  55. data/lib/fog/brightbox/requests/compute/delete_user_collaboration.rb +28 -0
  56. data/lib/fog/brightbox/requests/compute/destroy_user_collaboration.rb +21 -0
  57. data/lib/fog/brightbox/requests/compute/get_collaboration.rb +21 -0
  58. data/lib/fog/brightbox/requests/compute/get_user_collaboration.rb +21 -0
  59. data/lib/fog/brightbox/requests/compute/list_collaborations.rb +19 -0
  60. data/lib/fog/brightbox/requests/compute/list_user_collaborations.rb +19 -0
  61. data/lib/fog/brightbox/requests/compute/reject_user_collaboration.rb +21 -0
  62. data/lib/fog/brightbox/requests/compute/resend_collaboration.rb +21 -0
  63. data/lib/fog/cloudsigma/docs/getting_started.md +59 -0
  64. data/lib/fog/core.rb +7 -2
  65. data/lib/fog/core/connection.rb +62 -29
  66. data/lib/fog/core/deprecated/connection.rb +24 -0
  67. data/lib/fog/core/parser.rb +1 -1
  68. data/lib/fog/digitalocean/examples/getting_started.md +1 -1
  69. data/lib/fog/digitalocean/models/compute/server.rb +2 -2
  70. data/lib/fog/google/compute.rb +31 -7
  71. data/lib/fog/google/models/compute/disk.rb +80 -0
  72. data/lib/fog/google/models/compute/disks.rb +28 -0
  73. data/lib/fog/google/models/compute/image.rb +36 -0
  74. data/lib/fog/google/models/compute/server.rb +46 -33
  75. data/lib/fog/google/models/compute/servers.rb +15 -8
  76. data/lib/fog/google/requests/compute/delete_server.rb +5 -2
  77. data/lib/fog/google/requests/compute/get_disk.rb +3 -0
  78. data/lib/fog/google/requests/compute/get_server.rb +7 -1
  79. data/lib/fog/google/requests/compute/insert_disk.rb +8 -2
  80. data/lib/fog/google/requests/compute/insert_server.rb +51 -22
  81. data/lib/fog/google/requests/compute/list_machine_types.rb +3 -2
  82. data/lib/fog/google/requests/storage/get_object.rb +1 -1
  83. data/lib/fog/hp/requests/storage/get_object.rb +1 -1
  84. data/lib/fog/hp/storage.rb +26 -9
  85. data/lib/fog/ibm/requests/compute/create_instance.rb +20 -15
  86. data/lib/fog/internet_archive/requests/storage/get_object.rb +1 -1
  87. data/lib/fog/{core/json.rb → json.rb} +13 -2
  88. data/lib/fog/metering.rb +25 -0
  89. data/lib/fog/openstack.rb +1 -0
  90. data/lib/fog/openstack/metering.rb +215 -0
  91. data/lib/fog/openstack/models/compute/flavors.rb +2 -2
  92. data/lib/fog/openstack/models/compute/metadata.rb +1 -1
  93. data/lib/fog/openstack/models/compute/server.rb +5 -2
  94. data/lib/fog/openstack/models/image/images.rb +1 -1
  95. data/lib/fog/openstack/models/metering/meter.rb +0 -0
  96. data/lib/fog/openstack/models/metering/meters.rb +0 -0
  97. data/lib/fog/openstack/models/metering/resource.rb +24 -0
  98. data/lib/fog/openstack/models/metering/resources.rb +25 -0
  99. data/lib/fog/openstack/models/volume/volume.rb +3 -1
  100. data/lib/fog/openstack/models/volume/volumes.rb +2 -1
  101. data/lib/fog/openstack/network.rb +1 -1
  102. data/lib/fog/openstack/requests/compute/create_flavor.rb +1 -1
  103. data/lib/fog/openstack/requests/compute/create_server.rb +19 -1
  104. data/lib/fog/openstack/requests/compute/detach_volume.rb +2 -1
  105. data/lib/fog/openstack/requests/compute/list_flavors_detail.rb +4 -3
  106. data/lib/fog/openstack/requests/compute/list_security_groups.rb +1 -1
  107. data/lib/fog/openstack/requests/identity/create_tenant.rb +2 -2
  108. data/lib/fog/openstack/requests/metering/get_resource.rb +32 -0
  109. data/lib/fog/openstack/requests/metering/get_samples.rb +55 -0
  110. data/lib/fog/openstack/requests/metering/get_statistics.rb +56 -0
  111. data/lib/fog/openstack/requests/metering/list_meters.rb +50 -0
  112. data/lib/fog/openstack/requests/metering/list_resources.rb +32 -0
  113. data/lib/fog/openstack/requests/volume/create_volume.rb +4 -2
  114. data/lib/fog/rackspace.rb +16 -1
  115. data/lib/fog/rackspace/block_storage.rb +13 -28
  116. data/lib/fog/rackspace/cdn.rb +10 -24
  117. data/lib/fog/rackspace/compute.rb +17 -45
  118. data/lib/fog/rackspace/compute_v2.rb +13 -33
  119. data/lib/fog/rackspace/databases.rb +13 -29
  120. data/lib/fog/rackspace/dns.rb +27 -23
  121. data/lib/fog/rackspace/identity.rb +10 -26
  122. data/lib/fog/rackspace/load_balancers.rb +13 -29
  123. data/lib/fog/rackspace/mock_data.rb +3 -3
  124. data/lib/fog/rackspace/models/compute/server.rb +1 -1
  125. data/lib/fog/rackspace/models/dns/zones.rb +34 -21
  126. data/lib/fog/rackspace/models/identity/users.rb +2 -2
  127. data/lib/fog/rackspace/models/storage/file.rb +1 -0
  128. data/lib/fog/rackspace/requests/dns/list_domains.rb +2 -2
  129. data/lib/fog/rackspace/requests/storage/delete_multiple_objects.rb +75 -0
  130. data/lib/fog/rackspace/requests/storage/delete_static_large_object.rb +50 -0
  131. data/lib/fog/rackspace/requests/storage/get_object.rb +3 -1
  132. data/lib/fog/rackspace/requests/storage/put_dynamic_obj_manifest.rb +44 -0
  133. data/lib/fog/rackspace/requests/storage/put_object_manifest.rb +3 -30
  134. data/lib/fog/rackspace/requests/storage/put_static_obj_manifest.rb +60 -0
  135. data/lib/fog/rackspace/service.rb +43 -1
  136. data/lib/fog/rackspace/storage.rb +25 -43
  137. data/lib/fog/riakcs/provisioning.rb +2 -1
  138. data/lib/fog/riakcs/usage.rb +2 -1
  139. data/lib/fog/vcloud/requests/compute/configure_vm_cpus.rb +1 -1
  140. data/lib/fog/vcloud/requests/compute/configure_vm_memory.rb +1 -1
  141. data/lib/fog/version.rb +1 -1
  142. data/lib/fog/vsphere/requests/compute/get_folder.rb +1 -1
  143. data/lib/fog/xenserver/compute.rb +2 -0
  144. data/lib/fog/xenserver/models/compute/server.rb +9 -7
  145. data/lib/fog/xenserver/requests/compute/snapshot_revert.rb +22 -0
  146. data/lib/fog/xenserver/requests/compute/snapshot_server.rb +22 -0
  147. data/lib/fog/xml.rb +21 -0
  148. data/lib/fog/xml/sax_parser_connection.rb +43 -0
  149. data/lib/tasks/changelog_task.rb +1 -0
  150. data/tests/aws/models/auto_scaling/groups_test.rb +22 -0
  151. data/tests/aws/requests/compute/volume_tests.rb +3 -3
  152. data/tests/aws/requests/rds/helper.rb +14 -0
  153. data/tests/aws/requests/rds/log_file_tests.rb +19 -0
  154. data/tests/aws/requests/ses/verified_domain_identity_tests.rb +16 -0
  155. data/tests/aws/requests/sts/assume_role_tests.rb +19 -0
  156. data/tests/brightbox/requests/compute/collaboration_tests.rb +41 -0
  157. data/tests/brightbox/requests/compute/helper.rb +46 -2
  158. data/tests/brightbox/requests/compute/user_collaboration_tests.rb +67 -0
  159. data/tests/core/connection_tests.rb +26 -0
  160. data/tests/helper.rb +13 -0
  161. data/tests/openstack/requests/metering/meter_tests.rb +52 -0
  162. data/tests/openstack/requests/metering/resource_tests.rb +19 -0
  163. data/tests/openvz/helper.rb +14 -8
  164. data/tests/rackspace/block_storage_tests.rb +9 -0
  165. data/tests/rackspace/compute_tests.rb +9 -0
  166. data/tests/rackspace/compute_v2_tests.rb +9 -0
  167. data/tests/rackspace/databases_tests.rb +9 -0
  168. data/tests/rackspace/dns_tests.rb +20 -0
  169. data/tests/rackspace/helper.rb +12 -1
  170. data/tests/rackspace/identity_tests.rb +25 -0
  171. data/tests/rackspace/load_balancer_tests.rb +10 -0
  172. data/tests/rackspace/models/block_storage/volume_tests.rb +2 -2
  173. data/tests/rackspace/models/compute_v2/metadata_tests.rb +2 -2
  174. data/tests/rackspace/models/compute_v2/server_tests.rb +22 -21
  175. data/tests/rackspace/models/dns/zones_tests.rb +19 -5
  176. data/tests/rackspace/models/storage/file_tests.rb +22 -6
  177. data/tests/rackspace/rackspace_tests.rb +35 -0
  178. data/tests/rackspace/requests/block_storage/snapshot_tests.rb +2 -3
  179. data/tests/rackspace/requests/block_storage/volume_type_tests.rb +4 -11
  180. data/tests/rackspace/requests/compute_v2/address_tests.rb +1 -1
  181. data/tests/rackspace/requests/compute_v2/attachment_tests.rb +8 -9
  182. data/tests/rackspace/requests/compute_v2/flavor_tests.rb +1 -1
  183. data/tests/rackspace/requests/compute_v2/metadata_tests.rb +4 -4
  184. data/tests/rackspace/requests/databases/database_tests.rb +23 -20
  185. data/tests/rackspace/requests/databases/user_tests.rb +6 -6
  186. data/tests/rackspace/requests/identity/user_tests.rb +4 -1
  187. data/tests/rackspace/requests/load_balancers/usage_tests.rb +4 -2
  188. data/tests/rackspace/requests/storage/large_object_tests.rb +303 -59
  189. data/tests/rackspace/requests/storage/object_tests.rb +73 -18
  190. data/tests/rackspace/service_tests.rb +83 -0
  191. data/tests/rackspace/storage_tests.rb +9 -0
  192. data/tests/xenserver/models/compute/server_tests.rb +11 -1
  193. metadata +89 -19
  194. data/tests/core/user_agent_tests.rb +0 -6
@@ -30,7 +30,7 @@ module Fog
30
30
 
31
31
  request({
32
32
  'Action' => 'SendRawEmail',
33
- 'RawMessage.Data' => Base64.encode64(raw_message).chomp!,
33
+ 'RawMessage.Data' => Base64.encode64(raw_message.to_s).chomp!,
34
34
  :parser => Fog::Parsers::AWS::SES::SendRawEmail.new
35
35
  }.merge(params))
36
36
  end
@@ -0,0 +1,30 @@
1
+ module Fog
2
+ module AWS
3
+ class SES
4
+ class Real
5
+
6
+ require 'fog/aws/parsers/ses/verify_domain_identity'
7
+
8
+ # Verifies a domain. This action returns a verification authorization
9
+ # token which must be added as a DNS TXT record to the domain.
10
+ #
11
+ # ==== Parameters
12
+ # * domain<~String> - The domain to be verified
13
+ # ==== Returns
14
+ # * response<~Excon::Response>:
15
+ # * body<~Hash>:
16
+ # * 'ResponseMetadata'<~Hash>:
17
+ # * 'VerificationToken'<~String> - Verification token
18
+ # * 'RequestId'<~String> - Id of request
19
+ def verify_domain(domain)
20
+ request({
21
+ 'Action' => 'VerifyDomainIdentity',
22
+ 'Domain' => domain,
23
+ :parser => Fog::Parsers::AWS::SES::VerifyDomainIdentity.new
24
+ })
25
+ end
26
+
27
+ end
28
+ end
29
+ end
30
+ end
@@ -13,12 +13,16 @@ module Fog
13
13
  # @param [Array<String>] parts Array of etags as Strings for parts
14
14
  #
15
15
  # @return [Excon::Response]
16
- # * headers [Hash]:
16
+ # * body [Hash]: (success)
17
17
  # * Bucket [String] - bucket of new object
18
- # * ETag [String] - etag of new object (will be needed to complete upload)
18
+ # * ETag [String] - etag of new object
19
19
  # * Key [String] - key of new object
20
20
  # * Location [String] - location of new object
21
+ # * body [Hash]: (failure)
22
+ # * Code [String] - Error status code
23
+ # * Message [String] - Error description
21
24
  #
25
+ # @note This request could fail and still return +200 OK+, so it's important that you check the response.
22
26
  # @see http://docs.amazonwebservices.com/AmazonS3/latest/API/mpUploadComplete.html
23
27
  #
24
28
  def complete_multipart_upload(bucket_name, object_name, upload_id, parts)
@@ -87,7 +87,7 @@ module Fog
87
87
  if (object && !object[:delete_marker])
88
88
  if options['If-Match'] && options['If-Match'] != object['ETag']
89
89
  response.status = 412
90
- elsif options['If-Modified-Since'] && options['If-Modified-Since'] > Time.parse(object['Last-Modified'])
90
+ elsif options['If-Modified-Since'] && options['If-Modified-Since'] >= Time.parse(object['Last-Modified'])
91
91
  response.status = 304
92
92
  elsif options['If-None-Match'] && options['If-None-Match'] == object['ETag']
93
93
  response.status = 304
@@ -0,0 +1,46 @@
1
+ module Fog
2
+ module AWS
3
+ class STS
4
+ class Real
5
+
6
+ require 'fog/aws/parsers/sts/assume_role'
7
+
8
+ # Assume Role
9
+ #
10
+ # ==== Parameters
11
+ # * role_session_name<~String> - An identifier for the assumed role.
12
+ # * role_arn<~String> - The ARN of the role the caller is assuming.
13
+ # * external_id<~String> - An optional unique identifier required by the assuming role's trust identity.
14
+ # * policy<~String> - An optional JSON policy document
15
+ # * duration<~Integer> - Duration (of seconds) for the assumed role credentials to be valid (default 3600)
16
+ #
17
+ # ==== Returns
18
+ # * response<~Excon::Response>:
19
+ # * body<~Hash>:
20
+ # * 'Arn'<~String>: The ARN of the assumed role/user
21
+ # * 'AccessKeyId'<~String>: The AWS access key of the temporary credentials for the assumed role
22
+ # * 'SecretAccessKey'<~String>: The AWS secret key of the temporary credentials for the assumed role
23
+ # * 'SessionToken'<~String>: The AWS session token of the temporary credentials for the assumed role
24
+ # * 'Expiration'<~Time>: The expiration time of the temporary credentials for the assumed role
25
+ #
26
+ # ==== See Also
27
+ # http://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRole.html
28
+ #
29
+
30
+ def assume_role(role_session_name, role_arn, external_id=nil, policy=nil, duration=3600)
31
+ request({
32
+ 'Action' => 'AssumeRole',
33
+ 'RoleSessionName' => role_session_name,
34
+ 'RoleArn' => role_arn,
35
+ 'Policy' => policy && Fog::JSON.encode(policy),
36
+ 'DurationSeconds' => duration,
37
+ 'ExternalId' => external_id,
38
+ :idempotent => true,
39
+ :parser => Fog::Parsers::AWS::STS::AssumeRole.new
40
+ })
41
+ end
42
+
43
+ end
44
+ end
45
+ end
46
+ end
@@ -5,12 +5,16 @@ module Fog
5
5
  class SES < Fog::Service
6
6
  extend Fog::AWS::CredentialFetcher::ServiceMethods
7
7
 
8
+ class InvalidParameterError < Fog::Errors::Error; end
9
+ class MessageRejected < Fog::Errors::Error; end
10
+
8
11
  requires :aws_access_key_id, :aws_secret_access_key
9
12
  recognizes :region, :host, :path, :port, :scheme, :persistent, :use_iam_profile, :aws_session_token, :aws_credentials_expire_at
10
13
 
11
14
  request_path 'fog/aws/requests/ses'
12
15
  request :delete_verified_email_address
13
16
  request :verify_email_address
17
+ request :verify_domain_identity
14
18
  request :get_send_quota
15
19
  request :get_send_statistics
16
20
  request :list_verified_email_addresses
@@ -102,15 +106,28 @@ module Fog
102
106
  end
103
107
  body.chop! # remove trailing '&'
104
108
 
105
- response = @connection.request({
106
- :body => body,
107
- :expects => 200,
108
- :headers => headers,
109
- :idempotent => idempotent,
110
- :host => @host,
111
- :method => 'POST',
112
- :parser => parser
113
- })
109
+ begin
110
+ response = @connection.request({
111
+ :body => body,
112
+ :expects => 200,
113
+ :headers => headers,
114
+ :idempotent => idempotent,
115
+ :host => @host,
116
+ :method => 'POST',
117
+ :parser => parser
118
+ })
119
+ rescue Excon::Errors::HTTPStatusError => error
120
+ match = Fog::AWS::Errors.match_error(error)
121
+ raise if match.empty?
122
+ raise case match[:code]
123
+ when 'MessageRejected'
124
+ Fog::AWS::SES::MessageRejected.slurp(error, match[:message])
125
+ when 'InvalidParameterValue'
126
+ Fog::AWS::SES::InvalidParameterError.slurp(error, match[:message])
127
+ else
128
+ Fog::AWS::SES::Error.slurp(error, "#{match[:code]} => #{match[:message]}")
129
+ end
130
+ end
114
131
 
115
132
  response
116
133
  end
@@ -491,13 +491,14 @@ DATA
491
491
  refresh_credentials_if_expired
492
492
 
493
493
  expires = Fog::Time.now.to_date_header
494
+
495
+ params[:headers]['x-amz-security-token'] = @aws_session_token if @aws_session_token
494
496
  signature = signature(params, expires)
495
497
 
496
498
  params = request_params(params)
497
499
  params.delete(:port) unless params[:port]
498
500
 
499
501
  params[:headers]['Date'] = expires
500
- params[:headers]['x-amz-security-token'] = @aws_session_token if @aws_session_token
501
502
  params[:headers]['Authorization'] = "AWS #{@aws_access_key_id}:#{signature}"
502
503
  # FIXME: ToHashParser should make this not needed
503
504
  original_params = params.dup
@@ -3,16 +3,18 @@ require 'fog/aws'
3
3
  module Fog
4
4
  module AWS
5
5
  class STS < Fog::Service
6
+ extend Fog::AWS::CredentialFetcher::ServiceMethods
6
7
 
7
8
  class EntityAlreadyExists < Fog::AWS::STS::Error; end
8
9
  class ValidationError < Fog::AWS::STS::Error; end
9
10
 
10
11
  requires :aws_access_key_id, :aws_secret_access_key
11
- recognizes :host, :path, :port, :scheme, :persistent
12
+ recognizes :host, :path, :port, :scheme, :persistent, :aws_session_token, :use_iam_profile, :aws_credentials_expire_at
12
13
 
13
14
  request_path 'fog/aws/requests/sts'
14
15
  request :get_federation_token
15
16
  request :get_session_token
17
+ request :assume_role
16
18
 
17
19
  class Mock
18
20
  def self.data
@@ -33,7 +35,8 @@ module Fog
33
35
  end
34
36
 
35
37
  def initialize(options={})
36
- @aws_access_key_id = options[:aws_access_key_id]
38
+ @use_iam_profile = options[:use_iam_profile]
39
+ setup_credentials(options)
37
40
  end
38
41
 
39
42
  def data
@@ -43,10 +46,14 @@ module Fog
43
46
  def reset_data
44
47
  self.class.data.delete(@aws_access_key_id)
45
48
  end
49
+
50
+ def setup_credentials(options)
51
+ @aws_access_key_id = options[:aws_access_key_id]
52
+ end
46
53
  end
47
54
 
48
55
  class Real
49
-
56
+ include Fog::AWS::CredentialFetcher::ConnectionMethods
50
57
  # Initialize connection to STS
51
58
  #
52
59
  # ==== Notes
@@ -67,10 +74,10 @@ module Fog
67
74
  def initialize(options={})
68
75
  require 'fog/core/parser'
69
76
 
70
- @aws_access_key_id = options[:aws_access_key_id]
71
- @aws_secret_access_key = options[:aws_secret_access_key]
77
+ @use_iam_profile = options[:use_iam_profile]
78
+ setup_credentials(options)
72
79
  @connection_options = options[:connection_options] || {}
73
- @hmac = Fog::HMAC.new('sha256', @aws_secret_access_key)
80
+
74
81
  @host = options[:host] || 'sts.amazonaws.com'
75
82
  @path = options[:path] || '/'
76
83
  @persistent = options[:persistent] || false
@@ -85,6 +92,14 @@ module Fog
85
92
 
86
93
  private
87
94
 
95
+ def setup_credentials(options)
96
+ @aws_access_key_id = options[:aws_access_key_id]
97
+ @aws_secret_access_key = options[:aws_secret_access_key]
98
+ @aws_session_token = options[:aws_session_token]
99
+ @aws_credentials_expire_at = options[:aws_credentials_expire_at]
100
+ @hmac = Fog::HMAC.new('sha256', @aws_secret_access_key)
101
+ end
102
+
88
103
  def request(params)
89
104
  idempotent = params.delete(:idempotent)
90
105
  parser = params.delete(:parser)
@@ -93,6 +108,7 @@ module Fog
93
108
  params,
94
109
  {
95
110
  :aws_access_key_id => @aws_access_key_id,
111
+ :aws_session_token => @aws_session_token,
96
112
  :hmac => @hmac,
97
113
  :host => @host,
98
114
  :path => @path,
@@ -102,7 +118,7 @@ module Fog
102
118
  )
103
119
 
104
120
  begin
105
- response = @connection.request({
121
+ @connection.request({
106
122
  :body => body,
107
123
  :expects => 200,
108
124
  :idempotent => idempotent,
@@ -111,23 +127,17 @@ module Fog
111
127
  :method => 'POST',
112
128
  :parser => parser
113
129
  })
114
-
115
- response
116
130
  rescue Excon::Errors::HTTPStatusError => error
117
- if match = error.message.match(/(?:.*<Code>(.*)<\/Code>)(?:.*<Message>(.*)<\/Message>)/m)
118
- case match[1]
119
- when 'EntityAlreadyExists', 'KeyPairMismatch', 'LimitExceeded', 'MalformedCertificate', 'ValidationError'
120
- raise Fog::AWS::STS.const_get(match[1]).slurp(error, match[2])
121
- else
122
- raise Fog::AWS::STS::Error.slurp(error, "#{match[1]} => #{match[2]}") if match[1]
123
- raise
124
- end
125
- else
126
- raise
127
- end
131
+ match = Fog::AWS::Errors.match_error(error)
132
+ raise if match.empty?
133
+ raise case match[:code]
134
+ when 'EntityAlreadyExists', 'KeyPairMismatch', 'LimitExceeded', 'MalformedCertificate', 'ValidationError'
135
+ Fog::AWS::STS.const_get(match[:code]).slurp(error, match[:message])
136
+ else
137
+ Fog::AWS::STS::Error.slurp(error, "#{match[:code]} => #{match[:message]}")
138
+ end
128
139
  end
129
140
 
130
-
131
141
  end
132
142
 
133
143
  end
@@ -4,7 +4,6 @@ module Fog
4
4
  class << self
5
5
 
6
6
  def available_providers
7
- Kernel.const_get('Ninefold')
8
7
  @available_providers ||= Fog.providers.values.select {|provider| Kernel.const_get(provider).available?}.sort
9
8
  end
10
9
 
@@ -15,6 +15,8 @@ class OpenStack < Fog::Bin
15
15
  Fog::Storage::OpenStack
16
16
  when :volume
17
17
  Fog::Volume::OpenStack
18
+ when :metering
19
+ Fog::Metering::OpenStack
18
20
  else
19
21
  raise ArgumentError, "Unrecognized service: #{key}"
20
22
  end
@@ -41,6 +43,9 @@ class OpenStack < Fog::Bin
41
43
  when :volume
42
44
  Fog::Logger.warning("OpenStack[:volume] is not recommended, use Volume[:openstack] for portability")
43
45
  Fog::Volume.new(:provider => 'OpenStack')
46
+ when :metering
47
+ Fog::Logger.warning("OpenStack[:metering] is not recommended, use Metering[:openstack] for portability")
48
+ Fog::Metering.new(:provider => 'OpenStack')
44
49
  else
45
50
  raise ArgumentError, "Unrecognized service: #{key.inspect}"
46
51
  end
@@ -1,14 +1,12 @@
1
1
  require 'fog/brightbox'
2
2
  require 'fog/compute'
3
- require 'fog/brightbox/oauth2'
3
+ require 'fog/brightbox/compute/shared'
4
4
  require 'fog/brightbox/compute/image_selector'
5
5
 
6
6
  module Fog
7
7
  module Compute
8
8
  class Brightbox < Fog::Service
9
9
 
10
- API_URL = "https://api.gb1.brightbox.com/"
11
-
12
10
  # Client credentials
13
11
  requires :brightbox_client_id, :brightbox_secret
14
12
 
@@ -34,6 +32,8 @@ module Fog
34
32
  model :application
35
33
  collection :api_clients
36
34
  model :api_client
35
+ collection :collaborations
36
+ model :collaboration
37
37
  collection :servers
38
38
  model :server
39
39
  collection :server_groups
@@ -54,17 +54,22 @@ module Fog
54
54
  model :cloud_ip
55
55
  collection :users
56
56
  model :user
57
+ collection :user_collaborations
58
+ model :user_collaboration
57
59
 
58
60
  request_path 'fog/brightbox/requests/compute'
61
+ request :accept_user_collaboration
59
62
  request :activate_console_server
60
63
  request :add_listeners_load_balancer
61
64
  request :add_nodes_load_balancer
62
65
  request :add_servers_server_group
63
66
  request :apply_to_firewall_policy
67
+ request :accept_user_collaboration
64
68
  request :remove_firewall_policy
65
69
  request :create_api_client
66
70
  request :create_application
67
71
  request :create_cloud_ip
72
+ request :create_collaboration
68
73
  request :create_firewall_policy
69
74
  request :create_firewall_rule
70
75
  request :create_image
@@ -74,17 +79,20 @@ module Fog
74
79
  request :delete_api_client
75
80
  request :delete_application
76
81
  request :delete_cloud_ip
82
+ request :delete_collaboration
77
83
  request :delete_firewall_policy
78
84
  request :delete_firewall_rule
79
85
  request :delete_image
80
86
  request :delete_load_balancer
81
87
  request :delete_server
82
88
  request :delete_server_group
89
+ request :delete_user_collaboration
83
90
  request :get_account
84
91
  request :get_api_client
85
92
  request :get_application
86
93
  request :get_authenticated_user
87
94
  request :get_cloud_ip
95
+ request :get_collaboration
88
96
  request :get_firewall_policy
89
97
  request :get_firewall_rule
90
98
  request :get_image
@@ -95,11 +103,13 @@ module Fog
95
103
  request :get_server_group
96
104
  request :get_server_type
97
105
  request :get_user
106
+ request :get_user_collaboration
98
107
  request :get_zone
99
108
  request :list_accounts
100
109
  request :list_api_clients
101
110
  request :list_applications
102
111
  request :list_cloud_ips
112
+ request :list_collaborations
103
113
  request :list_firewall_policies
104
114
  request :list_images
105
115
  request :list_load_balancers
@@ -107,16 +117,21 @@ module Fog
107
117
  request :list_server_types
108
118
  request :list_servers
109
119
  request :list_users
120
+ request :list_user_collaborations
110
121
  request :list_zones
111
122
  request :map_cloud_ip
112
123
  request :move_servers_server_group
124
+ request :reject_user_collaboration
113
125
  request :remove_listeners_load_balancer
114
126
  request :remove_nodes_load_balancer
115
127
  request :remove_servers_server_group
128
+ request :resend_collaboration
116
129
  request :reset_ftp_password_account
117
130
  request :reset_ftp_password_scoped_account
118
131
  request :reset_secret_api_client
119
132
  request :reset_secret_application
133
+ request :resend_collaboration
134
+ request :reject_user_collaboration
120
135
  request :shutdown_server
121
136
  request :snapshot_server
122
137
  request :start_server
@@ -135,220 +150,13 @@ module Fog
135
150
  request :update_server_group
136
151
  request :update_user
137
152
 
138
- module Shared
139
- include Fog::Brightbox::OAuth2
140
-
141
- # Creates a new instance of the Brightbox Compute service
142
- #
143
- # @note If you create service using just a refresh token when it
144
- # expires the service will no longer be able to authenticate.
145
- #
146
- # @param [Hash] options
147
- # @option options [String] :brightbox_api_url Override the default (or configured) API endpoint
148
- # @option options [String] :brightbox_auth_url Override the default (or configured) API authentication endpoint
149
- # @option options [String] :brightbox_client_id Client identifier to authenticate with (overrides configured)
150
- # @option options [String] :brightbox_secret Client secret to authenticate with (overrides configured)
151
- # @option options [String] :brightbox_username Email or user identifier for user based authentication
152
- # @option options [String] :brightbox_password Password for user based authentication
153
- # @option options [String] :brightbox_account Account identifier to scope this connection to
154
- # @option options [String] :connection_options Settings to pass to underlying {Fog::Connection}
155
- # @option options [Boolean] :persistent Sets a persistent HTTP {Fog::Connection}
156
- # @option options [String] :brightbox_access_token Sets the OAuth access token to use rather than requesting a new token
157
- # @option options [String] :brightbox_refresh_token Sets the refresh token to use when requesting a newer access token
158
- # @option options [String] :brightbox_token_management Overide the existing behaviour to request access tokens if expired (default is `true`)
159
- #
160
- def initialize(options)
161
- # Currently authentication and api endpoints are the same but may change
162
- @auth_url = options[:brightbox_auth_url] || Fog.credentials[:brightbox_auth_url] || API_URL
163
- @auth_connection = Fog::Connection.new(@auth_url)
164
-
165
- @api_url = options[:brightbox_api_url] || Fog.credentials[:brightbox_api_url] || API_URL
166
- @connection_options = options[:connection_options] || {}
167
- @persistent = options[:persistent] || false
168
- @connection = Fog::Connection.new(@api_url, @persistent, @connection_options)
169
-
170
- # Authentication options
171
- client_id = options[:brightbox_client_id] || Fog.credentials[:brightbox_client_id]
172
- client_secret = options[:brightbox_secret] || Fog.credentials[:brightbox_secret]
173
-
174
- username = options[:brightbox_username] || Fog.credentials[:brightbox_username]
175
- password = options[:brightbox_password] || Fog.credentials[:brightbox_password]
176
- @configured_account = options[:brightbox_account] || Fog.credentials[:brightbox_account]
177
- # Request account can be changed at anytime and changes behaviour of future requests
178
- @scoped_account = @configured_account
179
-
180
- credential_options = {:username => username, :password => password}
181
- @credentials = CredentialSet.new(client_id, client_secret, credential_options)
182
-
183
- # If existing tokens have been cached, allow continued use of them in the service
184
- @credentials.update_tokens(options[:brightbox_access_token], options[:brightbox_refresh_token])
185
-
186
- @token_management = options.fetch(:brightbox_token_management, true)
187
- end
188
-
189
- # Sets the scoped account for future requests
190
- # @param [String] scoped_account Identifier of the account to scope request to
191
- def scoped_account=(scoped_account)
192
- @scoped_account = scoped_account
193
- end
194
-
195
- # This returns the account identifier that the request should be scoped by
196
- # based on the options passed to the request and current configuration
197
- #
198
- # @param [String] options_account Any identifier passed into the request
199
- #
200
- # @return [String, nil] The account identifier to scope the request to or nil
201
- def scoped_account(options_account = nil)
202
- [options_account, @scoped_account].compact.first
203
- end
204
-
205
- # Resets the scoped account back to intially configured one
206
- def scoped_account_reset
207
- @scoped_account = @configured_account
208
- end
209
-
210
- # Returns the scoped account being used for requests
211
- #
212
- # * For API clients this is the owning account
213
- # * For User applications this is the account specified by either +account_id+
214
- # option on the service or the +brightbox_account+ setting in your configuration
215
- #
216
- # @return [Fog::Compute::Brightbox::Account]
217
- #
218
- def account
219
- account_data = get_scoped_account.merge(:service => self)
220
- Fog::Compute::Brightbox::Account.new(account_data)
221
- end
222
-
223
- # Returns true if authentication is being performed as a user
224
- # @return [Boolean]
225
- def authenticating_as_user?
226
- @credentials.user_details?
227
- end
228
-
229
- # Returns true if an access token is set
230
- # @return [Boolean]
231
- def access_token_available?
232
- !! @credentials.access_token
233
- end
234
-
235
- # Returns the current access token or nil
236
- # @return [String,nil]
237
- def access_token
238
- @credentials.access_token
239
- end
240
-
241
- # Returns the current refresh token or nil
242
- # @return [String,nil]
243
- def refresh_token
244
- @credentials.refresh_token
245
- end
246
-
247
- # Returns the current token expiry time in seconds or nil
248
- # @return [Number,nil]
249
- def expires_in
250
- @credentials.expires_in
251
- end
252
-
253
- # Requests a new access token
254
- #
255
- # @return [String] New access token
256
- def get_access_token
257
- begin
258
- get_access_token!
259
- rescue Excon::Errors::Unauthorized, Excon::Errors::BadRequest
260
- @credentials.update_tokens(nil, nil)
261
- end
262
- @credentials.access_token
263
- end
264
-
265
- # Requests a new access token and raises if there is a problem
266
- #
267
- # @return [String] New access token
268
- # @raise [Excon::Errors::BadRequest] The credentials are expired or incorrect
269
- #
270
- def get_access_token!
271
- response = request_access_token(@auth_connection, @credentials)
272
- update_credentials_from_response(@credentials, response)
273
- @credentials.access_token
274
- end
275
-
276
- # Returns an identifier for the default image for use
277
- #
278
- # Currently tries to find the latest version of Ubuntu (i686) from
279
- # Brightbox.
280
- #
281
- # Highly recommended that you actually select the image you want to run
282
- # on your servers yourself!
283
- #
284
- # @return [String] if image is found, returns the identifier
285
- # @return [NilClass] if no image is found or an error occurs
286
- #
287
- def default_image
288
- return @default_image_id unless @default_image_id.nil?
289
- @default_image_id = Fog.credentials[:brightbox_default_image] || select_default_image
290
- end
291
-
292
- private
293
-
294
- # This makes a request of the API based on the configured setting for
295
- # token management.
296
- #
297
- # @param [Hash] options Excon compatible options
298
- # @see https://github.com/geemus/excon/blob/master/lib/excon/connection.rb
299
- #
300
- # @return [Hash] Data of response body
301
- #
302
- def make_request(options)
303
- if @token_management
304
- managed_token_request(options)
305
- else
306
- authenticated_request(options)
307
- end
308
- end
309
-
310
- # This request checks for access tokens and will ask for a new one if
311
- # it receives Unauthorized from the API before repeating the request
312
- #
313
- # @param [Hash] options Excon compatible options
314
- #
315
- # @return [Excon::Response]
316
- def managed_token_request(options)
317
- begin
318
- get_access_token unless access_token_available?
319
- response = authenticated_request(options)
320
- rescue Excon::Errors::Unauthorized
321
- get_access_token
322
- response = authenticated_request(options)
323
- end
324
- end
325
-
326
- # This request makes an authenticated request of the API using currently
327
- # setup credentials.
328
- #
329
- # @param [Hash] options Excon compatible options
330
- #
331
- # @see https://github.com/geemus/excon/blob/master/lib/excon/connection.rb
332
- #
333
- # @return [Excon::Response]
334
- def authenticated_request(options)
335
- headers = options[:headers] || {}
336
- headers.merge!("Authorization" => "OAuth #{@credentials.access_token}", "Content-Type" => "application/json")
337
- options[:headers] = headers
338
- # TODO This is just a wrapper around a call to Excon::Connection#request
339
- # so can be extracted from Compute by passing in the connection,
340
- # credentials and options
341
- @connection.request(options)
342
- end
343
- end
344
-
345
153
  # The Mock Service allows you to run a fake instance of the Service
346
154
  # which makes no real connections.
347
155
  #
348
156
  # @todo Implement
349
157
  #
350
158
  class Mock
351
- include Shared
159
+ include Fog::Brightbox::Compute::Shared
352
160
 
353
161
  def request(method, path, expected_responses, parameters = {})
354
162
  _request
@@ -373,7 +181,7 @@ module Fog
373
181
  # service.
374
182
  #
375
183
  class Real
376
- include Shared
184
+ include Fog::Brightbox::Compute::Shared
377
185
 
378
186
  # Makes an API request to the given path using passed options or those
379
187
  # set with the service setup