middleman-cdn 0.1.14 → 0.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +6 -3
- data/lib/middleman-cdn/cdns/cloudflare.rb +5 -2
- data/lib/middleman-cdn/version.rb +1 -1
- data/middleman-cdn.gemspec +1 -0
- data/spec/lib/middleman-cdn/cdns/cloudflare_spec.rb +66 -22
- metadata +5 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 62d3fe98c429ea088be61b3ecd2d31287dff6eb7
|
|
4
|
+
data.tar.gz: b07a340fb289b103d506eceb007f6a0e5d8156c5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4b07e0cceefa744a5dcbdb36a55ef35ccc994b01f37da02ee4c0447b761865772f0fd374c16faf857788e5d82d0f3f1236fc345c6d4c2e9a24c9adc042a47855
|
|
7
|
+
data.tar.gz: e1f798d993d882e51f27bb6ff964b0dafcd1311718c56509a30676772a9328b44f787020098ca5f92c3df7160f40eab8b18dbab91aa995dc45940912c3bca5eb
|
data/.travis.yml
CHANGED
|
@@ -6,6 +6,8 @@ module Middleman
|
|
|
6
6
|
module Cli
|
|
7
7
|
|
|
8
8
|
class CloudFlareCDN < BaseCDN
|
|
9
|
+
INVALIDATE_ZONE_THRESHOLD = 50
|
|
10
|
+
|
|
9
11
|
def self.key
|
|
10
12
|
"cloudflare"
|
|
11
13
|
end
|
|
@@ -15,7 +17,8 @@ module Middleman
|
|
|
15
17
|
client_api_key: ['"..."', "# default ENV['CLOUDFLARE_CLIENT_API_KEY']"],
|
|
16
18
|
email: ['"..."', "# default ENV['CLOUDFLARE_EMAIL']"],
|
|
17
19
|
zone: ['"..."', ""],
|
|
18
|
-
base_urls: [['http://example.com', 'https://example.com'], ""]
|
|
20
|
+
base_urls: [['http://example.com', 'https://example.com'], ""],
|
|
21
|
+
invalidate_zone_for_many_files: [true, "# default true"]
|
|
19
22
|
}
|
|
20
23
|
end
|
|
21
24
|
|
|
@@ -37,7 +40,7 @@ module Middleman
|
|
|
37
40
|
end
|
|
38
41
|
|
|
39
42
|
cloudflare = ::CloudFlare::connection(options[:client_api_key], options[:email])
|
|
40
|
-
if all
|
|
43
|
+
if all || (options[:invalidate_zone_for_many_files] && files.count > INVALIDATE_ZONE_THRESHOLD)
|
|
41
44
|
begin
|
|
42
45
|
say_status("Invalidating zone #{options[:zone]}... ", newline: false)
|
|
43
46
|
cloudflare.fpurge_ts(options[:zone])
|
data/middleman-cdn.gemspec
CHANGED
|
@@ -10,6 +10,7 @@ Gem::Specification.new do |s|
|
|
|
10
10
|
s.version = Middleman::CDN::VERSION
|
|
11
11
|
s.platform = Gem::Platform::RUBY
|
|
12
12
|
s.authors = ["Leigh McCulloch"]
|
|
13
|
+
s.licenses = ["MIT"]
|
|
13
14
|
s.homepage = "https://github.com/leighmcculloch/middleman-cdn"
|
|
14
15
|
s.summary = %q{Invalidate CloudFlare or CloudFront cache after deployment}
|
|
15
16
|
s.description = %q{Invalidate a specific set of files in your CloudFlare or CloudFront cache}
|
|
@@ -2,6 +2,36 @@
|
|
|
2
2
|
require 'spec_helper'
|
|
3
3
|
require 'lib/middleman-cdn/cdns/base_protocol'
|
|
4
4
|
|
|
5
|
+
shared_examples "invalidating the entire zone" do
|
|
6
|
+
before do
|
|
7
|
+
allow(double_cloudflare).to receive(:fpurge_ts)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "should invalidate the entire zone" do
|
|
11
|
+
expect(double_cloudflare).to receive(:fpurge_ts).once.with("example.com")
|
|
12
|
+
subject.invalidate(options, files, all: all)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "should not invalidate individual files" do
|
|
16
|
+
expect(double_cloudflare).to_not receive(:zone_file_purge)
|
|
17
|
+
subject.invalidate(options, files, all: all)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
shared_examples "invalidating individual files" do
|
|
22
|
+
it "should not invalidate the entire zone" do
|
|
23
|
+
expect(double_cloudflare).to_not receive(:fpurge_ts)
|
|
24
|
+
subject.invalidate(options, files, all: all)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "should invalidate individual files" do
|
|
28
|
+
files.each do |file|
|
|
29
|
+
expect(double_cloudflare).to receive(:zone_file_purge).once.ordered.with("example.com", "http://example.com#{file}")
|
|
30
|
+
end
|
|
31
|
+
subject.invalidate(options, files, all: all)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
5
35
|
describe Middleman::Cli::CloudFlareCDN do
|
|
6
36
|
it_behaves_like "BaseCDN"
|
|
7
37
|
|
|
@@ -13,7 +43,7 @@ describe Middleman::Cli::CloudFlareCDN do
|
|
|
13
43
|
|
|
14
44
|
describe '.example_configuration_elements' do
|
|
15
45
|
it "should contain these keys" do
|
|
16
|
-
required_keys = [:client_api_key, :email, :zone, :base_urls]
|
|
46
|
+
required_keys = [:client_api_key, :email, :zone, :base_urls, :invalidate_zone_for_many_files]
|
|
17
47
|
expect(described_class.example_configuration_elements.keys).to eq(required_keys)
|
|
18
48
|
end
|
|
19
49
|
end
|
|
@@ -26,7 +56,8 @@ describe Middleman::Cli::CloudFlareCDN do
|
|
|
26
56
|
allow(::CloudFlare).to receive(:connection).and_return(double_cloudflare)
|
|
27
57
|
end
|
|
28
58
|
|
|
29
|
-
let(:files) {
|
|
59
|
+
let(:files) { (1..50).map { |i| "/test/file_#{i}.txt" } }
|
|
60
|
+
let(:all) { false }
|
|
30
61
|
|
|
31
62
|
context "all options provided" do
|
|
32
63
|
let(:options) do
|
|
@@ -47,18 +78,6 @@ describe Middleman::Cli::CloudFlareCDN do
|
|
|
47
78
|
subject.invalidate(options, files)
|
|
48
79
|
end
|
|
49
80
|
|
|
50
|
-
it "should call cloudflare to purge each file for each base url" do
|
|
51
|
-
expect(double_cloudflare).to receive(:zone_file_purge).once.ordered.with("example.com", "http://example.com/index.html")
|
|
52
|
-
expect(double_cloudflare).to receive(:zone_file_purge).once.ordered.with("example.com", "http://example.com/")
|
|
53
|
-
expect(double_cloudflare).to receive(:zone_file_purge).once.ordered.with("example.com", "http://example.com/test/index.html")
|
|
54
|
-
expect(double_cloudflare).to receive(:zone_file_purge).once.ordered.with("example.com", "http://example.com/test/image.png")
|
|
55
|
-
expect(double_cloudflare).to receive(:zone_file_purge).once.ordered.with("example.com", "https://example.com/index.html")
|
|
56
|
-
expect(double_cloudflare).to receive(:zone_file_purge).once.ordered.with("example.com", "https://example.com/")
|
|
57
|
-
expect(double_cloudflare).to receive(:zone_file_purge).once.ordered.with("example.com", "https://example.com/test/index.html")
|
|
58
|
-
expect(double_cloudflare).to receive(:zone_file_purge).once.ordered.with("example.com", "https://example.com/test/image.png")
|
|
59
|
-
subject.invalidate(options, files)
|
|
60
|
-
end
|
|
61
|
-
|
|
62
81
|
it "should output saying invalidating each file checkmarks" do
|
|
63
82
|
files_escaped = files.map { |file| Regexp.escape(file) }
|
|
64
83
|
expect { subject.invalidate(options, files) }.to output(/#{files_escaped.join(".+")}/m).to_stdout
|
|
@@ -73,22 +92,47 @@ describe Middleman::Cli::CloudFlareCDN do
|
|
|
73
92
|
expect { subject.invalidate(options, files) }.to output(/✔/).to_stdout
|
|
74
93
|
end
|
|
75
94
|
|
|
76
|
-
context "
|
|
95
|
+
context "max 50 files to invalidate" do
|
|
96
|
+
before do
|
|
97
|
+
expect(files.count).to be <= 50
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
it_behaves_like "invalidating individual files"
|
|
101
|
+
|
|
102
|
+
it "should call cloudflare to purge each file for each base url" do
|
|
103
|
+
files.each do |file|
|
|
104
|
+
expect(double_cloudflare).to receive(:zone_file_purge).once.ordered.with("example.com", "http://example.com#{file}")
|
|
105
|
+
end
|
|
106
|
+
subject.invalidate(options, files)
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
context "more than 50 files to invalidate" do
|
|
111
|
+
let(:files) { super() + ["/index.html"] }
|
|
112
|
+
|
|
77
113
|
before do
|
|
78
|
-
|
|
114
|
+
expect(files.count).to be > 50
|
|
79
115
|
end
|
|
80
116
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
117
|
+
context "invalidate_zone_for_many_files is set to true" do
|
|
118
|
+
let(:options) { super().merge(invalidate_zone_for_many_files: true) }
|
|
119
|
+
|
|
120
|
+
it_behaves_like "invalidating the entire zone"
|
|
84
121
|
end
|
|
85
122
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
123
|
+
context "invalidate_zone_for_many_files is set to false" do
|
|
124
|
+
let(:options) { super().merge(invalidate_zone_for_many_files: false) }
|
|
125
|
+
|
|
126
|
+
it_behaves_like "invalidating individual files"
|
|
89
127
|
end
|
|
90
128
|
end
|
|
91
129
|
|
|
130
|
+
context "matching all files" do
|
|
131
|
+
let(:all) { true }
|
|
132
|
+
|
|
133
|
+
it_behaves_like "invalidating the entire zone"
|
|
134
|
+
end
|
|
135
|
+
|
|
92
136
|
context "and errors occurs when purging" do
|
|
93
137
|
before do
|
|
94
138
|
allow(double_cloudflare).to receive(:zone_file_purge).and_raise(StandardError)
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: middleman-cdn
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.15
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Leigh McCulloch
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2016-03-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: fog
|
|
@@ -201,7 +201,8 @@ files:
|
|
|
201
201
|
- spec/lib/middleman-cdn/commands_spec.rb
|
|
202
202
|
- spec/spec_helper.rb
|
|
203
203
|
homepage: https://github.com/leighmcculloch/middleman-cdn
|
|
204
|
-
licenses:
|
|
204
|
+
licenses:
|
|
205
|
+
- MIT
|
|
205
206
|
metadata: {}
|
|
206
207
|
post_install_message:
|
|
207
208
|
rdoc_options: []
|
|
@@ -219,7 +220,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
219
220
|
version: '0'
|
|
220
221
|
requirements: []
|
|
221
222
|
rubyforge_project:
|
|
222
|
-
rubygems_version: 2.4.
|
|
223
|
+
rubygems_version: 2.4.8
|
|
223
224
|
signing_key:
|
|
224
225
|
specification_version: 4
|
|
225
226
|
summary: Invalidate CloudFlare or CloudFront cache after deployment
|