fog-aws 0.6.0 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/fog/aws.rb +3 -1
- data/lib/fog/aws/errors.rb +3 -3
- data/lib/fog/aws/kinesis.rb +187 -0
- data/lib/fog/aws/lambda.rb +10 -2
- data/lib/fog/aws/models/dns/zones.rb +2 -2
- data/lib/fog/aws/parsers/compute/describe_route_tables.rb +3 -3
- data/lib/fog/aws/parsers/compute/describe_vpcs.rb +1 -1
- data/lib/fog/aws/requests/compute/describe_route_tables.rb +1 -0
- data/lib/fog/aws/requests/dns/change_resource_record_sets.rb +116 -107
- data/lib/fog/aws/requests/kinesis/add_tags_to_stream.rb +48 -0
- data/lib/fog/aws/requests/kinesis/create_stream.rb +70 -0
- data/lib/fog/aws/requests/kinesis/delete_stream.rb +45 -0
- data/lib/fog/aws/requests/kinesis/describe_stream.rb +54 -0
- data/lib/fog/aws/requests/kinesis/get_records.rb +72 -0
- data/lib/fog/aws/requests/kinesis/get_shard_iterator.rb +53 -0
- data/lib/fog/aws/requests/kinesis/list_streams.rb +40 -0
- data/lib/fog/aws/requests/kinesis/list_tags_for_stream.rb +57 -0
- data/lib/fog/aws/requests/kinesis/merge_shards.rb +85 -0
- data/lib/fog/aws/requests/kinesis/put_record.rb +70 -0
- data/lib/fog/aws/requests/kinesis/put_records.rb +68 -0
- data/lib/fog/aws/requests/kinesis/remove_tags_from_stream.rb +49 -0
- data/lib/fog/aws/requests/kinesis/split_shard.rb +85 -0
- data/lib/fog/aws/storage.rb +4 -8
- data/lib/fog/aws/version.rb +1 -1
- data/tests/helpers/mock_helper.rb +0 -1
- data/tests/requests/compute/route_tests.rb +8 -7
- data/tests/requests/dns/change_resource_record_sets_tests.rb +26 -2
- data/tests/requests/emr/helper.rb +0 -1
- data/tests/requests/kinesis/helper.rb +111 -0
- data/tests/requests/kinesis/stream_tests.rb +169 -0
- metadata +19 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84e01817c525f630628cc5228b64c4887fe88936
|
4
|
+
data.tar.gz: 54c9b3172b779d70f2a3ac3b373762b805dbee1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96d2bf8959b64f8b25c48082b620234f6c9a02d447f26266b93f2ee74dacda96f3f62aab5937aca0504b0addb80a4abbcf736463b6aef9bf4dd13c1b8b7dd356
|
7
|
+
data.tar.gz: 4a03a295b335373298ff9ddb808d31c5d49a1772f3cbab159b123613c0cc10b74ea61805491f78f9c70879364ce2dae35b9a3d2e8ab4ea06f5ddc88a56df8276
|
data/lib/fog/aws.rb
CHANGED
@@ -44,6 +44,7 @@ module Fog
|
|
44
44
|
autoload :Federation, File.expand_path('../aws/federation', __FILE__)
|
45
45
|
autoload :Glacier, File.expand_path('../aws/glacier', __FILE__)
|
46
46
|
autoload :IAM, File.expand_path('../aws/iam', __FILE__)
|
47
|
+
autoload :Kinesis, File.expand_path('../aws/kinesis', __FILE__)
|
47
48
|
autoload :KMS, File.expand_path('../aws/kms', __FILE__)
|
48
49
|
autoload :Lambda, File.expand_path('../aws/lambda', __FILE__)
|
49
50
|
autoload :RDS, File.expand_path('../aws/rds', __FILE__)
|
@@ -70,6 +71,7 @@ module Fog
|
|
70
71
|
service(:federation, 'Federation')
|
71
72
|
service(:glacier, 'Glacier')
|
72
73
|
service(:iam, 'IAM')
|
74
|
+
service(:kinesis, 'Kinesis')
|
73
75
|
service(:kms, 'KMS')
|
74
76
|
service(:lambda, 'Lambda')
|
75
77
|
service(:rds, 'RDS')
|
@@ -219,7 +221,7 @@ module Fog
|
|
219
221
|
|
220
222
|
def self.json_response?(response)
|
221
223
|
return false unless response && response.headers
|
222
|
-
response.get_header('Content-Type') =~ %r{application
|
224
|
+
response.get_header('Content-Type') =~ %r{application/.*json.*}i ? true : false
|
223
225
|
end
|
224
226
|
end
|
225
227
|
end
|
data/lib/fog/aws/errors.rb
CHANGED
@@ -17,9 +17,9 @@ module Fog
|
|
17
17
|
begin
|
18
18
|
full_msg_error = Fog::JSON.decode(error.response.body)
|
19
19
|
if (full_msg_error.has_key?('Message') || full_msg_error.has_key?('message')) &&
|
20
|
-
|
20
|
+
(error.response.headers.has_key?('x-amzn-ErrorType') || full_msg_error.has_key?('__type'))
|
21
21
|
matched_error = {
|
22
|
-
:code => error.response.headers['x-amzn-ErrorType'].split(':').first,
|
22
|
+
:code => full_msg_error['__type'] || error.response.headers['x-amzn-ErrorType'].split(':').first,
|
23
23
|
:message => full_msg_error['Message'] || full_msg_error['message']
|
24
24
|
}
|
25
25
|
return matched_error
|
@@ -32,4 +32,4 @@ module Fog
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
35
|
-
end
|
35
|
+
end
|
@@ -0,0 +1,187 @@
|
|
1
|
+
module Fog
|
2
|
+
module AWS
|
3
|
+
class Kinesis < Fog::Service
|
4
|
+
extend Fog::AWS::CredentialFetcher::ServiceMethods
|
5
|
+
|
6
|
+
class ExpiredIterator < Fog::Errors::Error; end
|
7
|
+
class LimitExceeded < Fog::Errors::Error; end
|
8
|
+
class ResourceInUse < Fog::Errors::Error; end
|
9
|
+
class ResourceNotFound < Fog::Errors::Error; end
|
10
|
+
class ExpiredIterator < Fog::Errors::Error; end
|
11
|
+
class InvalidArgument < Fog::Errors::Error; end
|
12
|
+
class ProvisionedThroughputExceeded < Fog::Errors::Error; end
|
13
|
+
|
14
|
+
requires :aws_access_key_id, :aws_secret_access_key
|
15
|
+
recognizes :region, :host, :path, :port, :scheme, :persistent, :use_iam_profile, :aws_session_token, :aws_credentials_expire_at, :instrumentor, :instrumentor_name
|
16
|
+
|
17
|
+
request_path 'fog/aws/requests/kinesis'
|
18
|
+
|
19
|
+
request :add_tags_to_stream
|
20
|
+
request :create_stream
|
21
|
+
request :delete_stream
|
22
|
+
request :describe_stream
|
23
|
+
request :get_records
|
24
|
+
request :get_shard_iterator
|
25
|
+
request :list_streams
|
26
|
+
request :list_tags_for_stream
|
27
|
+
request :merge_shards
|
28
|
+
request :put_record
|
29
|
+
request :put_records
|
30
|
+
request :remove_tags_from_stream
|
31
|
+
request :split_shard
|
32
|
+
|
33
|
+
class Real
|
34
|
+
include Fog::AWS::CredentialFetcher::ConnectionMethods
|
35
|
+
|
36
|
+
def initialize(options={})
|
37
|
+
@use_iam_profile = options[:use_iam_profile]
|
38
|
+
|
39
|
+
@connection_options = options[:connection_options] || {}
|
40
|
+
|
41
|
+
@instrumentor = options[:instrumentor]
|
42
|
+
@instrumentor_name = options[:instrumentor_name] || 'fog.aws.kinesis'
|
43
|
+
|
44
|
+
options[:region] ||= 'us-east-1'
|
45
|
+
@region = options[:region]
|
46
|
+
@host = options[:host] || "kinesis.#{options[:region]}.amazonaws.com"
|
47
|
+
@path = options[:path] || '/'
|
48
|
+
@persistent = options[:persistent] || true
|
49
|
+
@port = options[:port] || 443
|
50
|
+
@scheme = options[:scheme] || 'https'
|
51
|
+
@connection = Fog::XML::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", @persistent, @connection_options)
|
52
|
+
@version = "20131202"
|
53
|
+
|
54
|
+
setup_credentials(options)
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def setup_credentials(options)
|
60
|
+
@aws_access_key_id = options[:aws_access_key_id]
|
61
|
+
@aws_secret_access_key = options[:aws_secret_access_key]
|
62
|
+
@aws_session_token = options[:aws_session_token]
|
63
|
+
@aws_credentials_expire_at = options[:aws_credentials_expire_at]
|
64
|
+
|
65
|
+
@signer = Fog::AWS::SignatureV4.new( @aws_access_key_id, @aws_secret_access_key, @region, 'kinesis')
|
66
|
+
end
|
67
|
+
|
68
|
+
def request(params)
|
69
|
+
refresh_credentials_if_expired
|
70
|
+
idempotent = params.delete(:idempotent)
|
71
|
+
parser = params.delete(:parser)
|
72
|
+
|
73
|
+
date = Fog::Time.now
|
74
|
+
headers = {
|
75
|
+
'X-Amz-Target' => params['X-Amz-Target'],
|
76
|
+
'Content-Type' => 'application/x-amz-json-1.1',
|
77
|
+
'Host' => @host,
|
78
|
+
'x-amz-date' => date.to_iso8601_basic
|
79
|
+
}
|
80
|
+
headers['x-amz-security-token'] = @aws_session_token if @aws_session_token
|
81
|
+
body = MultiJson.dump(params[:body])
|
82
|
+
headers['Authorization'] = @signer.sign({:method => "POST", :headers => headers, :body => body, :query => {}, :path => @path}, date)
|
83
|
+
|
84
|
+
if @instrumentor
|
85
|
+
@instrumentor.instrument("#{@instrumentor_name}.request", params) do
|
86
|
+
_request(body, headers, idempotent, parser)
|
87
|
+
end
|
88
|
+
else
|
89
|
+
_request(body, headers, idempotent, parser)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def _request(body, headers, idempotent, parser)
|
94
|
+
@connection.request({
|
95
|
+
:body => body,
|
96
|
+
:expects => 200,
|
97
|
+
:headers => headers,
|
98
|
+
:idempotent => idempotent,
|
99
|
+
:method => 'POST',
|
100
|
+
:parser => parser
|
101
|
+
})
|
102
|
+
rescue Excon::Errors::HTTPStatusError => error
|
103
|
+
match = Fog::AWS::Errors.match_error(error)
|
104
|
+
raise if match.empty?
|
105
|
+
raise case match[:code]
|
106
|
+
when 'ExpiredIteratorException'
|
107
|
+
Fog::AWS::Kinesis::ExpiredIterator.slurp(error, match[:message])
|
108
|
+
when 'LimitExceededException'
|
109
|
+
Fog::AWS::Kinesis::LimitExceeded.slurp(error, match[:message])
|
110
|
+
when 'ResourceInUseException'
|
111
|
+
Fog::AWS::Kinesis::ResourceInUse.slurp(error, match[:message])
|
112
|
+
when 'ResourceNotFoundException'
|
113
|
+
Fog::AWS::Kinesis::ResourceNotFound.slurp(error, match[:message])
|
114
|
+
when 'ExpiredIteratorException'
|
115
|
+
Fog::AWS::Kinesis::ExpiredIterator.slurp(error, match[:message])
|
116
|
+
when 'InvalidArgumentException'
|
117
|
+
Fog::AWS::Kinesis::InvalidArgument.slurp(error, match[:message])
|
118
|
+
when 'ProvisionedThroughputExceededException'
|
119
|
+
Fog::AWS::Kinesis::ProvisionedThroughputExceeded.slurp(error, match[:message])
|
120
|
+
else
|
121
|
+
Fog::AWS::Kinesis::Error.slurp(error, "#{match[:code]} => #{match[:message]}")
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
class Mock
|
128
|
+
def self.mutex
|
129
|
+
@mutex ||= Mutex.new
|
130
|
+
end
|
131
|
+
def mutex; self.class.mutex; end
|
132
|
+
|
133
|
+
def self.data
|
134
|
+
@data ||= Hash.new do |hash, region|
|
135
|
+
hash[region] = Hash.new do |region_hash, key|
|
136
|
+
region_hash[key] = {
|
137
|
+
:kinesis_streams => {}
|
138
|
+
}
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def self.reset
|
144
|
+
@data = nil
|
145
|
+
end
|
146
|
+
|
147
|
+
def initialize(options={})
|
148
|
+
@account_id = Fog::AWS::Mock.owner_id
|
149
|
+
@aws_access_key_id = options[:aws_access_key_id]
|
150
|
+
@region = options[:region] || 'us-east-1'
|
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
|
155
|
+
end
|
156
|
+
|
157
|
+
def data
|
158
|
+
self.class.data[@region][@aws_access_key_id]
|
159
|
+
end
|
160
|
+
|
161
|
+
def reset_data
|
162
|
+
self.class.data[@region].delete(@aws_access_key_id)
|
163
|
+
end
|
164
|
+
|
165
|
+
def self.next_sequence_number
|
166
|
+
mutex.synchronize do
|
167
|
+
@sequence_number ||= -1
|
168
|
+
@sequence_number += 1
|
169
|
+
@sequence_number.to_s
|
170
|
+
end
|
171
|
+
end
|
172
|
+
def next_sequence_number; self.class.next_sequence_number; end
|
173
|
+
|
174
|
+
def self.next_shard_id
|
175
|
+
mutex.synchronize do
|
176
|
+
@shard_id ||= -1
|
177
|
+
@shard_id += 1
|
178
|
+
"shardId-#{@shard_id.to_s.rjust(12, "0")}"
|
179
|
+
end
|
180
|
+
end
|
181
|
+
def next_shard_id; self.class.next_shard_id; end
|
182
|
+
|
183
|
+
end
|
184
|
+
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
data/lib/fog/aws/lambda.rb
CHANGED
@@ -124,7 +124,8 @@ module Fog
|
|
124
124
|
|
125
125
|
idempotent = params.delete(:idempotent)
|
126
126
|
parser = params.delete(:parser)
|
127
|
-
|
127
|
+
path = params.delete(:path)
|
128
|
+
request_path = "/#{@version}#{path}"
|
128
129
|
query = params.delete(:query) || {}
|
129
130
|
method = params.delete(:method) || 'POST'
|
130
131
|
expects = params.delete(:expects) || 200
|
@@ -132,6 +133,13 @@ module Fog
|
|
132
133
|
|
133
134
|
headers.merge!(params[:headers] || {})
|
134
135
|
|
136
|
+
request_path_to_sign = case path
|
137
|
+
when %r{^/functions/([0-9a-zA-Z\:\-\_]+)(/.+)?$}
|
138
|
+
"/#{@version}/functions/#{Fog::AWS.escape($~[1])}#{$~[2]}"
|
139
|
+
else
|
140
|
+
request_path
|
141
|
+
end
|
142
|
+
|
135
143
|
body, headers = AWS.signed_params_v4(
|
136
144
|
params,
|
137
145
|
headers,
|
@@ -140,7 +148,7 @@ module Fog
|
|
140
148
|
:aws_session_token => @aws_session_token,
|
141
149
|
:signer => @signer,
|
142
150
|
:host => @host,
|
143
|
-
:path =>
|
151
|
+
:path => request_path_to_sign,
|
144
152
|
:port => @port,
|
145
153
|
:query => query,
|
146
154
|
:body => params[:body]
|
@@ -10,8 +10,8 @@ module Fog
|
|
10
10
|
model Fog::DNS::AWS::Zone
|
11
11
|
|
12
12
|
def all(options = {})
|
13
|
-
options[
|
14
|
-
options[
|
13
|
+
options[:marker] ||= marker
|
14
|
+
options[:maxitems] ||= max_items
|
15
15
|
data = service.list_hosted_zones(options).body['HostedZones']
|
16
16
|
load(data)
|
17
17
|
end
|
@@ -7,7 +7,7 @@ module Fog
|
|
7
7
|
@association = { 'routeTableAssociationId' => nil, 'routeTableId' => nil, 'subnetId' => nil, 'main' => false }
|
8
8
|
@in_association_set = false
|
9
9
|
@in_route_set = false
|
10
|
-
@route = { 'destinationCidrBlock' => nil, 'gatewayId' => nil, 'instanceId' => nil, 'instanceOwnerId' => nil, 'networkInterfaceId' => nil, 'state' => nil, 'origin' => nil }
|
10
|
+
@route = { 'destinationCidrBlock' => nil, 'gatewayId' => nil, 'instanceId' => nil, 'instanceOwnerId' => nil, 'networkInterfaceId' => nil, 'vpcPeeringConnectionId' => nil, 'state' => nil, 'origin' => nil }
|
11
11
|
@response = { 'routeTableSet' => [] }
|
12
12
|
@tag = {}
|
13
13
|
@route_table = { 'associationSet' => [], 'tagSet' => {}, 'routeSet' => [] }
|
@@ -54,11 +54,11 @@ module Fog
|
|
54
54
|
end
|
55
55
|
elsif @in_route_set
|
56
56
|
case name
|
57
|
-
when 'destinationCidrBlock', 'gatewayId', 'instanceId', 'instanceOwnerId', 'networkInterfaceId', 'state', 'origin'
|
57
|
+
when 'destinationCidrBlock', 'gatewayId', 'instanceId', 'instanceOwnerId', 'networkInterfaceId', 'vpcPeeringConnectionId', 'state', 'origin'
|
58
58
|
@route[name] = value
|
59
59
|
when 'item'
|
60
60
|
@route_table['routeSet'] << @route
|
61
|
-
@route = { 'destinationCidrBlock' => nil, 'gatewayId' => nil, 'instanceId' => nil, 'instanceOwnerId' => nil, 'networkInterfaceId' => nil, 'state' => nil, 'origin' => nil }
|
61
|
+
@route = { 'destinationCidrBlock' => nil, 'gatewayId' => nil, 'instanceId' => nil, 'instanceOwnerId' => nil, 'networkInterfaceId' => nil, 'vpcPeeringConnectionId' => nil, 'state' => nil, 'origin' => nil }
|
62
62
|
when 'routeSet'
|
63
63
|
@in_route_set = false
|
64
64
|
end
|
@@ -30,7 +30,7 @@ module Fog
|
|
30
30
|
end
|
31
31
|
else
|
32
32
|
case name
|
33
|
-
when 'vpcId', 'state', 'cidrBlock', 'dhcpOptionsId', 'instanceTenancy'
|
33
|
+
when 'vpcId', 'state', 'cidrBlock', 'dhcpOptionsId', 'instanceTenancy', 'isDefault'
|
34
34
|
@vpc[name] = value
|
35
35
|
when 'item'
|
36
36
|
@response['vpcSet'] << @vpc
|
@@ -23,6 +23,7 @@ module Fog
|
|
23
23
|
# * 'instanceId'<~String> - The ID of a NAT instance in your VPC.
|
24
24
|
# * 'instanceOwnerId'<~String> - The owner of the instance.
|
25
25
|
# * 'networkInterfaceId'<~String> - The network interface ID.
|
26
|
+
# * 'vpcPeeringConnectionId'<~String> - The peering connection ID.
|
26
27
|
# * 'state'<~String> - The state of the route. The blackhole state indicates that the route's target isn't available.
|
27
28
|
# * 'origin'<~String> - Describes how the route was created.
|
28
29
|
# * 'associationSet'<~Array>:
|
@@ -1,6 +1,110 @@
|
|
1
1
|
module Fog
|
2
2
|
module DNS
|
3
3
|
class AWS
|
4
|
+
|
5
|
+
def self.hosted_zone_for_alias_target(dns_name)
|
6
|
+
Hash[elb_hosted_zone_mapping.select { |k, _|
|
7
|
+
dns_name =~ /\A.+\.#{k}\.elb\.amazonaws\.com\.?\z/
|
8
|
+
}].values.last
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.elb_hosted_zone_mapping
|
12
|
+
@elb_hosted_zone_mapping ||= {
|
13
|
+
"ap-northeast-1" => "Z2YN17T5R711GT",
|
14
|
+
"ap-southeast-1" => "Z1WI8VXHPB1R38",
|
15
|
+
"ap-southeast-2" => "Z2999QAZ9SRTIC",
|
16
|
+
"eu-west-1" => "Z3NF1Z3NOM5OY2",
|
17
|
+
"eu-central-1" => "Z215JYRZR1TBD5",
|
18
|
+
"sa-east-1" => "Z2ES78Y61JGQKS",
|
19
|
+
"us-east-1" => "Z3DZXE0Q79N41H",
|
20
|
+
"us-west-1" => "Z1M58G0W56PQJA",
|
21
|
+
"us-west-2" => "Z33MTJ483KN6FU",
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
# Returns the xml request for a given changeset
|
26
|
+
def self.change_resource_record_sets_data(zone_id, change_batch, version, options = {})
|
27
|
+
# AWS methods return zone_ids that looks like '/hostedzone/id'. Let the caller either use
|
28
|
+
# that form or just the actual id (which is what this request needs)
|
29
|
+
zone_id = zone_id.sub('/hostedzone/', '')
|
30
|
+
|
31
|
+
optional_tags = ''
|
32
|
+
options.each do |option, value|
|
33
|
+
case option
|
34
|
+
when :comment
|
35
|
+
optional_tags += "<Comment>#{value}</Comment>"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
#build XML
|
40
|
+
if change_batch.count > 0
|
41
|
+
|
42
|
+
changes = "<ChangeBatch>#{optional_tags}<Changes>"
|
43
|
+
|
44
|
+
change_batch.each do |change_item|
|
45
|
+
action_tag = %Q{<Action>#{change_item[:action]}</Action>}
|
46
|
+
name_tag = %Q{<Name>#{change_item[:name]}</Name>}
|
47
|
+
type_tag = %Q{<Type>#{change_item[:type]}</Type>}
|
48
|
+
|
49
|
+
# TTL must be omitted if using an alias record
|
50
|
+
ttl_tag = ''
|
51
|
+
ttl_tag += %Q{<TTL>#{change_item[:ttl]}</TTL>} unless change_item[:alias_target]
|
52
|
+
|
53
|
+
weight_tag = ''
|
54
|
+
set_identifier_tag = ''
|
55
|
+
region_tag = ''
|
56
|
+
if change_item[:set_identifier]
|
57
|
+
set_identifier_tag += %Q{<SetIdentifier>#{change_item[:set_identifier]}</SetIdentifier>}
|
58
|
+
if change_item[:weight] # Weighted Record
|
59
|
+
weight_tag += %Q{<Weight>#{change_item[:weight]}</Weight>}
|
60
|
+
elsif change_item[:region] # Latency record
|
61
|
+
region_tag += %Q{<Region>#{change_item[:region]}</Region>}
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
failover_tag = if change_item[:failover]
|
66
|
+
%Q{<Failover>#{change_item[:failover]}</Failover>}
|
67
|
+
end
|
68
|
+
|
69
|
+
geolocation_tag = if change_item[:geo_location]
|
70
|
+
xml_geo = change_item[:geo_location].map { |k,v| "<#{k}>#{v}</#{k}>" }.join
|
71
|
+
%Q{<GeoLocation>#{xml_geo}</GeoLocation>}
|
72
|
+
end
|
73
|
+
|
74
|
+
resource_records = change_item[:resource_records] || []
|
75
|
+
resource_record_tags = ''
|
76
|
+
resource_records.each do |record|
|
77
|
+
resource_record_tags += %Q{<ResourceRecord><Value>#{record}</Value></ResourceRecord>}
|
78
|
+
end
|
79
|
+
|
80
|
+
# ResourceRecords must be omitted if using an alias record
|
81
|
+
resource_tag = ''
|
82
|
+
resource_tag += %Q{<ResourceRecords>#{resource_record_tags}</ResourceRecords>} if resource_records.any?
|
83
|
+
|
84
|
+
alias_target_tag = ''
|
85
|
+
if change_item[:alias_target]
|
86
|
+
# Accept either underscore or camel case for hash keys.
|
87
|
+
dns_name = change_item[:alias_target][:dns_name] || change_item[:alias_target][:DNSName]
|
88
|
+
hosted_zone_id = change_item[:alias_target][:hosted_zone_id] || change_item[:alias_target][:HostedZoneId] || AWS.hosted_zone_for_alias_target(dns_name)
|
89
|
+
evaluate_target_health = change_item[:alias_target][:evaluate_target_health] || change_item[:alias_target][:EvaluateTargetHealth] || false
|
90
|
+
evaluate_target_health_xml = !evaluate_target_health.nil? ? %Q{<EvaluateTargetHealth>#{evaluate_target_health}</EvaluateTargetHealth>} : ''
|
91
|
+
alias_target_tag += %Q{<AliasTarget><HostedZoneId>#{hosted_zone_id}</HostedZoneId><DNSName>#{dns_name}</DNSName>#{evaluate_target_health_xml}</AliasTarget>}
|
92
|
+
end
|
93
|
+
|
94
|
+
health_check_id_tag = if change_item[:health_check_id]
|
95
|
+
%Q{<HealthCheckId>#{change_item[:health_check_id]}</HealthCheckId>}
|
96
|
+
end
|
97
|
+
|
98
|
+
change_tags = %Q{<Change>#{action_tag}<ResourceRecordSet>#{name_tag}#{type_tag}#{set_identifier_tag}#{weight_tag}#{region_tag}#{failover_tag}#{geolocation_tag}#{ttl_tag}#{resource_tag}#{alias_target_tag}#{health_check_id_tag}</ResourceRecordSet></Change>}
|
99
|
+
changes += change_tags
|
100
|
+
end
|
101
|
+
|
102
|
+
changes += '</Changes></ChangeBatch>'
|
103
|
+
end
|
104
|
+
|
105
|
+
%Q{<?xml version="1.0" encoding="UTF-8"?><ChangeResourceRecordSetsRequest xmlns="https://route53.amazonaws.com/doc/#{version}/">#{changes}</ChangeResourceRecordSetsRequest>}
|
106
|
+
end
|
107
|
+
|
4
108
|
class Real
|
5
109
|
require 'fog/aws/parsers/dns/change_resource_record_sets'
|
6
110
|
|
@@ -61,84 +165,7 @@ module Fog
|
|
61
165
|
# change_resource_record_sets("ABCDEFGHIJKLMN", change_batch_options)
|
62
166
|
#
|
63
167
|
def change_resource_record_sets(zone_id, change_batch, options = {})
|
64
|
-
|
65
|
-
# that form or just the actual id (which is what this request needs)
|
66
|
-
zone_id = zone_id.sub('/hostedzone/', '')
|
67
|
-
|
68
|
-
optional_tags = ''
|
69
|
-
options.each do |option, value|
|
70
|
-
case option
|
71
|
-
when :comment
|
72
|
-
optional_tags += "<Comment>#{value}</Comment>"
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
#build XML
|
77
|
-
if change_batch.count > 0
|
78
|
-
|
79
|
-
changes = "<ChangeBatch>#{optional_tags}<Changes>"
|
80
|
-
|
81
|
-
change_batch.each do |change_item|
|
82
|
-
action_tag = %Q{<Action>#{change_item[:action]}</Action>}
|
83
|
-
name_tag = %Q{<Name>#{change_item[:name]}</Name>}
|
84
|
-
type_tag = %Q{<Type>#{change_item[:type]}</Type>}
|
85
|
-
|
86
|
-
# TTL must be omitted if using an alias record
|
87
|
-
ttl_tag = ''
|
88
|
-
ttl_tag += %Q{<TTL>#{change_item[:ttl]}</TTL>} unless change_item[:alias_target]
|
89
|
-
|
90
|
-
weight_tag = ''
|
91
|
-
set_identifier_tag = ''
|
92
|
-
region_tag = ''
|
93
|
-
if change_item[:set_identifier]
|
94
|
-
set_identifier_tag += %Q{<SetIdentifier>#{change_item[:set_identifier]}</SetIdentifier>}
|
95
|
-
if change_item[:weight] # Weighted Record
|
96
|
-
weight_tag += %Q{<Weight>#{change_item[:weight]}</Weight>}
|
97
|
-
elsif change_item[:region] # Latency record
|
98
|
-
region_tag += %Q{<Region>#{change_item[:region]}</Region>}
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
failover_tag = if change_item[:failover]
|
103
|
-
%Q{<Failover>#{change_item[:failover]}</Failover>}
|
104
|
-
end
|
105
|
-
|
106
|
-
geolocation_tag = if change_item[:geo_location]
|
107
|
-
%Q{<GeoLocation>#{change_item[:geo_location]}</GeoLocation>}
|
108
|
-
end
|
109
|
-
|
110
|
-
resource_records = change_item[:resource_records] || []
|
111
|
-
resource_record_tags = ''
|
112
|
-
resource_records.each do |record|
|
113
|
-
resource_record_tags += %Q{<ResourceRecord><Value>#{record}</Value></ResourceRecord>}
|
114
|
-
end
|
115
|
-
|
116
|
-
# ResourceRecords must be omitted if using an alias record
|
117
|
-
resource_tag = ''
|
118
|
-
resource_tag += %Q{<ResourceRecords>#{resource_record_tags}</ResourceRecords>} if resource_records.any?
|
119
|
-
|
120
|
-
alias_target_tag = ''
|
121
|
-
if change_item[:alias_target]
|
122
|
-
# Accept either underscore or camel case for hash keys.
|
123
|
-
dns_name = change_item[:alias_target][:dns_name] || change_item[:alias_target][:DNSName]
|
124
|
-
hosted_zone_id = change_item[:alias_target][:hosted_zone_id] || change_item[:alias_target][:HostedZoneId] || AWS.hosted_zone_for_alias_target(dns_name)
|
125
|
-
evaluate_target_health = change_item[:alias_target][:evaluate_target_health] || change_item[:alias_target][:EvaluateTargetHealth] || false
|
126
|
-
evaluate_target_health_xml = !evaluate_target_health.nil? ? %Q{<EvaluateTargetHealth>#{evaluate_target_health}</EvaluateTargetHealth>} : ''
|
127
|
-
alias_target_tag += %Q{<AliasTarget><HostedZoneId>#{hosted_zone_id}</HostedZoneId><DNSName>#{dns_name}</DNSName>#{evaluate_target_health_xml}</AliasTarget>}
|
128
|
-
end
|
129
|
-
|
130
|
-
health_check_id_tag = if change_item[:health_check_id]
|
131
|
-
%Q{<HealthCheckId>#{change_item[:health_check_id]}</HealthCheckId>}
|
132
|
-
end
|
133
|
-
|
134
|
-
change_tags = %Q{<Change>#{action_tag}<ResourceRecordSet>#{name_tag}#{type_tag}#{set_identifier_tag}#{weight_tag}#{region_tag}#{failover_tag}#{geolocation_tag}#{ttl_tag}#{resource_tag}#{alias_target_tag}#{health_check_id_tag}</ResourceRecordSet></Change>}
|
135
|
-
changes += change_tags
|
136
|
-
end
|
137
|
-
|
138
|
-
changes += '</Changes></ChangeBatch>'
|
139
|
-
end
|
140
|
-
|
141
|
-
body = %Q{<?xml version="1.0" encoding="UTF-8"?><ChangeResourceRecordSetsRequest xmlns="https://route53.amazonaws.com/doc/#{@version}/">#{changes}</ChangeResourceRecordSetsRequest>}
|
168
|
+
body = AWS.change_resource_record_sets_data(zone_id, change_batch, @version, options)
|
142
169
|
request({
|
143
170
|
:body => body,
|
144
171
|
:idempotent => true,
|
@@ -151,7 +178,9 @@ module Fog
|
|
151
178
|
end
|
152
179
|
|
153
180
|
class Mock
|
181
|
+
|
154
182
|
SET_PREFIX = 'SET_'
|
183
|
+
|
155
184
|
def record_exist?(zone,change,change_name)
|
156
185
|
return false if zone[:records][change[:type]].nil?
|
157
186
|
current_records = zone[:records][change[:type]][change_name]
|
@@ -187,15 +216,15 @@ module Fog
|
|
187
216
|
if !record_exist?(zone, change, change_name)
|
188
217
|
# raise change.to_s if change[:resource_records].nil?
|
189
218
|
new_record =
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
219
|
+
if change[:alias_target]
|
220
|
+
record = {
|
221
|
+
:alias_target => change[:alias_target]
|
222
|
+
}
|
223
|
+
else
|
224
|
+
record = {
|
225
|
+
:ttl => change[:ttl].to_s,
|
226
|
+
}
|
227
|
+
end
|
199
228
|
|
200
229
|
new_record = {
|
201
230
|
:change_id => change_id,
|
@@ -251,26 +280,6 @@ module Fog
|
|
251
280
|
end
|
252
281
|
end
|
253
282
|
end
|
254
|
-
|
255
|
-
def self.hosted_zone_for_alias_target(dns_name)
|
256
|
-
Hash[elb_hosted_zone_mapping.select { |k, _|
|
257
|
-
dns_name =~ /\A.+\.#{k}\.elb\.amazonaws\.com\.?\z/
|
258
|
-
}].values.last
|
259
|
-
end
|
260
|
-
|
261
|
-
def self.elb_hosted_zone_mapping
|
262
|
-
@elb_hosted_zone_mapping ||= {
|
263
|
-
"ap-northeast-1" => "Z2YN17T5R711GT",
|
264
|
-
"ap-southeast-1" => "Z1WI8VXHPB1R38",
|
265
|
-
"ap-southeast-2" => "Z2999QAZ9SRTIC",
|
266
|
-
"eu-west-1" => "Z3NF1Z3NOM5OY2",
|
267
|
-
"eu-central-1" => "Z215JYRZR1TBD5",
|
268
|
-
"sa-east-1" => "Z2ES78Y61JGQKS",
|
269
|
-
"us-east-1" => "Z3DZXE0Q79N41H",
|
270
|
-
"us-west-1" => "Z1M58G0W56PQJA",
|
271
|
-
"us-west-2" => "Z33MTJ483KN6FU",
|
272
|
-
}
|
273
|
-
end
|
274
283
|
end
|
275
284
|
end
|
276
285
|
end
|