lacquer 0.4.0 → 0.4.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.
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source :gemcutter
1
+ source 'http://rubygems.org'
2
2
 
3
3
  gem "activesupport", "3.0.1"
4
4
  gem "i18n", "0.4.1"
data/Gemfile.lock CHANGED
@@ -3,15 +3,12 @@ GEM
3
3
  specs:
4
4
  activesupport (3.0.1)
5
5
  diff-lcs (1.1.2)
6
- gemcutter (0.5.0)
7
- json_pure
8
6
  git (1.2.5)
9
7
  i18n (0.4.1)
10
- jeweler (1.4.0)
11
- gemcutter (>= 0.1.0)
8
+ jeweler (1.5.2)
9
+ bundler (~> 1.0.0)
12
10
  git (>= 1.2.5)
13
- rubyforge (>= 2.0.0)
14
- json_pure (1.4.6)
11
+ rake
15
12
  rake (0.8.7)
16
13
  rspec (2.0.0)
17
14
  rspec-core (= 2.0.0)
@@ -23,9 +20,7 @@ GEM
23
20
  rspec-mocks (2.0.0)
24
21
  rspec-core (= 2.0.0)
25
22
  rspec-expectations (= 2.0.0)
26
- rubyforge (2.0.4)
27
- json_pure (>= 1.1.7)
28
- yard (0.6.1)
23
+ yard (0.6.4)
29
24
 
30
25
  PLATFORMS
31
26
  ruby
data/README.rdoc CHANGED
@@ -21,7 +21,7 @@ config/initializers/lacquer.rb
21
21
 
22
22
  # Array of Varnish servers to manage
23
23
  config.varnish_servers << {
24
- :host => "0.0.0.0", :port => 6082
24
+ :host => "0.0.0.0", :port => 6082 # if you have authentication enabled, add :secret => "your secret"
25
25
  }
26
26
 
27
27
  # Number of retries
@@ -72,11 +72,11 @@ As a result, all you have to do to set a cacheable action is the before filter a
72
72
 
73
73
  == Note on Patches/Pull Requests
74
74
 
75
- * Fork the project.
76
- * Make your feature addition or bug fix.
77
- * Add tests for it. This is important so I don't break it in a future version unintentionally.
78
- * Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
79
- * Send me a pull request. Bonus points for topic branches.
75
+ * Fork the project.
76
+ * Make your feature addition or bug fix.
77
+ * Add tests for it. This is important so I don't break it in a future version unintentionally.
78
+ * Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
79
+ * Send me a pull request. Bonus points for topic branches.
80
80
 
81
81
  == Copyright
82
82
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.4.1
data/lacquer.gemspec CHANGED
@@ -1,61 +1,59 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{lacquer}
8
- s.version = "0.4.0"
8
+ s.version = "0.4.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Russ Smith (russ@bashme.org)", "Ryan Johns", "Garry Tan (garry@posterous.com), Gabe da Silveira (gabe@websaviour.com)"]
12
- s.date = %q{2010-11-03}
12
+ s.date = %q{2010-12-28}
13
13
  s.description = %q{Rails drop in for Varnish support.}
14
14
  s.email = %q{russ@bashme.org}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README.rdoc"
17
+ "README.rdoc"
18
18
  ]
19
19
  s.files = [
20
20
  ".bundle/config",
21
- ".document",
22
- ".gitignore",
23
- "Gemfile",
24
- "Gemfile.lock",
25
- "LICENSE",
26
- "README.rdoc",
27
- "Rakefile",
28
- "VERSION",
29
- "init.rb",
30
- "lacquer.gemspec",
31
- "lib/generators/lacquer/USAGE",
32
- "lib/generators/lacquer/install_generator.rb",
33
- "lib/generators/lacquer/templates/initializer.rb",
34
- "lib/generators/lacquer/templates/varnish.sample.vcl",
35
- "lib/lacquer.rb",
36
- "lib/lacquer/cache_utils.rb",
37
- "lib/lacquer/configuration.rb",
38
- "lib/lacquer/delayed_job_job.rb",
39
- "lib/lacquer/resque_job.rb",
40
- "lib/lacquer/varnish.rb",
41
- "rails/init.rb",
42
- "spec/lacquer/cache_utils_spec.rb",
43
- "spec/lacquer/delayed_job_job_spec.rb",
44
- "spec/lacquer/resque_job_spec.rb",
45
- "spec/lacquer/varnish_spec.rb",
46
- "spec/spec_helper.rb"
21
+ ".document",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "init.rb",
29
+ "lacquer.gemspec",
30
+ "lib/generators/lacquer/USAGE",
31
+ "lib/generators/lacquer/install_generator.rb",
32
+ "lib/generators/lacquer/templates/initializer.rb",
33
+ "lib/generators/lacquer/templates/varnish.sample.vcl",
34
+ "lib/lacquer.rb",
35
+ "lib/lacquer/cache_utils.rb",
36
+ "lib/lacquer/configuration.rb",
37
+ "lib/lacquer/delayed_job_job.rb",
38
+ "lib/lacquer/resque_job.rb",
39
+ "lib/lacquer/varnish.rb",
40
+ "rails/init.rb",
41
+ "spec/lacquer/cache_utils_spec.rb",
42
+ "spec/lacquer/delayed_job_job_spec.rb",
43
+ "spec/lacquer/resque_job_spec.rb",
44
+ "spec/lacquer/varnish_spec.rb",
45
+ "spec/spec_helper.rb"
47
46
  ]
