apache-config-generator 0.2.5.1 → 0.2.6

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/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ .loadpath
2
+ .project
3
+ coverage/*
4
+ docs/*
5
+ pkg/*
6
+ Manifest
7
+ *.gemspec
8
+ tmp/*
9
+ .bundle/*
10
+ .DS_Store
11
+ *.gem
12
+ .yardoc/*
13
+ doc/*
14
+
15
+
data/CHANGELOG CHANGED
@@ -1,3 +1,5 @@
1
+ v0.2.5.2. Make it work as standalone w/o Bundler.
2
+
1
3
  v0.2.5.1. Bad release, forgot to add files.
2
4
 
3
5
  v0.2.5. New option for default environments.
data/Gemfile CHANGED
@@ -1,9 +1,4 @@
1
- gem 'rainbow'
2
- gem 'echoe'
3
- gem 'rspec'
4
- gem 'autotest'
5
- gem 'mocha'
6
- gem 'reek'
7
- gem 'sdoc'
8
- gem 'sdoc-helpers', :require => 'sdoc_helpers'
9
- gem 'rdiscount'
1
+ source :rubygems
2
+
3
+ gemspec
4
+
data/Gemfile.lock CHANGED
@@ -1,19 +1,19 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ apache-config-generator (0.2.6)
5
+ rainbow
6
+
1
7
  GEM
8
+ remote: http://rubygems.org/
2
9
  specs:
3
- autotest (4.4.1)
10
+ autotest (4.4.2)
4
11
  diff-lcs (1.1.2)
5
- echoe (4.3.1)
6
- gemcutter
7
- rubyforge
8
- gemcutter (0.6.1)
9
- json (1.4.6)
10
- json_pure (1.4.3)
11
- mocha (0.9.8)
12
+ mocha (0.9.9)
12
13
  rake
14
+ nokogiri (1.4.3.1)
13
15
  rainbow (1.1)
14
16
  rake (0.8.7)
15
- rdiscount (1.6.5)
16
- rdoc (2.4.3)
17
17
  reek (1.2.8)
18
18
  ruby2ruby (~> 1.2)
19
19
  ruby_parser (~> 2.0)
@@ -33,25 +33,17 @@ GEM
33
33
  sexp_processor (~> 3.0)
34
34
  ruby_parser (2.0.4)
35
35
  sexp_processor (~> 3.0)
36
- rubyforge (2.0.4)
37
- json_pure (>= 1.1.7)
38
- sdoc (0.2.20)
39
- json (>= 1.1.3)
40
- rdoc (= 2.4.3)
41
- sdoc-helpers (0.1.4)
42
- sdoc (~> 0.2)
43
36
  sexp_processor (3.0.4)
44
37
 
45
38
  PLATFORMS
46
39
  ruby
47
40
 
48
41
  DEPENDENCIES
42
+ apache-config-generator!
49
43
  autotest
50
- echoe
44
+ bundler (>= 1.0.0)
51
45
  mocha
46
+ nokogiri
52
47
  rainbow
53
- rdiscount
54
48
  reek
55
- rspec
56
- sdoc
57
- sdoc-helpers
49
+ rspec (~> 2.0.0)
data/README.rdoc CHANGED
@@ -27,7 +27,7 @@ Configs center around the Apache::Config.build method:
27
27
  server_name 'my-cool-website.cool.wow'
28
28
  document_root '/var/www/my-cool-website'
29
29
 
30
- server_admin! "john@coswellproductions.com"
30
+ server_admin! "john@coswellproductions.com"
31
31
 
32
32
  directory '/' do
33
33
  options :follow_sym_links, :indexes
@@ -42,12 +42,12 @@ Configs center around the Apache::Config.build method:
42
42
  end
43
43
 
44
44
  rewrites "My old content" do
45
- cond "%{HTTP_REFERER}", '!^my-cool-website\.cool\.wow$'
46
- rule %r{\.(gif|jpg|png|pdf)$}, '/lol-image-stealer.html', :last => true, :redirect => true
45
+ cond "%{HTTP_REFERER}", '!^my-cool-website\.cool\.wow$'
46
+ rule %r{\.(gif|jpg|png|pdf)$}, '/lol-image-stealer.html', :last => true, :redirect => true
47
47
 
48
- rewrite_test '/index.html', '/index.html', :http_referer => 'other.site'
49
- rewrite_test '/index.gif', '/lol-image-stealer.html', :http_referer => 'other.site'
50
- rewrite_test '/index.gif', '/index.gif', :http_referer => 'my-cool-website.cool.wow'
48
+ rewrite_test '/index.html', '/index.html', :http_referer => 'other.site'
49
+ rewrite_test '/index.gif', '/lol-image-stealer.html', :http_referer => 'other.site'
50
+ rewrite_test '/index.gif', '/index.gif', :http_referer => 'my-cool-website.cool.wow'
51
51
  end
52
52
  end
53
53
 
@@ -58,7 +58,7 @@ Notes on how the conversion works:
58
58
  * Directives that expect regular expressions take a Regexp object.
59
59
  * Passing a String as a parameter, by default, double-quotes it.
60
60
  * Passing in a Symbol does not quote the parameter.
61
- ** Some directives NerdCap Symbols, such as Options
61
+ * Some directives NerdCap Symbols, such as Options
62
62
  * Appending an exclamation point to the method turns off quoting.
63
63
  * Shortcut methods are defined as modules under the Apache module.
64
64
 
@@ -71,23 +71,28 @@ There are also sanity checks that occur when configuration is being generated:
71
71
 
72
72
  The above config is transformed into the following:
73
73
 
74
- ServerName "my-cool-website.cool.wow"
75
- DocumentRoot "/var/www/my-cool-website"
76
- ServerAdmin john@coswellproductions.com
74
+ ServerName "my-cool-website.cool.wow"
75
+ DocumentRoot "/var/www/my-cool-website"
76
+ ServerAdmin john@coswellproductions.com
77
77
 
78
- <Directory "/">
79
- Options FollowSymLinks, Indexes
80
- Allow from all
81
- </Directory>
78
+ <Directory "/">
79
+ Options FollowSymLinks, Indexes
80
+ Allow from all
81
+ </Directory>
82
82
 
83
- <LocationMatch "^/secret">
84
- Deny from all
83
+ <LocationMatch "^/secret">
84
+ Deny from all
85
85
 
86
- AuthType Basic
87
- AuthName "My secret"
88
- AuthUserFile "/etc/apache2/users/global.users"
89
- Require user john
90
- </LocationMatch>
86
+ AuthType Basic
87
+ AuthName "My secret"
88
+ AuthUserFile "/etc/apache2/users/global.users"
89
+ Require user john
90
+ </LocationMatch>
91
91
 
92
- RewriteCond "%{HTTP_REFERER}" "^!my-cool-website\.cool\.wow"
93
- RewriteRule "\.(gif|jpg|png|pdf)$" "/lol-image-stealer.html" [L,R]
92
+ RewriteCond "%{HTTP_REFERER}" "^!my-cool-website\.cool\.wow"
93
+ RewriteRule "\.(gif|jpg|png|pdf)$" "/lol-image-stealer.html" [L,R]
94
+
95
+ == Using Apache::Config separately
96
+
97
+ Include the gem and access the methods on Apache::Config directly. See test/example_standalone.rb
98
+ for an example.
data/Rakefile CHANGED
@@ -6,10 +6,7 @@ Bundler.require(:default)
6
6
  $LOAD_PATH << 'lib'
7
7
 
8
8
  require 'yaml'
9
-
10
- require 'apache'
11
- require 'rspec/core/rake_task'
12
- require 'sdoc_helpers/markdown'
9
+ require 'apache/config'
13
10
 
14
11
  namespace :apache do
15
12
  desc "Generate the configs"
@@ -20,31 +17,6 @@ namespace :apache do
20
17
  end
21
18
  end
22
19
 
23
- Echoe.new('apache-config-generator') do |p|
24
- p.author = "John Bintz"
25
- p.summary = "A Ruby DSL for programmatically generating Apache configs"
26
- p.ignore_pattern = [ 'spec/**/*', 'test/**/*', 'docs/**/*' ]
27
- p.executable_pattern = [ 'bin/**/*' ]
28
- p.runtime_dependencies = [ 'rainbow' ]
29
- end
30
-
31
- namespace :spec do
32
- desc "Run RCov tests"
33
- RSpec::Core::RakeTask.new(:rcov) do |t|
34
- t.pattern = 'spec/*.rb'
35
- t.rcov = true
36
- t.rcov_opts = ['--exclude', 'spec', '--exclude', 'gems']
37
- t.rspec_opts = ['-b']
38
- end
39
- end
40
-
41
- Rake::RDocTask.new do |rdoc|
42
- rdoc.template = 'direct'
43
- rdoc.rdoc_files.add('lib', 'README.rdoc')
44
- rdoc.main = 'README.rdoc'
45
- rdoc.rdoc_dir = 'docs'
46
- end
47
-
48
20
  task :reek do
