cloudfront 0.0.1 → 1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/Gemfile +11 -8
  2. data/LICENSE.txt +1 -1
  3. data/README.rdoc +64 -7
  4. data/Rakefile +11 -14
  5. data/cloudfront.gemspec +85 -27
  6. data/lib/cloudfront.rb +39 -0
  7. data/lib/cloudfront/connection.rb +25 -0
  8. data/lib/cloudfront/distribution/distribution.rb +136 -0
  9. data/lib/cloudfront/distribution/download_distribution.rb +54 -0
  10. data/lib/cloudfront/distribution/streaming_distribution.rb +53 -0
  11. data/lib/cloudfront/errors/cloudfront_error.rb +13 -0
  12. data/lib/cloudfront/errors/cname_already_exists_error.rb +7 -0
  13. data/lib/cloudfront/errors/distribution_already_exists_error.rb +7 -0
  14. data/lib/cloudfront/errors/illegal_update_error.rb +7 -0
  15. data/lib/cloudfront/errors/invalid_origin_access_identity_error.rb +7 -0
  16. data/lib/cloudfront/errors/invalid_origin_error.rb +7 -0
  17. data/lib/cloudfront/errors/invalid_required_protocol_error.rb +7 -0
  18. data/lib/cloudfront/errors/missing_body_error.rb +7 -0
  19. data/lib/cloudfront/errors/precondition_failed_error.rb +7 -0
  20. data/lib/cloudfront/errors/too_many_distribution_cnames_error.rb +7 -0
  21. data/lib/cloudfront/errors/too_many_distributions_error.rb +7 -0
  22. data/lib/cloudfront/errors/too_many_trusted_signers_error.rb +7 -0
  23. data/lib/cloudfront/errors/trusted_signer_does_not_exist_error.rb +7 -0
  24. data/lib/cloudfront/exceptions/delete_enabled_distribution_exception.rb +7 -0
  25. data/lib/cloudfront/exceptions/distribution_already_disabled_exception.rb +7 -0
  26. data/lib/cloudfront/exceptions/distribution_already_enabled_exception.rb +7 -0
  27. data/lib/cloudfront/exceptions/distribution_configuration_exception.rb +7 -0
  28. data/lib/cloudfront/exceptions/missing_etag_exception.rb +7 -0
  29. data/lib/cloudfront/helpers/aliases.rb +71 -0
  30. data/lib/cloudfront/helpers/cache_behavior.rb +166 -0
  31. data/lib/cloudfront/helpers/cache_behaviors.rb +108 -0
  32. data/lib/cloudfront/helpers/download_distribution.rb +157 -0
  33. data/lib/cloudfront/helpers/invalidation.rb +83 -0
  34. data/lib/cloudfront/helpers/logging.rb +71 -0
  35. data/lib/cloudfront/helpers/origin.rb +101 -0
  36. data/lib/cloudfront/helpers/origin_access_identity.rb +58 -0
  37. data/lib/cloudfront/helpers/origins.rb +94 -0
  38. data/lib/cloudfront/helpers/s3_origin.rb +51 -0
  39. data/lib/cloudfront/helpers/streaming_distribution.rb +150 -0
  40. data/lib/cloudfront/helpers/trusted_signers.rb +73 -0
  41. data/lib/cloudfront/invalidation/invalidations.rb +57 -0
  42. data/lib/cloudfront/origin_access_identity/origin_access_identity.rb +60 -0
  43. data/lib/cloudfront/utils/api.rb +18 -0
  44. data/lib/cloudfront/utils/array.rb +5 -0
  45. data/lib/cloudfront/utils/configuration_checker.rb +19 -0
  46. data/lib/cloudfront/utils/string.rb +11 -0
  47. data/lib/cloudfront/utils/util.rb +20 -0
  48. data/lib/cloudfront/utils/xml_serializer.rb +18 -0
  49. data/lib/faraday/request/cloudfront_signer.rb +35 -0
  50. data/lib/faraday/request/xml_content_type.rb +18 -0
  51. metadata +198 -31
  52. data/.document +0 -5
  53. data/Gemfile.lock +0 -27
  54. data/test/helper.rb +0 -19
  55. data/test/test_cloudfront.rb +0 -7
