cloudfront-invalidator 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cloudfront-invalidator.rb +42 -0
- metadata +56 -0
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'base64'
|
3
|
+
require 'hmac-sha1'
|
4
|
+
|
5
|
+
class CloudfrontInvalidator
|
6
|
+
|
7
|
+
def initialize(aws_key, aws_secret, cf_dist_id)
|
8
|
+
@aws_key, @aws_secret, @cf_dist_id = aws_key, aws_secret, cf_dist_id
|
9
|
+
end
|
10
|
+
|
11
|
+
def invalidate(*keys)
|
12
|
+
keys = Array[keys]
|
13
|
+
|
14
|
+
uri = URI.parse "https://cloudfront.amazonaws.com/2010-11-01/distribution/#{@cf_dist_id}/invalidation"
|
15
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
16
|
+
http.use_ssl = true
|
17
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
18
|
+
body = xml_body(keys)
|
19
|
+
resp = http.send_request 'POST', uri.path, body, headers
|
20
|
+
puts resp.code
|
21
|
+
puts resp.body
|
22
|
+
end
|
23
|
+
|
24
|
+
def xml_body(keys)
|
25
|
+
xml = <<XML
|
26
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
27
|
+
<InvalidationBatch>
|
28
|
+
#{keys.map{|k| "<Path>#{k}</Path>" }.join("\n")}
|
29
|
+
<CallerReference>CloudFrontInvalidator at #{Time.now}</CallerReference>"
|
30
|
+
</InvalidationBatch>
|
31
|
+
XML
|
32
|
+
end
|
33
|
+
|
34
|
+
def headers
|
35
|
+
date = Time.now.strftime('%a, %d %b %Y %H:%M:%S %Z')
|
36
|
+
digest = HMAC::SHA1.new(@aws_secret)
|
37
|
+
digest << date
|
38
|
+
signature = Base64.encode64(digest.digest)
|
39
|
+
{'Date' => date, 'Authorization' => "AWS #{@aws_key}:#{signature}"}
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cloudfront-invalidator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Reid M Lynch
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-06-15 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: ruby-hmac
|
16
|
+
requirement: &774800 !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: *774800
|
25
|
+
description:
|
26
|
+
email: reid.lynch@gmail.com
|
27
|
+
executables: []
|
28
|
+
extensions: []
|
29
|
+
extra_rdoc_files: []
|
30
|
+
files:
|
31
|
+
- lib/cloudfront-invalidator.rb
|
32
|
+
homepage: http://github.com/reidiculous/cloudfront-invalidator
|
33
|
+
licenses: []
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ! '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
requirements: []
|
51
|
+
rubyforge_project: cloudfront-invalidator
|
52
|
+
rubygems_version: 1.8.5
|
53
|
+
signing_key:
|
54
|
+
specification_version: 3
|
55
|
+
summary: Simple gem to invalidate a list of keys belonging to a Cloudfront distribution
|
56
|
+
test_files: []
|