torquebox-webconsole 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +5 -0
- data/LICENSE +22 -0
- data/README.md +42 -0
- data/Rakefile +2 -0
- data/lib/torquebox/webconsole/rack-webconsole-patch.rb +65 -0
- data/lib/torquebox/webconsole/version.rb +5 -0
- data/lib/torquebox/webconsole.rb +43 -0
- data/torquebox-webconsole.gemspec +19 -0
- metadata +75 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Tobias Crawley
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# Torquebox::Webconsole
|
2
|
+
|
3
|
+
An extension to [rack-webconsole](http://codegram.github.com/rack-webconsole/) that
|
4
|
+
adds the ability to switch between application runtimes within
|
5
|
+
[TorqueBox](http://torquebox.org/).
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'torquebox-webconsole'
|
12
|
+
|
13
|
+
Then follow the [instructions](http://codegram.github.com/rack-webconsole/) for
|
14
|
+
rack-webconsole, replacing any instances of `require 'rack/webconsole'` with
|
15
|
+
`require 'torquebox/webconsole'`.
|
16
|
+
|
17
|
+
*Note:* don't add `rack-webconsole` to your Gemfile - `torquebox-webconsole`
|
18
|
+
will bring it in for you, and currently uses a fork of `rack-webconsole` pending
|
19
|
+
a [pull request](https://github.com/codegram/rack-webconsole/pull/44) and release
|
20
|
+
of the official gem.
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
Use it just like you would `rack-console`. When in the console, the following
|
25
|
+
TorqueBox specific methods are available to you:
|
26
|
+
|
27
|
+
* `list_runtimes` - returns an array of the available runtime names
|
28
|
+
* `current_runtime` - returns the name of the runtime that the console is
|
29
|
+
currently attached to
|
30
|
+
* `switch_runtime(name)` - attaches the console to the named runtime
|
31
|
+
* `help` - tells you about the above methods
|
32
|
+
|
33
|
+
The console will be attached to the web runtime by default, and you will
|
34
|
+
only be able to list/attach to runtimes for the current application.
|
35
|
+
|
36
|
+
## Contributing
|
37
|
+
|
38
|
+
1. Fork it
|
39
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
40
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
41
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
42
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'rack/webconsole'
|
2
|
+
|
3
|
+
module Rack
|
4
|
+
class Webconsole
|
5
|
+
class Sandbox
|
6
|
+
|
7
|
+
def switch_runtime(name)
|
8
|
+
runtime = TorqueBox::Webconsole.lookup_runtime(name)
|
9
|
+
if runtime.nil?
|
10
|
+
"runtime #{name} not found"
|
11
|
+
else
|
12
|
+
web_runtime = TorqueBox::Webconsole.web_runtime[0]
|
13
|
+
web_runtime.evaluate <<-EOS
|
14
|
+
runtime = TorqueBox::Webconsole.lookup_runtime(%q(#{name}))
|
15
|
+
$runtime = runtime
|
16
|
+
EOS
|
17
|
+
"switched to #{name} runtime"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def list_runtimes
|
22
|
+
TorqueBox::Webconsole.list_runtimes
|
23
|
+
end
|
24
|
+
|
25
|
+
def current_runtime
|
26
|
+
web_runtime = TorqueBox::Webconsole.web_runtime[0]
|
27
|
+
web_runtime.evaluate "$runtime[1]"
|
28
|
+
end
|
29
|
+
|
30
|
+
def help
|
31
|
+
"Welcome to the TorqueBox webconsole. It's rack-webconsole with the following " +
|
32
|
+
"additions: * list_runtimes - returns list of all of the TorqueBox runtimes " +
|
33
|
+
"for the current application. * switch_runtime(name) - switch " +
|
34
|
+
"your execution context to a different runtime. * current_runtime - returns " +
|
35
|
+
"the name of the current runtime."
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class Repl
|
40
|
+
|
41
|
+
def call(env)
|
42
|
+
status, headers, response = @app.call(env)
|
43
|
+
|
44
|
+
req = Rack::Request.new(env)
|
45
|
+
params = req.params
|
46
|
+
|
47
|
+
return [status, headers, response] unless check_legitimate(req)
|
48
|
+
$runtime ||= TorqueBox::Webconsole.web_runtime
|
49
|
+
query = params['query']
|
50
|
+
response_body = $runtime[0].evaluate("Rack::Webconsole::Repl.eval_query(%q(#{query}))")
|
51
|
+
headers = {}
|
52
|
+
headers['Content-Type'] = 'application/json'
|
53
|
+
headers['Content-Length'] = response_body.bytesize.to_s
|
54
|
+
[200, headers, [response_body]]
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.eval_query(query)
|
58
|
+
$sandbox ||= Sandbox.new
|
59
|
+
hash = Shell.eval_query(query)
|
60
|
+
MultiJson.encode(hash)
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "torquebox/webconsole/version"
|
2
|
+
require 'torquebox/webconsole/rack-webconsole-patch'
|
3
|
+
require 'java'
|
4
|
+
require 'torquebox'
|
5
|
+
|
6
|
+
module TorqueBox
|
7
|
+
class Webconsole
|
8
|
+
extend TorqueBox::Injectors
|
9
|
+
class << self
|
10
|
+
|
11
|
+
def lookup_runtime(name)
|
12
|
+
service_registry = inject('service-registry')
|
13
|
+
unit = inject('deployment-unit')
|
14
|
+
|
15
|
+
service_name = org.torquebox.core.as.CoreServices.runtimePoolName(unit, name)
|
16
|
+
service_controller = service_registry.get_service(service_name)
|
17
|
+
|
18
|
+
return nil unless service_controller
|
19
|
+
pool = service_controller.service.value
|
20
|
+
pool.evaluate "require 'torquebox/webconsole'"
|
21
|
+
|
22
|
+
[pool, name]
|
23
|
+
end
|
24
|
+
|
25
|
+
def web_runtime
|
26
|
+
lookup_runtime('web')
|
27
|
+
end
|
28
|
+
|
29
|
+
def list_runtimes
|
30
|
+
prefix = inject('deployment-unit').
|
31
|
+
service_name.
|
32
|
+
append(org.torquebox.core.as.CoreServices::RUNTIME).
|
33
|
+
append("pool").
|
34
|
+
canonical_name
|
35
|
+
|
36
|
+
inject('service-registry').service_names.to_a.map do |x|
|
37
|
+
$1 if x.canonical_name =~ %r{#{prefix}\.([^.]+)$}
|
38
|
+
end.reject(&:nil?)
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/torquebox/webconsole/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Ben Browning", "Tobias Crawley"]
|
6
|
+
gem.email = ["bbrowning@redhat.com", "tcrawley@redhat.com"]
|
7
|
+
gem.description = %q{Extends rack-webconsole to allow switching between TorqueBox app runtimes.}
|
8
|
+
gem.summary = gem.description
|
9
|
+
gem.homepage = "https://github.com/torquebox/torquebox-webconsole"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "torquebox-webconsole"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Torquebox::Webconsole::VERSION
|
17
|
+
|
18
|
+
gem.add_runtime_dependency 'tobias-rack-webconsole', '0.1.4'
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: torquebox-webconsole
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ben Browning
|
9
|
+
- Tobias Crawley
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
|
14
|
+
date: 2012-04-19 00:00:00 Z
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: tobias-rack-webconsole
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - "="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.1.4
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
27
|
+
description: Extends rack-webconsole to allow switching between TorqueBox app runtimes.
|
28
|
+
email:
|
29
|
+
- bbrowning@redhat.com
|
30
|
+
- tcrawley@redhat.com
|
31
|
+
executables: []
|
32
|
+
|
33
|
+
extensions: []
|
34
|
+
|
35
|
+
extra_rdoc_files: []
|
36
|
+
|
37
|
+
files:
|
38
|
+
- .gitignore
|
39
|
+
- Gemfile
|
40
|
+
- LICENSE
|
41
|
+
- README.md
|
42
|
+
- Rakefile
|
43
|
+
- lib/torquebox/webconsole.rb
|
44
|
+
- lib/torquebox/webconsole/rack-webconsole-patch.rb
|
45
|
+
- lib/torquebox/webconsole/version.rb
|
46
|
+
- torquebox-webconsole.gemspec
|
47
|
+
homepage: https://github.com/torquebox/torquebox-webconsole
|
48
|
+
licenses: []
|
49
|
+
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: "0"
|
67
|
+
requirements: []
|
68
|
+
|
69
|
+
rubyforge_project:
|
70
|
+
rubygems_version: 1.8.15
|
71
|
+
signing_key:
|
72
|
+
specification_version: 3
|
73
|
+
summary: Extends rack-webconsole to allow switching between TorqueBox app runtimes.
|
74
|
+
test_files: []
|
75
|
+
|