@@ -0,0 +1,60 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'cloudfront/helpers/origin_access_identity'
4
+
5
+ class Cloudfront
6
+ module OriginAccessIdentity
7
+
8
+ URL = "/#{Cloudfront::Utils::Api.version}/origin-access-identity/cloudfront"
9
+
10
+ def origin_access_identity_create(origin_access_identity = nil)
11
+ origin_access_identity ||= OriginAccessIdentity.new
12
+ connection.post do |request|
13
+ request.url URL
14
+ request.body = origin_access_identity.to_xml
15
+ end
16
+ end
17
+
18
+ def origin_access_identity_list(max_items = 0, marker = "")
19
+ connection.get do |request|
20
+ request.url URL
21
+ request.params['Marker'] = marker unless marker.nil? || marker.blank?
22
+ request.params['MaxItems'] = max_items if max_items > 0
23
+ end
24
+ end
25
+
26
+ def origin_access_identity_get(origin_access_identity_id)
27
+ connection.get URL + '/' + origin_access_identity_id
28
+ end
29
+
30
+ def origin_access_identity_get_config(origin_access_identity_id)
31
+ connection.get URL + '/' + origin_access_identity_id + '/config'
32
+ end
33
+
34
+ def origin_access_identity_put_config(origin_access_identity_id, origin_access_identity, etag)
35
+ connection.put do |request|
36
+ request.url URL + '/' + origin_access_identity_id + '/config'
37
+ request.headers['If-Match'] = etag
38
+ request.body = origin_access_identity.to_xml
39
+ end
40
+ end
41
+
42
+ def origin_access_identity_delete(origin_access_identity_id)
43
+ # 1. get the origin_access_identity configuration
44
+ response = origin_access_identity_get_config(origin_access_identity_id)
45
+ etag = response.headers['etag']
46
+ raise Cloudfront::Exceptions::MissingEtagException.new("The etag for the origin_access_identity #{origin_access_identity_id} is missing") if etag.nil? || etag.blank?
47
+
48
+ # 2. send a delete request with the returned etag
49
+ connection.delete do |request|
50
+ request.url URL + '/' + origin_access_identity_id
51
+ request.headers['If-Match'] = etag
52
+ end
53
+ end
54
+
55
+ def get_origin_access_identity_wrapper(hash)
56
+ end
57
+ end
58
+ end
59
+
60
+
@@ -0,0 +1,18 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'cloudfront/utils/string'
4
+ require 'cloudfront/utils/array'
5
+
6
+ class Cloudfront
7
+ module Utils
8
+ module Api
9
+ API = '2012-07-01'
10
+ module_function
11
+
12
+ # Returns the API version.
13
+ def version
14
+ API
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ class Array
2
+ def self.wrap(obj)
3
+ obj.is_a?(Array) ? obj : (obj.nil? ? [] : [obj])
4
+ end
5
+ end
@@ -0,0 +1,19 @@
1
+ class Cloudfront
2
+ module Utils
3
+ module ConfigurationChecker
4
+ attr_reader :error_messages
5
+
6
+ def valid?
7
+ (@error_messages ||= []).clear
8
+ validate
9
+ !@error_messages.any?
10
+ end
11
+
12
+ def check_configuration
13
+ unless valid?
14
+ raise Cloudfront::Exceptions::DistributionConfigurationException.new "Configuration error : \n #{@error_messages.join "\n"}"
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,11 @@
1
+ class String
2
+ def to_bool
3
+ return true if self == true || self =~ (/(true|t|yes|y|1)$/i)
4
+ return false if self == false || self.empty? || self =~ (/(false|f|no|n|0)$/i)
5
+ raise ArgumentError.new("invalid value for bool: \"#{self}\"")
6
+ end
7
+
8
+ def blank?
9
+ self.strip.empty?
10
+ end
11
+ end
@@ -0,0 +1,20 @@
1
+ # encoding: UTF-8
2
+
3
+ class Cloudfront
4
+ module Utils
5
+ module Util
6
+ FORWARD_POLICY_VALUES = %w(all whitelist none)
7
+ VIEWER_PROTOCOL_VALUES = %w(allow-all https-only)
8
+ MATCH_VIEWER_VALUES = %w(http-only match-viewer)
9
+ URL_REGEXP = /(^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$)/ix
10
+ PRICE_CLASS = %w(PriceClass_100 PriceClass_200 PriceClass_All)
11
+ module_function
12
+
13
+ # Generates a random caller reference.
14
+ def generate_caller_reference
15
+ Time.now.xmlschema + ' ' + (0...10).map { ('0'..'9').to_a[rand(10)] }.join
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,18 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'nokogiri'
4
+
5
+ class Cloudfront
6
+ module Utils
7
+ module XmlSerializer
8
+
9
+ def to_xml
10
+ builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
11
+ build_xml(xml)
12
+ end
13
+ builder.to_xml
14
+ end
15
+
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,35 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'time'
4
+ require 'openssl'
5
+
6
+ module Faraday
7
+ class Request::CloudfrontSigner < Faraday::Middleware
8
+ ALGORITHM = 'sha1'
9
+ CODE = 'm'
10
+ AUTHORIZATION = 'Authorization'
11
+ DATE = 'Date'
12
+ AWS = 'AWS'
13
+ SPACE = ' '
14
+ COLON = ':'
15
+ def initialize(app, *args)
16
+ @app = app
17
+ @aws_access_key_id = args.shift
18
+ @aws_secret_access_key = args.shift
19
+ end
20
+
21
+ # Method that builds the signature to the request.
22
+ # @param date_string [String] the string representation of date time.
23
+ # @return [String] the signature.
24
+ def build_signature(date_string)
25
+ digest = OpenSSL::Digest::Digest.new(ALGORITHM)
26
+ [OpenSSL::HMAC.digest(digest, @aws_secret_access_key, date_string)].pack(CODE).strip
27
+ end
28
+
29
+ def call(env)
30
+ date = Time.now.httpdate
31
+ env[:request_headers].merge!(AUTHORIZATION => "#{AWS}#{SPACE}#{@aws_access_key_id}#{COLON}#{build_signature(date)}", DATE => date)
32
+ @app.call env
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,18 @@
1
+ module Faraday
2
+ class Request::XmlContentType < Faraday::Middleware
3
+
4
+ CONTENT_TYPE = 'Content-Type'
5
+ TEXT_XML = 'text/xml'
6
+
7
+ def initialize(app, *args)
8
+ @app = app
9
+ end
10
+
11
+ def call(env)
12
+ if [:post, :put].include? env[:method]
13
+ env[:request_headers].merge!(CONTENT_TYPE => TEXT_XML)
14
+ end
15
+ @app.call env
16
+ end
17
+ end
18
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudfront
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: '1.0'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,75 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-27 00:00:00.000000000 Z
12
+ date: 2013-05-09 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: faraday
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: faraday_middleware
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: multi_xml
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: nokogiri
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
14
78
  - !ruby/object:Gem::Dependency
