web-facter 0.0.3 → 0.1.0
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 +8 -2
- data/Rakefile +9 -0
- data/bin/web-facter +2 -28
- data/lib/web-facter.rb +32 -1
- data/lib/web-facter/version.rb +1 -1
- data/test/integration_test.rb +46 -0
- data/test/test_helper.rb +9 -0
- data/web-facter.gemspec +5 -0
- metadata +55 -7
data/Gemfile
CHANGED
data/Rakefile
CHANGED
data/bin/web-facter
CHANGED
@@ -3,9 +3,8 @@
|
|
3
3
|
require 'rack'
|
4
4
|
require 'optparse'
|
5
5
|
require 'web-facter'
|
6
|
-
require 'parseconfig'
|
7
6
|
|
8
|
-
options = {}
|
7
|
+
options = {:daemonize => true, :port => 9294, :config => false}
|
9
8
|
|
10
9
|
optparse = OptionParser.new do |opts|
|
11
10
|
opts.banner = 'Usage: web-facter [options] ...'
|
@@ -13,17 +12,14 @@ optparse = OptionParser.new do |opts|
|
|
13
12
|
opts.separator ''
|
14
13
|
opts.separator 'Configuration options:'
|
15
14
|
|
16
|
-
options[:daemonize] = true
|
17
15
|
opts.on( '--no-daemonize', "Don't daemonize the web server process") do |_|
|
18
16
|
options[:daemonize] = false
|
19
17
|
end
|
20
18
|
|
21
|
-
options[:port] = 9294
|
22
19
|
opts.on( '-p', '--port PORT', 'The port to run web-facter on') do |port|
|
23
20
|
options[:port] = port
|
24
21
|
end
|
25
22
|
|
26
|
-
options[:config] = false
|
27
23
|
opts.on( '-c', '--config FILE', 'The file to load with configuration options') do |file|
|
28
24
|
options[:config] = file
|
29
25
|
end
|
@@ -36,29 +32,7 @@ end
|
|
36
32
|
|
37
33
|
begin
|
38
34
|
optparse.parse!
|
39
|
-
|
40
|
-
application = WebFacter::App.new
|
41
|
-
|
42
|
-
daemonize = options[:daemonize]
|
43
|
-
port = options[:port]
|
44
|
-
|
45
|
-
if options[:config]
|
46
|
-
conf = ParseConfig.new(options[:config])
|
47
|
-
|
48
|
-
if conf.get_value('password')
|
49
|
-
application = Rack::Auth::Basic.new(application) do |username, password|
|
50
|
-
username_check = conf.get_value('username') ? conf.get_value('username') == username : true
|
51
|
-
password_check = conf.get_value('password') == password
|
52
|
-
username_check && password_check
|
53
|
-
end
|
54
|
-
application.realm = 'Web Facter'
|
55
|
-
end
|
56
|
-
|
57
|
-
port = conf.get_value('port') ? conf.get_value('port') : port
|
58
|
-
daemonize = conf.get_value('daemonize') ? conf.get_value('daemonize') == "true" : daemonize
|
59
|
-
end
|
60
|
-
|
61
|
-
Rack::Server.new(:app => application, :Port => port, :daemonize => daemonize).start
|
35
|
+
WebFacter::App.run!(options)
|
62
36
|
rescue OptionParser::InvalidArgument, OptionParser::InvalidOption, OptionParser::MissingArgument
|
63
37
|
puts $!.to_s
|
64
38
|
puts optparse
|
data/lib/web-facter.rb
CHANGED
@@ -2,14 +2,45 @@ require "web-facter/version"
|
|
2
2
|
require 'rack'
|
3
3
|
require 'facter'
|
4
4
|
require 'json'
|
5
|
+
require 'parseconfig'
|
5
6
|
|
6
7
|
module WebFacter
|
7
8
|
class App
|
8
|
-
def call
|
9
|
+
def call(env)
|
9
10
|
response = Rack::Response.new
|
10
11
|
response.header['Content-Type'] = 'application/json'
|
11
12
|
response.write JSON.pretty_generate(Facter.to_hash)
|
12
13
|
response.finish
|
13
14
|
end
|
15
|
+
|
16
|
+
def add_auth(conf)
|
17
|
+
application = Rack::Auth::Basic.new(self) do |username, password|
|
18
|
+
stored_username = conf.get_value('username')
|
19
|
+
username_check = stored_username ? stored_username == username : true
|
20
|
+
password_check = conf.get_value('password') == password
|
21
|
+
username_check && password_check
|
22
|
+
end
|
23
|
+
application.realm = 'Web Facter'
|
24
|
+
application
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.run!(options)
|
28
|
+
application = self.new
|
29
|
+
|
30
|
+
daemonize = options[:daemonize]
|
31
|
+
port = options[:port]
|
32
|
+
|
33
|
+
if options[:config]
|
34
|
+
conf = ParseConfig.new(options[:config])
|
35
|
+
application = application.add_auth(conf) if conf.get_value('password')
|
36
|
+
daemonize = conf.get_value('daemonize') ? conf.get_value('daemonize') == "true" : daemonize
|
37
|
+
port = conf.get_value('port') ? conf.get_value('port') : port
|
38
|
+
end
|
39
|
+
|
40
|
+
Rack::Server.new(:app => application, :Port => port, :daemonize => daemonize).start
|
41
|
+
r
|
42
|
+
end
|
14
43
|
end
|
15
44
|
end
|
45
|
+
|
46
|
+
|
data/lib/web-facter/version.rb
CHANGED
@@ -0,0 +1,46 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "web-facter"
|
3
|
+
|
4
|
+
class SearchTest < Test::Unit::TestCase
|
5
|
+
include Rack::Test::Methods
|
6
|
+
|
7
|
+
def app
|
8
|
+
WebFacter::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
|
+
assert json.keys.include?("architecture")
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
class AuthenticationTest < Test::Unit::TestCase
|
25
|
+
include Rack::Test::Methods
|
26
|
+
|
27
|
+
def app
|
28
|
+
conf = mock()
|
29
|
+
conf.expects(:get_value).with('username').returns("admin")
|
30
|
+
conf.expects(:get_value).with('password').returns("password")
|
31
|
+
WebFacter::App.new().add_auth(conf)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_view_requires_authentication
|
35
|
+
authorize 'evil', 'password'
|
36
|
+
get "/"
|
37
|
+
assert_equal 401, last_response.status
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_view_renders_with_auth_details
|
41
|
+
authorize 'admin', 'password'
|
42
|
+
get "/"
|
43
|
+
assert last_response.ok?
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
data/test/test_helper.rb
ADDED
data/web-facter.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 "facter"
|
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-facter
|
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: &70273794104500 !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: *70273794104500
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: facter
|
27
|
-
requirement: &
|
27
|
+
requirement: &70273794104080 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,51 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70273794104080
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: parseconfig
|
38
|
+
requirement: &70273794103660 !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: *70273794103660
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: test-unit
|
49
|
+
requirement: &70273794103240 !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: *70273794103240
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: rack-test
|
60
|
+
requirement: &70273794102820 !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: *70273794102820
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: mocha
|
71
|
+
requirement: &70273794102400 !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: *70273794102400
|
36
80
|
description: Daemon which serves information from the facter gem as JSON over HTTP
|
37
81
|
email:
|
38
82
|
- gareth@morethanseven.net
|
@@ -49,6 +93,8 @@ files:
|
|
49
93
|
- bin/web-facter
|
50
94
|
- lib/web-facter.rb
|
51
95
|
- lib/web-facter/version.rb
|
96
|
+
- test/integration_test.rb
|
97
|
+
- test/test_helper.rb
|
52
98
|
- web-facter.gemspec
|
53
99
|
homepage: https://github.com/garethr/web-facter
|
54
100
|
licenses: []
|
@@ -74,4 +120,6 @@ rubygems_version: 1.8.6
|
|
74
120
|
signing_key:
|
75
121
|
specification_version: 3
|
76
122
|
summary: Display Facter information as JSON over HTTP
|
77
|
-
test_files:
|
123
|
+
test_files:
|
124
|
+
- test/integration_test.rb
|
125
|
+
- test/test_helper.rb
|