talaris-right_aws 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. data/History.txt +305 -0
  2. data/Manifest.txt +60 -0
  3. data/README.txt +163 -0
  4. data/Rakefile +104 -0
  5. data/lib/acf/right_acf_interface.rb +549 -0
  6. data/lib/acf/right_acf_invalidations.rb +144 -0
  7. data/lib/acf/right_acf_origin_access_identities.rb +230 -0
  8. data/lib/acf/right_acf_streaming_interface.rb +229 -0
  9. data/lib/acw/right_acw_interface.rb +248 -0
  10. data/lib/as/right_as_interface.rb +698 -0
  11. data/lib/awsbase/benchmark_fix.rb +39 -0
  12. data/lib/awsbase/right_awsbase.rb +1174 -0
  13. data/lib/awsbase/support.rb +35 -0
  14. data/lib/awsbase/version.rb +9 -0
  15. data/lib/ec2/right_ec2.rb +458 -0
  16. data/lib/ec2/right_ec2_ebs.rb +465 -0
  17. data/lib/ec2/right_ec2_images.rb +413 -0
  18. data/lib/ec2/right_ec2_instances.rb +785 -0
  19. data/lib/ec2/right_ec2_monitoring.rb +70 -0
  20. data/lib/ec2/right_ec2_placement_groups.rb +108 -0
  21. data/lib/ec2/right_ec2_reserved_instances.rb +174 -0
  22. data/lib/ec2/right_ec2_security_groups.rb +396 -0
  23. data/lib/ec2/right_ec2_spot_instances.rb +425 -0
  24. data/lib/ec2/right_ec2_tags.rb +139 -0
  25. data/lib/ec2/right_ec2_vpc.rb +583 -0
  26. data/lib/ec2/right_ec2_windows_mobility.rb +84 -0
  27. data/lib/elb/right_elb_interface.rb +571 -0
  28. data/lib/iam/right_iam_access_keys.rb +71 -0
  29. data/lib/iam/right_iam_groups.rb +195 -0
  30. data/lib/iam/right_iam_interface.rb +341 -0
  31. data/lib/iam/right_iam_mfa_devices.rb +67 -0
  32. data/lib/iam/right_iam_users.rb +251 -0
  33. data/lib/rds/right_rds_interface.rb +1309 -0
  34. data/lib/right_aws.rb +83 -0
  35. data/lib/route_53/right_route_53_interface.rb +630 -0
  36. data/lib/s3/right_s3.rb +1123 -0
  37. data/lib/s3/right_s3_interface.rb +1198 -0
  38. data/lib/sdb/active_sdb.rb +1107 -0
  39. data/lib/sdb/right_sdb_interface.rb +753 -0
  40. data/lib/sqs/right_sqs.rb +387 -0
  41. data/lib/sqs/right_sqs_gen2.rb +342 -0
  42. data/lib/sqs/right_sqs_gen2_interface.rb +523 -0
  43. data/lib/sqs/right_sqs_interface.rb +593 -0
  44. data/right_aws.gemspec +91 -0
  45. data/test/acf/test_helper.rb +2 -0
  46. data/test/acf/test_right_acf.rb +138 -0
  47. data/test/awsbase/test_helper.rb +2 -0
  48. data/test/awsbase/test_right_awsbase.rb +12 -0
  49. data/test/ec2/test_helper.rb +2 -0
  50. data/test/ec2/test_right_ec2.rb +108 -0
  51. data/test/http_connection.rb +87 -0
  52. data/test/rds/test_helper.rb +2 -0
  53. data/test/rds/test_right_rds.rb +120 -0
  54. data/test/s3/test_helper.rb +2 -0
  55. data/test/s3/test_right_s3.rb +421 -0
  56. data/test/s3/test_right_s3_stubbed.rb +97 -0
  57. data/test/sdb/test_active_sdb.rb +357 -0
  58. data/test/sdb/test_batch_put_attributes.rb +54 -0
  59. data/test/sdb/test_helper.rb +3 -0
  60. data/test/sdb/test_right_sdb.rb +253 -0
  61. data/test/sqs/test_helper.rb +2 -0
  62. data/test/sqs/test_right_sqs.rb +285 -0
  63. data/test/sqs/test_right_sqs_gen2.rb +264 -0
  64. data/test/test_credentials.rb +37 -0
  65. data/test/ts_right_aws.rb +14 -0
  66. metadata +214 -0
