middleman-cdn 0.3.0 → 0.3.1
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/lib/middleman-cdn/cdns/cloudflare.rb +14 -14
- data/lib/middleman-cdn/version.rb +1 -1
- data/middleman-cdn.gemspec +1 -1
- data/spec/lib/middleman-cdn/cdns/cloudflare_spec.rb +56 -18
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f975832d615b4eadaa5cd9faeee9666f4ac7e28c
|
|
4
|
+
data.tar.gz: da8f4109334891f5baf7f5497fe8ac9c946512b8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b59a7548cbb4fdfd2572bfe12c04bbf5bc85987b411d5a409a4f3329333975791fb2a1303703c97e13b6886d9a5b5ba91f6d5f40b86d302799609cdb2e656ff7
|
|
7
|
+
data.tar.gz: 744d1709675329e9494957f6ad43cf389c9117c2727225d0a41b888b7c9c3a021dfd9f871306defe01dad765a983a2827c1c33495ae1b22f25152673109098c8
|
|
@@ -39,29 +39,29 @@ module Middleman
|
|
|
39
39
|
raise
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
-
cloudflare = ::Cloudflare::
|
|
42
|
+
cloudflare = ::Cloudflare::connect(key: options[:client_api_key], email: options[:email])
|
|
43
|
+
zone = cloudflare.zones.find_by_name(options[:zone])
|
|
43
44
|
if all || (options[:invalidate_zone_for_many_files] && files.count > INVALIDATE_ZONE_THRESHOLD)
|
|
44
45
|
begin
|
|
45
|
-
say_status("Invalidating zone #{
|
|
46
|
-
|
|
46
|
+
say_status("Invalidating zone #{zone}... ", newline: false)
|
|
47
|
+
zone.purge_cache
|
|
47
48
|
rescue => e
|
|
48
49
|
say_status(", " + ANSI.red{ "error: #{e.message}" }, header: false)
|
|
49
50
|
else
|
|
50
51
|
say_status(ANSI.green{ "✔" }, header: false)
|
|
51
52
|
end
|
|
52
53
|
else
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
url = "#{base_url}#{file}"
|
|
57
|
-
say_status("Invalidating #{url}... ", newline: false)
|
|
58
|
-
cloudflare.zone_file_purge(options[:zone], "#{base_url}#{file}")
|
|
59
|
-
rescue => e
|
|
60
|
-
say_status(", " + ANSI.red{ "error: #{e.message}" }, header: false)
|
|
61
|
-
else
|
|
62
|
-
say_status(ANSI.green{ "✔" }, header: false)
|
|
63
|
-
end
|
|
54
|
+
begin
|
|
55
|
+
urls = options[:base_urls].map do |base_url|
|
|
56
|
+
files.map { |file| "#{base_url}#{file}" }
|
|
64
57
|
end
|
|
58
|
+
|
|
59
|
+
say_status("Invalidating #{urls}... ", newline: false)
|
|
60
|
+
zone.purge_cache(files: urls.flatten)
|
|
61
|
+
rescue => e
|
|
62
|
+
say_status(", " + ANSI.red{ "error: #{e.message}" }, header: false)
|
|
63
|
+
else
|
|
64
|
+
say_status(ANSI.green{ "✔" }, header: false)
|
|
65
65
|
end
|
|
66
66
|
end
|
|
67
67
|
end
|
data/middleman-cdn.gemspec
CHANGED
|
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
|
|
|
17
17
|
s.require_paths = ["lib"]
|
|
18
18
|
|
|
19
19
|
s.add_dependency 'fog-aws', '~> 1.4'
|
|
20
|
-
s.add_dependency 'cloudflare', '~> 3.
|
|
20
|
+
s.add_dependency 'cloudflare', '~> 3.2.1'
|
|
21
21
|
s.add_dependency 'fastly', '~> 1.1'
|
|
22
22
|
s.add_dependency 'maxcdn', '~> 0.1'
|
|
23
23
|
s.add_dependency 'ansi', '~> 1.5'
|
|
@@ -2,31 +2,25 @@ require 'spec_helper'
|
|
|
2
2
|
require 'lib/middleman-cdn/cdns/base_protocol'
|
|
3
3
|
|
|
4
4
|
shared_examples "invalidating the entire zone" do
|
|
5
|
-
before do
|
|
6
|
-
allow(double_cloudflare).to receive(:fpurge_ts)
|
|
7
|
-
end
|
|
8
|
-
|
|
9
5
|
it "should invalidate the entire zone" do
|
|
10
|
-
expect(
|
|
6
|
+
expect(double_zone).to receive(:purge_cache).once.with(no_args)
|
|
11
7
|
subject.invalidate(options, files, all: all)
|
|
12
8
|
end
|
|
13
9
|
|
|
14
10
|
it "should not invalidate individual files" do
|
|
15
|
-
expect(
|
|
11
|
+
expect(double_zone).to_not receive(:purge_cache).with(files: file_urls)
|
|
16
12
|
subject.invalidate(options, files, all: all)
|
|
17
13
|
end
|
|
18
14
|
end
|
|
19
15
|
|
|
20
16
|
shared_examples "invalidating individual files" do
|
|
21
17
|
it "should not invalidate the entire zone" do
|
|
22
|
-
expect(
|
|
18
|
+
expect(double_zone).to_not receive(:purge_cache).with(no_args)
|
|
23
19
|
subject.invalidate(options, files, all: all)
|
|
24
20
|
end
|
|
25
21
|
|
|
26
22
|
it "should invalidate individual files" do
|
|
27
|
-
|
|
28
|
-
expect(double_cloudflare).to receive(:zone_file_purge).once.ordered.with("example.com", "http://example.com#{file}")
|
|
29
|
-
end
|
|
23
|
+
expect(double_zone).to receive(:purge_cache).once.ordered.with(files: file_urls)
|
|
30
24
|
subject.invalidate(options, files, all: all)
|
|
31
25
|
end
|
|
32
26
|
end
|
|
@@ -47,15 +41,61 @@ describe Middleman::Cli::CloudFlareCDN do
|
|
|
47
41
|
end
|
|
48
42
|
end
|
|
49
43
|
|
|
44
|
+
describe "Cloudflare API" do
|
|
45
|
+
let(:options) do
|
|
46
|
+
{
|
|
47
|
+
key: '000000000000000000000',
|
|
48
|
+
email: 'test@example.com'
|
|
49
|
+
}
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
let(:cloudflare_module) { ::Cloudflare }
|
|
53
|
+
let(:cloudflare) { cloudflare_module.connect(options) }
|
|
54
|
+
|
|
55
|
+
it "should have #connect method" do
|
|
56
|
+
expect(cloudflare_module).to respond_to(:connect).with_keywords(:key, :email)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
context 'zones' do
|
|
60
|
+
it "should have #zones method" do
|
|
61
|
+
expect(cloudflare).to respond_to(:zones)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it "should have #zones.find_by_name method" do
|
|
65
|
+
expect(cloudflare.zones).to respond_to(:find_by_name).with(1).argument
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
context 'zone' do
|
|
70
|
+
before(:each) do
|
|
71
|
+
allow(cloudflare_response).to receive(:result) { double }
|
|
72
|
+
allow_any_instance_of(zone_class).to receive(:get) { cloudflare_response }
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
let(:zone_class) { ::Cloudflare::Zone }
|
|
76
|
+
let(:zone) { zone_class.new('http://example.com') }
|
|
77
|
+
let(:cloudflare_response) { double }
|
|
78
|
+
|
|
79
|
+
it "should have #purge_cache method" do
|
|
80
|
+
expect(zone).to respond_to(:purge_cache)
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
50
85
|
describe '#invalidate' do
|
|
51
86
|
let(:double_cloudflare) { double("::Cloudflare") }
|
|
87
|
+
let(:double_zone) { double("::Cloudflare::Zone") }
|
|
52
88
|
|
|
53
89
|
before do
|
|
54
|
-
allow(
|
|
55
|
-
allow(::Cloudflare).to receive(:
|
|
90
|
+
allow(double_zone).to receive(:purge_cache)
|
|
91
|
+
allow(::Cloudflare).to receive(:connect).and_return(double_cloudflare)
|
|
92
|
+
allow(double_cloudflare).to receive_message_chain('zones.find_by_name').and_return(double_zone)
|
|
56
93
|
end
|
|
57
94
|
|
|
58
95
|
let(:files) { (1..50).map { |i| "/test/file_#{i}.txt" } }
|
|
96
|
+
let(:http_file_urls) { files.map { |file| "http://example.com#{file}" } }
|
|
97
|
+
let(:https_file_urls) { files.map { |file| "https://example.com#{file}" } }
|
|
98
|
+
let(:file_urls) { http_file_urls.concat(https_file_urls) }
|
|
59
99
|
let(:all) { false }
|
|
60
100
|
|
|
61
101
|
context "all options provided" do
|
|
@@ -69,7 +109,7 @@ describe Middleman::Cli::CloudFlareCDN do
|
|
|
69
109
|
end
|
|
70
110
|
|
|
71
111
|
it "should connect to cloudflare with credentails" do
|
|
72
|
-
expect(::Cloudflare).to receive(:
|
|
112
|
+
expect(::Cloudflare).to receive(:connect).with(key: "000000000000000000000", email: "test@example.com")
|
|
73
113
|
subject.invalidate(options, files)
|
|
74
114
|
end
|
|
75
115
|
|
|
@@ -99,9 +139,7 @@ describe Middleman::Cli::CloudFlareCDN do
|
|
|
99
139
|
it_behaves_like "invalidating individual files"
|
|
100
140
|
|
|
101
141
|
it "should call cloudflare to purge each file for each base url" do
|
|
102
|
-
|
|
103
|
-
expect(double_cloudflare).to receive(:zone_file_purge).once.ordered.with("example.com", "http://example.com#{file}")
|
|
104
|
-
end
|
|
142
|
+
expect(double_zone).to receive(:purge_cache).once.with(files: file_urls)
|
|
105
143
|
subject.invalidate(options, files)
|
|
106
144
|
end
|
|
107
145
|
end
|
|
@@ -142,7 +180,7 @@ describe Middleman::Cli::CloudFlareCDN do
|
|
|
142
180
|
|
|
143
181
|
context "and errors occurs when purging" do
|
|
144
182
|
before do
|
|
145
|
-
allow(
|
|
183
|
+
allow(double_zone).to receive(:purge_cache).and_raise(StandardError)
|
|
146
184
|
end
|
|
147
185
|
|
|
148
186
|
it "should output saying error information" do
|
|
@@ -166,7 +204,7 @@ describe Middleman::Cli::CloudFlareCDN do
|
|
|
166
204
|
end
|
|
167
205
|
|
|
168
206
|
it "should connect to cloudflare with environment variable credentails" do
|
|
169
|
-
expect(::Cloudflare).to receive(:
|
|
207
|
+
expect(::Cloudflare).to receive(:connect).with(key: "111111111111111111111", email: "test-env@example.com")
|
|
170
208
|
subject.invalidate(options, files)
|
|
171
209
|
end
|
|
172
210
|
|
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.3.
|
|
4
|
+
version: 0.3.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Leigh McCulloch
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2018-
|
|
11
|
+
date: 2018-06-10 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: fog-aws
|
|
@@ -30,14 +30,14 @@ dependencies:
|
|
|
30
30
|
requirements:
|
|
31
31
|
- - "~>"
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
|
-
version:
|
|
33
|
+
version: 3.2.1
|
|
34
34
|
type: :runtime
|
|
35
35
|
prerelease: false
|
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
37
|
requirements:
|
|
38
38
|
- - "~>"
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
|
-
version:
|
|
40
|
+
version: 3.2.1
|
|
41
41
|
- !ruby/object:Gem::Dependency
|
|
42
42
|
name: fastly
|
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|