cloudfront-invalidator 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +18 -0
- data/lib/cloudfront-invalidator.rb +29 -22
- metadata +15 -14
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e9c506705dea1ec13c325675ff54744e363cc063
|
4
|
+
data.tar.gz: b153298128c3689329d67246d18579717feed3a5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 86e3448770eb5b67b4f4e4e6a3fbd2b60b5c851e18a419b0b2603906b361196f2ddeecd83df192f2ebdb86b9b3eaa89ddae29ab3143d19bfc7d0b925f18cb967
|
7
|
+
data.tar.gz: cbdccfb757faaece579606ecc4211fb39af7244a6d90ddfce840ef6d48f3edee30bb02414d5dbdf6998bd1b4ba7e349fd1ef9843120f3acd5d140f173db97c30
|
data/README.md
CHANGED
@@ -17,6 +17,24 @@ A command line utility is also included.
|
|
17
17
|
$ cloudfront-invalidator list $AWS_KEY $AWS_SECRET $DISTRIBUTION_ID
|
18
18
|
$ cloudfront-invalidator list_detail $AWS_KEY $AWS_SECRET $DISTRIBUTION_ID
|
19
19
|
|
20
|
+
Amazon IAM Policy
|
21
|
+
=================
|
22
|
+
|
23
|
+
{
|
24
|
+
"Version": "2012-10-17",
|
25
|
+
"Statement": [
|
26
|
+
{
|
27
|
+
"Action": [
|
28
|
+
"cloudfront:CreateInvalidation",
|
29
|
+
"cloudfront:GetInvalidation",
|
30
|
+
"cloudfront:ListInvalidations"
|
31
|
+
],
|
32
|
+
"Effect": "Allow",
|
33
|
+
"Resource": "*"
|
34
|
+
}
|
35
|
+
]
|
36
|
+
}
|
37
|
+
|
20
38
|
Authors
|
21
39
|
=======
|
22
40
|
|
@@ -3,23 +3,30 @@ require 'base64'
|
|
3
3
|
require 'rexml/document'
|
4
4
|
require 'hmac-sha1' # this is a gem
|
5
5
|
|
6
|
-
class CloudfrontInvalidator
|
7
|
-
API_VERSION = '2012-05-05'
|
8
|
-
BASE_URL = "https://cloudfront.amazonaws.com/#{API_VERSION}/distribution/"
|
9
|
-
DOC_URL = "http://cloudfront.amazonaws.com/doc/#{API_VERSION}/"
|
6
|
+
class CloudfrontInvalidator
|
10
7
|
BACKOFF_LIMIT = 8192
|
11
8
|
BACKOFF_DELAY = 0.025
|
12
9
|
|
13
|
-
def initialize(aws_key, aws_secret, cf_dist_id)
|
10
|
+
def initialize(aws_key, aws_secret, cf_dist_id, options={})
|
14
11
|
@aws_key, @aws_secret, @cf_dist_id = aws_key, aws_secret, cf_dist_id
|
12
|
+
|
13
|
+
@api_version = options[:api_version] || '2012-07-01'
|
14
|
+
end
|
15
|
+
|
16
|
+
def base_url
|
17
|
+
"https://cloudfront.amazonaws.com/#{@api_version}/distribution/"
|
15
18
|
end
|
16
|
-
|
19
|
+
|
20
|
+
def doc_url
|
21
|
+
"http://cloudfront.amazonaws.com/doc/#{@api_version}/"
|
22
|
+
end
|
23
|
+
|
17
24
|
def invalidate(*keys)
|
18
|
-
keys = keys.flatten.map do |k|
|
19
|
-
k.start_with?('/') ? k : '/' + k
|
25
|
+
keys = keys.flatten.map do |k|
|
26
|
+
k.start_with?('/') ? k : '/' + k
|
20
27
|
end
|
21
|
-
|
22
|
-
uri = URI.parse "#{
|
28
|
+
|
29
|
+
uri = URI.parse "#{base_url}#{@cf_dist_id}/invalidation"
|
23
30
|
http = Net::HTTP.new(uri.host, uri.port)
|
24
31
|
http.use_ssl = true
|
25
32
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
@@ -29,18 +36,18 @@ class CloudfrontInvalidator
|
|
29
36
|
begin
|
30
37
|
resp = http.send_request 'POST', uri.path, body, headers
|
31
38
|
doc = REXML::Document.new resp.body
|
32
|
-
|
39
|
+
|
33
40
|
# Create and raise an exception for any error the API returns to us.
|
34
41
|
if resp.code.to_i != 201
|
35
42
|
error_code = doc.elements["ErrorResponse/Error/Code"].text
|
36
43
|
self.class.const_set(error_code,Class.new(StandardError)) unless self.class.const_defined?(error_code.to_sym)
|
37
44
|
raise self.class.const_get(error_code).new(doc.elements["ErrorResponse/Error/Message"].text)
|
38
45
|
end
|
39
|
-
|
46
|
+
|
40
47
|
# Handle the common case of too many in progress by waiting until the others finish.
|
41
48
|
rescue TooManyInvalidationsInProgress => e
|
42
49
|
sleep delay * BACKOFF_DELAY
|
43
|
-
delay *= 2 unless delay >= BACKOFF_LIMIT
|
50
|
+
delay *= 2 unless delay >= BACKOFF_LIMIT
|
44
51
|
STDERR.puts e.inspect
|
45
52
|
retry
|
46
53
|
end
|
@@ -69,16 +76,16 @@ class CloudfrontInvalidator
|
|
69
76
|
end
|
70
77
|
|
71
78
|
def list(show_detail = false)
|
72
|
-
uri = URI.parse "#{
|
79
|
+
uri = URI.parse "#{base_url}#{@cf_dist_id}/invalidation"
|
73
80
|
http = Net::HTTP.new(uri.host, uri.port)
|
74
81
|
http.use_ssl = true
|
75
82
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
76
83
|
resp = http.send_request 'GET', uri.path, '', headers
|
77
84
|
|
78
85
|
doc = REXML::Document.new resp.body
|
79
|
-
puts "MaxItems " + doc.elements["InvalidationList/MaxItems"].text + "; " + (doc.elements["InvalidationList/
|
86
|
+
puts "MaxItems " + doc.elements["InvalidationList/MaxItems"].text + "; " + (doc.elements["InvalidationList/IsTruncated"].text == "true" ? "truncated" : "not truncated")
|
80
87
|
|
81
|
-
doc.each_element("/InvalidationList/InvalidationSummary") do |summary|
|
88
|
+
doc.each_element("/InvalidationList/Items/InvalidationSummary") do |summary|
|
82
89
|
invalidation_id = summary.elements["Id"].text
|
83
90
|
summary_text = "ID " + invalidation_id + ": " + summary.elements["Status"].text
|
84
91
|
|
@@ -91,8 +98,8 @@ class CloudfrontInvalidator
|
|
91
98
|
detail_doc.elements["Invalidation/InvalidationBatch/CallerReference"].text +
|
92
99
|
'"'
|
93
100
|
puts ' Invalidated URL paths:'
|
94
|
-
|
95
|
-
puts " " + detail_doc.elements.to_a(
|
101
|
+
|
102
|
+
puts " " + detail_doc.elements.to_a("Invalidation/InvalidationBatch/Paths/Items/Path").map(&:text).join(" ")
|
96
103
|
else
|
97
104
|
puts summary_text
|
98
105
|
end
|
@@ -104,7 +111,7 @@ class CloudfrontInvalidator
|
|
104
111
|
end
|
105
112
|
|
106
113
|
def get_invalidation_detail_xml(invalidation_id)
|
107
|
-
uri = URI.parse "#{
|
114
|
+
uri = URI.parse "#{base_url}#{@cf_dist_id}/invalidation/#{invalidation_id}"
|
108
115
|
http = Net::HTTP.new(uri.host, uri.port)
|
109
116
|
http.use_ssl = true
|
110
117
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
@@ -115,7 +122,7 @@ class CloudfrontInvalidator
|
|
115
122
|
def xml_body(keys)
|
116
123
|
xml = <<XML
|
117
124
|
<?xml version="1.0" encoding="UTF-8"?>
|
118
|
-
<InvalidationBatch xmlns="#{
|
125
|
+
<InvalidationBatch xmlns="#{doc_url}">
|
119
126
|
<Paths>
|
120
127
|
<Quantity>#{keys.size}</Quantity>
|
121
128
|
<Items>
|
@@ -126,9 +133,9 @@ class CloudfrontInvalidator
|
|
126
133
|
</InvalidationBatch>
|
127
134
|
XML
|
128
135
|
end
|
129
|
-
|
136
|
+
|
130
137
|
def headers
|
131
|
-
date = Time.now.strftime('%a, %d %b %Y %H:%M:%S %Z')
|
138
|
+
date = Time.now.utc.strftime('%a, %d %b %Y %H:%M:%S %Z')
|
132
139
|
digest = HMAC::SHA1.new(@aws_secret)
|
133
140
|
digest << date
|
134
141
|
signature = Base64.encode64(digest.digest)
|
metadata
CHANGED
@@ -1,27 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudfront-invalidator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Jacob Elder
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2015-02-19 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: ruby-hmac
|
16
|
-
requirement:
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
25
27
|
description:
|
26
28
|
email: jacob.elder@gmail.com
|
27
29
|
executables:
|
@@ -29,31 +31,30 @@ executables:
|
|
29
31
|
extensions: []
|
30
32
|
extra_rdoc_files: []
|
31
33
|
files:
|
32
|
-
- lib/cloudfront-invalidator.rb
|
33
34
|
- README.md
|
34
35
|
- bin/cloudfront-invalidator
|
36
|
+
- lib/cloudfront-invalidator.rb
|
35
37
|
homepage: http://github.com/reidiculous/cloudfront-invalidator
|
36
38
|
licenses: []
|
39
|
+
metadata: {}
|
37
40
|
post_install_message:
|
38
41
|
rdoc_options: []
|
39
42
|
require_paths:
|
40
43
|
- lib
|
41
44
|
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
-
none: false
|
43
45
|
requirements:
|
44
|
-
- -
|
46
|
+
- - ">="
|
45
47
|
- !ruby/object:Gem::Version
|
46
48
|
version: '0'
|
47
49
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
-
none: false
|
49
50
|
requirements:
|
50
|
-
- -
|
51
|
+
- - ">="
|
51
52
|
- !ruby/object:Gem::Version
|
52
53
|
version: '0'
|
53
54
|
requirements: []
|
54
55
|
rubyforge_project: cloudfront-invalidator
|
55
|
-
rubygems_version:
|
56
|
+
rubygems_version: 2.4.5
|
56
57
|
signing_key:
|
57
|
-
specification_version:
|
58
|
+
specification_version: 4
|
58
59
|
summary: Simple gem to invalidate a list of keys belonging to a Cloudfront distribution
|
59
60
|
test_files: []
|