right_aws-yodal 1.10.7 → 1.10.10
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +46 -1
- data/Manifest.txt +4 -0
- data/README.txt +0 -0
- data/Rakefile +0 -0
- data/lib/acf/right_acf_interface.rb +105 -33
- data/lib/acf/right_acf_origin_access_identities.rb +230 -0
- data/lib/acf/right_acf_streaming_interface.rb +236 -0
- data/lib/acw/right_acw_interface.rb +3 -3
- data/lib/as/right_as_interface.rb +55 -46
- data/lib/awsbase/benchmark_fix.rb +0 -0
- data/lib/awsbase/right_awsbase.rb +71 -12
- data/lib/awsbase/support.rb +0 -0
- data/lib/ec2/right_ec2.rb +22 -244
- data/lib/ec2/right_ec2_ebs.rb +23 -22
- data/lib/ec2/right_ec2_images.rb +21 -21
- data/lib/ec2/right_ec2_instances.rb +49 -54
- data/lib/ec2/right_ec2_reserved_instances.rb +7 -4
- data/lib/ec2/right_ec2_security_groups.rb +277 -0
- data/lib/ec2/right_ec2_spot_instances.rb +399 -0
- data/lib/ec2/right_ec2_vpc.rb +4 -4
- data/lib/elb/right_elb_interface.rb +112 -23
- data/lib/rds/right_rds_interface.rb +4 -4
- data/lib/right_aws.rb +8 -4
- data/lib/s3/right_s3.rb +25 -1
- data/lib/s3/right_s3_interface.rb +6 -2
- data/lib/sdb/active_sdb.rb +202 -10
- data/lib/sdb/right_sdb_interface.rb +61 -11
- data/lib/sqs/right_sqs.rb +0 -0
- data/lib/sqs/right_sqs_gen2.rb +0 -0
- data/lib/sqs/right_sqs_gen2_interface.rb +5 -4
- data/lib/sqs/right_sqs_interface.rb +0 -0
- data/test/acf/test_helper.rb +0 -0
- data/test/acf/test_right_acf.rb +10 -18
- data/test/ec2/test_helper.rb +0 -0
- data/test/ec2/test_right_ec2.rb +0 -0
- data/test/http_connection.rb +0 -0
- data/test/s3/test_helper.rb +0 -0
- data/test/s3/test_right_s3.rb +10 -8
- data/test/s3/test_right_s3_stubbed.rb +6 -4
- data/test/sdb/test_active_sdb.rb +70 -12
- data/test/sdb/test_batch_put_attributes.rb +54 -0
- data/test/sdb/test_helper.rb +0 -0
- data/test/sdb/test_right_sdb.rb +13 -7
- data/test/sqs/test_helper.rb +0 -0
- data/test/sqs/test_right_sqs.rb +0 -0
- data/test/sqs/test_right_sqs_gen2.rb +21 -33
- data/test/test_credentials.rb +0 -0
- data/test/ts_right_aws.rb +0 -0
- metadata +16 -4
data/History.txt
CHANGED
@@ -236,4 +236,49 @@ the source key.
|
|
236
236
|
- Boot from EBS support added
|
237
237
|
- VPC support added
|
238
238
|
- Latest EC2 API 2009-10-31 support added
|
239
|
-
- Some of bugs fixed
|
239
|
+
- Some of bugs fixed
|
240
|
+
|
241
|
+
=== 2.0.0
|
242
|
+
|
243
|
+
Release Notes:
|
244
|
+
- Added:
|
245
|
+
- Ruby 1.9 support
|
246
|
+
- Ec2:
|
247
|
+
- SpotInstances support
|
248
|
+
- m2.xlarge instances
|
249
|
+
- GetPasswordData API call (see get_password_data_v2)
|
250
|
+
- SecurityGroups support for Eucalyptus clouds
|
251
|
+
- EBS:
|
252
|
+
- :delete_on_termination field for volumes
|
253
|
+
- SimpleDB:
|
254
|
+
- BatchPutAttributes support
|
255
|
+
- ActiveSDB:
|
256
|
+
- Dynamic attribute accessors
|
257
|
+
- "Columns" support
|
258
|
+
- Simple Type Casting support
|
259
|
+
- ELB:
|
260
|
+
- API '2009-11-25' support (stickiness policies)
|
261
|
+
- ACF:
|
262
|
+
- API '2010-03-01' support (origin access policy and streaming distributions)
|
263
|
+
- Bunch of small issues were fixed
|
264
|
+
- Time objects were replaced by Strings (as Amazon returns them) to make the gem more consistent:
|
265
|
+
- :last_modified_time in:
|
266
|
+
RightAws::AcfInterface#incrementally_list_distributions,
|
267
|
+
RightAws::AcfInterface#create_distribution_by_config,
|
268
|
+
RightAws::AcfInterface#get_distribution,
|
269
|
+
RightAws::AcfInterface#get_distribution_config
|
270
|
+
- :timestamp in:
|
271
|
+
RightAws::AcwInterface#get_metric_statistics
|
272
|
+
- :aws_created_at in:
|
273
|
+
RightAws::Ec2#create_volume,
|
274
|
+
RightAws::Ec2#describe_volumes
|
275
|
+
- :aws_attached_at in:
|
276
|
+
RightAws::Ec2#attach_volume,
|
277
|
+
RightAws::Ec2#detach_volume,
|
278
|
+
RightAws::Ec2#describe_volumes
|
279
|
+
- :aws_started_at in:
|
280
|
+
RightAws::Ec2#describe_snapshots,
|
281
|
+
RightAws::Ec2#create_snapshot,
|
282
|
+
RightAws::Ec2#try_create_snapshot
|
283
|
+
- :created_time in:
|
284
|
+
RightAws::ElbInterface#describe_load_balancers
|
data/Manifest.txt
CHANGED
@@ -8,6 +8,8 @@ lib/awsbase/support.rb
|
|
8
8
|
lib/ec2/right_ec2.rb
|
9
9
|
lib/ec2/right_ec2_images.rb
|
10
10
|
lib/ec2/right_ec2_instances.rb
|
11
|
+
lib/ec2/right_ec2_security_groups.rb
|
12
|
+
lib/ec2/right_ec2_spot_instances.rb
|
11
13
|
lib/ec2/right_ec2_ebs.rb
|
12
14
|
lib/ec2/right_ec2_reserved_instances.rb
|
13
15
|
lib/ec2/right_ec2_vpc.rb
|
@@ -25,6 +27,8 @@ lib/sqs/right_sqs_gen2.rb
|
|
25
27
|
lib/sqs/right_sqs_gen2_interface.rb
|
26
28
|
lib/sqs/right_sqs_interface.rb
|
27
29
|
lib/acf/right_acf_interface.rb
|
30
|
+
lib/acf/right_acf_streaming_interface.rb
|
31
|
+
lib/acf/right_acf_origin_access_identities.rb
|
28
32
|
lib/rds/right_rds_interface.rb
|
29
33
|
test/ec2/test_helper.rb
|
30
34
|
test/ec2/test_right_ec2.rb
|
data/README.txt
CHANGED
File without changes
|
data/Rakefile
CHANGED
File without changes
|
@@ -20,7 +20,6 @@
|
|
20
20
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
21
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
22
|
#
|
23
|
-
|
24
23
|
module RightAws
|
25
24
|
|
26
25
|
# = RightAws::AcfInterface -- RightScale Amazon's CloudFront interface
|
@@ -42,7 +41,7 @@ module RightAws
|
|
42
41
|
# :origin => "my-bucket.s3.amazonaws.com",
|
43
42
|
# :cnames => ["x1.my-awesome-site.net", "x1.my-awesome-site.net"]
|
44
43
|
# :comment => "My comments",
|
45
|
-
# :last_modified_time =>
|
44
|
+
# :last_modified_time => "2008-09-10T17:00:04.000Z" }, ..., {...} ]
|
46
45
|
#
|
47
46
|
# distibution = list.first
|
48
47
|
#
|
@@ -56,7 +55,7 @@ module RightAws
|
|
56
55
|
# :aws_id => "E2REJM3VUN5RSI",
|
57
56
|
# :comment => "Woo-Hoo!",
|
58
57
|
# :origin => "my-bucket.s3.amazonaws.com",
|
59
|
-
# :last_modified_time =>
|
58
|
+
# :last_modified_time => "2008-09-10T17:00:54.000Z" }
|
60
59
|
#
|
61
60
|
# config = acf.get_distribution_config(distibution[:aws_id]) #=>
|
62
61
|
# {:enabled => true,
|
@@ -76,7 +75,7 @@ module RightAws
|
|
76
75
|
|
77
76
|
include RightAwsBaseInterface
|
78
77
|
|
79
|
-
API_VERSION = "
|
78
|
+
API_VERSION = "2010-03-01"
|
80
79
|
DEFAULT_HOST = 'cloudfront.amazonaws.com'
|
81
80
|
DEFAULT_PORT = 443
|
82
81
|
DEFAULT_PROTOCOL = 'https'
|
@@ -175,29 +174,55 @@ module RightAws
|
|
175
174
|
hash
|
176
175
|
end
|
177
176
|
|
178
|
-
def
|
177
|
+
def distribution_config_to_xml(config, xml_wrapper='DistributionConfig') # :nodoc:
|
179
178
|
cnames = ''
|
179
|
+
logging = ''
|
180
|
+
origin_access_identity = ''
|
181
|
+
trusted_signers = ''
|
182
|
+
# CNAMES
|
180
183
|
unless config[:cnames].blank?
|
181
|
-
config[:cnames].
|
184
|
+
Array(config[:cnames]).each { |cname| cnames += " <CNAME>#{cname}</CNAME>\n" }
|
182
185
|
end
|
183
|
-
#
|
184
|
-
logging = ''
|
186
|
+
# Logging
|
185
187
|
unless config[:logging].blank?
|
186
188
|
logging = " <Logging>\n" +
|
187
189
|
" <Bucket>#{config[:logging][:bucket]}</Bucket>\n" +
|
188
190
|
" <Prefix>#{config[:logging][:prefix]}</Prefix>\n" +
|
189
191
|
" </Logging>\n"
|
190
192
|
end
|
191
|
-
#
|
193
|
+
# Origin Access Identity
|
194
|
+
unless config[:origin_access_identity].blank?
|
195
|
+
origin_access_identity = config[:origin_access_identity]
|
196
|
+
unless origin_access_identity[%r{^origin-access-identity}]
|
197
|
+
origin_access_identity = "origin-access-identity/cloudfront/#{origin_access_identity}"
|
198
|
+
end
|
199
|
+
origin_access_identity = " <OriginAccessIdentity>#{origin_access_identity}</OriginAccessIdentity>\n"
|
200
|
+
end
|
201
|
+
# Trusted Signers
|
202
|
+
unless config[:trusted_signers].blank?
|
203
|
+
trusted_signers = " <TrustedSigners>\n"
|
204
|
+
Array(config[:trusted_signers]).each do |trusted_signer|
|
205
|
+
trusted_signers += if trusted_signer.to_s[/self/i]
|
206
|
+
" <Self/>\n"
|
207
|
+
else
|
208
|
+
" <AwsAccountNumber>#{trusted_signer}</AwsAccountNumber>\n"
|
209
|
+
end
|
210
|
+
end
|
211
|
+
trusted_signers += " </TrustedSigners>\n"
|
212
|
+
end
|
213
|
+
|
214
|
+
# XML
|
192
215
|
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
|
193
|
-
"
|
216
|
+
"<#{xml_wrapper} xmlns=\"http://#{@params[:server]}/doc/#{API_VERSION}/\">\n" +
|
194
217
|
" <Origin>#{config[:origin]}</Origin>\n" +
|
195
218
|
" <CallerReference>#{config[:caller_reference]}</CallerReference>\n" +
|
196
219
|
" <Comment>#{AcfInterface::escape(config[:comment].to_s)}</Comment>\n" +
|
197
220
|
" <Enabled>#{config[:enabled]}</Enabled>\n" +
|
198
221
|
cnames +
|
199
222
|
logging +
|
200
|
-
|
223
|
+
origin_access_identity +
|
224
|
+
trusted_signers +
|
225
|
+
"</#{xml_wrapper}>"
|
201
226
|
end
|
202
227
|
|
203
228
|
#-----------------------------------------------------------------
|
@@ -234,11 +259,10 @@ module RightAws
|
|
234
259
|
# {:distributions=>
|
235
260
|
# [{:status=>"Deployed",
|
236
261
|
# :aws_id=>"E2Q0AOOMFNPSYL",
|
237
|
-
# :logging=>{},
|
238
262
|
# :origin=>"my-bucket.s3.amazonaws.com",
|
239
263
|
# :domain_name=>"d1s5gmdtmafnre.6hops.net",
|
240
264
|
# :comment=>"ONE LINE OF COMMENT",
|
241
|
-
# :last_modified_time=>
|
265
|
+
# :last_modified_time=>"2008-10-22T19:31:23.000Z",
|
242
266
|
# :enabled=>true,
|
243
267
|
# :cnames=>[]}],
|
244
268
|
# :is_truncated=>true,
|
@@ -252,7 +276,7 @@ module RightAws
|
|
252
276
|
# # list distributions by 10
|
253
277
|
# incrementally_list_distributions(:max_items => 10) do |response|
|
254
278
|
# puts response.inspect # a list of 10 distributions
|
255
|
-
#
|
279
|
+
# true # return false if the listing should be broken otherwise use true
|
256
280
|
# end
|
257
281
|
#
|
258
282
|
def incrementally_list_distributions(params={}, &block)
|
@@ -272,7 +296,7 @@ module RightAws
|
|
272
296
|
# Create a new distribution.
|
273
297
|
# Returns the just created distribution or RightAws::AwsError exception.
|
274
298
|
#
|
275
|
-
# acf.create_distribution('my-bucket.s3.amazonaws.com', 'Woo-Hoo!', true, ['web1.my-awesome-site.net'],
|
299
|
+
# acf.create_distribution('my-bucket.s3.amazonaws.com', 'Woo-Hoo!', true, ['web1.my-awesome-site.net'], nil,
|
276
300
|
# { :prefix=>"log/", :bucket=>"my-logs.s3.amazonaws.com" } ) #=>
|
277
301
|
# {:comment => "Woo-Hoo!",
|
278
302
|
# :enabled => true,
|
@@ -284,14 +308,14 @@ module RightAws
|
|
284
308
|
# :cnames => ["web1.my-awesome-site.net"],
|
285
309
|
# :logging => { :prefix => "log/",
|
286
310
|
# :bucket => "my-logs.s3.amazonaws.com"},
|
287
|
-
# :last_modified_time =>
|
311
|
+
# :last_modified_time => "2008-10-22T19:31:23.000Z",
|
288
312
|
# :caller_reference => "200809102100536497863003"}
|
289
313
|
#
|
290
314
|
def create_distribution(origin, comment='', enabled=true, cnames=[], caller_reference=nil, logging={})
|
291
315
|
config = { :origin => origin,
|
292
316
|
:comment => comment,
|
293
317
|
:enabled => enabled,
|
294
|
-
:cnames => cnames
|
318
|
+
:cnames => Array(cnames),
|
295
319
|
:caller_reference => caller_reference }
|
296
320
|
config[:logging] = logging unless logging.blank?
|
297
321
|
create_distribution_by_config(config)
|
@@ -299,7 +323,7 @@ module RightAws
|
|
299
323
|
|
300
324
|
def create_distribution_by_config(config)
|
301
325
|
config[:caller_reference] ||= generate_call_reference
|
302
|
-
link = generate_request('POST', 'distribution', {},
|
326
|
+
link = generate_request('POST', 'distribution', {}, distribution_config_to_xml(config))
|
303
327
|
merge_headers(request_info(link, AcfDistributionListParser.new(:logger => @logger))[:distributions].first)
|
304
328
|
end
|
305
329
|
|
@@ -316,7 +340,26 @@ module RightAws
|
|
316
340
|
# :aws_id => "E2REJM3VUN5RSI",
|
317
341
|
# :comment => "Woo-Hoo!",
|
318
342
|
# :origin => "my-bucket.s3.amazonaws.com",
|
319
|
-
# :last_modified_time =>
|
343
|
+
# :last_modified_time => "2008-09-10T17:00:54.000Z" }
|
344
|
+
#
|
345
|
+
# acf.get_distribution('E2FNSBHNVVF11E') #=>
|
346
|
+
# {:e_tag=>"E1Q2DJEPTQOLJD",
|
347
|
+
# :status=>"InProgress",
|
348
|
+
# :last_modified_time=>"2010-04-17T17:24:25.000Z",
|
349
|
+
# :cnames=>["web1.my-awesome-site.net", "web2.my-awesome-site.net"],
|
350
|
+
# :aws_id=>"E2FNSBHNVVF11E",
|
351
|
+
# :logging=>{:prefix=>"xlog/", :bucket=>"my-bucket.s3.amazonaws.com"},
|
352
|
+
# :enabled=>true,
|
353
|
+
# :active_trusted_signers=>
|
354
|
+
# [{:aws_account_number=>"120288270000",
|
355
|
+
# :key_pair_ids=>["APKAJTD5OHNDX0000000", "APKAIK74BJWCL0000000"]},
|
356
|
+
# {:aws_account_number=>"self"},
|
357
|
+
# {:aws_account_number=>"648772220000"}],
|
358
|
+
# :caller_reference=>"201004171154450740700072",
|
359
|
+
# :domain_name=>"d1f6lpevremt5m.cloudfront.net",
|
360
|
+
# :origin_access_identity=>"origin-access-identity/cloudfront/E3JPJZ80ZBX24G",
|
361
|
+
# :trusted_signers=>["self", "648772220000", "120288270000"],
|
362
|
+
# :origin=>"my-bucket.s3.amazonaws.com"}
|
320
363
|
#
|
321
364
|
def get_distribution(aws_id)
|
322
365
|
link = generate_request('GET', "distribution/#{aws_id}")
|
@@ -334,6 +377,15 @@ module RightAws
|
|
334
377
|
# :comment => "Woo-Hoo!",
|
335
378
|
# :origin => "my-bucket.s3.amazonaws.com"}
|
336
379
|
#
|
380
|
+
# acf.get_distribution_config('E2FNSBHNVVF11E') #=>
|
381
|
+
# {:e_tag=>"E1Q2DJEPTQOLJD",
|
382
|
+
# :logging=>{:prefix=>"xlog/", :bucket=>"my-bucket.s3.amazonaws.com"},
|
383
|
+
# :enabled=>true,
|
384
|
+
# :caller_reference=>"201004171154450740700072",
|
385
|
+
# :origin_access_identity=>"origin-access-identity/cloudfront/E3JPJZ80ZBX24G",
|
386
|
+
# :trusted_signers=>["self", "648772220000", "120288270000"],
|
387
|
+
# :origin=>"my-bucket.s3.amazonaws.com"}
|
388
|
+
#
|
337
389
|
def get_distribution_config(aws_id)
|
338
390
|
link = generate_request('GET', "distribution/#{aws_id}/config")
|
339
391
|
merge_headers(request_info(link, AcfDistributionListParser.new(:logger => @logger))[:distributions].first)
|
@@ -350,12 +402,19 @@ module RightAws
|
|
350
402
|
# :cnames => ["web1.my-awesome-site.net", "web2.my-awesome-site.net"]
|
351
403
|
# :comment => "Woo-Hoo!",
|
352
404
|
# :origin => "my-bucket.s3.amazonaws.com"}
|
353
|
-
#
|
354
|
-
# config[:
|
405
|
+
#
|
406
|
+
# config[:comment] = 'Olah-lah!'
|
407
|
+
# config[:enabled] = false
|
408
|
+
# config[:origin_access_identity] = "origin-access-identity/cloudfront/E3JPJZ80ZBX24G"
|
409
|
+
# # or just
|
410
|
+
# # config[:origin_access_identity] = "E3JPJZ80ZBX24G"
|
411
|
+
# config[:trusted_signers] = ['self', '648772220000', '120288270000']
|
412
|
+
# config[:logging] = { :bucket => 'my-bucket.s3.amazonaws.com', :prefix => 'xlog/' }
|
413
|
+
#
|
355
414
|
# acf.set_distribution_config('E2REJM3VUN5RSI', config) #=> true
|
356
415
|
#
|
357
416
|
def set_distribution_config(aws_id, config)
|
358
|
-
link = generate_request('PUT', "distribution/#{aws_id}/config", {},
|
417
|
+
link = generate_request('PUT', "distribution/#{aws_id}/config", {}, distribution_config_to_xml(config),
|
359
418
|
'If-Match' => config[:e_tag])
|
360
419
|
request_info(link, RightHttp2xxParser.new(:logger => @logger))
|
361
420
|
end
|
@@ -380,9 +439,13 @@ module RightAws
|
|
380
439
|
@result = { :distributions => [] }
|
381
440
|
end
|
382
441
|
def tagstart(name, attributes)
|
383
|
-
|
384
|
-
|
385
|
-
@
|
442
|
+
case full_tag_name
|
443
|
+
when %r{/Signer$}
|
444
|
+
@active_signer = {}
|
445
|
+
when %r{(Streaming)?DistributionSummary$},
|
446
|
+
%r{^(Streaming)?Distribution$},
|
447
|
+
%r{^(Streaming)?DistributionConfig$}
|
448
|
+
@distribution = { }
|
386
449
|
end
|
387
450
|
end
|
388
451
|
def tagend(name)
|
@@ -390,21 +453,30 @@ module RightAws
|
|
390
453
|
when 'Marker' then @result[:marker] = @text
|
391
454
|
when 'NextMarker' then @result[:next_marker] = @text
|
392
455
|
when 'MaxItems' then @result[:max_items] = @text.to_i
|
393
|
-
when 'IsTruncated' then @result[:is_truncated] = @text == 'true'
|
456
|
+
when 'IsTruncated' then @result[:is_truncated] = (@text == 'true')
|
394
457
|
when 'Id' then @distribution[:aws_id] = @text
|
395
458
|
when 'Status' then @distribution[:status] = @text
|
396
|
-
when 'LastModifiedTime' then @distribution[:last_modified_time] =
|
459
|
+
when 'LastModifiedTime' then @distribution[:last_modified_time] = @text
|
397
460
|
when 'DomainName' then @distribution[:domain_name] = @text
|
398
461
|
when 'Origin' then @distribution[:origin] = @text
|
399
462
|
when 'Comment' then @distribution[:comment] = AcfInterface::unescape(@text)
|
400
463
|
when 'CallerReference' then @distribution[:caller_reference] = @text
|
401
|
-
when 'CNAME' then @distribution[:cnames]
|
402
|
-
when 'Enabled' then @distribution[:enabled] = @text == 'true'
|
403
|
-
when 'Bucket' then @distribution[:logging][:bucket]
|
404
|
-
when 'Prefix' then @distribution[:logging][:prefix]
|
464
|
+
when 'CNAME' then (@distribution[:cnames] ||= []) << @text
|
465
|
+
when 'Enabled' then @distribution[:enabled] = (@text == 'true')
|
466
|
+
when 'Bucket' then (@distribution[:logging] ||= {})[:bucket] = @text
|
467
|
+
when 'Prefix' then (@distribution[:logging] ||= {})[:prefix] = @text
|
468
|
+
when 'OriginAccessIdentity' then @distribution[:origin_access_identity] = @text
|
405
469
|
end
|
406
|
-
|
407
|
-
|
470
|
+
case full_tag_name
|
471
|
+
when %r{/TrustedSigners/Self$} then (@distribution[:trusted_signers] ||= []) << 'self'
|
472
|
+
when %r{/TrustedSigners/AwsAccountNumber$} then (@distribution[:trusted_signers] ||= []) << @text
|
473
|
+
when %r{/Signer/Self$} then @active_signer[:aws_account_number] = 'self'
|
474
|
+
when %r{/Signer/AwsAccountNumber$} then @active_signer[:aws_account_number] = @text
|
475
|
+
when %r{/Signer/KeyPairId$} then (@active_signer[:key_pair_ids] ||= []) << @text
|
476
|
+
when %r{/Signer$} then (@distribution[:active_trusted_signers] ||= []) << @active_signer
|
477
|
+
when %r{(Streaming)?DistributionSummary$},
|
478
|
+
%r{^(Streaming)?Distribution$},
|
479
|
+
%r{^(Streaming)?DistributionConfig$}
|
408
480
|
@result[:distributions] << @distribution
|
409
481
|
end
|
410
482
|
end
|
@@ -0,0 +1,230 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2010 RightScale Inc
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#
|
23
|
+
module RightAws
|
24
|
+
|
25
|
+
class AcfInterface
|
26
|
+
|
27
|
+
# List Origin Access Identities.
|
28
|
+
#
|
29
|
+
# acf.list_origin_access_identities #=>
|
30
|
+
# [{:comment=>"kd: TEST",
|
31
|
+
# :s3_canonical_user_id=>
|
32
|
+
# "c7ca36f6c5d384e60aeca02032ac748bae3c458c5322a2e279382935f1f71b16d9ac251f7f71f1ea91c37d3c214645b8",
|
33
|
+
# :aws_id=>"E3TL4XWF5KTGH"},
|
34
|
+
# {:comment=>"kd: TEST-2",
|
35
|
+
# :s3_canonical_user_id=>
|
36
|
+
# "9af7058b1d197c2c03fdcc3ddad07012a7822f5fc4a8156025409ffac646bdae4dc714820482c92e6988e5703c8d9954",
|
37
|
+
# :aws_id=>"E3HJ7V8C3324VF"},
|
38
|
+
# {:comment=>"MyTestAccessIdentity",
|
39
|
+
# :s3_canonical_user_id=>
|
40
|
+
# "de4361b33dbaf499d3d77159bfa1571d3451eaec25a2b16553de5e534da8089bb8c31a4898d73d1a658155d0e48872a7",
|
41
|
+
# :aws_id=>"E3JPJZ80ZBX24G"}]
|
42
|
+
#
|
43
|
+
def list_origin_access_identities
|
44
|
+
result = []
|
45
|
+
incrementally_list_origin_access_identities do |response|
|
46
|
+
result += response[:origin_access_identities]
|
47
|
+
true
|
48
|
+
end
|
49
|
+
result
|
50
|
+
end
|
51
|
+
|
52
|
+
# Incrementally list Origin Access Identities.
|
53
|
+
# Optional params: +:marker+ and +:max_items+.
|
54
|
+
#
|
55
|
+
# acf.incrementally_list_origin_access_identities(:max_items => 2) #=>
|
56
|
+
# {:origin_access_identities=>
|
57
|
+
# [{:comment=>"kd: TEST",
|
58
|
+
# :s3_canonical_user_id=>
|
59
|
+
# "c7ca36f6c5d384e60aeca02032ac748bae3c458c5322a2e279382935f1f71b16d9ac251f7f71f1ea91c37d3c214645b8",
|
60
|
+
# :aws_id=>"E3TL4XWF5KTGH"},
|
61
|
+
# {:comment=>"kd: TEST-2",
|
62
|
+
# :s3_canonical_user_id=>
|
63
|
+
# "9af7058b1d197c2c03fdcc3ddad07012a7822f5fc4a8156025409ffac646bdae4dc714820482c92e6988e5703c8d9954",
|
64
|
+
# :aws_id=>"E3HJ7V8C3324VF"}],
|
65
|
+
# :is_truncated=>true,
|
66
|
+
# :max_items=>2,
|
67
|
+
# :marker=>"",
|
68
|
+
# :next_marker=>"E3HJ7V8C3324VF"}
|
69
|
+
#
|
70
|
+
# # get max 100 origin access identities (the list will be restricted by a default MaxItems value ==100 )
|
71
|
+
# incrementally_list_origin_access_identities
|
72
|
+
#
|
73
|
+
# # list origin access identities by 10
|
74
|
+
# acf.incrementally_list_origin_access_identities(:max_items => 10) do |response|
|
75
|
+
# puts response.inspect # a list of 10 distributions
|
76
|
+
# true # return false if the listing should be broken otherwise use true
|
77
|
+
# end
|
78
|
+
#
|
79
|
+
def incrementally_list_origin_access_identities(params={}, &block)
|
80
|
+
opts = {}
|
81
|
+
opts['MaxItems'] = params[:max_items] if params[:max_items]
|
82
|
+
opts['Marker'] = params[:marker] if params[:marker]
|
83
|
+
last_response = nil
|
84
|
+
loop do
|
85
|
+
link = generate_request('GET', 'origin-access-identity/cloudfront', opts)
|
86
|
+
last_response = request_info(link, AcfOriginAccesIdentitiesListParser.new(:logger => @logger))
|
87
|
+
opts['Marker'] = last_response[:next_marker]
|
88
|
+
break unless block && block.call(last_response) && !last_response[:next_marker].blank?
|
89
|
+
end
|
90
|
+
last_response
|
91
|
+
end
|
92
|
+
|
93
|
+
#-----------------------------------------------------------------
|
94
|
+
# Origin Access Identity
|
95
|
+
#-----------------------------------------------------------------
|
96
|
+
|
97
|
+
# Create a new CloudFront Origin Access Identity.
|
98
|
+
#
|
99
|
+
# acf.create_origin_access_identity('MyTestAccessIdentity') #=>
|
100
|
+
# {:e_tag=>"E2QOKZEXCUWHJX",
|
101
|
+
# :comment=>"MyTestAccessIdentity",
|
102
|
+
# :location=>
|
103
|
+
# "https://cloudfront.amazonaws.com/origin-access-identity/cloudfront/E3JPJZ80ZBX24G",
|
104
|
+
# :caller_reference=>"201004161657467493031273",
|
105
|
+
# :s3_canonical_user_id=>
|
106
|
+
# "de4361b33dbaf499d3d77159bfa1571d3451eaec25a2b16553de5e534da8089bb8c31a4898d73d1a658155d0e48872a7",
|
107
|
+
# :aws_id=>"E3JPJZ80ZBX24G"}
|
108
|
+
#
|
109
|
+
def create_origin_access_identity(comment='', caller_reference=nil)
|
110
|
+
config = { :comment => comment,
|
111
|
+
:caller_reference => caller_reference }
|
112
|
+
create_origin_access_identity_by_config(config)
|
113
|
+
end
|
114
|
+
|
115
|
+
def create_origin_access_identity_by_config(config)
|
116
|
+
config[:caller_reference] ||= generate_call_reference
|
117
|
+
link = generate_request('POST', 'origin-access-identity/cloudfront', {}, origin_access_identity_config_to_xml(config))
|
118
|
+
merge_headers(request_info(link, AcfOriginAccesIdentitiesListParser.new(:logger => @logger))[:origin_access_identities].first)
|
119
|
+
end
|
120
|
+
|
121
|
+
# Get Origin Access Identity
|
122
|
+
#
|
123
|
+
# acf.get_origin_access_identity('E3HJ7V8C3324VF') #=>
|
124
|
+
# {:comment=>"kd: TEST-2",
|
125
|
+
# :caller_reference=>"201004161655035372351604",
|
126
|
+
# :aws_id=>"E3HJ7V8C3324VF",
|
127
|
+
# :s3_canonical_user_id=>
|
128
|
+
# "9af7058b1d197c2c03fdcc3ddad07012a7822f5fc4a8156025409ffac646bdae4dc714820482c92e6988e5703c8d9954",
|
129
|
+
# :e_tag=>"E309Q4IM450498"}
|
130
|
+
#
|
131
|
+
def get_origin_access_identity(aws_id)
|
132
|
+
link = generate_request('GET', "origin-access-identity/cloudfront/#{aws_id}")
|
133
|
+
merge_headers(request_info(link, AcfOriginAccesIdentitiesListParser.new(:logger => @logger))[:origin_access_identities].first)
|
134
|
+
end
|
135
|
+
|
136
|
+
# Get Origin Access Identity
|
137
|
+
#
|
138
|
+
# acf.get_origin_access_identity('E3HJ7V8C3324VF') #=>
|
139
|
+
# {:comment=>"kd: TEST-2",
|
140
|
+
# :caller_reference=>"201004161655035372351604",
|
141
|
+
# :aws_id=>"E3HJ7V8C3324VF",
|
142
|
+
# :s3_canonical_user_id=>
|
143
|
+
# "9af7058b1d197c2c03fdcc3ddad07012a7822f5fc4a8156025409ffac646bdae4dc714820482c92e6988e5703c8d9954",
|
144
|
+
# :e_tag=>"E309Q4IM450498"}
|
145
|
+
#
|
146
|
+
# acf.delete_origin_access_identity("E3HJ7V8C3324VF","E309Q4IM450498") #=> true
|
147
|
+
#
|
148
|
+
def delete_origin_access_identity(aws_id, e_tag)
|
149
|
+
link = generate_request('DELETE', "origin-access-identity/cloudfront/#{aws_id}", {}, nil,
|
150
|
+
'If-Match' => e_tag)
|
151
|
+
request_info(link, RightHttp2xxParser.new(:logger => @logger))
|
152
|
+
end
|
153
|
+
|
154
|
+
#-----------------------------------------------------------------
|
155
|
+
# Config
|
156
|
+
#-----------------------------------------------------------------
|
157
|
+
|
158
|
+
def origin_access_identity_config_to_xml(config) # :nodoc:
|
159
|
+
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
|
160
|
+
"<CloudFrontOriginAccessIdentityConfig xmlns=\"http://#{@params[:server]}/doc/#{API_VERSION}/\">\n" +
|
161
|
+
" <CallerReference>#{config[:caller_reference]}</CallerReference>\n" +
|
162
|
+
" <Comment>#{AcfInterface::escape(config[:comment].to_s)}</Comment>\n" +
|
163
|
+
"</CloudFrontOriginAccessIdentityConfig>"
|
164
|
+
end
|
165
|
+
|
166
|
+
# Get Origin Access Identity config
|
167
|
+
#
|
168
|
+
# acf.get_origin_access_identity_config("E3JPJZ80ZBX24G") #=>
|
169
|
+
# {:comment=>"MyTestAccessIdentity",
|
170
|
+
# :caller_reference=>"201004161657467493031273",
|
171
|
+
# :e_tag=>"E2QOKZEXCUWHJX"}
|
172
|
+
#
|
173
|
+
def get_origin_access_identity_config(aws_id)
|
174
|
+
link = generate_request('GET', "origin-access-identity/cloudfront/#{aws_id}/config")
|
175
|
+
merge_headers(request_info(link, AcfOriginAccesIdentitiesListParser.new(:logger => @logger))[:origin_access_identities].first)
|
176
|
+
end
|
177
|
+
|
178
|
+
# Set Origin Access Identity config
|
179
|
+
#
|
180
|
+
#
|
181
|
+
# acf.set_origin_access_identity_config("E2QOKZEXCUWHJX",
|
182
|
+
# :comment => "MyBestOriginAccessConfig",
|
183
|
+
# :caller_reference => '01234567890',
|
184
|
+
# :e_tag=>"E2QOKZEXCUWHJX") #=> true
|
185
|
+
#
|
186
|
+
# P.S. This guy is not tested yet: http://developer.amazonwebservices.com/connect/thread.jspa?threadID=45256
|
187
|
+
def set_origin_access_identity_config(aws_id, config)
|
188
|
+
link = generate_request('PUT', "origin-access-identity/cloudfront/#{aws_id}/config", {}, origin_access_identity_config_to_xml(config),
|
189
|
+
'If-Match' => config[:e_tag])
|
190
|
+
request_info(link, RightHttp2xxParser.new(:logger => @logger))
|
191
|
+
end
|
192
|
+
|
193
|
+
#-----------------------------------------------------------------
|
194
|
+
# PARSERS:
|
195
|
+
#-----------------------------------------------------------------
|
196
|
+
|
197
|
+
class AcfOriginAccesIdentitiesListParser < RightAWSParser # :nodoc:
|
198
|
+
def reset
|
199
|
+
@result = { :origin_access_identities => [] }
|
200
|
+
end
|
201
|
+
def tagstart(name, attributes)
|
202
|
+
case full_tag_name
|
203
|
+
when %r{CloudFrontOriginAccessIdentitySummary$},
|
204
|
+
%r{^CloudFrontOriginAccessIdentity$},
|
205
|
+
%r{^CloudFrontOriginAccessIdentityConfig$}
|
206
|
+
@item = {}
|
207
|
+
end
|
208
|
+
end
|
209
|
+
def tagend(name)
|
210
|
+
case name
|
211
|
+
when 'Marker' then @result[:marker] = @text
|
212
|
+
when 'NextMarker' then @result[:next_marker] = @text
|
213
|
+
when 'MaxItems' then @result[:max_items] = @text.to_i
|
214
|
+
when 'IsTruncated' then @result[:is_truncated] = (@text == 'true')
|
215
|
+
when 'Id' then @item[:aws_id] = @text
|
216
|
+
when 'S3CanonicalUserId' then @item[:s3_canonical_user_id] = @text
|
217
|
+
when 'CallerReference' then @item[:caller_reference] = @text
|
218
|
+
when 'Comment' then @item[:comment] = AcfInterface::unescape(@text)
|
219
|
+
end
|
220
|
+
case full_tag_name
|
221
|
+
when %r{CloudFrontOriginAccessIdentitySummary$},
|
222
|
+
%r{^CloudFrontOriginAccessIdentity$},
|
223
|
+
%r{^CloudFrontOriginAccessIdentityConfig$}
|
224
|
+
@result[:origin_access_identities] << @item
|
225
|
+
end
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
end
|
230
|
+
end
|