tomahawk 0.0.3 → 0.0.4
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/.travis.yml +6 -0
- data/README.md +77 -7
- data/Rakefile +5 -0
- data/lib/tomahawk/config.rb +4 -0
- data/lib/tomahawk/directive_groups/base.rb +8 -3
- data/lib/tomahawk/directive_groups/directory.rb +2 -2
- data/lib/tomahawk/directive_groups/httpd.rb +2 -2
- data/lib/tomahawk/directive_groups/virtual_host.rb +2 -2
- data/lib/tomahawk/directive_groups.rb +1 -1
- data/lib/tomahawk/generators/base.rb +1 -1
- data/lib/tomahawk/generators/httpd.rb +1 -1
- data/lib/tomahawk/version.rb +1 -1
- data/lib/tomahawk.rb +1 -0
- data/spec/lib/tomahawk/config_parser_spec.rb +1 -1
- data/spec/lib/tomahawk/config_spec.rb +7 -0
- data/spec/lib/tomahawk/directive_groups/base_spec.rb +34 -0
- data/spec/lib/tomahawk/directive_groups/virtual_host_spec.rb +12 -12
- data/spec/lib/tomahawk/generators/httpd_spec.rb +40 -0
- data/tomahawk.gemspec +2 -1
- metadata +39 -23
- checksums.yaml +0 -7
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
[](https://travis-ci.org/Sophisticates/Tomahawk)
|
2
|
+
[](https://codeclimate.com/github/Sophisticates/Tomahawk)
|
1
3
|
# Tomahawk
|
2
4
|
|
3
5
|
Tomahawk helps generating and parsing Apache 2 configuration files. You can for example parse VirtualHost configs, CRUD some directives in your Ruby code and generate a new config file out of it afterwards.
|
@@ -19,19 +21,87 @@ Or install it yourself as:
|
|
19
21
|
$ gem install tomahawk
|
20
22
|
|
21
23
|
## Usage
|
22
|
-
require 'tomahawk'
|
23
24
|
|
24
|
-
|
25
|
+
The following builds a new Apache Config
|
25
26
|
|
26
|
-
|
27
|
+
```ruby
|
28
|
+
require 'tomahawk'
|
27
29
|
|
28
|
-
|
30
|
+
# initalize
|
31
|
+
config = Tomahawk::Config.new do |directives, groups|
|
32
|
+
directives[:timeout] = '300'
|
33
|
+
directives[:max_keep_alive_requests] = '100'
|
34
|
+
end
|
29
35
|
|
30
|
-
|
36
|
+
# ...
|
31
37
|
|
32
|
-
|
38
|
+
httpd_config.directives[:keep_alive] = 'On' # change a directive
|
39
|
+
|
40
|
+
config.to_s # =>
|
41
|
+
# Timeout 300
|
42
|
+
# MaxKeepAliveRequests 100
|
43
|
+
# KeepAlive On
|
44
|
+
|
45
|
+
```
|
46
|
+
|
47
|
+
Nested directive groups can be added as well
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
require 'tomahawk'
|
51
|
+
|
52
|
+
config = Tomahawk::Config.new do |directives, groups|
|
53
|
+
directives[:timeout] = '300'
|
54
|
+
directives[:max_keep_alive_requests] = '100'
|
55
|
+
|
56
|
+
groups << Tomahawk::DirectiveGroups::VirtualHost.new('*:80') do |directives, groups|
|
57
|
+
directives[:server_name] = 'example.com'
|
58
|
+
directives[:document_root] = '/var/www/example.com'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# ...
|
63
|
+
|
64
|
+
config.groups.first.groups << Tomahawk::DirectiveGroups::Directory.new('/var/www/example.com') do |directives, groups|
|
65
|
+
directives[:options] = '-Indexes FollowSymLinks MultiViews'
|
66
|
+
end
|
67
|
+
|
68
|
+
config.to_s # =>
|
69
|
+
# Timeout 300
|
70
|
+
# MaxKeepAliveRequests 100
|
71
|
+
#
|
72
|
+
# <VirtualHost *:80>
|
73
|
+
# ServerName example.com
|
74
|
+
# DocumentRoot /var/www/example.com
|
75
|
+
#
|
76
|
+
# <Directory /var/www/example.com>
|
77
|
+
# Options -Indexes FollowSymLinks MultiViews
|
78
|
+
# </Directory>
|
79
|
+
#
|
80
|
+
# </VirtualHost>
|
81
|
+
```
|
82
|
+
|
83
|
+
Only two types of directive groups are currently implemented: `VirtualHost` and `Directory`. More groups are possible of course, just open a new issue :)
|
84
|
+
|
85
|
+
### Parsing
|
86
|
+
|
87
|
+
Tomahawk can also parse existing configs
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
require 'tomahawk'
|
91
|
+
|
92
|
+
config = Tomahawk.parse File.read('/etc/apache2/apache.conf')
|
93
|
+
|
94
|
+
config.directives # lists parsed directives such as ServerName and LogLevel
|
95
|
+
|
96
|
+
config.groups # lists parsed directive groups such as <VirtualHost> and <Directory>
|
97
|
+
|
98
|
+
config.directives['server_name'] = 'google.com' # change a directive
|
99
|
+
|
100
|
+
config.directives['some_new_directive'] = 'foo' # create a new directive
|
101
|
+
|
102
|
+
File.write('/etc/apache2/apache.conf.new', httpd_config.to_s) # write your new configuration back to disk
|
103
|
+
```
|
33
104
|
|
34
|
-
File.write('/etc/apache2/apache.conf.new', httpd_config.to_conf) # write your new configuration back to disk
|
35
105
|
|
36
106
|
## Contributing
|
37
107
|
|
data/Rakefile
CHANGED
@@ -3,16 +3,21 @@ module Tomahawk
|
|
3
3
|
class Base
|
4
4
|
attr_accessor :parameters, :directives, :groups
|
5
5
|
|
6
|
-
def initialize(parameters = '', directives = {})
|
6
|
+
def initialize(parameters = '', directives = {}, groups = [])
|
7
|
+
yield(directives, groups) if block_given?
|
7
8
|
@parameters = parameters
|
8
9
|
@directives = Hash[directives]
|
9
|
-
@groups =
|
10
|
+
@groups = Array(groups)
|
10
11
|
end
|
11
12
|
|
12
|
-
def
|
13
|
+
def to_str
|
13
14
|
raise "#{self.class.name} doesn't support #conf!"
|
14
15
|
end
|
15
16
|
|
17
|
+
def to_s
|
18
|
+
to_str
|
19
|
+
end
|
20
|
+
|
16
21
|
def ==(obj)
|
17
22
|
self.class == self.class && self.parameters == obj.parameters && self.directives == obj.directives && self.groups == obj.groups
|
18
23
|
rescue
|
@@ -10,7 +10,7 @@ module Tomahawk
|
|
10
10
|
def DirectiveGroup(directive_group_name)
|
11
11
|
directive_group_name = String(directive_group_name)
|
12
12
|
|
13
|
-
|
13
|
+
Tomahawk::DirectiveGroups.const_get(directive_group_name)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
data/lib/tomahawk/version.rb
CHANGED
data/lib/tomahawk.rb
CHANGED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Tomahawk::DirectiveGroups::Base do
|
4
|
+
it 'can get initialized' do
|
5
|
+
config = Tomahawk::DirectiveGroups::Base.new('abcd', { 'server_name' => 'example.com', 'foo' => 'bar'})
|
6
|
+
|
7
|
+
expect(config.directives['server_name']).to eq('example.com')
|
8
|
+
expect(config.directives['foo']).to eq('bar')
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'can get initialized by block' do
|
12
|
+
config = Tomahawk::DirectiveGroups::Base.new do |directives, groups|
|
13
|
+
directives['server_name'] = 'example.com'
|
14
|
+
directives['foo'] = 'bar'
|
15
|
+
|
16
|
+
groups << Tomahawk::DirectiveGroups::Base.new do |directives, groups|
|
17
|
+
directives['group_test'] = 'works'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
expect(config.directives['server_name']).to eq('example.com')
|
22
|
+
expect(config.directives['foo']).to eq('bar')
|
23
|
+
expect(config.groups.first.directives['group_test']).to eq('works')
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'forwards #to_s/#to_str messages to a generator' do
|
27
|
+
config = Tomahawk::DirectiveGroups::HTTPd.new
|
28
|
+
|
29
|
+
expect(Tomahawk::Generators::HTTPd).to receive(:new).exactly(2).times
|
30
|
+
|
31
|
+
config.to_s # explicitly
|
32
|
+
"#{config}" # implicitly
|
33
|
+
end
|
34
|
+
end
|
@@ -20,21 +20,21 @@ describe Tomahawk::DirectiveGroups::VirtualHost do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
describe '#to_conf' do
|
23
|
-
it 'prints attributes in Apache Conf format' do
|
24
|
-
|
23
|
+
# it 'prints attributes in Apache Conf format' do
|
24
|
+
# address = '*:80'
|
25
25
|
|
26
|
-
|
27
|
-
|
26
|
+
# server_name = 'example.com'
|
27
|
+
# document_root = '/tmp/tomahawk/test'
|
28
28
|
|
29
|
-
|
29
|
+
# vhost = Tomahawk::DirectiveGroups::VirtualHost.new(address, { server_name: server_name, document_root: document_root })
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
# expect(strip_whitespaces(vhost.to_conf)).to eq(strip_whitespaces(<<-CONF))
|
32
|
+
# <VirtualHost #{address}>
|
33
|
+
# ServerName #{server_name}
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
35
|
+
# DocumentRoot #{document_root}
|
36
|
+
# </VirtualHost>
|
37
|
+
# CONF
|
38
|
+
# end
|
39
39
|
end
|
40
40
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
def normalize_config_string(config_string)
|
4
|
+
config_string.strip.gsub('/^\n$/','').gsub(/^\s*/,'').gsub(/\s*$/,'')
|
5
|
+
end
|
6
|
+
|
7
|
+
describe Tomahawk::Generators::HTTPd do
|
8
|
+
it "generates configs correctly" do
|
9
|
+
config = Tomahawk::Config.new do |directives, groups|
|
10
|
+
directives[:timeout] = '300'
|
11
|
+
directives[:max_keep_alive_requests] = '100'
|
12
|
+
|
13
|
+
groups << Tomahawk::DirectiveGroups::VirtualHost.new('*:80') do |directives, groups|
|
14
|
+
directives[:server_name] = 'example.com'
|
15
|
+
directives[:document_root] = '/var/www/example.com'
|
16
|
+
|
17
|
+
groups << Tomahawk::DirectiveGroups::Directory.new('/var/www/example.com') do |directives, groups|
|
18
|
+
directives[:options] = '-Indexes FollowSymLinks MultiViews'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
expected_result = <<-SAMPLE
|
24
|
+
Timeout 300
|
25
|
+
MaxKeepAliveRequests 100
|
26
|
+
<VirtualHost *:80>
|
27
|
+
|
28
|
+
ServerName example.com
|
29
|
+
DocumentRoot /var/www/example.com
|
30
|
+
<Directory /var/www/example.com>
|
31
|
+
|
32
|
+
Options -Indexes FollowSymLinks MultiViews
|
33
|
+
</Directory>
|
34
|
+
|
35
|
+
</VirtualHost>
|
36
|
+
SAMPLE
|
37
|
+
|
38
|
+
expect(normalize_config_string(Tomahawk::Generators::HTTPd.new(config).to_s)).to eq(normalize_config_string(expected_result))
|
39
|
+
end
|
40
|
+
end
|
data/tomahawk.gemspec
CHANGED
@@ -18,7 +18,8 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
+
spec.add_dependency 'rake', '>= 10.0.0'
|
22
|
+
|
21
23
|
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
-
spec.add_development_dependency "rake"
|
23
24
|
spec.add_development_dependency "rspec"
|
24
25
|
end
|
metadata
CHANGED
@@ -1,55 +1,62 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tomahawk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Christian Schell
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2014-
|
12
|
+
date: 2014-02-11 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
15
|
+
name: rake
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
16
18
|
requirements:
|
17
|
-
- -
|
19
|
+
- - ! '>='
|
18
20
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
20
|
-
type: :
|
21
|
+
version: 10.0.0
|
22
|
+
type: :runtime
|
21
23
|
prerelease: false
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
23
26
|
requirements:
|
24
|
-
- -
|
27
|
+
- - ! '>='
|
25
28
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
29
|
+
version: 10.0.0
|
27
30
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
31
|
+
name: bundler
|
29
32
|
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
30
34
|
requirements:
|
31
|
-
- -
|
35
|
+
- - ~>
|
32
36
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
37
|
+
version: '1.5'
|
34
38
|
type: :development
|
35
39
|
prerelease: false
|
36
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
37
42
|
requirements:
|
38
|
-
- -
|
43
|
+
- - ~>
|
39
44
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
45
|
+
version: '1.5'
|
41
46
|
- !ruby/object:Gem::Dependency
|
42
47
|
name: rspec
|
43
48
|
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
44
50
|
requirements:
|
45
|
-
- -
|
51
|
+
- - ! '>='
|
46
52
|
- !ruby/object:Gem::Version
|
47
53
|
version: '0'
|
48
54
|
type: :development
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
51
58
|
requirements:
|
52
|
-
- -
|
59
|
+
- - ! '>='
|
53
60
|
- !ruby/object:Gem::Version
|
54
61
|
version: '0'
|
55
62
|
description: ''
|
@@ -59,14 +66,16 @@ executables: []
|
|
59
66
|
extensions: []
|
60
67
|
extra_rdoc_files: []
|
61
68
|
files:
|
62
|
-
-
|
63
|
-
-
|
64
|
-
-
|
69
|
+
- .gitignore
|
70
|
+
- .rspec
|
71
|
+
- .ruby-version
|
72
|
+
- .travis.yml
|
65
73
|
- Gemfile
|
66
74
|
- LICENSE.txt
|
67
75
|
- README.md
|
68
76
|
- Rakefile
|
69
77
|
- lib/tomahawk.rb
|
78
|
+
- lib/tomahawk/config.rb
|
70
79
|
- lib/tomahawk/config_parser.rb
|
71
80
|
- lib/tomahawk/directive_groups.rb
|
72
81
|
- lib/tomahawk/directive_groups/base.rb
|
@@ -80,38 +89,45 @@ files:
|
|
80
89
|
- lib/tomahawk/generators/virtual_host.rb
|
81
90
|
- lib/tomahawk/version.rb
|
82
91
|
- spec/lib/tomahawk/config_parser_spec.rb
|
92
|
+
- spec/lib/tomahawk/config_spec.rb
|
93
|
+
- spec/lib/tomahawk/directive_groups/base_spec.rb
|
83
94
|
- spec/lib/tomahawk/directive_groups/virtual_host_spec.rb
|
84
95
|
- spec/lib/tomahawk/directive_groups_spec.rb
|
96
|
+
- spec/lib/tomahawk/generators/httpd_spec.rb
|
85
97
|
- spec/lib/tomahawk_spec.rb
|
86
98
|
- spec/spec_helper.rb
|
87
99
|
- tomahawk.gemspec
|
88
100
|
homepage: https://github.com/Sophisticates/tomahawk
|
89
101
|
licenses:
|
90
102
|
- MIT
|
91
|
-
metadata: {}
|
92
103
|
post_install_message:
|
93
104
|
rdoc_options: []
|
94
105
|
require_paths:
|
95
106
|
- lib
|
96
107
|
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
97
109
|
requirements:
|
98
|
-
- -
|
110
|
+
- - ! '>='
|
99
111
|
- !ruby/object:Gem::Version
|
100
112
|
version: '0'
|
101
113
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
102
115
|
requirements:
|
103
|
-
- -
|
116
|
+
- - ! '>='
|
104
117
|
- !ruby/object:Gem::Version
|
105
118
|
version: '0'
|
106
119
|
requirements: []
|
107
120
|
rubyforge_project:
|
108
|
-
rubygems_version:
|
121
|
+
rubygems_version: 1.8.23
|
109
122
|
signing_key:
|
110
|
-
specification_version:
|
123
|
+
specification_version: 3
|
111
124
|
summary: Tomahawk parses and generates Apache 2 configuration files.
|
112
125
|
test_files:
|
113
126
|
- spec/lib/tomahawk/config_parser_spec.rb
|
127
|
+
- spec/lib/tomahawk/config_spec.rb
|
128
|
+
- spec/lib/tomahawk/directive_groups/base_spec.rb
|
114
129
|
- spec/lib/tomahawk/directive_groups/virtual_host_spec.rb
|
115
130
|
- spec/lib/tomahawk/directive_groups_spec.rb
|
131
|
+
- spec/lib/tomahawk/generators/httpd_spec.rb
|
116
132
|
- spec/lib/tomahawk_spec.rb
|
117
133
|
- spec/spec_helper.rb
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: bdedd4162b4541f5585a387a2c57f58c3df00e99
|
4
|
-
data.tar.gz: 14466f1fa3b839d42cadebcbfe4eaeb0cd9d76c2
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: c92bf8f091b9f09c4f8ff3f16f881a2ca7c647fdc2185646a082f556ba8e22bf2763547abef2b41d81434006b3f39fd0a8650bf032c9e9f80147870020fd83be
|
7
|
-
data.tar.gz: 69ce697949fe15130a26fc760a8c590fb38b6b971df899841b9f86ecf72a6f9ade930caa00b12385a8a46472147d088e23f202274109663d94f9686989814a1a
|