middleman-cdn 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c0db2d194f1dd93aea915bd2a954c977f24678d4
4
- data.tar.gz: c59dc210e2d7a273e5255a85376d283496b0d6d5
3
+ metadata.gz: f2489e5e48befb67ac4262785c5d50eafc4f38bc
4
+ data.tar.gz: 06de2636504f543675da89ffccf1f9e8b364704b
5
5
  SHA512:
6
- metadata.gz: a4f961344e60c4297417cc6152b0673387d44c786f8b505c5b0a4c68d44523a2dcb0fa2ffc184e2c29574c14c3d7bf2189d1abd5048512396edddacf3cb049c1
7
- data.tar.gz: e586736630bf84c1d6eccd1eb997671f6cfc162f2f26f034952346cf1bb66e0b6ddae7a962461b799430d3af174cbabed46f18594b5894550d6d9b9d55bfc96d
6
+ metadata.gz: 04ceb24a4ed31df414973cf66396c8add45475c27984ae9e80b8ebc51df7718e9f24183f263cd87c7510d980461f281a6da2161ec55ada2f1eb9ef94c3ea675b
7
+ data.tar.gz: b65fa9621dcfcece07031d290b8a4a1794026c9123da238da053a47237ed69b1c9c0f7e797d432f285166a495812643ef7e08695115319d559618202beca269b
data/README.md CHANGED
@@ -1,6 +1,5 @@
1
- # Middleman CDN [![Build Status](https://travis-ci.org/leighmcculloch/middleman-cdn.svg)](https://travis-ci.org/leighmcculloch/middleman-cdn) [![Dependency Status](https://gemnasium.com/leighmcculloch/middleman-cdn.png)](https://gemnasium.com/leighmcculloch/middleman-cdn)
2
-
3
- ** Build status failing due to [RubyGem's dependency issues affecting some gems](https://twitter.com/rubygems_status/statuses/489119131862462464). Tests do pass.
1
+ # Middleman CDN
2
+ [![Gem Version](https://badge.fury.io/rb/middleman-cdn.svg)](http://badge.fury.io/rb/middleman-cdn) [![Build Status](https://travis-ci.org/leighmcculloch/middleman-cdn.svg)](https://travis-ci.org/leighmcculloch/middleman-cdn) [![Dependency Status](https://gemnasium.com/leighmcculloch/middleman-cdn.png)](https://gemnasium.com/leighmcculloch/middleman-cdn)
4
3
 
5
4
  A [middleman](http://middlemanapp.com/) deploy tool for invalidating resources cached
6
5
  on common Content Delivery Networks (CDNs).
@@ -8,14 +7,14 @@ on common Content Delivery Networks (CDNs).
8
7
  * Cache invalidation of files on:
9
8
  * [CloudFlare](https://cloudflare.com)
10
9
  * [Fastly](https://fastly.com)
11
- * [Amazon CloudFront](http://aws.amazon.com/cloudfront/)
10
+ * [MaxCDN](https://maxcdn.com)
11
+ * [Amazon CloudFront](https://aws.amazon.com/cloudfront/)
12
12
  * Select files for invalidation with regex.
13
13
  * Automatically invalidate after build.
14
14
  * Manually trigger invalidation with single command.
15
15
 
16
16
  What's next?
17
17
 
18
- * Add support for MaxCDN.
19
18
  * Add support for RackspaceCDN (Akamai).
20
19
  * [Open an issue](../../issues/new) if you'd like your CDN provider added.
21
20
 
@@ -54,6 +53,12 @@ activate :cdn do |cdn|
54
53
  'https://www.example.com'
55
54
  ],
56
55
  }
56
+ cdn.maxcdn = {
57
+ alias: "...", # default ENV['MAXCDN_ALIAS']
58
+ consumer_key: "...", # default ENV['MAXCDN_CONSUMER_KEY']
59
+ consumer_secret: "...", # default ENV['MAXCDN_CONSUMER_SECRET']
60
+ zone_id: "...",
61
+ }
57
62
  cdn.cloudfront = {
58
63
  access_key_id: '...', # default ENV['AWS_ACCESS_KEY_ID']
59
64
  secret_access_key: '...', # default ENV['AWS_SECRET_ACCESS_KEY']
@@ -116,6 +121,23 @@ at.
116
121
 
117
122
  Fastly invalidations often take a few seconds.
118
123
 
124
+ ### Configuration: MaxCDN
125
+
126
+ The `maxcdn` parameter contains the information specific to your MaxCDN
127
+ account. You'll need to create an `application` in your MaxCDN account which
128
+ will provide you with API keys, and your alias can be found on the API tab of
129
+ your account page. The extension works by invalidating files in pull zones.
130
+ Make sure you add your website as a pull zone.
131
+
132
+ | Parameter | Description |
133
+ |:--------- |:----------- |
134
+ | `alias` | You can find this by logging into MaxCDN, going to your account page, and then going to the API tab and it will be down the bottom right. |
135
+ | `consumer_key` | You can find this by logging into MaxCDN, going to your account page, and then going to the API tab and creating an application which will give you a key and secret. |
136
+ | `secret_key` | You can find this by logging into MaxCDN, going to your account page, and then going to the API tab and creating an application which will give you a key and secret. |
137
+ | `zone_id` | Each pull zone has a zone_id, you'll find this in your account. |
138
+
139
+ MaxCDN invalidations often take a few seconds.
140
+
119
141
  ### Configuration: CloudFront
120
142
 
121
143
  The `cloudfront` parameter contains the information specific to your AWS CloudFront
@@ -0,0 +1,48 @@
1
+ #Encoding: UTF-8
2
+ require "maxcdn"
3
+ require "active_support/core_ext/string"
4
+
5
+ module Middleman
6
+ module Cli
7
+
8
+ class MaxCDN < BaseCDN
9
+ def self.key
10
+ "maxcdn"
11
+ end
12
+
13
+ def self.example_configuration_elements
14
+ {
15
+ alias: ['"..."', "# default ENV['MAXCDN_ALIAS']"],
16
+ consumer_key: ['"..."', "# default ENV['MAXCDN_CONSUMER_KEY']"],
17
+ consumer_secret: ['"..."', "# default ENV['MAXCDN_CONSUMER_SECRET']"],
18
+ zone_id: ['"..."', ""]
19
+ }
20
+ end
21
+
22
+ def invalidate(options, files)
23
+ options[:alias] ||= ENV['MAXCDN_ALIAS']
24
+ options[:consumer_key] ||= ENV['MAXCDN_CONSUMER_KEY']
25
+ options[:consumer_secret] ||= ENV['MAXCDN_CONSUMER_SECRET']
26
+
27
+ [:alias, :consumer_key, :consumer_secret, :zone_id].each do |key|
28
+ if options[key].blank?
29
+ say_status("Error: Configuration key maxcdn[:#{key}] is missing.".light_red)
30
+ raise
31
+ end
32
+ end
33
+
34
+ maxcdn = ::MaxCDN::Client.new(options[:alias], options[:consumer_key], options[:consumer_secret])
35
+
36
+ begin
37
+ say_status("Invalidating #{files.count} files...", newline: false)
38
+ maxcdn.purge(options[:zone_id], files)
39
+ rescue => e
40
+ say_status(", " + "error: #{e.message}".light_red, header: false)
41
+ else
42
+ say_status("✔".light_green, header: false)
43
+ end
44
+ end
45
+ end
46
+
47
+ end
48
+ end
@@ -4,6 +4,7 @@ require "middleman-cdn/cdns/base.rb"
4
4
  require "middleman-cdn/cdns/cloudflare.rb"
5
5
  require "middleman-cdn/cdns/cloudfront.rb"
6
6
  require "middleman-cdn/cdns/fastly.rb"
7
+ require "middleman-cdn/cdns/maxcdn.rb"
7
8
  require "colorize"
8
9
 
9
10
  module Middleman
@@ -39,6 +40,7 @@ module Middleman
39
40
 
40
41
  files = list_files(options.filter)
41
42
  self.class.say_status(nil, "Invalidating #{files.count} files with filter: " + "#{options.filter.source}".magenta.bold)
43
+ files.each { |file| self.class.say_status(nil, " • #{file}") }
42
44
  return if files.empty?
43
45
 
44
46
  cdns_keyed.each do |cdn_key, cdn|
@@ -65,7 +67,8 @@ module Middleman
65
67
  [
66
68
  CloudFlareCDN,
67
69
  CloudFrontCDN,
68
- FastlyCDN
70
+ FastlyCDN,
71
+ MaxCDN
69
72
  ]
70
73
  end
71
74
 
@@ -12,6 +12,7 @@ module Middleman
12
12
  option :cloudflare, nil, 'CloudFlare options'
13
13
  option :cloudfront, nil, 'CloudFront options'
14
14
  option :fastly, nil, 'Fastly options'
15
+ option :maxcdn, nil, 'MaxCDN options'
15
16
  option :filter, nil, 'Cloudflare options'
16
17
  option :after_build, false, 'Cloudflare options'
17
18
 
@@ -1,5 +1,5 @@
1
1
  module Middleman
2
2
  module CDN
3
- VERSION = '0.1.8'
3
+ VERSION = '0.1.9'
4
4
  end
5
5
  end
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
20
20
  s.add_dependency 'fog', '~> 1.9'
21
21
  s.add_dependency 'cloudflare', '~> 2.0'
22
22
  s.add_dependency 'fastly', '~> 1.1'
23
+ s.add_dependency 'maxcdn', '~> 0.1'
23
24
  s.add_dependency 'colorize', '~> 0.7'
24
25
  s.add_dependency 'activesupport', '~> 4.1'
25
26
 
@@ -0,0 +1,185 @@
1
+ #Encoding: UTF-8
2
+ require 'spec_helper'
3
+ require 'lib/middleman-cdn/cdns/base_protocol'
4
+
5
+ describe Middleman::Cli::MaxCDN do
6
+ it_behaves_like "BaseCDN"
7
+
8
+ describe '.key' do
9
+ it "should be 'maxcdn'" do
10
+ expect(described_class.key).to eq("maxcdn")
11
+ end
12
+ end
13
+
14
+ describe '.example_configuration_elements' do
15
+ it "should contain these keys" do
16
+ required_keys = [:alias, :consumer_key, :consumer_secret, :zone_id]
17
+ expect(described_class.example_configuration_elements.keys).to eq(required_keys)
18
+ end
19
+ end
20
+
21
+ describe '#invalidate' do
22
+ let(:double_maxcdn) { double("::MaxCDN::Client") }
23
+
24
+ before do
25
+ allow(double_maxcdn).to receive(:purge)
26
+ allow(::MaxCDN::Client).to receive(:new).and_return(double_maxcdn)
27
+ end
28
+
29
+ let(:files) { [ "/index.html", "/", "/test/index.html", "/test/image.png" ] }
30
+
31
+ context "all options provided" do
32
+ let(:options) do
33
+ {
34
+ alias: "00000000000000000000",
35
+ consumer_key: "11111111111111111111",
36
+ consumer_secret: "22222222222222222222",
37
+ zone_id: "33333333",
38
+ }
39
+ end
40
+
41
+ it "should connect to maxcdn with credentails" do
42
+ expect(::MaxCDN::Client).to receive(:new).with("00000000000000000000", "11111111111111111111", "22222222222222222222")
43
+ subject.invalidate(options, files)
44
+ end
45
+
46
+ it "should not raise errors" do
47
+ subject.invalidate(options, files)
48
+ end
49
+
50
+ it "should call cloudflare to purge all files in one hit" do
51
+ expect(double_maxcdn).to receive(:purge).with("33333333", ["/index.html", "/", "/test/index.html", "/test/image.png"])
52
+ subject.invalidate(options, files)
53
+ end
54
+
55
+ it "should output saying invalidating each file" do
56
+ expect { subject.invalidate(options, files) }.to output(/Invalidating 4 files.../).to_stdout
57
+ end
58
+
59
+ it "should output saying success checkmarks" do
60
+ expect { subject.invalidate(options, files) }.to output(/✔/).to_stdout
61
+ end
62
+
63
+ context "and errors occurs when purging" do
64
+ before do
65
+ allow(double_maxcdn).to receive(:purge).and_raise(StandardError)
66
+ end
67
+
68
+ it "should output saying error information" do
69
+ expect { subject.invalidate(options, files) }.to output(/error: StandardError/).to_stdout
70
+ end
71
+ end
72
+ end
73
+
74
+ context "environment variables used for credentials" do
75
+ before do
76
+ allow(ENV).to receive(:[])
77
+ allow(ENV).to receive(:[]).with("MAXCDN_ALIAS").and_return("00000000000000000000")
78
+ allow(ENV).to receive(:[]).with("MAXCDN_CONSUMER_KEY").and_return("11111111111111111111")
79
+ allow(ENV).to receive(:[]).with("MAXCDN_CONSUMER_SECRET").and_return("22222222222222222222")
80
+ end
81
+
82
+ let(:options) do
83
+ {
84
+ zone_id: "33333333",
85
+ }
86
+ end
87
+
88
+ it "should connect to maxcdn with environment variable credentails" do
89
+ expect(::MaxCDN::Client).to receive(:new).with("00000000000000000000", "11111111111111111111", "22222222222222222222")
90
+ subject.invalidate(options, files)
91
+ end
92
+
93
+ it "should not raise errors" do
94
+ subject.invalidate(options, files)
95
+ end
96
+ end
97
+
98
+ context "if alias not provided" do
99
+ before do
100
+ allow(ENV).to receive(:[])
101
+ allow(ENV).to receive(:[]).with("MAXCDN_ALIAS").and_return(nil)
102
+ end
103
+
104
+ let(:options) do
105
+ {
106
+ consumer_key: "11111111111111111111",
107
+ consumer_secret: "22222222222222222222",
108
+ zone_id: "33333333",
109
+ }
110
+ end
111
+
112
+ it "should raise error" do
113
+ expect { subject.invalidate(options, files) }.to raise_error(RuntimeError)
114
+ end
115
+
116
+ it "should output saying error" do
117
+ expect { subject.invalidate(options, files) rescue nil }.to output(/Error: Configuration key maxcdn\[:alias\] is missing\./).to_stdout
118
+ end
119
+ end
120
+
121
+ context "if consumer_key not provided" do
122
+ before do
123
+ allow(ENV).to receive(:[])
124
+ allow(ENV).to receive(:[]).with("MAXCDN_CONSUMER_KEY").and_return(nil)
125
+ end
126
+
127
+ let(:options) do
128
+ {
129
+ alias: "00000000000000000000",
130
+ consumer_secret: "22222222222222222222",
131
+ zone_id: "33333333",
132
+ }
133
+ end
134
+
135
+ it "should raise error" do
136
+ expect { subject.invalidate(options, files) }.to raise_error(RuntimeError)
137
+ end
138
+
139
+ it "should output saying error" do
140
+ expect { subject.invalidate(options, files) rescue nil }.to output(/Error: Configuration key maxcdn\[:consumer_key\] is missing\./).to_stdout
141
+ end
142
+ end
143
+
144
+ context "if consumer_secret not provided" do
145
+ before do
146
+ allow(ENV).to receive(:[])
147
+ allow(ENV).to receive(:[]).with("MAXCDN_CONSUMER_SECRET").and_return(nil)
148
+ end
149
+
150
+ let(:options) do
151
+ {
152
+ alias: "00000000000000000000",
153
+ consumer_key: "11111111111111111111",
154
+ zone_id: "33333333",
155
+ }
156
+ end
157
+
158
+ it "should raise error" do
159
+ expect { subject.invalidate(options, files) }.to raise_error(RuntimeError)
160
+ end
161
+
162
+ it "should output saying error" do
163
+ expect { subject.invalidate(options, files) rescue nil }.to output(/Error: Configuration key maxcdn\[:consumer_secret\] is missing\./).to_stdout
164
+ end
165
+ end
166
+
167
+ context "if zone_id not provided" do
168
+ let(:options) do
169
+ {
170
+ alias: "00000000000000000000",
171
+ consumer_key: "11111111111111111111",
172
+ consumer_secret: "22222222222222222222",
173
+ }
174
+ end
175
+
176
+ it "should raise error" do
177
+ expect { subject.invalidate(options, files) }.to raise_error(RuntimeError)
178
+ end
179
+
180
+ it "should output saying error" do
181
+ expect { subject.invalidate(options, files) rescue nil }.to output(/Error: Configuration key maxcdn\[:zone_id\] is missing\./).to_stdout
182
+ end
183
+ end
184
+ end
185
+ end
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.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leigh McCulloch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-16 00:00:00.000000000 Z
11
+ date: 2014-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fog
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: maxcdn
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.1'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.1'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: colorize
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -140,6 +154,7 @@ files:
140
154
  - lib/middleman-cdn/cdns/cloudflare.rb
141
155
  - lib/middleman-cdn/cdns/cloudfront.rb
142
156
  - lib/middleman-cdn/cdns/fastly.rb
157
+ - lib/middleman-cdn/cdns/maxcdn.rb
143
158
  - lib/middleman-cdn/commands.rb
144
159
  - lib/middleman-cdn/extension.rb
145
160
  - lib/middleman-cdn/version.rb
@@ -149,6 +164,7 @@ files:
149
164
  - spec/lib/middleman-cdn/cdns/cloudflare_spec.rb
150
165
  - spec/lib/middleman-cdn/cdns/cloudfront_spec.rb
151
166
  - spec/lib/middleman-cdn/cdns/fastly_spec.rb
167
+ - spec/lib/middleman-cdn/cdns/maxcdn_spec.rb
152
168
  - spec/lib/middleman-cdn/commands_spec.rb
153
169
  - spec/spec_helper.rb
154
170
  homepage: https://github.com/leighmcculloch/middleman-cdn