49
21
  system('reek -c config/config.reek lib/*')
50
22
  end
data/lib/apache/config.rb CHANGED
@@ -1,12 +1,9 @@
1
- require 'rubygems'
2
- require 'bundler'
3
-
4
- Bundler.require(:default)
5
-
6
1
  require 'fileutils'
7
2
  require 'rainbow'
8
3
 
9
- Dir[File.join(File.dirname(__FILE__), '*.rb')].each { |f| require f }
4
+ %w{apachify directory logging master modules mpm_prefork performance permissions rewrites ssl}.each do |file|
5
+ require "apache/#{file}"
6
+ end
10
7
 
11
8
  module Apache
12
9
  # The core class of Apache Config Generator.
@@ -71,7 +68,7 @@ module Apache
71
68
 
72
69
  # Build the provided configuration only if the current environment matches one of the conditions
73
70
  def build_if(target, *conditions, &block)
74
- build(target, &block) if conditions.include? APACHE_ENV
71
+ build(target, &block) if environment_ok?(*conditions)
75
72
  end
76
73
 
77
74
  # Build the provided configuration
@@ -84,7 +81,12 @@ module Apache
84
81
  end
85
82
 
86
83
  def build_and_return_if(*conditions, &block)
87
- build_and_return(&block) if conditions.include? APACHE_ENV
84
+ build_and_return(&block) if environment_ok?(*conditions)
85
+ end
86
+
87
+ def environment_ok?(*environments)
88
+ return true if APACHE_ENV == true
89
+ environments.include?(APACHE_ENV)
88
90
  end
89
91
 