15
79
  name: minitest
16
- requirement: &2154204360 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
17
81
  none: false
18
82
  requirements:
19
83
  - - ! '>='
@@ -21,32 +85,31 @@ dependencies:
21
85
  version: '0'
22
86
  type: :development
23
87
  prerelease: false
24
- version_requirements: *2154204360
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
25
94
  - !ruby/object:Gem::Dependency
26
95
  name: yard
27
- requirement: &2154203360 !ruby/object:Gem::Requirement
96
+ requirement: !ruby/object:Gem::Requirement
28
97
  none: false
29
98
  requirements:
30
99
  - - ~>
31
100
  - !ruby/object:Gem::Version
32
- version: '0.7'
101
+ version: 0.6.0
33
102
  type: :development
34
103
  prerelease: false
35
- version_requirements: *2154203360
36
- - !ruby/object:Gem::Dependency
37
- name: rdoc
38
- requirement: &2154202040 !ruby/object:Gem::Requirement
104
+ version_requirements: !ruby/object:Gem::Requirement
39
105
  none: false
40
106
  requirements:
41
107
  - - ~>
42
108
  - !ruby/object:Gem::Version
43
- version: '3.12'
44
- type: :development
45
- prerelease: false
46
- version_requirements: *2154202040
109
+ version: 0.6.0
47
110
  - !ruby/object:Gem::Dependency