48
47
  s.homepage = %q{http://github.com/russ/lacquer}
49
- s.rdoc_options = ["--charset=UTF-8"]
50
48
  s.require_paths = ["lib"]
51
49
  s.rubygems_version = %q{1.3.7}
52
50
  s.summary = %q{Rails drop in for Varnish support.}
53
51
  s.test_files = [
54
52
  "spec/lacquer/cache_utils_spec.rb",
55
- "spec/lacquer/delayed_job_job_spec.rb",
56
- "spec/lacquer/resque_job_spec.rb",
57
- "spec/lacquer/varnish_spec.rb",
58
- "spec/spec_helper.rb"
53
+ "spec/lacquer/delayed_job_job_spec.rb",
54
+ "spec/lacquer/resque_job_spec.rb",
55
+ "spec/lacquer/varnish_spec.rb",
56
+ "spec/spec_helper.rb"
59
57
  ]
60
58
 
61
59
  if s.respond_to? :specification_version then
@@ -63,11 +61,29 @@ Gem::Specification.new do |s|
63
61
  s.specification_version = 3
64
62
 
65
63
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
64
+ s.add_runtime_dependency(%q<activesupport>, ["= 3.0.1"])
65
+ s.add_runtime_dependency(%q<i18n>, ["= 0.4.1"])
66
+ s.add_runtime_dependency(%q<jeweler>, [">= 0"])
67
+ s.add_runtime_dependency(%q<rake>, [">= 0"])
68
+ s.add_runtime_dependency(%q<rspec>, ["= 2.0.0"])
69
+ s.add_runtime_dependency(%q<yard>, [">= 0"])
66
70
  s.add_development_dependency(%q<rspec>, ["~> 1.3.0"])
67
71
  else
72
+ s.add_dependency(%q<activesupport>, ["= 3.0.1"])
73
+ s.add_dependency(%q<i18n>, ["= 0.4.1"])
74
+ s.add_dependency(%q<jeweler>, [">= 0"])
75
+ s.add_dependency(%q<rake>, [">= 0"])
76
+ s.add_dependency(%q<rspec>, ["= 2.0.0"])
77
+ s.add_dependency(%q<yard>, [">= 0"])
68
78
  s.add_dependency(%q<rspec>, ["~> 1.3.0"])
69
79
  end
70
80
  else
81
+ s.add_dependency(%q<activesupport>, ["= 3.0.1"])
82
+ s.add_dependency(%q<i18n>, ["= 0.4.1"])
83
+ s.add_dependency(%q<jeweler>, [">= 0"])
84
+ s.add_dependency(%q<rake>, [">= 0"])
85
+ s.add_dependency(%q<rspec>, ["= 2.0.0"])
86
+ s.add_dependency(%q<yard>, [">= 0"])
71
87
  s.add_dependency(%q<rspec>, ["~> 1.3.0"])
72
88
  end
73
89
  end
@@ -10,7 +10,7 @@ Lacquer.configure do |config|
10
10
 
11
11
  # Array of Varnish servers to manage
12
12
  config.varnish_servers << {
13
- :host => "0.0.0.0", :port => 6082
13
+ :host => "0.0.0.0", :port => 6082 # if you have authentication enabled, add :secret => "your secret"
14
14
  }
15
15
 
16
16
  # Number of retries
@@ -29,6 +29,31 @@ module Lacquer
29
29
  'Host' => server[:host],
30
30
  'Port' => server[:port],
31
31
  'Timeout' => server[:timeout] || 5)
