fog-aws 0.7.4 → 0.7.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d5bfdd4651881d56cd47ad871e5b8b7a993418cd
4
- data.tar.gz: 5bd28c47be8f7e7aabf993c499b09bdd79b25cbe
3
+ metadata.gz: 4397f9c8c33ed518c2029eaed97241723b4bde0b
4
+ data.tar.gz: 717bb82a0012393747acc56f4ab39213ea76d2ff
5
5
  SHA512:
6
- metadata.gz: 83234e86990287d8151a86c98cc1d3e72d697397278b73ca48b991fb7d827eb360576012f72031dd0c4b2401027370a5ebcccac4abc29cd81df16f43ee702d86
7
- data.tar.gz: be95bfbfe84599f9f53de207fa68bc3ce920c6f53ba27b9846abae103c4b4837b91de8537af5f4b87b2577bef910a0117331fae73fb90c4509219a5d94a49a30
6
+ metadata.gz: b22396fa794717e82b93969954722ae4614facf95107cbd0e03eeaa94c562a6d4dbced6beabbaed4f7fbdc844107223e2957b5255c30b254a89ea724c631b4ed
7
+ data.tar.gz: 4237cdf3e82649d353fadb7b9f1f6a89fa74e71d40b675ccb1e6462fddc807010031447a2522310b09eb98d8e3c39528f6bf8e205c18596a953e24acc9525d7b
@@ -27,7 +27,6 @@ module Fog
27
27
  autoload :CredentialFetcher, File.expand_path('../aws/credential_fetcher', __FILE__)
28
28
  autoload :Errors, File.expand_path('../aws/errors', __FILE__)
29
29
  autoload :Mock, File.expand_path('../aws/mock', __FILE__)
30
- autoload :RegionMethods, File.expand_path('../aws/region_methods', __FILE__)
31
30
  autoload :SignatureV4, File.expand_path('../aws/signaturev4', __FILE__)
32
31
 
33
32
  # Services
@@ -103,18 +102,18 @@ module Fog
103
102
 
104
103
  def self.serialize_keys(key, value, options = {})
105
104
  case value
106
- when Hash
107
- value.each do | k, v |
108
- options.merge!(serialize_keys("#{key}.#{k}", v))
109
- end
110
- return options
111
- when Array
112
- value.each_with_index do | it, idx |
113
- options.merge!(serialize_keys("#{key}.member.#{(idx + 1)}", it))
114
- end
115
- return options
116
- else
117
- return {key => value}
105
+ when Hash
106
+ value.each do | k, v |
107
+ options.merge!(serialize_keys("#{key}.#{k}", v))
108
+ end
109
+ return options
110
+ when Array
111
+ value.each_with_index do | it, idx |
112
+ options.merge!(serialize_keys("#{key}.member.#{(idx + 1)}", it))
113
+ end
114
+ return options
115
+ else
116
+ return {key => value}
118
117
  end
119
118
  end
120
119
 
@@ -173,16 +172,16 @@ module Fog
173
172
 
174
173
  def self.signed_params(params, options = {})
175
174
  params.merge!({
176
- 'AWSAccessKeyId' => options[:aws_access_key_id],
177
- 'SignatureMethod' => 'HmacSHA256',
178
- 'SignatureVersion' => '2',
179
- 'Timestamp' => Time.now.utc.strftime("%Y-%m-%dT%H:%M:%SZ"),
180
- 'Version' => options[:version]
181
- })
175
+ 'AWSAccessKeyId' => options[:aws_access_key_id],
176
+ 'SignatureMethod' => 'HmacSHA256',
177
+ 'SignatureVersion' => '2',
178
+ 'Timestamp' => Time.now.utc.strftime("%Y-%m-%dT%H:%M:%SZ"),
179
+ 'Version' => options[:version]
180
+ })
182
181
 
183
182
  params.merge!({
184
- 'SecurityToken' => options[:aws_session_token]
185
- }) if options[:aws_session_token]
183
+ 'SecurityToken' => options[:aws_session_token]
184
+ }) if options[:aws_session_token]
186
185
 
187
186
  body = ''
188
187
  for key in params.keys.sort
@@ -223,5 +222,15 @@ module Fog
223
222
  return false unless response && response.headers
224
223
  response.get_header('Content-Type') =~ %r{application/.*json.*}i ? true : false
225
224
  end
225
+
226
+ def self.regions
227
+ @regions ||= ['ap-northeast-1', 'ap-southeast-1', 'ap-southeast-2', 'eu-central-1', 'eu-west-1', 'us-east-1', 'us-west-1', 'us-west-2', 'sa-east-1', 'cn-north-1']
228
+ end
229
+
230
+ def self.validate_region!(region, host=nil)
231
+ if (!host || host.end_with?('.amazonaws.com')) && !regions.include?(region)
232
+ raise ArgumentError, "Unknown region: #{region.inspect}"
233
+ end
234
+ end
226
235
  end
227
236
  end
@@ -147,7 +147,7 @@ module Fog
147
147
  :body => body,
148
148
  :expects => 200,
