web-puppet 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +8 -0
- data/Gemfile.lock +13 -0
- data/README +26 -0
- data/Rakefile +9 -0
- data/bin/web-puppet +38 -1
- data/lib/web-puppet/version.rb +1 -1
- data/lib/web-puppet.rb +28 -0
- data/test/integration_test.rb +45 -0
- data/test/test_helper.rb +9 -0
- data/web-puppet.gemspec +5 -0
- metadata +55 -7
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -2,13 +2,26 @@ GEM
|
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
4
|
facter (1.6.2)
|
5
|
+
metaclass (0.0.1)
|
6
|
+
mocha (0.10.0)
|
7
|
+
metaclass (~> 0.0.1)
|
8
|
+
parseconfig (0.5.2)
|
5
9
|
puppet (2.7.6)
|
6
10
|
facter (>= 1.5.1)
|
7
11
|
rack (1.3.5)
|
12
|
+
rack-test (0.6.1)
|
13
|
+
rack (>= 1.0)
|
14
|
+
rake (0.9.2.2)
|
15
|
+
test-unit (2.4.0)
|
8
16
|
|
9
17
|
PLATFORMS
|
10
18
|
ruby
|
11
19
|
|
12
20
|
DEPENDENCIES
|
21
|
+
mocha
|
22
|
+
parseconfig
|
13
23
|
puppet (>= 2.7.0)
|
14
24
|
rack
|
25
|
+
rack-test
|
26
|
+
rake
|
27
|
+
test-unit
|
data/README
CHANGED
@@ -1,3 +1,29 @@
|
|
1
1
|
A tiny ruby rack application which exposes the data from puppet as JSON over HTTP.
|
2
2
|
|
3
3
|
gem install web-puppet
|
4
|
+
|
5
|
+
Provides a simple command line tool which runs a built in web server. On accessing
|
6
|
+
the specified port you should get a JSON response containing the current node information.
|
7
|
+
|
8
|
+
web-puppet --help
|
9
|
+
Usage: web-puppet [options] ...
|
10
|
+
|
11
|
+
Configuration options:
|
12
|
+
--no-daemonize Don't daemonize the web server process
|
13
|
+
-p, --port PORT The port to run web-facter on
|
14
|
+
-c, --config FILE The file to load with configuration options
|
15
|
+
-h, --help Display this screenp
|
16
|
+
|
17
|
+
Note that in most setups the yaml directory containing the node information isn't readable
|
18
|
+
by all users, so you may need to run this as puppet or root.
|
19
|
+
|
20
|
+
You can configure web-puppet using a configuration file, using the following format, and
|
21
|
+
specifying the filename with the --config option above.
|
22
|
+
|
23
|
+
username=gilbert
|
24
|
+
password=george
|
25
|
+
port=3009
|
26
|
+
daemonize=true
|
27
|
+
|
28
|
+
Note that the port and daemonize options will override those on the command line.
|
29
|
+
The username and password options enable HTTP basic authentication using those details.
|
data/Rakefile
CHANGED
data/bin/web-puppet
CHANGED
@@ -1,6 +1,43 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'rack'
|
4
|
+
require 'optparse'
|
4
5
|
require 'web-puppet'
|
5
6
|
|
6
|
-
|
7
|
+
options = {:daemonize => true, :port => 9295, :config => false}
|
8
|
+
|
9
|
+
optparse = OptionParser.new do |opts|
|
10
|
+
opts.banner = 'Usage: web-puppet [options] ...'
|
11
|
+
|
12
|
+
opts.separator ''
|
13
|
+
opts.separator 'Configuration options:'
|
14
|
+
|
15
|
+
opts.on( '--no-daemonize', "Don't daemonize the web server process") do |username|
|
16
|
+
options[:daemonize] = false
|
17
|
+
end
|
18
|
+
|
19
|
+
opts.on( '-p', '--port PORT', 'The port to run web-puppet on') do |port|
|
20
|
+
options[:port] = port
|
21
|
+
end
|
22
|
+
|
23
|
+
opts.on( '-c', '--config FILE', 'The file to load with configuration options') do |file|
|
24
|
+
options[:config] = file
|
25
|
+
end
|
26
|
+
|
27
|
+
opts.on_tail('-h', '--help', 'Display this screen' ) do
|
28
|
+
puts opts
|
29
|
+
exit
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
begin
|
34
|
+
optparse.parse!
|
35
|
+
WebPuppet::App.run!(options)
|
36
|
+
rescue OptionParser::InvalidArgument, OptionParser::InvalidOption, OptionParser::MissingArgument
|
37
|
+
puts $!.to_s
|
38
|
+
puts optparse
|
39
|
+
exit
|
40
|
+
rescue Errno::EACCES
|
41
|
+
puts $!.to_s
|
42
|
+
exit
|
43
|
+
end
|
data/lib/web-puppet/version.rb
CHANGED
data/lib/web-puppet.rb
CHANGED
@@ -31,5 +31,33 @@ module WebPuppet
|
|
31
31
|
response.write JSON.pretty_generate(data)
|
32
32
|
response.finish
|
33
33
|
end
|
34
|
+
|
35
|
+
def add_auth(conf)
|
36
|
+
application = Rack::Auth::Basic.new(self) do |username, password|
|
37
|
+
stored_username = conf.get_value('username')
|
38
|
+
username_check = stored_username ? stored_username == username : true
|
39
|
+
password_check = conf.get_value('password') == password
|
40
|
+
username_check && password_check
|
41
|
+
end
|
42
|
+
application.realm = 'Web Puppet'
|
43
|
+
application
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.run!(options)
|
47
|
+
application = self.new
|
48
|
+
|
49
|
+
daemonize = options[:daemonize]
|
50
|
+
port = options[:port]
|
51
|
+
|
52
|
+
if options[:config]
|
53
|
+
conf = ParseConfig.new(options[:config])
|
54
|
+
application = application.add_auth(conf) if conf.get_value('password')
|
55
|
+
daemonize = conf.get_value('daemonize') ? conf.get_value('daemonize') == "true" : daemonize
|
56
|
+
port = conf.get_value('port') ? conf.get_value('port') : port
|
57
|
+
end
|
58
|
+
|
59
|
+
Rack::Server.new(:app => application, :Port => port, :daemonize => daemonize).start
|
60
|
+
|
61
|
+
end
|
34
62
|
end
|
35
63
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "web-puppet"
|
3
|
+
|
4
|
+
class AppTest < Test::Unit::TestCase
|
5
|
+
include Rack::Test::Methods
|
6
|
+
|
7
|
+
def app
|
8
|
+
WebPuppet::App.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_view_renders_successfully
|
12
|
+
get "/"
|
13
|
+
assert last_response.ok?
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_view_returns_json
|
17
|
+
get "/"
|
18
|
+
json = JSON.load(last_response.body)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
class AuthenticationTest < Test::Unit::TestCase
|
24
|
+
include Rack::Test::Methods
|
25
|
+
|
26
|
+
def app
|
27
|
+
conf = mock()
|
28
|
+
conf.expects(:get_value).with('username').returns("admin")
|
29
|
+
conf.expects(:get_value).with('password').returns("password")
|
30
|
+
WebPuppet::App.new().add_auth(conf)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_view_requires_authentication
|
34
|
+
authorize 'evil', 'password'
|
35
|
+
get "/"
|
36
|
+
assert_equal 401, last_response.status
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_view_renders_with_auth_details
|
40
|
+
authorize 'admin', 'password'
|
41
|
+
get "/"
|
42
|
+
assert last_response.ok?
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
data/test/test_helper.rb
ADDED
data/web-puppet.gemspec
CHANGED
@@ -20,4 +20,9 @@ Gem::Specification.new do |s|
|
|
20
20
|
|
21
21
|
s.add_runtime_dependency "rack"
|
22
22
|
s.add_runtime_dependency "puppet", ">= 2.7.0"
|
23
|
+
s.add_runtime_dependency "parseconfig"
|
24
|
+
|
25
|
+
s.add_development_dependency "test-unit"
|
26
|
+
s.add_development_dependency "rack-test"
|
27
|
+
s.add_development_dependency "mocha"
|
23
28
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: web-puppet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-11-02 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
16
|
-
requirement: &
|
16
|
+
requirement: &70356553014700 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70356553014700
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: puppet
|
27
|
-
requirement: &
|
27
|
+
requirement: &70356553014200 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,51 @@ dependencies:
|
|
32
32
|
version: 2.7.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70356553014200
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: parseconfig
|
38
|
+
requirement: &70356553013780 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70356553013780
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: test-unit
|
49
|
+
requirement: &70356553013320 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70356553013320
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: rack-test
|
60
|
+
requirement: &70356553012900 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70356553012900
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: mocha
|
71
|
+
requirement: &70356553012480 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70356553012480
|
36
80
|
description: Daemon which serves information from a local puppet master as JSON over
|
37
81
|
HTTP
|
38
82
|
email:
|
@@ -50,6 +94,8 @@ files:
|
|
50
94
|
- bin/web-puppet
|
51
95
|
- lib/web-puppet.rb
|
52
96
|
- lib/web-puppet/version.rb
|
97
|
+
- test/integration_test.rb
|
98
|
+
- test/test_helper.rb
|
53
99
|
- web-puppet.gemspec
|
54
100
|
homepage: https://github.com/garethr/web-puppet
|
55
101
|
licenses: []
|
@@ -75,4 +121,6 @@ rubygems_version: 1.8.6
|
|
75
121
|
signing_key:
|
76
122
|
specification_version: 3
|
77
123
|
summary: Display Puppet node information as JSON over HTTP
|
78
|
-
test_files:
|
124
|
+
test_files:
|
125
|
+
- test/integration_test.rb
|
126
|
+
- test/test_helper.rb
|