32
+
33
+ if(server[:secret])
34
+ connection.waitfor("Match" => /^107/) do |authentication_request|
35
+ matchdata = /^107 \d{2}\s*(.{32}).*$/m.match(authentication_request) # Might be a bit ugly regex, but it works great!
36
+ salt = matchdata[1]
37
+ if(salt.empty?)
38
+ raise VarnishError, "Bad authentication request"
39
+ end
40
+
41
+ digest = OpenSSL::Digest::Digest.new('sha256')
42
+ digest << salt
43
+ digest << "\n"
44
+ digest << server[:secret]
45
+ digest << "\n"
46
+ digest << salt
47
+ digest << "\n"
48
+
49
+ connection.cmd("String" => "auth #{digest.to_s}", "Match" => /\d{3}/) do |auth_response|
50
+ if(!(/^200/ =~ auth_response))
51
+ raise AuthenticationError, "Could not authenticate"
52
+ end
53
+ end
54
+ end
55
+ end
56
+
32
57
  connection.cmd('String' => command, 'Match' => /\n\n/) {|r| response = r.split("\n").first.strip}
33
58
  connection.close
34
59
  rescue Exception => e
data/lib/lacquer.rb CHANGED
@@ -1,5 +1,9 @@
1
1
  require "rubygems"
2
2
  require "net/telnet"
3
+
4
+ require "openssl"
5
+ require "digest/sha2"
6
+
3
7
  require "active_support/core_ext"
4
8
 
5
9
  require "lacquer/configuration"
@@ -8,6 +12,7 @@ require "lacquer/varnish"
8
12
 
9
13
  module Lacquer
10
14
  class VarnishError < Exception; end # @private
15
+ class AuthenticationError < VarnishError; end # @private
11
16
 
12
17
  class << self
13
18
  attr_accessor :configuration
@@ -33,6 +33,49 @@ describe "Varnish" do
33
33
  Lacquer::Varnish.new.purge('/')
34
34
  end
35
35
  end
36
+
37
+ describe "when using authentication" do
38
+ after(:each) do
39
+ Lacquer.configuration.varnish_servers.first[:secret] = nil
40
+ end
41
+ describe "with correct secret" do
42
+ before(:each) do
43
+ Lacquer.configuration.varnish_servers.first[:secret] = "the real secret"
44
+ end
45
+
46
+ it "should return successfully when using correct secret" do
47
+ @telnet_mock.stub!(:waitfor).with("Match" => /^107/).and_yield('107 59 \nhaalpffwlcvblmdrinpnjwigwsbiiigq\n\nAuthentication required.\n\n')
48
+ @telnet_mock.stub!(:cmd).with("String" => "auth d218942acc92753db0c9fedddb32cde6158de28e903356caed1808cf0e23a15a", "Match" => /\d{3}/).and_yield('200')
49
+ @telnet_mock.stub!(:cmd).with("String" => "url.purge /", "Match" => /\n\n/).and_yield('200')
50
+
51
+ lambda {
52
+ Lacquer::Varnish.new.purge('/')
53
+ }.should_not raise_error
54
+ end
55
+
56
+ after(:each) do
57
+ Lacquer.configuration.varnish_servers.first[:secret] = nil
58
+ end
59
+ end
60
+
61
+ describe "with wrong secret" do
62
+ before(:each) do
63
+ Lacquer.configuration.varnish_servers.first[:secret] = "the wrong secret"
64
+ end
65
+ it "should raise Lacquer::AuthenticationError when using wrong secret" do
66
+ @telnet_mock.stub!(:waitfor).with("Match" => /^107/).and_yield('107 59 \nhaalpffwlcvblmdrinpnjwigwsbiiigq\n\nAuthentication required.\n\n')
67
+ @telnet_mock.stub!(:cmd).with("String" => "auth 49725ec6723b64774a7ab918a24cba811130e99b7ac4b4c9d21ce9a8144762c8", "Match" => /\d{3}/).and_yield('107')
68
+ @telnet_mock.stub!(:cmd).with("url.purge /").and_yield('200')
69
+
70
+ lambda {
71
+ Lacquer::Varnish.new.purge('/')
72
+ }.should raise_error(Lacquer::VarnishError)
73
+ end
74
+ after(:each) do
75
+ Lacquer.configuration.varnish_servers.first[:secret] = nil
76
+ end
77
+ end
78
+ end
36
79
 
37
80
  describe "when connection is unsuccessful and an error handler is set" do
38
81
  before(:each) do