149
149
  :idempotent => idempotent,
150
- :headers => headers,
150
+ :headers => headers,
151
151
  :method => 'POST',
152
152
  :parser => parser
153
153
  })
@@ -253,9 +253,7 @@ module Fog
253
253
  setup_credentials(options)
254
254
  @region = options[:region] || 'us-east-1'
255
255
 
256
- unless ['ap-northeast-1', 'ap-southeast-1', 'ap-southeast-2', 'eu-central-1', 'eu-west-1', 'sa-east-1', 'us-east-1', 'us-west-1', 'us-west-2'].include?(@region)
257
- raise ArgumentError, "Unknown region: #{@region.inspect}"
258
- end
256
+ Fog::AWS.validate_region!(@region)
259
257
  end
260
258
 
261
259
  def region_data
@@ -52,9 +52,7 @@ module Fog
52
52
 
53
53
  @region = options[:region] || 'us-east-1'
54
54
 
55
- unless ['ap-northeast-1', 'ap-southeast-1', 'ap-southeast-2', 'eu-central-1', 'eu-west-1', 'sa-east-1', 'us-east-1', 'us-west-1', 'us-west-2'].include?(@region)
56
- raise ArgumentError, "Unknown region: #{@region.inspect}"
57
- end
55
+ Fog::AWS.validate_region!(@region)
58
56
  end
59
57
 
60
58
  def data
@@ -185,7 +185,6 @@ module Fog
185
185
  }
186
186
 
187
187
  include Fog::AWS::CredentialFetcher::ConnectionMethods
188
- include Fog::AWS::RegionMethods
189
188
 
190
189
  def self.data
191
190
  @data ||= Hash.new do |hash, region|
@@ -315,7 +314,7 @@ module Fog
315
314
  @port = options[:port] || 443
316
315
  @scheme = options[:scheme] || 'https'
317
316
  end
318
- validate_aws_region(@host, @region)
317
+ Fog::AWS.validate_region!(@region, @host)
319
318
  end
320
319
 
321
320
  def region_data
@@ -429,7 +428,6 @@ module Fog
429
428
 
430
429
  class Real
431
430
  include Fog::AWS::CredentialFetcher::ConnectionMethods
432
- include Fog::AWS::RegionMethods
433
431
  # Initialize connection to EC2
434
432
  #
435
433
  # ==== Notes
@@ -478,7 +476,7 @@ module Fog
478
476
  @scheme = options[:scheme] || 'https'
479
477
  end
480
478
 
481
- validate_aws_region(@host, @region)
479
+ Fog::AWS.validate_region!(@region, @host)
482
480
  @connection = Fog::XML::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", @persistent, @connection_options)
483
481
  end
484
482
 
@@ -163,9 +163,7 @@ module Fog
163
163
  @use_iam_profile = options[:use_iam_profile]
164
164
  @region = options[:region] || 'us-east-1'
165
165
 
166
- unless ['ap-northeast-1', 'ap-southeast-1', 'ap-southeast-2', 'eu-central-1', 'eu-west-1', 'us-east-1', 'us-west-1', 'us-west-2', 'sa-east-1'].include?(@region)
167
- raise ArgumentError, "Unknown region: #{@region.inspect}"
168
- end
166
+ Fog::AWS.validate_region!(@region)
169
167
 
170
168
  setup_credentials(options)
171
169
  end
@@ -80,15 +80,15 @@ module Fog
80
80
  @data = nil
81
81
  end
82
82
 
83
+ attr_reader :region
84
+
83
85
  def initialize(options={})
84
86
  @use_iam_profile = options[:use_iam_profile]
85
87
 
86
88
  @region = options[:region] || 'us-east-1'
87
89
  setup_credentials(options)
88
90
 
89
- unless ['ap-northeast-1', 'ap-southeast-1', 'ap-southeast-2', 'eu-central-1', 'eu-west-1', 'us-east-1', 'us-west-1', 'us-west-2', 'sa-east-1'].include?(@region)
90
- raise ArgumentError, "Unknown region: #{@region.inspect}"
91
- end
91
+ Fog::AWS.validate_region!(@region)
92
92
  end
93
93
 
94
94
  def setup_credentials(options)
@@ -144,9 +144,10 @@ module Fog
144
144
  @connection = Fog::XML::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", @persistent, @connection_options)
145
145
 
146
146
  setup_credentials(options)
147
-
148
147
  end
149
148
 
149
+ attr_reader :region
150
+
150
151
  def reload
151
152
  @connection.reset
152
153
  end
@@ -154,12 +155,12 @@ module Fog
154
155
  private
155
156
 
156
157
  def setup_credentials(options={})
157
- @aws_access_key_id = options[:aws_access_key_id]
158
- @aws_secret_access_key = options[:aws_secret_access_key]
159
- @aws_session_token = options[:aws_session_token]
158
+ @aws_access_key_id = options[:aws_access_key_id]
159
+ @aws_secret_access_key = options[:aws_secret_access_key]
160
+ @aws_session_token = options[:aws_session_token]
160
161
  @aws_credentials_expire_at = options[:aws_credentials_expire_at]