@@ -0,0 +1,144 @@
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 Invalidations
28
+ #
29
+ # acf.list_invalidations('E3LTBMK4EAQS7D') #=>
30
+ # [{:status=>"InProgress", :aws_id=>"I3AW9PPQS0CBKV"},
31
+ # {:status=>"InProgress", :aws_id=>"I1HV23N5KD3XH9"}]
32
+ #
33
+ def list_invalidations(distribution_aws_id)
34
+ result = []
35
+ incrementally_list_invalidations(distribution_aws_id) do |response|
36
+ result += response[:invalidations]
37
+ true
38
+ end
39
+ result
40
+ end
41
+
42
+ # Incrementally list Invalidations.
43
+ # Optional params: +:marker+ and +:max_items+.
44
+ #
45
+ def incrementally_list_invalidations(distribution_aws_id, params={}, &block)
46
+ opts = {}
47
+ opts['MaxItems'] = params[:max_items] if params[:max_items]
48
+ opts['Marker'] = params[:marker] if params[:marker]
49
+ last_response = nil
50
+ loop do
51
+ link = generate_request('GET', "distribution/#{distribution_aws_id}/invalidation", opts)
52
+ last_response = request_info(link, AcfInvalidationsListParser.new(:logger => @logger))
53
+ opts['Marker'] = last_response[:next_marker]
54
+ break unless block && block.call(last_response) && !last_response[:next_marker].right_blank?
55
+ end
56
+ last_response
57
+ end
58
+
59
+ #-----------------------------------------------------------------
60
+ # Origin Access Identity
61
+ #-----------------------------------------------------------------
62
+
63
+ # Create a new Invalidation batch.
64
+ #
65
+ # acf.create_invalidation('E3LTBMK4EAQS7D', :path => ['/boot.jpg', '/kd/boot.public.1.jpg']) #=>
66
+ # {:status=>"InProgress",
67
+ # :create_time=>"2010-12-08T14:03:38.449Z",
68
+ # :location=> "https://cloudfront.amazonaws.com/2010-11-01/distribution/E3LTBMK4EAQS7D/invalidation/I3AW9PPQS0CBKV",
69
+ # :aws_id=>"I3AW9PPQS0CBKV",
70
+ # :invalidation_batch=>
71
+ # {:caller_reference=>"201012081703372555972012",
72
+ # :path=>["/boot.jpg", "/kd/boot.public.1.jpg"]}}
73
+ #
74
+ def create_invalidation(distribution_aws_id, invalidation_batch)
75
+ invalidation_batch[:caller_reference] ||= generate_call_reference
76
+ link = generate_request('POST', "/distribution/#{distribution_aws_id}/invalidation", {}, invalidation_batch_to_xml(invalidation_batch))
77
+ merge_headers(request_info(link, AcfInvalidationsListParser.new(:logger => @logger))[:invalidations].first)
78
+ end
79
+
80
+ # Get Invalidation
81
+ #
82
+ # acf.get_invalidation('E3LTBMK4EAQS7D', 'I3AW9PPQS0CBKV') #=>
83
+ # {:create_time=>"2010-12-08T14:03:38.449Z",
84
+ # :status=>"InProgress",
85
+ # :aws_id=>"I3AW9PPQS0CBKV",
86
+ # :invalidation_batch=>
87
+ # {:caller_reference=>"201012081703372555972012",
88
+ # :path=>["/boot.jpg", "/kd/boot.public.1.jpg"]}}
89
+ #
90
+ def get_invalidation(distribution_aws_id, aws_id)
91
+ link = generate_request('GET', "distribution/#{distribution_aws_id}/invalidation/#{aws_id}")
92
+ merge_headers(request_info(link, AcfInvalidationsListParser.new(:logger => @logger))[:invalidations].first)
93
+ end
94
+
95
+ #-----------------------------------------------------------------
96
+ # Batch
97
+ #-----------------------------------------------------------------
98
+
99
+ def invalidation_batch_to_xml(invalidation_batch) # :nodoc:
100
+ paths = ''
101
+ Array(invalidation_batch[:path]).each do |path|
102
+ paths << " <Path>#{AwsUtils::xml_escape(path)}</Path>\n"
103
+ end
104
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
105
+ "<InvalidationBatch xmlns=\"http://#{@params[:server]}/doc/#{API_VERSION}/\">\n" +
106
+ " <CallerReference>#{invalidation_batch[:caller_reference]}</CallerReference>\n" +
107
+ paths +
108
+ "</InvalidationBatch>"
109
+ end
110
+
111
+ #-----------------------------------------------------------------
112
+ # PARSERS:
113
+ #-----------------------------------------------------------------
114
+
115
+ class AcfInvalidationsListParser < RightAWSParser # :nodoc:
116
+ def reset
117
+ @result = { :invalidations => [] }
118
+ end
119
+ def tagstart(name, attributes)
120
+ case name
121
+ when %r{(InvalidationSummary|Invalidation)$} then @item = {}
122
+ when %r{InvalidationBatch} then @item[:invalidation_batch] = {}
123
+ end
124
+ end
125
+ def tagend(name)
126
+ case name
127
+ when 'Marker' then @result[:marker] = @text
128
+ when 'NextMarker' then @result[:next_marker] = @text
129
+ when 'MaxItems' then @result[:max_items] = @text.to_i
130
+ when 'IsTruncated' then @result[:is_truncated] = (@text == 'true')
131
+ when 'Id' then @item[:aws_id] = @text
132
+ when 'Status' then @item[:status] = @text
133
+ when 'CreateTime' then @item[:create_time] = @text
134
+ when 'Path' then (@item[:invalidation_batch][:path] ||= []) << @text
135
+ when 'CallerReference' then @item[:invalidation_batch][:caller_reference] = @text
136
+ when %r{(InvalidationSummary|Invalidation)$}
137
+ @item[:invalidation_batch][:path].sort! if @item[:invalidation_batch] && !@item[:invalidation_batch][:path].right_blank?
138
+ @result[:invalidations] << @item
139
+ end
140
+ end
141
+ end
142
+
143
+ end
144
+ 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].right_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>#{AwsUtils::xml_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] = AwsUtils::xml_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
@@ -0,0 +1,229 @@
1
+ #
2
+ # Copyright (c) 2008 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
+ def streaming_distribution_config_to_xml(config) # :nodoc:
28
+ distribution_config_to_xml(config, 'StreamingDistributionConfig')
29
+ end
30
+
31
+ #-----------------------------------------------------------------
32
+ # API Calls:
33
+ #-----------------------------------------------------------------
34
+
35
+ # List all streaming distributions.
36
+ # Returns an array of distributions or RightAws::AwsError exception.
37
+ #
38
+ # acf.list_streaming_distributions #=>
39
+ # [{:status=>"Deployed",
40
+ # :aws_id=>"E3CWE2Z9USOS6B",
41
+ # :enabled=>true,
42
+ # :domain_name=>"s2jz1ourvss1fj.cloudfront.net",
43
+ # :s3_origin=> {:dns_name=>"bucket-for-konstantin-00.s3.amazonaws.com"},
44
+ # :last_modified_time=>"2010-04-19T08:53:32.574Z",
45
+ # :comment=>"Woo-Hoo!",
46
+ # :cnames=>["stream.web.my-awesome-site.net"]},
47
+ # ...
48
+ # {:status=>"Deployed",
49
+ # :aws_id=>"E3NPQZY4LKAYQ8",
50
+ # :enabled=>true,
51
+ # :domain_name=>"sw9nrsq9pudk3.cloudfront.net",
52
+ # :s3_origin=> {:dns_name=>"bucket-for-konstantin-00.s3.amazonaws.com"},
53
+ # :last_modified_time=>"2010-04-19T08:59:09.600Z",
54
+ # :comment=>"Woo-Hoo!",
55
+ # :cnames=>["stream-6.web.my-awesome-site.net"]}]
56
+ #
57
+ def list_streaming_distributions
58
+ result = []
59
+ incrementally_list_streaming_distributions do |response|
60
+ result += response[:distributions]
61
+ true
62
+ end
63
+ result
64
+ end
65
+
66
+ # Incrementally list streaming distributions.
67
+ #
68
+ # Optional params: +:marker+ and +:max_items+.
69
+ #
70
+ # # get first streaming distribution
71
+ # incrementally_list_distributions(:max_items => 1) #=>
72
+ # {:marker=>"",
73
+ # :next_marker=>"E3CWE2Z9USOS6B",
74
+ # :distributions=>
75
+ # [{:status=>"Deployed",
76
+ # :cnames=>["stream.web.my-awesome-site.net"],
77
+ # :aws_id=>"E3CWE2Z9USOS6B",
78
+ # :enabled=>true,
79
+ # :last_modified_time=>"2010-04-19T08:53:32.574Z",
80
+ # :domain_name=>"s2jz1ourvss1fj.cloudfront.net",
81
+ # :s3_origin=> {:dns_name=>"bucket-for-konstantin-00.s3.amazonaws.com"},
82
+ # :comment=>"Woo-Hoo!"}],
83
+ # :max_items=>1,
84
+ # :is_truncated=>true}
85
+ #
86
+ # # get max 100 streaming distributions (the list will be restricted by a default MaxItems value ==100 )
87
+ # incrementally_list_streaming_distributions
88
+ #
89
+ # # list streaming distributions by 10
90
+ # incrementally_list_streaming_distributions(:max_items => 10) do |response|
91
+ # puts response.inspect # a list of 10 distributions
92
+ # true # return false if the listing should be broken otherwise use true
93
+ # end
94
+ #
95
+ def incrementally_list_streaming_distributions(params={}, &block)
96
+ opts = {}
97
+ opts['MaxItems'] = params[:max_items] if params[:max_items]
98
+ opts['Marker'] = params[:marker] if params[:marker]
99
+ last_response = nil
100
+ loop do
101
+ link = generate_request('GET', 'streaming-distribution', opts)
102
+ last_response = request_info(link, AcfDistributionListParser.new(:logger => @logger))
103
+ opts['Marker'] = last_response[:next_marker]
104
+ break unless block && block.call(last_response) && !last_response[:next_marker].right_blank?
105
+ end
106
+ last_response
107
+ end
108
+
109
+ # Create a new streaming distribution.
110
+ # Returns the just created distribution or RightAws::AwsError exception.
111
+ #
112
+ # acf.create_streaming_distribution('bucket-for-konstantin-00.s3.amazonaws.com', 'Woo-Hoo!', true,
113
+ # ['stream-1.web.my-awesome-site.net']) #=>
114
+ # {:status=>"InProgress",
115
+ # :caller_reference=>"201004191254412191173215",
116
+ # :cnames=>["stream-1.web.my-awesome-site.net"],
117
+ # :aws_id=>"E1M5LERJLU636F",
118
+ # :e_tag=>"E2588L5QL4BLXH",
119
+ # :enabled=>true,
120
+ # :domain_name=>"s1di8imd85wgld.cloudfront.net",
121
+ # :s3_origin=> {:dns_name=>"bucket-for-konstantin-00.s3.amazonaws.com"},
122
+ # :last_modified_time=>Mon Apr 19 08:54:42 UTC 2010,
123
+ # :location=>
124
+ # "https://cloudfront.amazonaws.com/streaming-distribution/E1M5LERJLU636F",
125
+ # :comment=>"Woo-Hoo!"}
126
+ #
127
+ def create_streaming_distribution(config)
128
+ config[:caller_reference] ||= generate_call_reference
129
+ link = generate_request('POST', 'streaming-distribution', {}, streaming_distribution_config_to_xml(config))
130
+ merge_headers(request_info(link, AcfDistributionListParser.new(:logger => @logger))[:distributions].first)
131
+ end
132
+ alias_method :create_streaming_distribution_by_config, :create_streaming_distribution
133
+
134
+ # Get a streaming distribution's information.
135
+ # Returns a distribution's information or RightAws::AwsError exception.
136
+ #
137
+ # acf.get_streaming_distribution('E3CWE2Z9USOS6B') #=>
138
+ # {:status=>"Deployed",
139
+ # :e_tag=>"EXTZ2SXAQT39K",
140
+ # :cnames=>["stream.web.my-awesome-site.net"],
141
+ # :aws_id=>"E3CWE2Z9USOS6B",
142
+ # :enabled=>true,
143
+ # :domain_name=>"s2jz1ourvss1fj.cloudfront.net",
144
+ # :s3_origin=> {:dns_name=>"bucket-for-konstantin-00.s3.amazonaws.com"},
145
+ # :last_modified_time=>"2010-04-19T08:53:32.574Z",
146
+ # :comment=>"Woo-Hoo!",
147
+ # :caller_reference=>"201004191253311625537161"}
148
+ #
149
+ # acf.get_streaming_distribution('E1M5LERJLU636F') #=>
150
+ # {:trusted_signers=>["self", "648772220000", "120288270000"],
151
+ # :status=>"InProgress",
152
+ # :e_tag=>"E2K6XD13RCJQ6E",
153
+ # :cnames=>["stream-1.web.my-awesome-site.net"],
154
+ # :active_trusted_signers=>
155
+ # [{:key_pair_ids=>["APKAIK74BJWCLXZUMEJA"],
156
+ # :aws_account_number=>"120288270000"},
157
+ # {:aws_account_number=>"self"},
158
+ # {:aws_account_number=>"648772220000"}],
159
+ # :aws_id=>"E1M5LERJLU636F",
160
+ # :enabled=>false,
161
+ # :domain_name=>"s1di8imd85wgld.cloudfront.net",
162
+ # :s3_origin=> {
163
+ # :dns_name=>"bucket-for-konstantin-00.s3.amazonaws.com",
164
+ # :origin_access_identity=>"origin-access-identity/cloudfront/E3JPJZ80ZBX24G"},
165
+ # :last_modified_time=>"2010-04-19T09:14:07.160Z",
166
+ # :comment=>"Olah-lah!",
167
+ # :caller_reference=>"201004191254412191173215"}
168
+ #
169
+ def get_streaming_distribution(aws_id)
170
+ link = generate_request('GET', "streaming-distribution/#{aws_id}")
171
+ merge_headers(request_info(link, AcfDistributionListParser.new(:logger => @logger))[:distributions].first)
172
+ end
173
+
174
+ # Get a streaming distribution's configuration.
175
+ # Returns a distribution's configuration or RightAws::AwsError exception.
176
+ #
177
+ # acf.get_streaming_distribution_config('E1M5LERJLU636F') #=>
178
+ # {:trusted_signers=>["self", "648772220000", "120288270000"],
179
+ # :e_tag=>"E2K6XD13RCJQ6E",
180
+ # :cnames=>["stream-1.web.my-awesome-site.net"],
181
+ # :enabled=>false,
182
+ # :s3_origin=> {
183
+ # :dns_name=>"bucket-for-konstantin-00.s3.amazonaws.com",
184
+ # :origin_access_identity=>"origin-access-identity/cloudfront/E3JPJZ80ZBX24G",},
185
+ # :comment=>"Olah-lah!",
186
+ # :caller_reference=>"201004191254412191173215"}
187
+ #
188
+ def get_streaming_distribution_config(aws_id)
189
+ link = generate_request('GET', "streaming-distribution/#{aws_id}/config")
190
+ merge_headers(request_info(link, AcfDistributionListParser.new(:logger => @logger))[:distributions].first)
191
+ end
192
+
193
+ # Set a streaming distribution's configuration
194
+ # Returns +true+ on success or RightAws::AwsError exception.
195
+ #
196
+ # acf.get_streaming_distribution_config('E1M5LERJLU636F') #=>
197
+ # {:e_tag=>"E2588L5QL4BLXH",
198
+ # :cnames=>["stream-1.web.my-awesome-site.net"],
199
+ # :enabled=>true,
200
+ # :s3_origin=> {:dns_name=>"bucket-for-konstantin-00.s3.amazonaws.com"},
201
+ # :comment=>"Woo-Hoo!",
202
+ # :caller_reference=>"201004191254412191173215"}
203
+ #
204
+ # config[:comment] = 'Olah-lah!'
205
+ # config[:enabled] = false
206
+ # config[:s3_origin][:origin_access_identity] = "origin-access-identity/cloudfront/E3JPJZ80ZBX24G"
207
+ # config[:trusted_signers] = ['self', '648772220000', '120288270000']
208
+ #
209
+ # acf.set_distribution_config('E2REJM3VUN5RSI', config) #=> true
210
+ #
211
+ def set_streaming_distribution_config(aws_id, config)
212
+ link = generate_request('PUT', "streaming-distribution/#{aws_id}/config", {}, streaming_distribution_config_to_xml(config),
213
+ 'If-Match' => config[:e_tag])
214
+ request_info(link, RightHttp2xxParser.new(:logger => @logger))
215
+ end
216
+
217
+ # Delete a streaming distribution. The enabled distribution cannot be deleted.
218
+ # Returns +true+ on success or RightAws::AwsError exception.
219
+ #
220
+ # acf.delete_streaming_distribution('E1M5LERJLU636F', 'E2588L5QL4BLXH') #=> true
221
+ #
222
+ def delete_streaming_distribution(aws_id, e_tag)
223
+ link = generate_request('DELETE', "streaming-distribution/#{aws_id}", {}, nil,
224
+ 'If-Match' => e_tag)
225
+ request_info(link, RightHttp2xxParser.new(:logger => @logger))
226
+ end
227
+
228
+ end
229
+ end