aws 2.3.25 → 2.3.26

Sign up to get free protection for your applications and to get access to all the features.
@@ -195,6 +195,11 @@ module Aws
195
195
  request_cache_or_info :list_distributions, request_hash, AcfDistributionListParser, @@bench
196
196
  end
197
197
 
198
+ def list_streaming_distributions
199
+ request_hash = generate_request('GET', 'streaming-distribution')
200
+ request_cache_or_info :list_streaming_distributions, request_hash, AcfStreamingDistributionListParser, @@bench
201
+ end
202
+
198
203
  # Create a new distribution.
199
204
  # Returns the just created distribution or Aws::AwsError exception.
200
205
  #
@@ -210,26 +215,38 @@ module Aws
210
215
  # :last_modified_time => Wed Sep 10 17:00:54 UTC 2008,
211
216
  # :caller_reference => "200809102100536497863003"}
212
217
  #
213
- def create_distribution(origin, comment='', enabled=true, cnames=[], caller_reference=nil)
218
+ def create_distribution(origin, comment='', enabled=true, cnames=[], caller_reference=nil, default_root_object=nil)
219
+ body = distribution_config_for(origin, comment, enabled, cnames, caller_reference, false, default_root_object)
220
+ request_hash = generate_request('POST', 'distribution', body.strip)
221
+ merge_headers(request_info(request_hash, AcfDistributionParser.new))
222
+ end
223
+
224
+ def create_streaming_distribution(origin, comment='', enabled=true, cnames=[], caller_reference=nil, default_root_object=nil)
225
+ body = distribution_config_for(origin, comment, enabled, cnames, caller_reference, true, default_root_object)
226
+ request_hash = generate_request('POST', 'streaming-distribution', body.strip)
227
+ merge_headers(request_info(request_hash, AcfDistributionParser.new))
228
+ end
229
+
230
+ def distribution_config_for(origin, comment='', enabled=true, cnames=[], caller_reference=nil, streaming = false, default_root_object=nil)
231
+ rootElement = streaming ? "StreamingDistributionConfig" : "DistributionConfig"
214
232
  # join CNAMES
215
233
  cnames_str = ''
216
234
  unless cnames.blank?
217
235
  cnames.to_a.each { |cname| cnames_str += "\n <CNAME>#{cname}</CNAME>" }
218
236
  end
219
- # reference
220
237
  caller_reference ||= generate_call_reference
238
+ root_ob = default_root_object ? "<DefaultRootObject>#{config[:default_root_object]}</DefaultRootObject>" : ""
221
239
  body = <<-EOXML
222
240
  <?xml version="1.0" encoding="UTF-8"?>
223
- <DistributionConfig xmlns=#{xmlns}>
241
+ <#{rootElement} xmlns=#{xmlns}>
224
242
  <Origin>#{origin}</Origin>
225
243
  <CallerReference>#{caller_reference}</CallerReference>
226
244
  #{cnames_str.lstrip}
227
245
  <Comment>#{AcfInterface::escape(comment.to_s)}</Comment>
228
246
  <Enabled>#{enabled}</Enabled>
229
- </DistributionConfig>
247
+ #{root_ob}
248
+ </#{rootElement}>
230
249
  EOXML
231
- request_hash = generate_request('POST', 'distribution', body.strip)
232
- merge_headers(request_info(request_hash, AcfDistributionParser.new))
233
250
  end
234
251
 
235
252
  # Get a distribution's information.
@@ -252,6 +269,11 @@ module Aws
252
269
  merge_headers(request_info(request_hash, AcfDistributionParser.new))
253
270
  end
254
271
 
272
+ def get_streaming_distribution(aws_id)
273
+ request_hash = generate_request('GET', "streaming-distribution/#{aws_id}")
274
+ merge_headers(request_info(request_hash, AcfDistributionParser.new))
275
+ end
276
+
255
277
  # Get a distribution's configuration.
256
278
  # Returns a distribution's configuration or Aws::AwsError exception.
257
279
  #