161
162
 
162
- @signer = Fog::AWS::SignatureV4.new( @aws_access_key_id, @aws_secret_access_key,@region,'elasticloadbalancing')
163
+ @signer = Fog::AWS::SignatureV4.new(@aws_access_key_id, @aws_secret_access_key, @region, 'elasticloadbalancing')
163
164
  end
164
165
 
165
166
  def request(params)
@@ -149,9 +149,7 @@ module Fog
149
149
  @aws_access_key_id = options[:aws_access_key_id]
150
150
  @region = options[:region] || 'us-east-1'
151
151
 
152
- unless ['ap-northeast-1', 'ap-southeast-1', 'ap-southeast-2', 'eu-central-1', 'eu-west-1', 'sa-east-1', 'us-east-1', 'us-west-1', 'us-west-2'].include?(@region)
153
- raise ArgumentError, "Unknown region: #{@region.inspect}"
154
- end
152
+ Fog::AWS.validate_region!(@region)
155
153
  end
156
154
 
157
155
  def data
@@ -49,9 +49,7 @@ module Fog
49
49
  @region = options[:region] || 'us-east-1'
50
50
  setup_credentials(options)
51
51
 
52
- unless ['ap-northeast-1', 'ap-southeast-1', 'ap-southeast-2', 'eu-central-1', 'eu-west-1', 'us-east-1', 'us-west-1', 'us-west-2', 'sa-east-1'].include?(@region)
53
- raise ArgumentError, "Unknown region: #{@region.inspect}"
54
- end
52
+ Fog::AWS.validate_region!(@region)
55
53
  end
56
54
 
57
55
  def setup_credentials(options)
@@ -49,9 +49,7 @@ module Fog
49
49
  @account_id = Fog::AWS::Mock.owner_id
50
50
  @module = "lambda"
51
51
 
52
- unless ['ap-northeast-1', 'ap-southeast-1', 'ap-southeast-2', 'eu-central-1', 'eu-west-1', 'us-east-1', 'us-west-1', 'us-west-2', 'sa-east-1'].include?(@region)
53
- raise ArgumentError, "Unknown region: #{@region.inspect}"
54
- end
52
+ Fog::AWS.validate_region!(@region)
55
53
  end
56
54
 
57
55
  def data
@@ -9,10 +9,11 @@ module Fog
9
9
  attribute :created_at, :aliases => 'createTime'
10
10
  attribute :delete_on_termination, :aliases => 'deleteOnTermination'
11
11
  attribute :device
12
+ attribute :encrypted
13
+ attribute :key_id, :aliases => ['KmsKeyId', 'kmsKeyId']
12
14
  attribute :iops
13
15
  attribute :server_id, :aliases => 'instanceId'
14
16
  attribute :size
15
- attribute :encrypted
16
17
  attribute :snapshot_id, :aliases => 'snapshotId'
17
18
  attribute :state, :aliases => 'status'
18
19
  attribute :tags, :aliases => 'tagSet'
@@ -44,9 +45,8 @@ module Fog
44
45
  requires :iops
45
46
  end
46
47
 
47
- data = service.create_volume(availability_zone, size, 'SnapshotId' => snapshot_id, 'VolumeType' => type, 'Iops' => iops, 'Encrypted' => encrypted).body
48
- new_attributes = data.reject {|key,value| key == 'requestId'}
49
- merge_attributes(new_attributes)
48
+ data = service.create_volume(availability_zone, size, create_params).body
49
+ merge_attributes(data)
50
50
 
51
51
  if tags = self.tags
52
52
  # expect eventual consistency
@@ -118,6 +118,16 @@ module Fog
118
118
  reload
119
119
  end
120
120
  end
121
+
122
+ def create_params
123
+ {
124
+ 'Encrypted' => encrypted,
125
+ 'KmsKeyId' => key_id,
126
+ 'Iops' => iops,
127
+ 'SnapshotId' => snapshot_id,
128
+ 'VolumeType' => type
129
+ }
130
+ end
121
131
  end
122
132
  end
123
133
  end
@@ -87,9 +87,14 @@ module Fog
87
87
 
88
88
  def promote_read_replica
89
89
  requires :id
90
- service.promote_read_replica(id)
90
+
91
+ data = service.promote_read_replica(id).body["PromoteReadReplicaResult"]["DBInstance"]
92
+
93
+ merge_attributes(data)
91
94
  end
92
95
 
96
+ alias promote promote_read_replica
97
+
93
98
  def modify(immediately, options)
94
99
  options[:security_group_names] ||= options['DBSecurityGroups']
95
100
  params = self.class.new(options).attributes_to_params
@@ -5,7 +5,7 @@ module Fog
5
5
  class CreateVolume < Fog::Parsers::Base
6
6
  def end_element(name)
7
7
  case name
8
- when 'availabilityZone', 'requestId', 'snapshotId', 'status', 'volumeId', 'volumeType'
8
+ when 'availabilityZone', 'requestId', 'snapshotId', 'status', 'volumeId', 'volumeType', 'kmsKeyId'
9
9
  @response[name] = value