@@ -46,6 +89,7 @@ describe "Varnish" do
46
89
  }.should_not raise_error(Lacquer::VarnishError)
47
90
  end
48
91
  end
92
+
49
93
  end
50
94
 
51
95
  describe "when sending a stats command" do
@@ -125,7 +169,7 @@ Closing CLI connection
125
169
 
126
170
  describe "when sending a purge command" do
127
171
  it "should return successfully" do
128
- @telnet_mock.stub!(:cmd).and_yield('200')
172
+ @telnet_mock.stub!(:cmd).with("String" => "url.purge /", "Match" => /\n\n/).and_yield('200')
129
173
  Lacquer::Varnish.new.purge('/').should be(true)
130
174
  end
131
175
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lacquer
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 0
10
- version: 0.4.0
9
+ - 1
10
+ version: 0.4.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Russ Smith (russ@bashme.org)
@@ -17,14 +17,104 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2010-11-03 00:00:00 -07:00
20
+ date: 2010-12-28 00:00:00 -08:00
21
21
  default_executable:
22
22
  dependencies:
23
+ - !ruby/object:Gem::Dependency
24
+ type: :runtime
25
+ prerelease: false
26
+ name: activesupport
27
+ version_requirements: &id001 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - "="
31
+ - !ruby/object:Gem::Version
32
+ hash: 5
33
+ segments:
34
+ - 3
35
+ - 0
36
+ - 1
37
+ version: 3.0.1
38
+ requirement: *id001
39
+ - !ruby/object:Gem::Dependency
40
+ type: :runtime
41
+ prerelease: false
42
+ name: i18n
43
+ version_requirements: &id002 !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - "="
47
+ - !ruby/object:Gem::Version
48
+ hash: 13
49
+ segments:
50
+ - 0
51
+ - 4
52
+ - 1
53
+ version: 0.4.1
54
+ requirement: *id002
55
+ - !ruby/object:Gem::Dependency
56
+ type: :runtime
57
+ prerelease: false
58
+ name: jeweler
59
+ version_requirements: &id003 !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ hash: 3
65
+ segments:
66
+ - 0
67
+ version: "0"
68
+ requirement: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ type: :runtime
71
+ prerelease: false
72
+ name: rake
73
+ version_requirements: &id004 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ hash: 3
79
+ segments:
80
+ - 0
81
+ version: "0"
82
+ requirement: *id004
83
+ - !ruby/object:Gem::Dependency
84
+ type: :runtime
85
+ prerelease: false
86
+ name: rspec
87
+ version_requirements: &id005 !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - "="
91
+ - !ruby/object:Gem::Version
92
+ hash: 15
93
+ segments:
94
+ - 2
95
+ - 0
96
+ - 0
97
+ version: 2.0.0
98
+ requirement: *id005
99
+ - !ruby/object:Gem::Dependency
100
+ type: :runtime
101
+ prerelease: false
102
+ name: yard
103
+ version_requirements: &id006 !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ hash: 3
109
+ segments:
110
+ - 0
111
+ version: "0"
112
+ requirement: *id006
23
113
  - !ruby/object:Gem::Dependency
24
114
  type: :development
25
115
  prerelease: false
26
116
  name: rspec
27
- version_requirements: &id001 !ruby/object:Gem::Requirement
117
+ version_requirements: &id007 !ruby/object:Gem::Requirement
28
118
  none: false
29
119
  requirements:
30
120
  - - ~>
@@ -35,7 +125,7 @@ dependencies:
35
125
  - 3
36
126
  - 0
37
127
  version: 1.3.0
38
- requirement: *id001
128
+ requirement: *id007
39
129
  description: Rails drop in for Varnish support.
40
130
  email: russ@bashme.org
41
131
  executables: []
@@ -48,7 +138,6 @@ extra_rdoc_files:
48
138
  files:
49
139
  - .bundle/config
50
140
  - .document
51
- - .gitignore
52
141
  - Gemfile
53
142
  - Gemfile.lock
54
143
  - LICENSE
@@ -78,8 +167,8 @@ homepage: http://github.com/russ/lacquer
78
167
  licenses: []
79
168
 
80
169
  post_install_message:
81
- rdoc_options:
82
- - --charset=UTF-8
170
+ rdoc_options: []
171
+
83
172
  require_paths:
84
173
  - lib
85
174
  required_ruby_version: !ruby/object:Gem::Requirement
data/.gitignore DELETED
@@ -1,21 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
- doc
21
- .yardoc