90
92
  def build(target, &block)
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+
3
+ require 'bundler/setup'
4
+ Bundler.require(:default)
5
+
6
+ require 'apache/rake/apache/create'
@@ -0,0 +1,53 @@
1
+ require 'apache/config'
2
+ require 'apache/rake/support'
3
+
4
+ include Apache::Rake::Support
5
+
6
+ task :default => 'apache:create'
7
+
8
+ namespace :apache do
9
+ desc "Create all defined configs for the specified environment"
10
+ task :create, :environment do |t, args|
11
+ if get_environments.empty?
12
+ APACHE_ENV = true
13
+ else
14
+ need_environment if !args[:environment] && !get_default_environment
15
+
16
+ APACHE_ENV = (args[:environment] || get_default_environment).to_sym
17
+ end
18
+
19
+ config[:source_path] = File.expand_path(config[:source])
20
+ config[:dest_path] = File.expand_path(config[:destination])
21
+
22
+ Apache::Config.rotate_logs_path = config[:rotate_logs_path]
23
+
24
+ FileUtils.mkdir_p config[:dest_path]
25
+ Dir.chdir config[:dest_path]
26
+
27
+ # using CONFIG is deprecated
28
+ CONFIG = config
29
+
30
+ Dir[File.join(config[:source_path], '**', '*.rb')].each do |file|
31
+ puts file.foreground(:green)
32
+ require file
33
+ end
34
+ end
35
+
36
+ desc "List all possible environments"
37
+ task :environments do
38
+ puts get_environments * "\n"
39
+ end
40
+
41
+ desc "Set the default environment (currently #{get_default_environment || 'nil'})"
42
+ task :default, :environment do |t, args|
43
+ need_environment if !args[:environment]
44
+
45
+ if get_environments.include?(args[:environment])
46
+ File.open('.environment', 'w') { |fh| fh.puts args[:environment] }
47
+ puts "Calls to apache:create will now use #{args[:environment]} when you don't specify the environment."
48
+ else
49
+ puts "You need to specify a valid default environment. Here are the possibilities:"
50
+ Rake::Task['apache:environments'].invoke
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,35 @@
1
+ require 'yaml'
2
+ require 'fileutils'
3
+
4
+ module Apache
5
+ module Rake
6
+ module Support
7
+ def config
8
+ @config ||= Hash[YAML.load_file('config.yml').collect { |k,v| [ k.to_sym, v ] }]
9
+ end
10
+
11
+ def get_environments
12
+ config[:source_path] = File.expand_path(config[:source])
13
+
14
+ Dir[File.join(config[:source_path], '**', '*.rb')].collect { |file|
15
+ File.readlines(file).find_all { |line| line[%r{(if_environment|build_if)}] }.collect { |line| line.scan(%r{:[a-z_]+}) }
16
+ }.flatten.uniq.sort.collect { |name| name[1..-1] }
17
+ end
18
+
19
+ def get_default_environment
20
+ File.read('.environment').strip rescue nil
21
+ end
22
+
23
+ def need_environment
24
+ puts "You need to specify an environment. Available environments:"
25
+ puts
26
+ puts get_environments.collect { |env| "rake apache:create[#{env}]" } * "\n"
27
+ puts
28
+ puts "Additionally, you can set a default environment for this server:"
29
+ puts
30
+ puts "rake apache:default[#{get_environments.first}]"
31
+ exit 1
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ module Apache
2
+ VERSION = '0.2.6'
3
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+ require 'apache/apachify'
3
+
4
+ describe Apache::Apachify, "extends objects to apachify themselves" do
5
+ it "should Apachify the name" do
6
+ [
7
+ %w{test Test},
8
+ %w{test_full_name TestFullName},
9
+ %w{ssl_option SSLOption},
10
+ %w{exec_cgi ExecCGI},
11
+ %w{authz_ldap_authoritative AuthzLDAPAuthoritative},
12
+ %w{authz_ldap_url AuthzLDAPURL},
13
+ [ ["name", "other_name"], [ 'Name', 'OtherName' ] ]
14
+ ].each do |input, output|
15
+ input.apachify.should == output
16
+ end
17
+ end
18
+
19
+ it "should optionify the symbol" do
20
+ [
21
+ [ :not_multiviews, '-Multiviews' ]
22
+ ].each do |symbol, output|
23
+ symbol.optionify.should == output
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,140 @@
1
+ require 'apache/config'
2
+ require 'fileutils'
3
+
4
+ describe Apache::Config, "builds configurations" do
5
+ let(:apache) { Apache::Config }
6
+
7
+ before { apache.reset! }
8
+
9
+ def set_apache_env(env)
10
+ Object.send(:remove_const, :APACHE_ENV) if Object.const_defined? :APACHE_ENV
11
+ Object.send(:const_set, :APACHE_ENV, env)
12
+ end
13
+
14
+ describe '.environment_ok?' do
15
+ subject { Apache::Config.environment_ok?(:good) }
16
+
17
+ context 'empty environment' do
18
+ before { set_apache_env(true) }
19
+
20
+ it { should be_true }
21
+ end
22
+
23
+ context 'bad environment' do
24
+ before { set_apache_env(:bad) }
25
+
26
+ it { should be_false }
27
+ end
28
+
29
+ context 'good environment' do
30
+ before { set_apache_env(:good) }
31
+
32
+ it { should be_true }
33
+ end
34
+ end
35
+
36
+ it "should handle indent" do
37
+ apache.line_indent = 1
38
+
39
+ [
40
+ [ 'hello', ' hello' ],
41
+ [ [ 'hello', 'goodbye' ], [ ' hello', ' goodbye' ] ]
42
+ ].each do |input, output|
43
+ apache.indent(input).should == output
44
+ end
45
+ end
46
+
47
+ it "should add a line to the config" do
48
+ apache << "hello"
49
+ apache.to_a.should == [ 'hello' ]
50
+
51
+ apache + [ 'goodbye' ]
52
+ apache.to_a.should == [ 'hello', 'goodbye' ]
53
+ end
54
+
55
+ it "should handle method_missing" do
56
+ apache.test "test2", "test3"
57
+ apache.test_again! "test2", "test3"
58
+
59
+ apache.to_a.should == [
60
+ 'Test "test2" "test3"',
61
+ 'TestAgain test2 test3'
62
+ ]
63
+ end
64
+
65
+ it "should quoteize properly" do
66
+ ["test", "test2"].quoteize.should == %w{"test" "test2"}
67
+ [:test, :test2].quoteize.should == %w{test test2}
68
+ end
69
+
70
+ it "should blockify a block" do
71
+ apache.blockify("Tag", [ 'part', 'part2' ]) do
72
+ something "goes here"
73
+ end.should == ['', '<Tag "part" "part2">', ' Something "goes here"', '</Tag>', '']
74
+ end
75
+
76
+ it "should blockify the name of a block" do
77
+ [
78
+ [ 'part', '"part"' ],
79
+ [ :part, 'part' ],
80
+ [ [ 'part', 'part2' ], '"part" "part2"' ]
81
+ ].each do |name, attribute|
82
+ name.blockify.should == attribute
83
+ end
84
+ end
85
+
86
+ it "should handle a build" do
87
+ FileUtils.mkdir_p 'test'
88
+ apache.build('test/fake.conf') { my_test "this" }.should == [ 'MyTest "this"' ]
89
+ FileUtils.rm 'test/fake.conf'
90
+ end
91
+
92
+ it "should handle building if the environment is correct" do
93
+ set_apache_env(:test)
94
+
95
+ apache.build_and_return_if(:other) { my_test 'this' }.should == nil
96
+ apache.build_and_return_if(:test) { my_test 'this' }.should == [ 'MyTest "this"' ]
97
+ end
98
+
99
+ it "should only execute a block if the environment is correct" do
100
+ set_apache_env(:test)
101
+
102
+ test = 0
103
+ apache.if_environment(:other) { test = 1 }
104
+ test.should == 0
105
+
106
+ test = 0
107
+ apache.if_environment(:test) { test = 1 }
108
+ test.should == 1
109
+ end
110
+
111
+ it "should create an IfModule block" do
112
+ apache.if_module("test") { my_test }
113
+ apache.to_a.should == [ '', '<IfModule test_module>', ' MyTest', '</IfModule>', '' ]
114
+ end
115
+
116
+ it "should create a Directory block" do
117
+ dir = File.dirname(__FILE__)
118
+
119
+ apache.directory(dir) { my_test }
120
+ apache.to_a.should == [ '', %{<Directory "#{dir}">}, ' MyTest', '</Directory>', '' ]
121
+
122
+ apache.reset!
123
+
124
+ apache.directory('/does/not/exist') { my_test }
125
+ apache.to_a.should == [ '', %{<Directory "/does/not/exist">}, ' MyTest', '</Directory>', '' ]
126
+ end
127
+
128
+ it "should create a LocationMatch block" do
129
+ apache.location_match(%r{^/$}) { my_test }
130
+ apache.to_a.should == [ '', '<LocationMatch "^/$">', ' MyTest', '</LocationMatch>', '' ]
131
+ end
132
+ end
133
+
134
+ describe "Apache::Config used separately" do
135
+ context "it works" do
136
+ subject { Apache::Config.build_and_return { this_works }.first }
137
+
138
+ it { should == "ThisWorks" }
139
+ end
140
+ end
@@ -0,0 +1,15 @@
1
+ require 'apache/config'
2
+
3
+ describe Apache::Master, "should provide basic helpers for configuration" do
4
+ let(:apache) { Apache::Config }
5
+
6
+ before { apache.reset! }
7
+
8
+ it "should create the list of options" do
9
+ { :options => 'Options', :index_options => 'IndexOptions' }.each do |method, tag|
10
+ apache.reset!
11
+ apache.send(method, :test, 'test2')
12
+ apache.to_a.should == [ "#{tag} Test Test2" ]
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+ require 'apache/config'
3
+
4
+ describe Apache::Config, "logging directives" do
5
+ let(:apache) { Apache::Config }
6
+ before { apache.reset! }
7
+
8
+ it "should handle a defined log type" do
9
+ apache.rotate_logs_path = '/path/to/rotatelogs'
10
+
11
+ [ :custom, :error, :script, :rewrite ].each do |type|
12
+ apache.reset!
13
+ apache.send("#{type}_log".to_sym, 'test', 'test2')
14
+ apache.to_a.should == [ %{#{type.to_s.capitalize}Log "test" test2} ]
15
+
16
+ apache.reset!
17
+ apache.send("rotate_#{type}_log".to_sym, 'test', 86400, 'test2')
18
+ apache.to_a.should == [ %{#{type.to_s.capitalize}Log "|/path/to/rotatelogs test 86400" test2} ]
19
+ end
20
+ end
21
+
22
+ it "should give log formats" do
23
+ apache.combined_log_format
24
+ apache.common_log_format
25
+ end
26
+ end
@@ -0,0 +1,84 @@
1
+ require 'apache/config'
2
+
3
+ describe Apache::Master, "should provide basic helpers for configuration" do
4
+ let(:apache) { Apache::Config }
5
+
6
+ before { apache.reset! }
7
+
8
+ it "should build the modules with the provided block" do
9
+ apache.modules(:this, :that) do
10
+ my "is here"
11
+ end.should == [
12
+ '',
13
+ 'LoadModule "this_module" "modules/mod_this.so"',
14
+ 'LoadModule "that_module" "modules/mod_that.so"',
15
+ 'LoadModule "my_module" "is here"',
16
+ ''
17
+ ]
18
+ end
19
+
20
+ it "should set up the runner" do
21
+ apache.runner('test', 'test2')
22
+ apache.to_a.should == [ 'User test', 'Group test2' ]
23
+ end
24
+
25
+
26
+ it "should handle miscellaneous Apache directives" do
27
+ [
28
+ [ [ :apache_include, 'test' ], [ 'Include test' ] ],
29
+ [ [ :apache_alias, 'test', 'test2' ], [ 'Alias "test" "test2"' ] ],
30
+ [ [ :timeout, 300 ], [ 'Timeout 300' ] ]
31
+ ].each do |call, config|
32
+ apache.reset!
33
+ apache.send(*call)
34
+ apache.to_a.should == config
35
+ end
36
+ end
37
+
38
+ it "should handle rotate logs" do
39
+ apache.rotate_logs_path = "/my/path"
40
+ apache.rotatelogs('/log/path', 12345).should == "|/my/path /log/path 12345"
41
+ end
42
+
43
+ it "should create Passenger directives" do
44
+ apache.passenger '/opt/local/ruby', '1.8', '2.2.11'
45
+ apache.to_a.should == [
46
+ 'LoadModule "passenger_module" "/opt/local/ruby/lib/ruby/gems/1.8/gems/passenger-2.2.11/ext/apache2/mod_passenger.so"',
47
+ 'PassengerRoot "/opt/local/ruby/lib/ruby/gems/1.8/gems/passenger-2.2.11"',
48
+ 'PassengerRuby "/opt/local/ruby/bin/ruby"'
49
+ ]
50
+ end
51
+
52
+ # not testing this big blob for output correctness...
53
+ it "should enable gzip server-wide" do
54
+ apache.enable_gzip!
55
+ end
56
+
57
+ it "should create Apache comments" do
58
+ apache.comment("This is a comment")
59
+ apache.to_a.should == [ '#', '# This is a comment', '#' ]
60
+
61
+ apache.reset!
62
+
63
+ apache.comment(["This is", "a comment"])
64
+ apache.to_a.should == [ '#', '# This is', '# a comment', '#' ]
65
+ end
66
+
67
+ it "should create & check a script alias" do
68
+ dir = File.dirname(__FILE__)
69
+
70
+ apache.script_alias '/script/', dir
71
+ apache.to_a.should == [ %{ScriptAlias "/script/" "#{dir}"} ]
72
+ end
73
+
74
+ it "should add a type with some other options" do
75
+ apache.add_type! 'text/html', '.html', :handler => 'html-handler'
76
+ apache.to_a.should == [ 'AddType text/html .html', 'AddHandler html-handler .html' ]
77
+ end
78
+
79
+ it "should create headers" do
80
+ apache.set_header :test => :test2
81
+ apache.set_header 'test3' => [ 'test4', "test5=test6" ]
82
+ apache.to_a.should == [ 'Header set test test2', 'Header set "test3" "test4" test5=test6' ]
83
+ end
84
+ end
@@ -0,0 +1,25 @@
1
+ require 'apache/modules'
2
+
3
+ describe Apache::Modules, "should build a list of modules" do
4
+ before do
5
+ Apache::Modules.reset!
6
+ end
7
+
8
+ it "should handle method_missing" do
9
+ Apache::Modules.mine
10
+
11
+ Apache::Modules.modules.should == [ 'LoadModule "mine_module" "modules/mod_mine.so"' ]
12
+ end
13
+
14
+ it "should build a set of modules" do
15
+ Apache::Modules.build(:this, :that) do
16
+ mine "my_path"
17
+ end.should == [
18
+ '',
19
+ 'LoadModule "this_module" "modules/mod_this.so"',
20
+ 'LoadModule "that_module" "modules/mod_that.so"',
21
+ 'LoadModule "mine_module" "my_path"',
22
+ ''
23
+ ]
24
+ end
25
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe Apache::Config, "prefork MPM" do
4
+ let(:apache) { Apache::Config }
5
+ before { apache.reset! }
6
+
7
+ it "should build the prefork options" do
8
+ apache.prefork_config do
9
+ start 10
10
+ spares 10, 30
11
+ limit 20
12
+ clients 100
13
+ max_requests 1000
14
+ end
15
+
16
+ apache.to_a.should == [
17
+ '',
18
+ '# Prefork config',
19
+ '',
20
+ 'StartServers 10',
21
+ 'MinSpareServers 10',
22
+ 'MaxSpareServers 30',
23
+ 'ServerLimit 20',
24
+ 'MaxClients 100',
25
+ 'MaxRequestsPerChild 1000'
26
+ ]
27
+ end
28
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Apache::Config, "performance settings" do
4
+ let(:apache) { Apache::Config }
5
+ before { apache.reset! }
6
+
7
+ it "should set keepalive" do
8
+ apache.activate_keepalive({ :timeout => 10, :requests => 100 })
9
+
10
+ apache.to_a.sort.should == [
11
+ 'KeepAlive On',
12
+ 'KeepAliveTimeout 10',
13
+ 'MaxKeepAliveRequests 100'
14
+ ]
15
+ end
16
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe Apache::Config, "permissions" do
4
+ let(:apache) { Apache::Config }
5
+ before { apache.reset! }
6
+
7
+ it "should set up allow and deny groups" do
8
+ apache.deny_from_all!
9
+ apache.to_a.should == [ 'Order deny,allow', 'Deny from all' ]
10
+
11
+ apache.reset!
12
+ apache.allow_from_all!
13
+ apache.to_a.should == [ 'Order allow,deny', 'Allow from all' ]
14
+ end
15
+
16
+ it "should allow from somewhere" do
17
+ apache.allow_from '1.2.3.4'
18
+ apache.to_a.should == [ 'Allow from "1.2.3.4"' ]
19
+ end
20
+
21
+ # Verify the blob output in apache itself, just make sure the method doesn't bomb
22
+ it "should verify some blob functions don't fail" do
23
+ apache.default_restrictive!
24
+ apache.no_htfiles!
25
+
26
+ apache.basic_authentication("My site", '/path/to/users/file', :user => :john)
27
+ apache.ldap_authentication("My site", 'ldap url', 'ldap-path' => 'path')
28
+ end
29
+
30
+ it "should add an auth require" do
31
+ apache.apache_require 'user', :john, :scott
32
+ apache.to_a.should == [ 'Require user john scott' ]
33
+ end
34
+ end
@@ -0,0 +1,105 @@
1
+ require 'spec_helper'
2
+
3
+ describe Apache::Config, "rewrites" do
4
+ let(:apache) { Apache::Config }
5
+ before { apache.reset! }
6
+
7
+ it "should enable the rewrite engine" do
8
+ apache.enable_rewrite_engine :log_level => 1
9
+ apache.to_a.should == [
10
+ '',
11
+ 'RewriteEngine on',
12
+ 'RewriteLogLevel 1',
13
+ ''
14
+ ]
15
+ end
16
+
17
+ it "should add a simple redirect permanent" do
18
+ apache.r301 '/here', '/there'
19
+ apache.to_a.should == [
20
+ 'Redirect permanent "/here" "/there"'
21
+ ]
22
+ end
23
+
24
+ it "should build rewrites" do
25
+ apache.rewrites do
26
+ rule %r{^/$}, '/test'
27
+ end
28
+ apache.to_a[1..-1].should == [
29
+ '', 'RewriteRule "^/$" "/test"', ''
30
+ ]
31
+ end
32
+ end
33
+
34
+ describe Apache::RewriteManager, "specific rewrite rules" do
35
+ let(:rewrite) { Apache::RewriteManager }
36
+ before { rewrite.reset! }
37
+
38
+ it "should create a rewrite" do
39
+ rewrite.build do
40
+ cond '%{REQUEST_FILENAME}', 'test'
41
+ rule %r{^/$}, '/test'
42
+
43
+ r301 %r{^/success$}, '/test'
44
+
45
+ rewrite_test '/', '/test'
46
+ rewrite_test '/fail', '/test'
47
+ rewrite_test '/%{REQUEST_FILENAME}', '/test', :request_filename => 'success'
48
+ end[1..-1].should == [
49
+ '',
50
+ 'RewriteCond "%{REQUEST_FILENAME}" "test"',
51
+ 'RewriteRule "^/$" "/test"',
52
+ 'RedirectMatch permanent "^/success$" "/test"'
53
+ ]
54
+ end
55
+ end
56
+
57
+ describe Apache::MatchableThing, "something that can be matched" do
58
+ subject do
59
+ thing = Apache::MatchableThing.new
60
+ thing.rule('here', 'there')
61
+
62
+ class << thing
63
+ def tag; "RSpec"; end
64
+ end
65
+
66
+ thing
67
+ end
68
+
69
+ its(:to_s) { should == 'RSpec "here" "there"' }
70
+ its(:to_a) { should == [ 'RSpec "here" "there"' ] }
71
+ end
72
+
73
+ describe Apache::RewriteRule, "a RewriteRule" do
74
+ subject do
75
+ rule = Apache::RewriteRule.new
76
+ rule.cond('/%{REQUEST_FILENAME}', '^/test$')
77
+ rule.rule(%r{^/test$}, '/test2', :last => true, :preserve_query_string => true)
78
+ rule
79
+ end
80
+
81
+ its(:to_s) { should == 'RewriteRule "^/test$" "/test2" [L,QSA]' }
82
+ its(:to_a) { should == [
83
+ '',
84
+ 'RewriteCond "/%{REQUEST_FILENAME}" "^/test$"',
85
+ 'RewriteRule "^/test$" "/test2" [L,QSA]'
86
+ ] }
87
+
88
+ it "should not the test" do
89
+ subject.test('/test', :request_filename => 'test').should == '/test2'
90
+ end
91
+
92
+ it "should fail if opts is not provided" do
93
+ lambda { subject.match?('test', nil) }.should raise_error
94
+ end
95
+ end
96
+
97
+ describe Apache::RewriteCondition, "a RewriteCond" do
98
+ subject do
99
+ cond = Apache::RewriteCondition.new
100
+ cond.cond('%{REQUEST_FILENAME}', '^/test$', :or, :case_insensitive, :no_vary)
101
+ cond
102
+ end
103
+
104
+ its(:to_s) { should == 'RewriteCond "%{REQUEST_FILENAME}" "^/test$" [OR,NC,NV]' }
105
+ end
File without changes
@@ -0,0 +1,29 @@
1
+ IPS = [ '127.0.0.1:80', '127.0.0.1:81' ]
2
+
3
+ Apache::Config.build('httpd.conf') do
4
+ server_root '/var/html/apache'
5
+
6
+ modules :expires, :headers
7
+ modules :usertrack, :rewrite
8
+ load_module "php5_module", "modules/libphp5.so"
9
+
10
+ passenger '/var/html/ree', '1.8', '2.2.11'
11
+
12
+ if_module "!mpm_netware" do
13
+ runner 'webby', 'opoadm'
14
+ end
15
+
16
+ directory '/' do
17
+ options! 'FollowSymLinks'
18
+ allow_override! 'None'
19
+ deny_from_all
20
+ end
21
+
22
+ virtual_host *IPS do
23
+ directory '/' do
24
+ allow_from_all
25
+ end
26
+
27
+
28
+ end
29
+ end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'rubygems'
4
+ gem 'apache-config-generator'
5
+ require 'apache/config'
6
+
7
+ puts Apache::Config.build_and_return { this_works }
data/tools.watchr ADDED
@@ -0,0 +1,22 @@
1
+ def growl(title, message)
2
+ system %{growlnotify -m "#{message}" "#{title}"}
3
+ end
4
+
5
+ def reek(file)
6
+ output = %x{reek #{file}}
7
+
8
+ puts output
9
+
10
+ file, warnings = output.split("\n").first.split(" -- ")
11
+
12
+ growl "REEK: #{file}", warnings
13
+ end
14
+
15
+ def yard
16
+ system %{yard doc {app,lib}/**/*.rb}
17
+ end
18
+
19
+ watch('(app|lib)/(.*)\.rb') { |match|
20
+ reek(match[0])
21
+ yard
22
+ }
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apache-config-generator
3
3
  version: !ruby/object:Gem::Version
4
- hash: 73
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 5
10
- - 1
11
- version: 0.2.5.1
9
+ - 6
10
+ version: 0.2.6
12
11
  platform: ruby
13
12
  authors:
14
13
  - John Bintz
@@ -16,14 +15,101 @@ autorequire:
16
15
  bindir: bin
17
16
  cert_chain: []
18
17
 
19
- date: 2010-10-26 00:00:00 -04:00
18
+ date: 2010-11-29 00:00:00 -05:00
20
19
  default_executable:
21
20
  dependencies:
22
21
  - !ruby/object:Gem::Dependency
22
+ name: bundler
23
23
  prerelease: false
24
- type: :runtime
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 23
30
+ segments:
31
+ - 1
32
+ - 0
33
+ - 0
34
+ version: 1.0.0
35
+ type: :development
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rspec
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 15
46
+ segments:
47
+ - 2
48
+ - 0
49
+ - 0
50
+ version: 2.0.0
51
+ type: :development
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: nokogiri
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 3
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ type: :development
66
+ version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ name: mocha
69
+ prerelease: false
70
+ requirement: &id004 !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ type: :development
80
+ version_requirements: *id004
81
+ - !ruby/object:Gem::Dependency
82
+ name: autotest
83
+ prerelease: false
84
+ requirement: &id005 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ hash: 3
90
+ segments:
91
+ - 0
92
+ version: "0"
93
+ type: :development
94
+ version_requirements: *id005
95
+ - !ruby/object:Gem::Dependency
96
+ name: reek
97
+ prerelease: false
98
+ requirement: &id006 !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ hash: 3
104
+ segments:
105
+ - 0
106
+ version: "0"
107
+ type: :development
108
+ version_requirements: *id006
109
+ - !ruby/object:Gem::Dependency
25
110
  name: rainbow
26
- version_requirements: &id001 !ruby/object:Gem::Requirement
111
+ prerelease: false
112
+ requirement: &id007 !ruby/object:Gem::Requirement
27
113
  none: false
28
114
  requirements:
29
115
  - - ">="
@@ -32,31 +118,18 @@ dependencies:
32
118
  segments:
33
119
  - 0
34
120
  version: "0"
35
- requirement: *id001
121
+ type: :runtime
122
+ version_requirements: *id007
36
123
  description: A Ruby DSL for programmatically generating Apache configs
37
- email: ""
124
+ email: john@coswellproductions.com
38
125
  executables:
39
126
  - apache-configurator
40
127
  extensions: []
41
128
 
42
- extra_rdoc_files:
43
- - CHANGELOG
44
- - README.rdoc
45
- - bin/apache-configurator
46
- - lib/apache.rb
47
- - lib/apache/apachify.rb
48
- - lib/apache/config.rb
49
- - lib/apache/directory.rb
50
- - lib/apache/logging.rb
51
- - lib/apache/master.rb
52
- - lib/apache/modules.rb
53
- - lib/apache/mpm_prefork.rb
54
- - lib/apache/performance.rb
55
- - lib/apache/permissions.rb
56
- - lib/apache/rake/create.rb
57
- - lib/apache/rewrites.rb
58
- - lib/apache/ssl.rb
129
+ extra_rdoc_files: []
130
+
59
131
  files:
132
+ - .gitignore
60
133
  - CHANGELOG
61
134
  - Gemfile
62
135
  - Gemfile.lock
@@ -75,26 +148,36 @@ files:
75
148
  - lib/apache/mpm_prefork.rb
76
149
  - lib/apache/performance.rb
77
150
  - lib/apache/permissions.rb
78
- - lib/apache/rake/create.rb
151
+ - lib/apache/rake.rb
152
+ - lib/apache/rake/apache/create.rb
153
+ - lib/apache/rake/support.rb
79
154
  - lib/apache/rewrites.rb
80
155
  - lib/apache/ssl.rb
156
+ - lib/apache/version.rb
81
157
  - skel/Gemfile
82
158
  - skel/Rakefile
83
159
  - skel/config.yml
84
- - Manifest
85
- - apache-config-generator.gemspec
160
+ - spec/apache/apachify_spec.rb
161
+ - spec/apache/config_spec.rb
162
+ - spec/apache/directory_spec.rb
163
+ - spec/apache/logging_spec.rb
164
+ - spec/apache/master_spec.rb
165
+ - spec/apache/modules_spec.rb
166
+ - spec/apache/mpm_prefork_spec.rb
167
+ - spec/apache/performance_spec.rb
168
+ - spec/apache/permissions_spec.rb
169
+ - spec/apache/rewrites_spec.rb
170
+ - spec/spec_helper.rb
171
+ - test/config/httpd.rb
172
+ - test/example_standalone.rb
173
+ - tools.watchr
86
174
  has_rdoc: true
87
- homepage: ""
175
+ homepage: http://johnbintz.com/
88
176
  licenses: []
89
177
 
90
178
  post_install_message:
91
179
  rdoc_options:
92
- - --line-numbers
93
- - --inline-source
94
- - --title
95
- - Apache-config-generator
96
- - --main
97
- - README.rdoc
180
+ - --charset=UTF-8
98
181
  require_paths:
99
182
  - lib
100
183
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -111,14 +194,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
194
  requirements:
112
195
  - - ">="
113
196
  - !ruby/object:Gem::Version
114
- hash: 11
197
+ hash: 23
115
198
  segments:
116
199
  - 1
117
- - 2
118
- version: "1.2"
200
+ - 3
201
+ - 6
202
+ version: 1.3.6
119
203
  requirements: []
120
204
 
121
- rubyforge_project: apache-config-generator
205
+ rubyforge_project:
122
206
  rubygems_version: 1.3.7
123
207
  signing_key:
124
208
  specification_version: 3
data/Manifest DELETED
@@ -1,25 +0,0 @@
1
- CHANGELOG
2
- Gemfile
3
- Gemfile.lock
4
- README.rdoc
5
- Rakefile
6
- autotest/discover.rb
7
- bin/apache-configurator
8
- config/config.reek
9
- lib/apache.rb
10
- lib/apache/apachify.rb
11
- lib/apache/config.rb
12
- lib/apache/directory.rb
13
- lib/apache/logging.rb
14
- lib/apache/master.rb
15
- lib/apache/modules.rb
16
- lib/apache/mpm_prefork.rb
17
- lib/apache/performance.rb
18
- lib/apache/permissions.rb
19
- lib/apache/rake/create.rb
20
- lib/apache/rewrites.rb
21
- lib/apache/ssl.rb
22
- skel/Gemfile
23
- skel/Rakefile
24
- skel/config.yml
25
- Manifest
@@ -1,35 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- Gem::Specification.new do |s|
4
- s.name = %q{apache-config-generator}
5
- s.version = "0.2.5.1"
6
-
7
- s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["John Bintz"]
9
- s.date = %q{2010-10-26}
10
- s.default_executable = %q{apache-configurator}
11
- s.description = %q{A Ruby DSL for programmatically generating Apache configs}
12
- s.email = %q{}
13
- s.executables = ["apache-configurator"]
14
- s.extra_rdoc_files = ["CHANGELOG", "README.rdoc", "bin/apache-configurator", "lib/apache.rb", "lib/apache/apachify.rb", "lib/apache/config.rb", "lib/apache/directory.rb", "lib/apache/logging.rb", "lib/apache/master.rb", "lib/apache/modules.rb", "lib/apache/mpm_prefork.rb", "lib/apache/performance.rb", "lib/apache/permissions.rb", "lib/apache/rake/create.rb", "lib/apache/rewrites.rb", "lib/apache/ssl.rb"]
15
- s.files = ["CHANGELOG", "Gemfile", "Gemfile.lock", "README.rdoc", "Rakefile", "autotest/discover.rb", "bin/apache-configurator", "config/config.reek", "lib/apache.rb", "lib/apache/apachify.rb", "lib/apache/config.rb", "lib/apache/directory.rb", "lib/apache/logging.rb", "lib/apache/master.rb", "lib/apache/modules.rb", "lib/apache/mpm_prefork.rb", "lib/apache/performance.rb", "lib/apache/permissions.rb", "lib/apache/rake/create.rb", "lib/apache/rewrites.rb", "lib/apache/ssl.rb", "skel/Gemfile", "skel/Rakefile", "skel/config.yml", "Manifest", "apache-config-generator.gemspec"]
16
- s.homepage = %q{}
17
- s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Apache-config-generator", "--main", "README.rdoc"]
18
- s.require_paths = ["lib"]
19
- s.rubyforge_project = %q{apache-config-generator}
20
- s.rubygems_version = %q{1.3.7}
21
- s.summary = %q{A Ruby DSL for programmatically generating Apache configs}
22
-
23
- if s.respond_to? :specification_version then
24
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
- s.specification_version = 3
26
-
27
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
28
- s.add_runtime_dependency(%q<rainbow>, [">= 0"])
29
- else
30
- s.add_dependency(%q<rainbow>, [">= 0"])
31
- end
32
- else
33
- s.add_dependency(%q<rainbow>, [">= 0"])
34
- end
35
- end
@@ -1,73 +0,0 @@
1
- Bundler.require(:default)
2
-
3
- require 'fileutils'
4
- require 'yaml'
5
- require 'apache/config'
6
- require 'apache/rake/create'
7
-
8
- CONFIG = Hash[YAML.load_file('config.yml').collect { |k,v| [ k.to_sym, v ] }]
9
-
10
- def get_environments
11
- CONFIG[:source_path] = File.expand_path(CONFIG[:source])
12
-
13
- Dir[File.join(CONFIG[:source_path], '**', '*.rb')].collect { |file|
14
- File.readlines(file).find_all { |line| line[%r{(if_environment|build_if)}] }.collect { |line| line.scan(%r{:[a-z_]+}) }
15
- }.flatten.uniq.sort.collect { |name| name[1..-1] }
16
- end
17
-
18
- def get_default_environment
19
- File.read('.environment').strip rescue nil
20
- end
21
-
22
- def need_environment
23
- puts "You need to specify an environment. Available environments:"
24
- puts
25
- puts get_environments.collect { |env| "rake apache:create[#{env}]" } * "\n"
26
- puts
27
- puts "Additionally, you can set a default environment for this server:"
28
- puts
29
- puts "rake apache:default[#{get_environments.first}]"
30
- exit 1
31
- end
32
-
33
- task :default => 'apache:create'
34
-
35
- namespace :apache do
36
- desc "Create all defined configs for the specified environment"
37
- task :create, :environment do |t, args|
38
- need_environment if !args[:environment] && !get_default_environment
39
-
40
- APACHE_ENV = (args[:environment] || get_default_environment).to_sym
41
-
42
- CONFIG[:source_path] = File.expand_path(CONFIG[:source])
43
- CONFIG[:dest_path] = File.expand_path(CONFIG[:destination])
44
-
45
- Apache::Config.rotate_logs_path = CONFIG[:rotate_logs_path]
46
-
47
- FileUtils.mkdir_p CONFIG[:dest_path]
48
- Dir.chdir CONFIG[:dest_path]
49
-
50
- Dir[File.join(CONFIG[:source_path], '**', '*.rb')].each do |file|
51
- puts file.foreground(:green)
52
- require file
53
- end
54
- end
55
-
56
- desc "List all possible environments"
57
- task :environments do
58
- puts get_environments * "\n"
59
- end
60
-
61
- desc "Set the default environment (currently #{get_default_environment || 'nil'})"
62
- task :default, :environment do |t, args|
63
- need_environment if !args[:environment]
64
-
65
- if get_environments.include?(args[:environment])
66
- File.open('.environment', 'w') { |fh| fh.puts args[:environment] }
67
- puts "Calls to apache:create will now use #{args[:environment]} when you don't specify the environment."
68
- else
69
- puts "You need to specify a valid default environment. Here are the possibilities:"
70
- Rake::Task['apache:environments'].invoke
71
- end
72
- end
73
- end