10
10
  when 'createTime'
11
11
  @response[name] = Time.parse(value)
@@ -30,7 +30,7 @@ module Fog
30
30
  @attachment[name] = Time.parse(value)
31
31
  when 'deleteOnTermination'
32
32
  @attachment[name] = value == 'true'
33
- when 'device', 'instanceId', 'status', 'volumeId'
33
+ when 'device', 'instanceId', 'status', 'volumeId', 'kmsKeyId'
34
34
  @attachment[name] = value
35
35
  when 'item'
36
36
  @volume['attachmentSet'] << @attachment
@@ -4,6 +4,7 @@ module Fog
4
4
  extend Fog::AWS::CredentialFetcher::ServiceMethods
5
5
 
6
6
  class IdentifierTaken < Fog::Errors::Error; end
7
+ class InvalidParameterCombination < Fog::Errors::Error; end
7
8
 
8
9
  class AuthorizationAlreadyExists < Fog::Errors::Error; end
9
10
 
@@ -142,9 +143,7 @@ module Fog
142
143
  @use_iam_profile = options[:use_iam_profile]
143
144
  @region = options[:region] || 'us-east-1'
144
145
 
145
- unless ['ap-northeast-1', 'ap-southeast-1', 'ap-southeast-2', 'eu-central-1', 'eu-west-1', 'us-east-1', 'us-west-1', 'us-west-2', 'sa-east-1'].include?(@region)
146
- raise ArgumentError, "Unknown region: #{@region.inspect}"
147
- end
146
+ Fog::AWS.validate_region!(@region)
148
147
 
149
148
  setup_credentials(options)
150
149
  end
@@ -87,19 +87,24 @@ module Fog
87
87
  end
88
88
  end
89
89
 
90
+ if options['KmsKeyId'] && !options['Encrypted']
91
+ raise Fog::Compute::AWS::Error.new("InvalidParameterDependency => The parameter KmsKeyId requires the parameter Encrypted to be set.")
92
+ end
93
+
90
94
  response.status = 200
91
95
  volume_id = Fog::AWS::Mock.volume_id
92
96
  data = {
93
- 'availabilityZone' => availability_zone,
94
- 'attachmentSet' => [],
95
- 'createTime' => Time.now,
96
- 'iops' => options['Iops'],
97
- 'encrypted' => options['Encrypted'] || false,
98
- 'size' => size,
99
- 'snapshotId' => options['SnapshotId'],
100
- 'status' => 'creating',
101
- 'volumeId' => volume_id,
102
- 'volumeType' => options['VolumeType'] || 'standard'
97
+ 'availabilityZone' => availability_zone,
98
+ 'attachmentSet' => [],
99
+ 'createTime' => Time.now,
100
+ 'iops' => options['Iops'],
101
+ 'encrypted' => options['Encrypted'] || false,
102
+ 'size' => size,
103
+ 'snapshotId' => options['SnapshotId'],
104
+ 'kmsKeyId' => options['KmsKeyId'] || nil, # @todo validate
105
+ 'status' => 'creating',
106
+ 'volumeId' => volume_id,
107
+ 'volumeType' => options['VolumeType'] || 'standard'
103
108
  }
104
109
  self.data[:volumes][volume_id] = data
