jnewland-god_web 0.0.2

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.
Files changed (4) hide show
  1. data/Readme.txt +55 -0
  2. data/bin/god_web +36 -0
  3. data/lib/sinatra_http_auth.rb +53 -0
  4. metadata +72 -0
data/Readme.txt ADDED
@@ -0,0 +1,55 @@
1
+ = god_web
2
+
3
+ * http://github.com/jnewland/god_web
4
+
5
+ == DESCRIPTION:
6
+
7
+ Sinatra web frontend for God
8
+
9
+ == REQUIREMENTS:
10
+
11
+ * God
12
+ * Sinatra
13
+
14
+ == INSTALL:
15
+
16
+ * sudo gem install jnewland-god_web -s http://gems.github.com
17
+
18
+ == USAGE:
19
+
20
+ * sudo god_web -p PORT_TO_RUN_ON -e production
21
+
22
+ Optionally, you can password protect your god_web instance. To do so, create
23
+ a YAML config file with username and password keys, like so:
24
+
25
+ username: foo
26
+ password: sekret
27
+
28
+ Then provide that yaml file as the first argument to god_web:
29
+
30
+ * sudo god_web /path/to/god_web.yml -p PORT_TO_RUN_ON -e production
31
+
32
+ == LICENSE:
33
+
34
+ (The MIT License)
35
+
36
+ Copyright (c) 2008 Jesse Newland
37
+
38
+ Permission is hereby granted, free of charge, to any person obtaining
39
+ a copy of this software and associated documentation files (the
40
+ 'Software'), to deal in the Software without restriction, including
41
+ without limitation the rights to use, copy, modify, merge, publish,
42
+ distribute, sublicense, and/or sell copies of the Software, and to
43
+ permit persons to whom the Software is furnished to do so, subject to
44
+ the following conditions:
45
+
46
+ The above copyright notice and this permission notice shall be
47
+ included in all copies or substantial portions of the Software.
48
+
49
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
50
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
51
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
52
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
53
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
54
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
55
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/bin/god_web ADDED
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'god'
5
+ require 'sinatra'
6
+ require 'stringio'
7
+ require 'yaml'
8
+ #included until http://sinatra.lighthouseapp.com/projects/9779/tickets/16-patch-http-authentication is in a released version
9
+ require File.dirname(__FILE__) + '/../lib/sinatra_http_auth'
10
+
11
+ config = {
12
+ 'god_port' => 17165,
13
+ 'username' => nil,
14
+ 'password' => nil
15
+ }
16
+ begin
17
+ config.merge!(YAML.load(File.read(ARGV[0])))
18
+ rescue
19
+ end
20
+
21
+ before do
22
+ unless config['username'].nil? && config['password'].nil?
23
+ authenticate_or_request_with_http_basic "GodWeb" do
24
+ |user, pass| user == config['username'] && pass == config['password']
25
+ end
26
+ end
27
+ end
28
+
29
+ get '/' do
30
+ io = StringIO.new
31
+ $stdout = io
32
+ response.header['Content-Type'] = 'text/plain'
33
+ God::CLI::Command.new('status', {:port => config['god_port']}, [])
34
+ $stdout = STDOUT
35
+ io.string
36
+ end
@@ -0,0 +1,53 @@
1
+ module HttpAuthentication
2
+ module Basic
3
+
4
+ def authenticate_or_request_with_http_basic(realm = "Application", &login_procedure)
5
+ authenticate_with_http_basic(&login_procedure) || request_http_basic_authentication(realm)
6
+ end
7
+
8
+ def authenticate_with_http_basic(&login_procedure)
9
+ authenticate(&login_procedure)
10
+ end
11
+
12
+ def request_http_basic_authentication(realm = "Application")
13
+ authentication_request(realm)
14
+ end
15
+
16
+ private
17
+
18
+ def authenticate(&login_procedure)
19
+ if authorization
20
+ login_procedure.call(*user_name_and_password)
21
+ end
22
+ end
23
+
24
+ def user_name_and_password
25
+ decode_credentials.split(/:/, 2)
26
+ end
27
+
28
+ def authorization
29
+ request.env['HTTP_AUTHORIZATION'] ||
30
+ request.env['X-HTTP_AUTHORIZATION'] ||
31
+ request.env['X_HTTP_AUTHORIZATION'] ||
32
+ request.env['REDIRECT_X_HTTP_AUTHORIZATION']
33
+ end
34
+
35
+ # Base64
36
+ def decode_credentials
37
+ (authorization.split.last || '').unpack("m").first
38
+ end
39
+
40
+ def authentication_request(realm)
41
+ status(401)
42
+ header("WWW-Authenticate" => %(Basic realm="#{realm.gsub(/"/, "")}"))
43
+ throw :halt, "HTTP Basic: Access denied.\n"
44
+ end
45
+
46
+ end
47
+ end
48
+
49
+ module Sinatra
50
+ class EventContext
51
+ include HttpAuthentication::Basic
52
+ end
53
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jnewland-god_web
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Jesse Newland
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-05-02 00:00:00 -07:00
13
+ default_executable: god_web
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: god
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.7.3
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: sinatra
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: 0.2.2
32
+ version:
33
+ description: Sinatra web frontend for God
34
+ email: jnewland@gmail.com
35
+ executables:
36
+ - god_web
37
+ extensions: []
38
+
39
+ extra_rdoc_files:
40
+ - Readme.txt
41
+ files:
42
+ - bin/god_web
43
+ - lib/sinatra_http_auth.rb
44
+ - Readme.txt
45
+ has_rdoc: false
46
+ homepage: http://github.com/jnewland/god_web
47
+ post_install_message:
48
+ rdoc_options: []
49
+
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ requirements: []
65
+
66
+ rubyforge_project: god_web
67
+ rubygems_version: 1.0.1
68
+ signing_key:
69
+ specification_version: 2
70
+ summary: Sinatra web frontend for God
71
+ test_files: []
72
+