48
111
  name: bundler
49
- requirement: &2154199940 !ruby/object:Gem::Requirement
112
+ requirement: !ruby/object:Gem::Requirement
50
113
  none: false
51
114
  requirements:
52
115
  - - ~>
@@ -54,21 +117,63 @@ dependencies:
54
117
  version: 1.0.0
55
118
  type: :development
56
119
  prerelease: false
57
- version_requirements: *2154199940
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: 1.0.0
58
126
  - !ruby/object:Gem::Dependency
59
127
  name: jeweler
60
- requirement: &2154198900 !ruby/object:Gem::Requirement
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ~>
132
+ - !ruby/object:Gem::Version
133
+ version: 1.6.4
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
61
137
  none: false
62
138
  requirements:
63
139
  - - ~>
64
140
  - !ruby/object:Gem::Version
65
- version: 1.8.3
141
+ version: 1.6.4
142
+ - !ruby/object:Gem::Dependency
143
+ name: simplecov
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ - !ruby/object:Gem::Dependency
159
+ name: vcr
160
+ requirement: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
66
166
  type: :development
67
167
  prerelease: false
68
- version_requirements: *2154198900
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
69
174
  - !ruby/object:Gem::Dependency
70
- name: rcov
71
- requirement: &2154196680 !ruby/object:Gem::Requirement
175
+ name: webmock
176
+ requirement: !ruby/object:Gem::Requirement
72
177
  none: false
73
178
  requirements:
74
179
  - - ! '>='
@@ -76,8 +181,30 @@ dependencies:
76
181
  version: '0'
77
182
  type: :development
78
183
  prerelease: false
79
- version_requirements: *2154196680
80
- description: longer description of your gem
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ! '>='
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
190
+ - !ruby/object:Gem::Dependency
191
+ name: timecop
192
+ requirement: !ruby/object:Gem::Requirement
193
+ none: false
194
+ requirements:
195
+ - - ! '>='
196
+ - !ruby/object:Gem::Version
197
+ version: '0'
198
+ type: :development
199
+ prerelease: false
200
+ version_requirements: !ruby/object:Gem::Requirement
201
+ none: false
202
+ requirements:
203
+ - - ! '>='
204
+ - !ruby/object:Gem::Version
205
+ version: '0'
206
+ description: A tested Cloudfront™ client, that handles all api actions on distributions
207
+ and invalidations
81
208
  email: belkacem@rebbouh.com
82
209
  executables: []
83
210
  extensions: []
@@ -85,17 +212,57 @@ extra_rdoc_files:
85
212
  - LICENSE.txt
86
213
  - README.rdoc
87
214
  files:
88
- - .document
89
215
  - Gemfile
90
- - Gemfile.lock
91
216
  - LICENSE.txt
92
217
  - README.rdoc
93
218
  - Rakefile
94
219
  - cloudfront.gemspec
95
220
  - lib/cloudfront.rb
