web-facter 0.0.1 → 0.0.3

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
@@ -3,3 +3,4 @@ source "http://rubygems.org"
3
3
 
4
4
  gem "facter"
5
5
  gem "rack"
6
+ gem "parseconfig"
data/Gemfile.lock CHANGED
@@ -2,6 +2,7 @@ GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
4
  facter (1.6.2)
5
+ parseconfig (0.5.2)
5
6
  rack (1.3.5)
6
7
 
7
8
  PLATFORMS
@@ -9,4 +10,5 @@ PLATFORMS
9
10
 
10
11
  DEPENDENCIES
11
12
  facter
13
+ parseconfig
12
14
  rack
data/README CHANGED
@@ -2,4 +2,26 @@ A tiny ruby rack application which exposes the data from facter as JSON over HTT
2
2
 
3
3
  gem install web-facter
4
4
 
5
- Currently this is pretty raw. I plan on making it a little more configurable shortly at which point I'll write a proper README.
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 facts.
7
+
8
+ web-facter --help
9
+ Usage: web-facter [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
+
18
+ You can configure web-facter using a configuration file, using the following format, and
19
+ specifying the filename with the --config option above.
20
+
21
+ username=gilbert
22
+ password=george
23
+ port=3009
24
+ daemonize=true
25
+
26
+ Note that the port and daemonize options will override those on the command line.
27
+ The username and password options enable HTTP basic authentication using those details.
data/bin/web-facter CHANGED
@@ -1,6 +1,69 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'rack'
4
+ require 'optparse'
4
5
  require 'web-facter'
6
+ require 'parseconfig'
5
7
 
6
- Rack::Server.new(:app => WebFacter::App.new, :Port => 9294, :daemonize => true).start
8
+ options = {}
9
+
10
+ optparse = OptionParser.new do |opts|
11
+ opts.banner = 'Usage: web-facter [options] ...'
12
+
13
+ opts.separator ''
14
+ opts.separator 'Configuration options:'
15
+
16
+ options[:daemonize] = true
17
+ opts.on( '--no-daemonize', "Don't daemonize the web server process") do |_|
18
+ options[:daemonize] = false
19
+ end
20
+
21
+ options[:port] = 9294
22
+ opts.on( '-p', '--port PORT', 'The port to run web-facter on') do |port|
23
+ options[:port] = port
24
+ end
25
+
26
+ options[:config] = false
27
+ opts.on( '-c', '--config FILE', 'The file to load with configuration options') do |file|
28
+ options[:config] = file
29
+ end
30
+
31
+ opts.on_tail('-h', '--help', 'Display this screen') do
32
+ puts opts
33
+ exit
34
+ end
35
+ end
36
+
37
+ begin
38
+ 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
62
+ rescue OptionParser::InvalidArgument, OptionParser::InvalidOption, OptionParser::MissingArgument
63
+ puts $!.to_s
64
+ puts optparse
65
+ exit
66
+ rescue Errno::EACCES
67
+ puts $!.to_s
68
+ exit
69
+ end
@@ -1,3 +1,3 @@
1
1
  module WebFacter
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.3"
3
3
  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.1
4
+ version: 0.0.3
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-10-30 00:00:00.000000000Z
12
+ date: 2011-10-31 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
16
- requirement: &70344602869480 !ruby/object:Gem::Requirement
16
+ requirement: &70139598663080 !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: *70344602869480
24
+ version_requirements: *70139598663080
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: facter
27
- requirement: &70344602869060 !ruby/object:Gem::Requirement
27
+ requirement: &70139598662660 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70344602869060
35
+ version_requirements: *70139598662660
36
36
  description: Daemon which serves information from the facter gem as JSON over HTTP
37
37
  email:
38
38
  - gareth@morethanseven.net