105
110
  response.body = {
@@ -78,6 +78,37 @@ module Fog
78
78
  end
79
79
  end
80
80
 
81
+ if !!options["MultiAZ"] && !!options["AvailabilityZone"]
82
+ raise Fog::AWS::RDS::InvalidParameterCombination.new('Requesting a specific availability zone is not valid for Multi-AZ instances.')
83
+ end
84
+
85
+ ec2 = Fog::Compute::AWS::Mock.data[@region][@aws_access_key_id]
86
+
87
+ db_security_group_names = Array(options.delete("DBSecurityGroups"))
88
+ rds_security_groups = self.data[:security_groups].values
89
+ ec2_security_groups = ec2[:security_groups].values
90
+ vpc = !ec2[:account_attributes].find { |h| "supported-platforms" == h["attributeName"] }["values"].include?("EC2")
91
+
92
+ db_security_groups = db_security_group_names.map do |group_name|
93
+ unless rds_security_groups.find { |sg| sg["DBSecurityGroupName"] == group_name }
94
+ raise Fog::AWS::RDS::Error.new("InvalidParameterValue => Invalid security group , groupId= , groupName=#{group_name}")
95
+ end
96
+
97
+ {"Status" => "active", "DBSecurityGroupName" => group_name }
98
+ end
99
+
100
+ if !vpc && db_security_groups.empty?
101
+ db_security_groups << { "Status" => "active", "DBSecurityGroupName" => "default" }
102
+ end
103
+
104
+ vpc_security_groups = Array(options.delete("VpcSecurityGroups")).map do |group_id|
105
+ unless ec2_security_groups.find { |sg| sg["groupId"] == group_id }
106
+ raise Fog::AWS::RDS::Error.new("InvalidParameterValue => Invalid security group , groupId=#{group_id} , groupName=")
107
+ end
108
+
109
+ {"Status" => "active", "VpcSecurityGroupId" => group_id }
110
+ end
111
+
81
112
  data = {
82
113
  "AllocatedStorage" => options["AllocatedStorage"],
83
114
  "AutoMinorVersionUpgrade" => options["AutoMinorVersionUpgrade"].nil? ? true : options["AutoMinorVersionUpgrade"],
@@ -89,7 +120,7 @@ module Fog
89
120
  "DBInstanceStatus" =>"creating",
90
121
  "DBName" => options["DBName"],
91
122
  "DBParameterGroups" => [{ "DBParameterGroupName" => "default.mysql5.5", "ParameterApplyStatus" => "in-sync" }],
92
- "DBSecurityGroups" => [{ "Status" => "active", "DBSecurityGroupName" => "default" }],
123
+ "DBSecurityGroups" => db_security_groups,
93
124
  "DBSubnetGroupName" => options["DBSubnetGroupName"],
94
125
  "Endpoint" =>{},
95
126
  "Engine" => options["Engine"],
@@ -98,7 +129,7 @@ module Fog
98
129
  "Iops" => options["Iops"],
99
130
  "LicenseModel" => "general-public-license",
100
131
  "MasterUsername" => options["MasterUsername"],
101
- "MultiAZ" => !!options['MultiAZ'],
132
+ "MultiAZ" => !!options["MultiAZ"],
102
133
  "PendingModifiedValues" => { "MasterUserPassword" => "****" }, # This clears when is available
103
134
  "PreferredBackupWindow" => options["PreferredBackupWindow"] || "08:00-08:30",
104
135
  "PreferredMaintenanceWindow" => options["PreferredMaintenanceWindow"] || "mon:04:30-mon:05:00",
@@ -106,7 +137,7 @@ module Fog
106
137
  "ReadReplicaDBInstanceIdentifiers" => [],
107
138
  "StorageEncrypted" => options["StorageEncrypted"] || false,
108
139
  "StorageType" => options["StorageType"] || "standard",
109
- "VpcSecurityGroups" => options["VpcSecurityGroups"],
140
+ "VpcSecurityGroups" => vpc_security_groups,
110
141
  }
111
142
 
112
143
  self.data[:servers][db_name] = data
@@ -61,6 +61,7 @@ module Fog
61
61
  'ReadReplicaSourceDBInstanceIdentifier' => source_identifier,
62
62
  'StorageType' => options['StorageType'] || 'standard',
63
63
  'StorageEncrypted' => false,
64
+ 'VpcSecurityGroups' => source['VpcSecurityGroups'],
64
65
  }
65
66
  self.data[:servers][instance_identifier] = data
66
67
  self.data[:servers][source_identifier]['ReadReplicaDBInstanceIdentifiers'] << instance_identifier
@@ -77,7 +77,7 @@ module Fog
77
77
 
78
78
  response.status = 200
79
79
  response.body = {
80
- "ResponseMetadata"=>{ "RequestId"=> Fog::AWS::Mock.request_id },
80
+ "ResponseMetadata" => { "RequestId" => Fog::AWS::Mock.request_id },
81
81
  "DescribeDBInstancesResult" => { "DBInstances" => server_set }
82
82
  }
83
83
  response
@@ -35,11 +35,12 @@ module Fog
35
35
  response = Excon::Response.new
36
36
  snapshots = self.data[:snapshots].values
37
37
  if opts[:identifier]
38
- snapshots = snapshots.select{|snapshot| snapshot['DBInstanceIdentifier'] == opts[:identifier]}
38
+ snapshots = snapshots.select { |snapshot| snapshot['DBInstanceIdentifier'] == opts[:identifier] }
39
+
39
40
  end
40
41
 
41
42
  if opts[:snapshot_id]
42
- snapshots = snapshots.select{|snapshot| snapshot['DBSnapshotIdentifier'] == opts[:snapshot_id]}
43
+ snapshots = snapshots.select { |snapshot| snapshot['DBSnapshotIdentifier'] == opts[:snapshot_id] }
43
44
  raise Fog::AWS::RDS::NotFound.new("DBSnapshot #{opts[:snapshot_id]} not found") if snapshots.empty?
44
45
  end
45
46
 
@@ -46,10 +46,11 @@ module Fog
46
46
  end
47
47
 
48
48
  class Mock
49
- def modify_db_instance(db_name, apply_immediately, options={})
49
+ def modify_db_instance(db_name, apply_immediately, _options={})
50
+ options = _options
50
51
  response = Excon::Response.new
51
- if self.data[:servers][db_name]
52
- if self.data[:servers][db_name]["DBInstanceStatus"] != "available"
52
+ if server = self.data[:servers][db_name]
53
+ if server["DBInstanceStatus"] != "available"
53
54
  raise Fog::AWS::RDS::NotFound.new("DBInstance #{db_name} not available for modification")
54
55
  else
55
56
  self.data[:modify_time] = Time.now
@@ -61,11 +62,38 @@ module Fog
61
62
  #else
62
63
  # modified_server = server["PendingModifiedValues"].merge!(options) # it appends