@@ -286,25 +308,15 @@ module Aws
286
308
  # acf.set_distribution_config('E2REJM3VUN5RSI', config) #=> true
287
309
  #
288
310
  def set_distribution_config(aws_id, config)
289
- # join CNAMES
290
- cnames_str = ''
291
- unless config[:cnames].blank?
292
- config[:cnames].to_a.each { |cname| cnames_str += "\n <CNAME>#{cname}</CNAME>" }
293
- end
294
- root_ob = config[:default_root_object] ? "<DefaultRootObject>#{config[:default_root_object]}</DefaultRootObject>" : ""
295
- # format request's XML body
296
- body = <<-EOXML
297
- <?xml version="1.0" encoding="UTF-8"?>
298
- <DistributionConfig xmlns=#{xmlns}>
299
- <Origin>#{config[:origin]}</Origin>
300
- <CallerReference>#{config[:caller_reference]}</CallerReference>
301
- #{cnames_str.lstrip}
302
- <Comment>#{AcfInterface::escape(config[:comment].to_s)}</Comment>
303
- <Enabled>#{config[:enabled]}</Enabled>
304
- #{root_ob}
305
- </DistributionConfig>
306
- EOXML
307
- request_hash = generate_request('PUT', "distribution/#{aws_id}/config", body.strip,
311
+ body = distribution_config_for(config[:origin], config[:comment], config[:enabled], config[:cnames], config[:caller_reference], false)
312
+ request_hash = generate_request('PUT', "distribution/#{aws_id}/config", body.strip,
313
+ 'If-Match' => config[:e_tag])
314
+ request_info(request_hash, RightHttp2xxParser.new)
315
+ end
316
+
317
+ def set_streaming_distribution_config(aws_id, config)
318
+ body = distribution_config_for(config[:origin], config[:comment], config[:enabled], config[:cnames], config[:caller_reference], true)
319
+ request_hash = generate_request('PUT', "streaming-distribution/#{aws_id}/config", body.strip,
308
320
  'If-Match' => config[:e_tag])
309
321
  request_info(request_hash, RightHttp2xxParser.new)
310
322
  end
@@ -320,46 +332,52 @@ module Aws
320
332
  request_info(request_hash, RightHttp2xxParser.new)
321
333
  end
322
334
 
335
+ def delete_streaming_distribution(aws_id, e_tag)
336
+ request_hash = generate_request('DELETE', "streaming-distribution/#{aws_id}", nil,
337
+ 'If-Match' => e_tag)
338
+ request_info(request_hash, RightHttp2xxParser.new)
339
+ end
340
+
323
341
  #-----------------------------------------------------------------
324
342
  # PARSERS:
325
343
  #-----------------------------------------------------------------
326
344
 
327
- class AcfDistributionListParser < AwsParser # :nodoc:
345
+ # Parses attributes common to many CF distribution API calls
346
+ class AcfBaseDistributionParser < AwsParser # :nodoc:
328
347
  def reset
348
+ @distribution = { :cnames => [] }
329
349
  @result = []
330
350
  end
331
- def tagstart(name, attributes)
332
- @distribution = { :cnames => [] } if name == 'DistributionSummary'
333
- end
334
351
  def tagend(name)
335
352
  case name
336
- when 'Id' then @distribution[:aws_id] = @text
337
- when 'Status' then @distribution[:status] = @text
338
- when 'LastModifiedTime' then @distribution[:last_modified_time] = Time.parse(@text)
339
- when 'DomainName' then @distribution[:domain_name] = @text
340
- when 'Origin' then @distribution[:origin] = @text
341
- when 'Comment' then @distribution[:comment] = AcfInterface::unescape(@text)
342
- when 'CNAME' then @distribution[:cnames] << @text
343
- when 'DistributionSummary' then @result << @distribution
353
+ when 'Id' then @distribution[:aws_id] = @text
354
+ when 'Status' then @distribution[:status] = @text
355
+ when 'LastModifiedTime' then @distribution[:last_modified_time] = Time.parse(@text)
356
+ when 'DomainName' then @distribution[:domain_name] = @text
357
+ when 'Origin' then @distribution[:origin] = @text
358
+ when 'CallerReference' then @distribution[:caller_reference] = @text
359
+ when 'Comment' then @distribution[:comment] = AcfInterface::unescape(@text)
360
+ when 'Enabled' then @distribution[:enabled] = @text == 'true' ? true : false
361
+ when 'CNAME' then @distribution[:cnames] << @text
344
362
  end
345
363
  end
346
364
  end
347
365
 
348
- class AcfDistributionParser < AwsParser # :nodoc:
349
- def reset
350
- @result = { :cnames => [] }
366
+ class AcfDistributionParser < AcfBaseDistributionParser # :nodoc:
367
+ def tagend(name)
368
+ super
369
+ @result = @distribution
370
+ end
371
+ end
372
+
373
+ class AcfDistributionListParser < AcfBaseDistributionParser # :nodoc:
374
+ def tagstart(name, attributes)
375
+ @distribution = { :cnames => [] } if name == 'DistributionSummary'
351
376
  end
352
377
  def tagend(name)
378
+ super(name)
353
379
  case name
354
- when 'Id' then @result[:aws_id] = @text
355
- when 'Status' then @result[:status] = @text
356
- when 'LastModifiedTime' then @result[:last_modified_time] = Time.parse(@text)
357
- when 'DomainName' then @result[:domain_name] = @text
358
- when 'Origin' then @result[:origin] = @text
359
- when 'CallerReference' then @result[:caller_reference] = @text
360
- when 'Comment' then @result[:comment] = AcfInterface::unescape(@text)
361
- when 'Enabled' then @result[:enabled] = @text == 'true' ? true : false
362
- when 'CNAME' then @result[:cnames] << @text
380
+ when 'DistributionSummary' then @result << @distribution
363
381
  end
364
382
  end
365
383
  end
@@ -379,5 +397,17 @@ module Aws
379
397
  end
380
398
  end
381
399
 
400
+ class AcfStreamingDistributionListParser < AcfBaseDistributionParser # :nodoc:
401
+ def tagstart(name, attributes)
402
+ @distribution = { :cnames => [] } if name == 'StreamingDistributionSummary'
403
+ end
404
+ def tagend(name)
405
+ super(name)
406
+ case name
407
+ when 'StreamingDistributionSummary' then @result << @distribution
408
+ end
409
+ end
410
+ end
411
+
382
412
  end
383
413
  end
data/lib/aws.rb CHANGED
@@ -27,4 +27,5 @@ require 'sdb/right_sdb_interface'
27
27
  require 'acf/right_acf_interface'
28
28
  require 'elb/elb_interface'
29
29
  require 'rds/rds'
30
+ require 'iam/iam'
30
31
 
data/lib/ec2/right_ec2.rb CHANGED
@@ -81,7 +81,7 @@ module Aws
81
81
  # Amazon EC2 Instance Types : http://www.amazon.com/b?ie=UTF8&node=370375011
82
82
  # Default EC2 instance type (platform)
83
83
  DEFAULT_INSTANCE_TYPE = 'm1.small'
84
- INSTANCE_TYPES = ['m1.small','c1.medium','m1.large','m1.xlarge','c1.xlarge']
84
+ INSTANCE_TYPES = ['t1.micro', 'm1.small','c1.medium','m1.large','m1.xlarge','c1.xlarge']
85
85
 
86
86
  @@bench = AwsBenchmarkingBlock.new
87
87
  def self.bench_xml
@@ -186,7 +186,10 @@ module Aws
186
186
  params.each do |list_by, list|
187
187
  request_hash.merge! hash_params(list_by, list.to_a)
188
188
  end
189
- request_hash['ImageType'] = image_type if image_type
189
+ if image_type
190
+ request_hash['Filter.1.Name'] = "image-type"
191
+ request_hash['Filter.1.Value.1'] = image_type
192
+ end
190
193
  link = generate_request("DescribeImages", request_hash)
191
194
  request_cache_or_info cache_for, link, QEc2DescribeImagesParser, @@bench, cache_for
192
195
  rescue Exception
@@ -1433,6 +1436,8 @@ module Aws
1433
1436
  def tagend(name)
1434
1437
  case name
1435
1438
  when 'imageId' then @image[:aws_id] = @text
1439
+ when 'name' then @image[:aws_name] = @text
1440
+ when 'description' then @image[:aws_description] = @text
1436
1441
  when 'imageLocation' then @image[:aws_location] = @text
1437
1442
  when 'imageState' then @image[:aws_state] = @text
1438
1443
  when 'imageOwnerId' then @image[:aws_owner] = @text
data/lib/iam/iam.rb ADDED
@@ -0,0 +1,118 @@
1
+ module Aws
2
+
3
+ require 'xmlsimple'
4
+
5
+ class Iam < AwsBase
6
+
7
+ include AwsBaseInterface
8
+
9
+ API_VERSION = "2010-05-08"
10
+ DEFAULT_HOST = "iam.amazonaws.com"
11
+ DEFAULT_PATH = '/'
12
+ DEFAULT_PROTOCOL = 'https'
13
+ DEFAULT_PORT = 443
14
+
15
+ @@bench = AwsBenchmarkingBlock.new
16
+
17
+ def self.bench_xml
18
+ @@bench.xml
19
+ end
20
+
21
+ def self.bench_ec2
22
+ @@bench.service
23
+ end
24
+
25
+ # Current API version (sometimes we have to check it outside the GEM).
26
+ @@api = ENV['IAM_API_VERSION'] || API_VERSION
27
+
28
+ def self.api
29
+ @@api
30
+ end
31
+
32
+
33
+ def initialize(aws_access_key_id=nil, aws_secret_access_key=nil, params={})
34
+ init({:name => 'IAM',
35
+ :default_host => ENV['IAM_URL'] ? URI.parse(ENV['IAM_URL']).host : DEFAULT_HOST,
36
+ :default_port => ENV['IAM_URL'] ? URI.parse(ENV['IAM_URL']).port : DEFAULT_PORT,
37
+ :default_service => ENV['IAM_URL'] ? URI.parse(ENV['IAM_URL']).path : DEFAULT_PATH,
38
+ :default_protocol => ENV['IAM_URL'] ? URI.parse(ENV['IAM_URL']).scheme : DEFAULT_PROTOCOL,
39
+ :api_version => API_VERSION},
40
+ aws_access_key_id || ENV['AWS_ACCESS_KEY_ID'],
41
+ aws_secret_access_key|| ENV['AWS_SECRET_ACCESS_KEY'],
42
+ params)
43
+ end
44
+
45
+ def do_request(action, params, options={})
46
+ link = generate_request(action, params)
47
+ p link[:request]
48
+ resp = request_info_xml_simple(:iam_connection, @params, link, @logger,
49
+ :group_tags =>{"LoadBalancersDescriptions"=>"LoadBalancersDescription",
50
+ "DBParameterGroups" =>"DBParameterGroup",
51
+ "DBSecurityGroups" =>"DBSecurityGroup",
52
+ "EC2SecurityGroups" =>"EC2SecurityGroup",
53
+ "IPRanges" =>"IPRange"},
54
+ :force_array =>["DBInstances",
55
+ "DBParameterGroups",
56
+ "DBSecurityGroups",
57
+ "EC2SecurityGroups",
58
+ "IPRanges"],
59
+ :pull_out_array =>options[:pull_out_array],
60
+ :pull_out_single=>options[:pull_out_single],
61
+ :wrapper =>options[:wrapper])
62
+ end
63
+
64
+
65
+ #-----------------------------------------------------------------
66
+ # REQUESTS
67
+ #-----------------------------------------------------------------
68
+
69
+
70
+ # options:
71
+ # :marker => value received from previous response if IsTruncated = true
72
+ # :max_items => number of items you want returned
73
+ # :path_previx => for filtering results, default is /
74
+ def list_server_certificates(options={})
75
+ @logger.info("Listing server certificates...")
76
+
77
+ params = {}
78
+ params['Marker'] = options[:marker] if options[:marker]
79
+ params['MaxItems'] = options[:max_items] if options[:max_items]
80
+ params['PathPrefix'] = options[:path_prefix] if options[:path_prefix]
81
+
82
+ resp = do_request("ListServerCertificates", params, :pull_out_array=>[:list_server_certificates_result, :server_certificate_metadata_list])
83
+
84
+
85
+ rescue Exception
86
+ on_exception
87
+ end
88
+
89
+ #
90
+ # name: name of certificate
91
+ # public_key: public key certificate in PEM-encoded format
92
+ # private_key: private key in PEM-encoded format
93
+ # options:
94
+ # :path => specify a path you want it stored in
95
+ # :certificate_chain => contents of certificate chain
96
+ def upload_server_certificate(name, public_key, private_key, options={})
97
+ params = {}
98
+ params['ServerCertificateName'] = name
99
+ params['PrivateKey'] = private_key
100
+ params['CertificateBody'] = public_key
101
+
102
+ params['CertificateChain'] = options[:certificate_chain] if options[:certificate_chain]
103
+ params['Path'] = options[:path] if options[:path]
104
+
105
+ p params
106
+
107
+ resp = do_request("UploadServerCertificate", params, :pull_out_array=>[:list_server_certificates_result, :server_certificate_metadata_list])
108
+
109
+
110
+ rescue Exception
111
+ on_exception
112
+ end
113
+
114
+
115
+ end
116
+
117
+
118
+ end
@@ -0,0 +1,36 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../../lib/aws'
3
+ require 'pp'
4
+ require File.dirname(__FILE__) + '/../test_credentials.rb'
5
+
6
+ class TestElb < Test::Unit::TestCase
7
+
8
+ # Some of RightEc2 instance methods concerning instance launching and image registration
9
+ # are not tested here due to their potentially risk.
10
+
11
+ def setup
12
+ TestCredentials.get_credentials
13
+
14
+ @iam = Aws::Iam.new(TestCredentials.aws_access_key_id,
15
+ TestCredentials.aws_secret_access_key)
16
+
17
+ end
18
+
19
+ def test_01_list_server_certificates
20
+
21
+ ret = @iam.list_server_certificates
22
+ p ret
23
+ assert_true(ret.size == 0)
24
+ end
25
+
26
+ def test_02_upload_server_certificate
27
+ ret = @iam.upload_server_certificate("test_cert",
28
+ IO.read('x').strip,
29
+ IO.read('y').strip,
30
+ :certificate_chain=>IO.read('z').strip)
31
+
32
+ p ret
33
+ end
34
+
35
+
36
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 2
7
7
  - 3
8
- - 25
9
- version: 2.3.25
8
+ - 26
9
+ version: 2.3.26
10
10
  platform: ruby
11
11
  authors:
12
12
  - Travis Reeder
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-11-04 00:00:00 -07:00
19
+ date: 2010-11-15 00:00:00 -08:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -89,6 +89,7 @@ files:
89
89
  - lib/ec2/right_ec2.rb
90
90
  - lib/ec2/right_mon_interface.rb
91
91
  - lib/elb/elb_interface.rb
92
+ - lib/iam/iam.rb
92
93
  - lib/rds/rds.rb
93
94
  - lib/right_aws.rb
94
95
  - lib/s3/right_s3.rb
@@ -105,6 +106,7 @@ files:
105
106
  - test/ec2/test_mon.rb
106
107
  - test/elb/test_elb.rb
107
108
  - test/http_connection.rb
109
+ - test/iam/test_iam.rb
108
110
  - test/rds/test_rds.rb
109
111
  - test/s3/test_helper.rb
110
112
  - test/s3/test_s3.rb
@@ -156,6 +158,7 @@ test_files:
156
158
  - test/ec2/test_mon.rb
157
159
  - test/elb/test_elb.rb
158
160
  - test/http_connection.rb
161
+ - test/iam/test_iam.rb
159
162
  - test/rds/test_rds.rb
160
163
  - test/s3/test_helper.rb
161
164
  - test/s3/test_s3.rb