96
- - test/helper.rb
97
- - test/test_cloudfront.rb
98
- homepage: http://github.com/Belkacem/cloudfront
221
+ - lib/cloudfront/connection.rb
222
+ - lib/cloudfront/distribution/distribution.rb
223
+ - lib/cloudfront/distribution/download_distribution.rb
224
+ - lib/cloudfront/distribution/streaming_distribution.rb
225
+ - lib/cloudfront/errors/cloudfront_error.rb
226
+ - lib/cloudfront/errors/cname_already_exists_error.rb
227
+ - lib/cloudfront/errors/distribution_already_exists_error.rb
228
+ - lib/cloudfront/errors/illegal_update_error.rb
229
+ - lib/cloudfront/errors/invalid_origin_access_identity_error.rb
230
+ - lib/cloudfront/errors/invalid_origin_error.rb
231
+ - lib/cloudfront/errors/invalid_required_protocol_error.rb
232
+ - lib/cloudfront/errors/missing_body_error.rb
233
+ - lib/cloudfront/errors/precondition_failed_error.rb
234
+ - lib/cloudfront/errors/too_many_distribution_cnames_error.rb
235
+ - lib/cloudfront/errors/too_many_distributions_error.rb
236
+ - lib/cloudfront/errors/too_many_trusted_signers_error.rb
237
+ - lib/cloudfront/errors/trusted_signer_does_not_exist_error.rb
238
+ - lib/cloudfront/exceptions/delete_enabled_distribution_exception.rb
239
+ - lib/cloudfront/exceptions/distribution_already_disabled_exception.rb
240
+ - lib/cloudfront/exceptions/distribution_already_enabled_exception.rb
241
+ - lib/cloudfront/exceptions/distribution_configuration_exception.rb
242
+ - lib/cloudfront/exceptions/missing_etag_exception.rb
243
+ - lib/cloudfront/helpers/aliases.rb
244
+ - lib/cloudfront/helpers/cache_behavior.rb
245
+ - lib/cloudfront/helpers/cache_behaviors.rb
246
+ - lib/cloudfront/helpers/download_distribution.rb
247
+ - lib/cloudfront/helpers/invalidation.rb
248
+ - lib/cloudfront/helpers/logging.rb
249
+ - lib/cloudfront/helpers/origin.rb
250
+ - lib/cloudfront/helpers/origin_access_identity.rb
251
+ - lib/cloudfront/helpers/origins.rb
252
+ - lib/cloudfront/helpers/s3_origin.rb
253
+ - lib/cloudfront/helpers/streaming_distribution.rb
254
+ - lib/cloudfront/helpers/trusted_signers.rb
255
+ - lib/cloudfront/invalidation/invalidations.rb
256
+ - lib/cloudfront/origin_access_identity/origin_access_identity.rb
257
+ - lib/cloudfront/utils/api.rb
258
+ - lib/cloudfront/utils/array.rb
259
+ - lib/cloudfront/utils/configuration_checker.rb
260
+ - lib/cloudfront/utils/string.rb
261
+ - lib/cloudfront/utils/util.rb
262
+ - lib/cloudfront/utils/xml_serializer.rb
263
+ - lib/faraday/request/cloudfront_signer.rb
264
+ - lib/faraday/request/xml_content_type.rb
265
+ homepage: https://github.com/Belkacem/cloudfront
99
266
  licenses:
100
267
  - MIT
101
268
  post_install_message:
@@ -110,7 +277,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
110
277
  version: '0'
111
278
  segments:
112
279
  - 0
113
- hash: 2034824330173150277
280
+ hash: 481865253389327909
114
281
  required_rubygems_version: !ruby/object:Gem::Requirement
115
282
  none: false
116
283
  requirements:
@@ -119,8 +286,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
286
  version: '0'
120
287
  requirements: []
121
288
  rubyforge_project:
122
- rubygems_version: 1.8.8
289
+ rubygems_version: 1.8.24
123
290
  signing_key:
124
291
  specification_version: 3
125
- summary: one-line summary of your gem
292
+ summary: A tested Cloudfront™ gem
126
293
  test_files: []