63
64
  #end
65
+
66
+ db_security_group_names = Array(options.delete("DBSecurityGroups"))
67
+
68
+ rds_security_groups = self.data[:security_groups].values
69
+
70
+ db_security_groups = db_security_group_names.map do |r, group_name|
71
+ unless rds_security_groups.find { |sg| sg["DBSecurityGroupName"] == group_name }
72
+ raise Fog::AWS::RDS::Error.new("InvalidParameterValue => Invalid security group , groupId= , groupName=#{group_name}")
73
+ end
74
+ r << {"Status" => "active", "DBSecurityGroupName" => group_name }
75
+ end
76
+
77
+ ec2_security_groups = Fog::Compute::AWS::Mock.data[@region][@aws_access_key_id][:security_groups].values
78
+
79
+ vpc_security_groups = Array(options.delete("VpcSecurityGroups")).map do |group_id|
80
+ unless ec2_security_groups.find { |sg| sg["groupId"] == group_id }
81
+ raise Fog::AWS::RDS::Error.new("InvalidParameterValue => Invalid security group , groupId=#{group_id} , groupName=")
82
+ end
83
+
84
+ {"Status" => "active", "VpcSecurityGroupId" => group_id }
85
+ end
86
+
87
+ options.merge!(
88
+ "DBSecurityGroups" => db_security_groups,
89
+ "VpcSecurityGroups" => vpc_security_groups
90
+ )
91
+
64
92
  self.data[:servers][db_name]["PendingModifiedValues"].merge!(options) # it appends
65
93
  self.data[:servers][db_name]["DBInstanceStatus"] = "modifying"
66
94
  response.status = 200
67
95
  response.body = {
68
- "ResponseMetadata"=>{ "RequestId"=> Fog::AWS::Mock.request_id },
96
+ "ResponseMetadata" => { "RequestId" => Fog::AWS::Mock.request_id },
69
97
  "ModifyDBInstanceResult" => { "DBInstance" => self.data[:servers][db_name] }
70
98
  }
71
99
  response
@@ -25,34 +25,43 @@ module Fog
25
25
  params['BackupRetentionPeriod'] = backup_retention_period if backup_retention_period
26
26
  params['PreferredBackupWindow'] = preferred_backup_window if preferred_backup_window
27
27
  request({
28
- 'Action' => 'PromoteReadReplica',
28
+ 'Action' => 'PromoteReadReplica',
29
29
  'DBInstanceIdentifier' => identifier,
30
- :parser => Fog::Parsers::AWS::RDS::PromoteReadReplica.new
30
+ :parser => Fog::Parsers::AWS::RDS::PromoteReadReplica.new
31
31
  }.merge(params))
32
32
  end
33
33
  end
34
34
 
35
35
  class Mock
36
36
  def promote_read_replica(identifier, backup_retention_period = nil, preferred_backup_window = nil)
37
- if self.data[:servers][identifier]
38
- data = {
39
- 'BackupRetentionPeriod' => backup_retention_period || 1,
40
- 'PreferredBackupWindow' => preferred_backup_window || '08:00-08:30',
41
- 'DBInstanceIdentifier' => identifier,
42
- }
37
+ server = self.data[:servers][identifier]
38
+ server || raise(Fog::AWS::RDS::NotFound.new("DBInstance #{identifier} not found"))
39
+
40
+ if server["ReadReplicaSourceDBInstanceIdentifier"].nil?
41
+ raise(Fog::AWS::RDS::Error.new("InvalidDBInstanceState => DB Instance is not a read replica."))
42
+ end
43
43
 
44
- db_instance = self.data[:servers][identifier].merge(data)
44
+ self.data[:modify_time] = Time.now
45
45
 
46
- response = Excon::Response.new
47
- response.body = {
48
- "ResponseMetadata" => { "RequestId" => Fog::AWS::Mock.request_id },
49
- "PromoteReadReplicaResult" => { "DBInstance" => db_instance }
46
+ data = {
47
+ 'BackupRetentionPeriod' => backup_retention_period || 1,
48
+ 'PreferredBackupWindow' => preferred_backup_window || '08:00-08:30',
49
+ 'DBInstanceIdentifier' => identifier,
50
+ 'DBInstanceStatus' => "modifying",
51
+ 'PendingModifiedValues' => {
52
+ 'ReadReplicaSourceDBInstanceIdentifier' => nil,
50
53
  }
51
- response.status = 200
52
- response
53
- else
54
- raise Fog::AWS::RDS::NotFound.new("DBInstance #{identifier} not found")
55
- end
54
+ }
55
+
56
+ server.merge!(data)
57
+
58
+ response = Excon::Response.new
59
+ response.body = {
60
+ "ResponseMetadata" => { "RequestId" => Fog::AWS::Mock.request_id },
61
+ "PromoteReadReplicaResult" => { "DBInstance" => server }
62
+ }
63
+ response.status = 200
64
+ response
56
65
  end
57
66
  end
58
67
  end
@@ -36,7 +36,7 @@ module Fog
36
36
  QueueConfiguration do
37
37
  Id queue['Id']
38
38
  Queue queue['Queue']
39
- Event topic['Event']
39
+ Event queue['Event']
40
40
  end
41
41
  end
42
42
  notification.fetch('CloudFunctions', []).each do |func|
@@ -47,9 +47,7 @@ module Fog
47
47
  @account_id = Fog::AWS::Mock.owner_id
48
48
  @module = "sns"
49
49
 
50
- unless ['ap-northeast-1', 'ap-southeast-1', 'ap-southeast-2', 'eu-central-1', 'eu-west-1', 'us-east-1', 'us-west-1', 'us-west-2', 'sa-east-1'].include?(@region)
51
- raise ArgumentError, "Unknown region: #{@region.inspect}"
52
- end
50
+ Fog::AWS.validate_region!(@region)
53
51
  end
54
52
 
55
53
  def data
@@ -38,9 +38,7 @@ module Fog
38
38
  setup_credentials(options)
39
39
  @region = options[:region] || 'us-east-1'
40
40
 
41
- unless ['ap-northeast-1', 'ap-southeast-1', 'ap-southeast-2', 'eu-central-1', 'eu-west-1', 'us-east-1', 'us-west-1', 'us-west-2', 'sa-east-1'].include?(@region)
42
- raise ArgumentError, "Unknown region: #{@region.inspect}"
43
- end
41
+ Fog::AWS.validate_region!(@region)
44
42
  end
45
43
 
46
44
  def data
@@ -606,7 +606,7 @@ module Fog
606
606
  Fog::Logger.warning("fog: followed redirect to #{host}, connecting to the matching region will be more performant")
607
607
  original_region, original_signer = @region, @signer
608
608
  @region = @new_region || case new_params[:host]
609
- when 's3.amazonaws.com', 's3-external-1.amazonaws.com'
609
+ when /s3.amazonaws.com/, /s3-external-1.amazonaws.com/
610
610
  DEFAULT_REGION
611
611
  else
612
612
  %r{s3[\.\-]([^\.]*).amazonaws.com}.match(new_params[:host]).captures.first
@@ -1,5 +1,5 @@
1
1
  module Fog
2
2
  module AWS
3
- VERSION = "0.7.4"
3
+ VERSION = "0.7.5"
4
4
  end
5
5
  end
@@ -87,8 +87,9 @@ Shindo.tests("AWS::RDS | server", ['aws', 'rds']) do
87
87
  @instance.wait_for { state == 'rebooting' }
88
88
  @instance.wait_for { ready? }
89
89
 
90
- tests('#create_read_replica').succeeds do
90
+ replica = nil
91
91
 
92
+ tests('#create_read_replica').succeeds do
92
93
  replica = @instance_with_final_snapshot.create_read_replica(uniq_id('fog-replica'))
93
94
  @instance_with_final_snapshot.reload
94
95
  returns([replica.id]) { @instance_with_final_snapshot.read_replica_identifiers }
@@ -98,10 +99,20 @@ Shindo.tests("AWS::RDS | server", ['aws', 'rds']) do
98
99
 
99
100
  # FinalDBSnapshotIdentifier can not be specified when deleting a replica instance
100
101
  raises(Fog::AWS::RDS::Error) { replica.destroy("foobar") }
102
+ end
101
103
 
102
- replica.destroy
104
+ tests('#promote_read_replica').succeeds do
105
+ replica.promote.wait_for { state != "modifying" }
106
+
107
+ replica.read_replica_source == nil
103
108
  end
104
109
 
110
+ tests('#promote_read_replica', 'master').raises(Fog::AWS::RDS::Error) {
111
+ @instance_with_final_snapshot.promote
112
+ }
113
+
114
+ replica && replica.destroy
115
+
105
116
  test("Destroying with a final snapshot") do
106
117
  final_snapshot_id = uniq_id('fog-test-snapshot')
107
118
 
@@ -1,25 +1,25 @@
1
1
  Shindo.tests('Fog::Compute[:aws] | volume requests', ['aws']) do
2
2
 
3
3
  @volume_format = {
4
- 'availabilityZone' => String,
5
- 'createTime' => Time,
6
- 'encrypted' => Fog::Boolean,
7
- 'iops' => Fog::Nullable::Integer,
8
- 'requestId' => String,
9
- 'size' => Integer,
10
- 'snapshotId' => Fog::Nullable::String,
11
- 'status' => String,
12
- 'volumeId' => String,
13
- 'volumeType' => String
4
+ 'availabilityZone' => String,
5
+ 'createTime' => Time,
6
+ 'encrypted' => Fog::Boolean,
7
+ 'iops' => Fog::Nullable::Integer,
8
+ 'requestId' => String,
9
+ 'size' => Integer,
10
+ 'snapshotId' => Fog::Nullable::String,
11
+ 'status' => String,
12
+ 'volumeId' => String,
13
+ 'volumeType' => String
14
14
  }
15
15
 
16
16
  @volume_attachment_format = {
17
- 'attachTime' => Time,
18
- 'device' => String,
19
- 'instanceId' => String,
20
- 'requestId' => String,
21
- 'status' => String,
22
- 'volumeId' => String
17
+ 'attachTime' => Time,
18
+ 'device' => String,
19
+ 'instanceId' => String,
20
+ 'requestId' => String,
21
+ 'status' => String,
22
+ 'volumeId' => String
23
23
  }
24
24
 
25
25
  @volume_status_format = {
@@ -52,17 +52,18 @@ Shindo.tests('Fog::Compute[:aws] | volume requests', ['aws']) do
52
52
 
53
53
  @volumes_format = {
54
54
  'volumeSet' => [{
55
- 'availabilityZone' => String,
56
- 'attachmentSet' => Array,
57
- 'createTime' => Time,
58
- 'encrypted' => Fog::Boolean,
59
- 'iops' => Fog::Nullable::Integer,
60
- 'size' => Integer,
61
- 'snapshotId' => Fog::Nullable::String,
62
- 'status' => String,
63
- 'tagSet' => Hash,
64
- 'volumeId' => String,
65
- 'volumeType' => String
55
+ 'availabilityZone' => String,
56
+ 'attachmentSet' => Array,
57
+ 'createTime' => Time,
58
+ 'encrypted' => Fog::Boolean,
59
+ 'iops' => Fog::Nullable::Integer,
60
+ 'size' => Integer,
61
+ 'snapshotId' => Fog::Nullable::String,
62
+ 'kmsKeyId' => Fog::Nullable::String,
63
+ 'status' => String,
64
+ 'tagSet' => Hash,
65
+ 'volumeId' => String,
66
+ 'volumeType' => String
66
67
  }],
67
68
  'requestId' => String
68
69
  }
@@ -83,7 +84,11 @@ Shindo.tests('Fog::Compute[:aws] | volume requests', ['aws']) do
83
84
 
84
85
  tests('#create_volume from snapshot').formats(@volume_format) do
85
86
  volume = Fog::Compute[:aws].volumes.create(:availability_zone => 'us-east-1d', :size => 1)
87
+ volume.wait_for { ready? }
88
+
86
89
  snapshot = Fog::Compute[:aws].create_snapshot(volume.identity).body
90
+ Fog::Compute[:aws].snapshots.new(snapshot).wait_for { ready? }
91
+
87
92
  data = Fog::Compute[:aws].create_volume(@server.availability_zone, nil, 'SnapshotId' => snapshot['snapshotId']).body
88
93
  @volume_id = data['volumeId']
89
94
  data
@@ -99,9 +104,21 @@ Shindo.tests('Fog::Compute[:aws] | volume requests', ['aws']) do
99
104
 
100
105
  Fog::Compute[:aws].delete_volume(@volume_id)
101
106
 
107
+ tests('#create_volume with encryption').returns(true) do
108
+ volume = Fog::Compute[:aws].volumes.create(:availability_zone => 'us-east-1d', :size => 1, :encrypted => true)
109
+ @volume_id = volume.id
110
+ volume.reload.encrypted
111
+ end
112
+
113
+ Fog::Compute[:aws].delete_volume(@volume_id)
114
+
102
115
  tests('#create_volume from snapshot with size').formats(@volume_format) do
103
116
  volume = Fog::Compute[:aws].volumes.create(:availability_zone => 'us-east-1d', :size => 1)
117
+ volume.wait_for { ready? }
118
+
104
119
  snapshot = Fog::Compute[:aws].create_snapshot(volume.identity).body
120
+ Fog::Compute[:aws].snapshots.new(snapshot).wait_for { ready? }
121
+
105
122
  data = Fog::Compute[:aws].create_volume(@server.availability_zone, 1, 'SnapshotId' => snapshot['snapshotId']).body
106
123
  @volume_id = data['volumeId']
107
124
  data
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fog-aws
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.4
4
+ version: 0.7.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Lane
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-07-30 00:00:00.000000000 Z
12
+ date: 2015-08-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -693,7 +693,6 @@ files:
693
693
  - lib/fog/aws/parsers/sts/get_session_token.rb
694
694
  - lib/fog/aws/rds.rb
695
695
  - lib/fog/aws/redshift.rb
696
- - lib/fog/aws/region_methods.rb
697
696
  - lib/fog/aws/requests/auto_scaling/attach_load_balancers.rb
698
697
  - lib/fog/aws/requests/auto_scaling/create_auto_scaling_group.rb
699
698
  - lib/fog/aws/requests/auto_scaling/create_launch_configuration.rb
@@ -1,11 +0,0 @@
1
- module Fog
2
- module AWS
3
- module RegionMethods
4
- def validate_aws_region(host, region)
5
- if host.end_with?('.amazonaws.com') && !['ap-northeast-1', 'ap-southeast-1', 'ap-southeast-2', 'eu-west-1', 'us-east-1', 'us-west-1', 'us-west-2', 'sa-east-1', 'us-gov-west-1', 'eu-central-1'].include?(region)
6
- raise ArgumentError, "Unknown region: #{region.inspect}"
7
- end
8
- end
9
- end
10
- end
11
- end