trinidad_sandbox_extension 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README +18 -0
- data/Rakefile +157 -0
- data/lib/trinidad_sandbox_extension.rb +52 -0
- data/lib/trinidad_sandbox_extension/app/helpers/sandbox.rb +50 -0
- data/lib/trinidad_sandbox_extension/app/model/application_context.rb +49 -0
- data/lib/trinidad_sandbox_extension/app/public/css/main.css +133 -0
- data/lib/trinidad_sandbox_extension/app/sandbox.rb +82 -0
- data/lib/trinidad_sandbox_extension/app/views/actions.html.haml +7 -0
- data/lib/trinidad_sandbox_extension/app/views/app.html.haml +8 -0
- data/lib/trinidad_sandbox_extension/app/views/app.xml.haml +9 -0
- data/lib/trinidad_sandbox_extension/app/views/index.html.haml +6 -0
- data/lib/trinidad_sandbox_extension/app/views/index.xml.haml +3 -0
- data/lib/trinidad_sandbox_extension/app/views/layout.html.haml +12 -0
- data/lib/trinidad_sandbox_extension/config.ru +29 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/trinidad_sandbox_extension_spec.rb +52 -0
- data/trinidad-libs/trinidad-sandbox-extension.jar +0 -0
- data/trinidad_sandbox_extension.gemspec +83 -0
- metadata +153 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 David Calavera
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Trinidad sandbox extension
|
2
|
+
======
|
3
|
+
|
4
|
+
# DESCRIPTION
|
5
|
+
|
6
|
+
Extension to allow manage the applications deployed on Trinidad, ala Tomcat manager.
|
7
|
+
|
8
|
+
This extension is in an early development stage and right now just shows you a
|
9
|
+
list of the applications loaded on Trinidad.
|
10
|
+
|
11
|
+
# TODO
|
12
|
+
|
13
|
+
sorted by priorities
|
14
|
+
|
15
|
+
* Buttons to start/stop applications
|
16
|
+
* UI
|
17
|
+
* REST api
|
18
|
+
* Capistrano recipes to do hot deploys
|
data/Rakefile
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'date'
|
4
|
+
|
5
|
+
#############################################################################
|
6
|
+
#
|
7
|
+
# Helper functions
|
8
|
+
#
|
9
|
+
#############################################################################
|
10
|
+
|
11
|
+
def name
|
12
|
+
@name ||= Dir['*.gemspec'].first.split('.').first
|
13
|
+
end
|
14
|
+
|
15
|
+
def version
|
16
|
+
line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
|
17
|
+
line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
|
18
|
+
end
|
19
|
+
|
20
|
+
def date
|
21
|
+
Date.today.to_s
|
22
|
+
end
|
23
|
+
|
24
|
+
def rubyforge_project
|
25
|
+
name
|
26
|
+
end
|
27
|
+
|
28
|
+
def gemspec_file
|
29
|
+
"#{name}.gemspec"
|
30
|
+
end
|
31
|
+
|
32
|
+
def gem_file
|
33
|
+
"#{name}-#{version}.gem"
|
34
|
+
end
|
35
|
+
|
36
|
+
def replace_header(head, header_name)
|
37
|
+
head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
|
38
|
+
end
|
39
|
+
|
40
|
+
#############################################################################
|
41
|
+
#
|
42
|
+
# Standard tasks
|
43
|
+
#
|
44
|
+
#############################################################################
|
45
|
+
|
46
|
+
task :default => :test
|
47
|
+
|
48
|
+
require 'rake/testtask'
|
49
|
+
Rake::TestTask.new(:test) do |test|
|
50
|
+
test.libs << 'lib' << 'test'
|
51
|
+
test.pattern = 'test/**/test_*.rb'
|
52
|
+
test.verbose = true
|
53
|
+
end
|
54
|
+
|
55
|
+
desc "Generate RCov test coverage and open in your browser"
|
56
|
+
task :coverage do
|
57
|
+
require 'rcov'
|
58
|
+
sh "rm -fr coverage"
|
59
|
+
sh "rcov test/test_*.rb"
|
60
|
+
sh "open coverage/index.html"
|
61
|
+
end
|
62
|
+
|
63
|
+
require 'rake/rdoctask'
|
64
|
+
Rake::RDocTask.new do |rdoc|
|
65
|
+
rdoc.rdoc_dir = 'rdoc'
|
66
|
+
rdoc.title = "#{name} #{version}"
|
67
|
+
rdoc.rdoc_files.include('README*')
|
68
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
69
|
+
end
|
70
|
+
|
71
|
+
desc "Open an irb session preloaded with this library"
|
72
|
+
task :console do
|
73
|
+
sh "irb -rubygems -r ./lib/#{name}.rb"
|
74
|
+
end
|
75
|
+
|
76
|
+
#############################################################################
|
77
|
+
#
|
78
|
+
# Custom tasks (add your own tasks here)
|
79
|
+
#
|
80
|
+
#############################################################################
|
81
|
+
|
82
|
+
task :default => :spec
|
83
|
+
|
84
|
+
require 'spec/rake/spectask'
|
85
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
86
|
+
spec.libs << 'lib' << 'spec'
|
87
|
+
spec.spec_opts = ['--options', 'spec/spec.opts']
|
88
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
#############################################################################
|
94
|
+
#
|
95
|
+
# Packaging tasks
|
96
|
+
#
|
97
|
+
#############################################################################
|
98
|
+
|
99
|
+
task :release => :build do
|
100
|
+
unless `git branch` =~ /^\* master$/
|
101
|
+
puts "You must be on the master branch to release!"
|
102
|
+
exit!
|
103
|
+
end
|
104
|
+
sh "git commit --allow-empty -a -m 'Release #{version}'"
|
105
|
+
sh "git tag v#{version}"
|
106
|
+
sh "git push origin master"
|
107
|
+
sh "git push v#{version}"
|
108
|
+
sh "gem push pkg/#{name}-#{version}.gem"
|
109
|
+
end
|
110
|
+
|
111
|
+
task :build => ['ant:build', 'gemspec'] do
|
112
|
+
sh "mkdir -p pkg"
|
113
|
+
sh "gem build #{gemspec_file}"
|
114
|
+
sh "mv #{gem_file} pkg"
|
115
|
+
end
|
116
|
+
|
117
|
+
task :gemspec => :validate do
|
118
|
+
# read spec file and split out manifest section
|
119
|
+
spec = File.read(gemspec_file)
|
120
|
+
head, manifest, tail = spec.split(" # = MANIFEST =\n")
|
121
|
+
|
122
|
+
# replace name version and date
|
123
|
+
replace_header(head, :name)
|
124
|
+
replace_header(head, :version)
|
125
|
+
replace_header(head, :date)
|
126
|
+
#comment this out if your rubyforge_project has a different name
|
127
|
+
replace_header(head, :rubyforge_project)
|
128
|
+
|
129
|
+
# determine file list from git ls-files
|
130
|
+
files = `git ls-files`.
|
131
|
+
split("\n").
|
132
|
+
sort.
|
133
|
+
reject { |file| file =~ /^\./ }.
|
134
|
+
reject { |file| file =~ /^(rdoc|pkg|src|trinidad-libs|rakelib)/ }.
|
135
|
+
map { |file| " #{file}" }.
|
136
|
+
join("\n")
|
137
|
+
|
138
|
+
files << "\n trinidad-libs/trinidad-sandbox-extension.jar"
|
139
|
+
|
140
|
+
# piece file back together and write
|
141
|
+
manifest = " s.files = %w[\n#{files}\n ]\n"
|
142
|
+
spec = [head, manifest, tail].join(" # = MANIFEST =\n")
|
143
|
+
File.open(gemspec_file, 'w') { |io| io.write(spec) }
|
144
|
+
puts "Updated #{gemspec_file}"
|
145
|
+
end
|
146
|
+
|
147
|
+
task :validate do
|
148
|
+
libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
|
149
|
+
unless libfiles.empty?
|
150
|
+
puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
|
151
|
+
exit!
|
152
|
+
end
|
153
|
+
unless Dir['VERSION*'].empty?
|
154
|
+
puts "A `VERSION` file at root level violates Gem best practices."
|
155
|
+
exit!
|
156
|
+
end
|
157
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'trinidad'
|
3
|
+
|
4
|
+
require File.expand_path('../../trinidad-libs/trinidad-sandbox-extension', __FILE__)
|
5
|
+
|
6
|
+
module Trinidad
|
7
|
+
module Extensions
|
8
|
+
class SandboxServerExtension < ServerExtension
|
9
|
+
VERSION = '0.1.0'
|
10
|
+
|
11
|
+
def configure(tomcat)
|
12
|
+
opts = prepare_options
|
13
|
+
|
14
|
+
app_context = create_application_context(tomcat, opts)
|
15
|
+
|
16
|
+
web_app = Trinidad::RackupWebApp.new({}, opts,
|
17
|
+
'org.jruby.trinidad.SandboxRackServlet', 'SandboxServlet')
|
18
|
+
|
19
|
+
app_context.add_lifecycle_listener(WebAppLifecycleListener.new(web_app))
|
20
|
+
web_app
|
21
|
+
end
|
22
|
+
|
23
|
+
def prepare_options
|
24
|
+
opts = {
|
25
|
+
:context_path => '/sandbox',
|
26
|
+
:jruby_min_runtimes => 1,
|
27
|
+
:jruby_max_runtimes => 2,
|
28
|
+
:libs_dir => 'libs',
|
29
|
+
:classes_dir => 'classes',
|
30
|
+
:public => 'app/public'
|
31
|
+
}
|
32
|
+
|
33
|
+
opts.deep_merge!(@options)
|
34
|
+
opts[:rackup] = 'config.ru'
|
35
|
+
opts[:web_app_dir] = File.expand_path('../trinidad_sandbox_extension', __FILE__)
|
36
|
+
opts
|
37
|
+
end
|
38
|
+
|
39
|
+
def create_application_context(tomcat, opts)
|
40
|
+
app_ctx = tomcat.addWebapp(opts[:context_path], opts[:web_app_dir])
|
41
|
+
app_ctx.privileged = true
|
42
|
+
|
43
|
+
if opts[:username] && opts[:password]
|
44
|
+
app_ctx.servlet_context.setAttribute("sandbox_username", opts[:username].to_s);
|
45
|
+
app_ctx.servlet_context.setAttribute("sandbox_password", opts[:password].to_s);
|
46
|
+
end
|
47
|
+
|
48
|
+
app_ctx
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
|
2
|
+
module Trinidad
|
3
|
+
module Sandbox
|
4
|
+
module Helpers
|
5
|
+
|
6
|
+
module Auth
|
7
|
+
require 'sinatra/authorization'
|
8
|
+
include Sinatra::Authorization
|
9
|
+
|
10
|
+
def authorize(user, pass)
|
11
|
+
user == sandbox_username && pass == sandbox_password
|
12
|
+
end
|
13
|
+
|
14
|
+
def authorized?
|
15
|
+
sandbox_username && sandbox_password ? request.env['REMOTE_USER'] && !request.env['REMOTE_USER'].empty? : true
|
16
|
+
end
|
17
|
+
|
18
|
+
def authorization_realm; "Trinidad's sandbox"; end
|
19
|
+
|
20
|
+
private
|
21
|
+
def sandbox_username
|
22
|
+
@sandbox_username ||= $servlet_context.getAttribute('sandbox_username')
|
23
|
+
end
|
24
|
+
|
25
|
+
def sandbox_password
|
26
|
+
@sandbox_password ||= $servlet_context.getAttribute('sandbox_password')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
module Context
|
31
|
+
def sandbox_context
|
32
|
+
@sandbox_context ||= $servlet_context.getAttribute('sandbox_context')
|
33
|
+
end
|
34
|
+
|
35
|
+
def context_not_found(name)
|
36
|
+
flash[:warning] = "application not found: #{name}"
|
37
|
+
$servlet_context.log "application not found: #{name}"
|
38
|
+
respond_to do |wants|
|
39
|
+
wants.html { redirect sandbox_context.path }
|
40
|
+
wants.xml { status 404 }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def host
|
45
|
+
$servlet_context.getAttribute('tomcat_host')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'delegate'
|
2
|
+
require 'cgi'
|
3
|
+
|
4
|
+
require File.expand_path('../../helpers/sandbox', __FILE__)
|
5
|
+
|
6
|
+
module Trinidad
|
7
|
+
module Sandbox
|
8
|
+
class ApplicationContext < DelegateClass(Trinidad::Tomcat::Context)
|
9
|
+
extend Trinidad::Sandbox::Helpers::Context
|
10
|
+
|
11
|
+
def self.all
|
12
|
+
apps = host ? host.find_children : []
|
13
|
+
apps.select {|app| app.name != sandbox_context.name }.
|
14
|
+
map {|app| ApplicationContext.new(app) }
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.find(name)
|
18
|
+
name = '/' + name unless name[0..1] == '/'
|
19
|
+
path = CGI.unescape(name)
|
20
|
+
context = host.findChild(path)
|
21
|
+
ApplicationContext.new(context) if context
|
22
|
+
end
|
23
|
+
|
24
|
+
def initialize(context)
|
25
|
+
super(context)
|
26
|
+
end
|
27
|
+
|
28
|
+
def slug
|
29
|
+
@slug ||= CGI.escape(name.sub('/', ''))
|
30
|
+
end
|
31
|
+
|
32
|
+
def self_path
|
33
|
+
@self_path ||= "#{ApplicationContext.sandbox_context.path}/apps/#{slug}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def actions
|
37
|
+
[
|
38
|
+
{:rel => 'start', :href => "#{self_path}/start"},
|
39
|
+
{:rel => 'stop', :href => "#{self_path}/stop"}
|
40
|
+
]
|
41
|
+
end
|
42
|
+
|
43
|
+
def parameters
|
44
|
+
@parameters ||= find_parameters
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
@@ -0,0 +1,133 @@
|
|
1
|
+
/* Reset */
|
2
|
+
|
3
|
+
ul {
|
4
|
+
padding: 0px;
|
5
|
+
}
|
6
|
+
|
7
|
+
li {
|
8
|
+
list-style: none;
|
9
|
+
margin: 0px;
|
10
|
+
padding: 0px;
|
11
|
+
display: list-item;
|
12
|
+
}
|
13
|
+
|
14
|
+
/* End: Reset */
|
15
|
+
|
16
|
+
|
17
|
+
body {
|
18
|
+
font-family: 'Lucida Grande', Verdana, Arial, Sans-Serif;
|
19
|
+
font-size:10.5pt;
|
20
|
+
color:#222222;
|
21
|
+
background: #333333;
|
22
|
+
margin: 0;
|
23
|
+
}
|
24
|
+
|
25
|
+
a {
|
26
|
+
color: #617fc3;
|
27
|
+
font-weight: bold;
|
28
|
+
text-decoration: none;
|
29
|
+
}
|
30
|
+
|
31
|
+
a:hover {
|
32
|
+
color: #395490;
|
33
|
+
}
|
34
|
+
|
35
|
+
h1 {
|
36
|
+
font-family: Helvetica, Arial, Sans-Serif;
|
37
|
+
letter-spacing: -0.03em;
|
38
|
+
color:#CCCCCC;
|
39
|
+
font-size:3em;
|
40
|
+
margin-top:2em;
|
41
|
+
margin-bottom:0;
|
42
|
+
}
|
43
|
+
|
44
|
+
h2 {
|
45
|
+
color:#CCCCCC;
|
46
|
+
font-size: 3em;
|
47
|
+
}
|
48
|
+
|
49
|
+
#title {
|
50
|
+
font-family: Helvetica, Arial, Sans-Serif;
|
51
|
+
letter-spacing:-0.07em;
|
52
|
+
text-align: left;
|
53
|
+
font-size:1.7em;
|
54
|
+
margin-left: .7em;
|
55
|
+
margin-bottom: 1.5em;
|
56
|
+
color:#666666;
|
57
|
+
}
|
58
|
+
|
59
|
+
#title h1 {
|
60
|
+
font-size:3em;
|
61
|
+
line-height:0.5em;
|
62
|
+
margin: 0;
|
63
|
+
margin-bottom: -0.05em;
|
64
|
+
}
|
65
|
+
|
66
|
+
#content {
|
67
|
+
line-height: 1.5em;
|
68
|
+
margin-bottom: 1em;
|
69
|
+
margin-right:-0.5em;
|
70
|
+
}
|
71
|
+
|
72
|
+
.site {
|
73
|
+
width:45em;
|
74
|
+
margin: 0 auto;
|
75
|
+
padding: 5em 5em;
|
76
|
+
background: #F5F5F5;
|
77
|
+
}
|
78
|
+
|
79
|
+
#parameters {
|
80
|
+
background: black;
|
81
|
+
color: white;
|
82
|
+
font-size: 0.9em;
|
83
|
+
max-height: 50em;
|
84
|
+
overflow: auto;
|
85
|
+
margin: 0.5em;
|
86
|
+
padding: 0.5em;
|
87
|
+
line-height: 2em;
|
88
|
+
}
|
89
|
+
|
90
|
+
.ack {
|
91
|
+
padding-top: 1em;
|
92
|
+
float: right;
|
93
|
+
font-size: 9pt;
|
94
|
+
}
|
95
|
+
|
96
|
+
.note {
|
97
|
+
background-color: #ffffcc;
|
98
|
+
border: solid 1px #ffff76;
|
99
|
+
|
100
|
+
padding: 1em;
|
101
|
+
}
|
102
|
+
|
103
|
+
#content #applications {
|
104
|
+
margin: 1em 0px 2em;
|
105
|
+
border-top: 1px solid silver;
|
106
|
+
}
|
107
|
+
|
108
|
+
#content #applications li {
|
109
|
+
border-bottom: 1px solid silver;
|
110
|
+
position: relative;
|
111
|
+
}
|
112
|
+
|
113
|
+
.app_name {
|
114
|
+
display: block;
|
115
|
+
font-size: 2em;
|
116
|
+
font-weight: bold;
|
117
|
+
line-height: 1.2;
|
118
|
+
padding: 0.25em;
|
119
|
+
}
|
120
|
+
|
121
|
+
.actions {
|
122
|
+
font-size: 0.8em;
|
123
|
+
position: absolute;
|
124
|
+
right: 0.6em;
|
125
|
+
text-align: right;
|
126
|
+
top: 1.5em;
|
127
|
+
}
|
128
|
+
|
129
|
+
.application {
|
130
|
+
border-top: 1px solid silver;
|
131
|
+
border-bottom: 1px solid silver;
|
132
|
+
position: relative;
|
133
|
+
}
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'sinatra'
|
3
|
+
require 'haml'
|
4
|
+
require File.expand_path('../helpers/sandbox', __FILE__)
|
5
|
+
require File.expand_path('../model/application_context', __FILE__)
|
6
|
+
require 'sinatra/respond_to'
|
7
|
+
require 'sinatra/flash'
|
8
|
+
|
9
|
+
enable :sessions
|
10
|
+
|
11
|
+
set :views, File.expand_path('../views', __FILE__)
|
12
|
+
|
13
|
+
Sinatra::Application.register Sinatra::RespondTo
|
14
|
+
|
15
|
+
helpers {
|
16
|
+
include Trinidad::Sandbox::Helpers::Auth
|
17
|
+
include Trinidad::Sandbox::Helpers::Context
|
18
|
+
}
|
19
|
+
before { login_required }
|
20
|
+
|
21
|
+
get '/' do
|
22
|
+
redirect sandbox_context.path + '/apps'
|
23
|
+
end
|
24
|
+
|
25
|
+
get '/apps' do
|
26
|
+
@applications = Trinidad::Sandbox::ApplicationContext.all
|
27
|
+
|
28
|
+
respond_to do |wants|
|
29
|
+
wants.html { haml :index }
|
30
|
+
wants.xml { haml :index }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
get '/apps/:name' do
|
35
|
+
@app = Trinidad::Sandbox::ApplicationContext.find(params[:name])
|
36
|
+
context_not_found(params[:name]) unless @app
|
37
|
+
|
38
|
+
respond_to do |wants|
|
39
|
+
wants.html { haml :app }
|
40
|
+
wants.xml { haml :app }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
post '/apps/:name/stop' do
|
45
|
+
context = Trinidad::Sandbox::ApplicationContext.find(params[:name])
|
46
|
+
|
47
|
+
context_not_found(params[:name]) unless context
|
48
|
+
|
49
|
+
if context.name == sandbox_context.name
|
50
|
+
$servet_context.log "can't stop the sandbox application"
|
51
|
+
respond_to do |wants|
|
52
|
+
wants.html { redirect sandbox_context.path }
|
53
|
+
wants.xml { status 500 }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context.stop
|
58
|
+
$servlet_context.log "#{context.name} stopped"
|
59
|
+
|
60
|
+
respond_to do |wants|
|
61
|
+
wants.html { redirect sandbox_context.path }
|
62
|
+
wants.xml { status 204 }
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
post '/apps/:name/start' do
|
67
|
+
context = Trinidad::Sandbox::ApplicationContext.find(params[:name])
|
68
|
+
|
69
|
+
context_not_found(params[:name]) unless context
|
70
|
+
|
71
|
+
context.start
|
72
|
+
if context.available == true
|
73
|
+
$servlet_context.log "#{context.name} started successfully"
|
74
|
+
else
|
75
|
+
$servlet_context.log "#{context.name} start failed"
|
76
|
+
end
|
77
|
+
|
78
|
+
respond_to do |wants|
|
79
|
+
wants.html { redirect sandbox_context.path }
|
80
|
+
wants.xml { status 204 }
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
.application
|
2
|
+
%a(href = "#{app.self_path}" class="app_name")= app.name
|
3
|
+
= haml :actions, :locals => {:app => app}, :layout => false
|
4
|
+
- if app.parameters
|
5
|
+
#parameters
|
6
|
+
%ul
|
7
|
+
- app.parameters.each do |param_name|
|
8
|
+
%li= "#{param_name} => #{app.find_parameter(param_name)}"
|
@@ -0,0 +1,9 @@
|
|
1
|
+
%application
|
2
|
+
%name= app.name
|
3
|
+
%available= app.available
|
4
|
+
- app.actions.each do |action|
|
5
|
+
%link(rel = "#{action[:rel]}" href = "#{action[:href]}")
|
6
|
+
- if app.parameters
|
7
|
+
%context-parameters
|
8
|
+
- app.parameters.each do |param_name|
|
9
|
+
%parameter(name = "#{param_name}" value = "#{app.find_parameter(param_name)}")
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'sinatra'
|
3
|
+
|
4
|
+
gem 'trinidad_jars'
|
5
|
+
require 'trinidad/jars'
|
6
|
+
|
7
|
+
app_path = $servlet_context.get_real_path('app/sandbox.rb')
|
8
|
+
require app_path
|
9
|
+
|
10
|
+
set :environment, :development
|
11
|
+
set :app_file, app_path
|
12
|
+
disable :run
|
13
|
+
|
14
|
+
run Sinatra::Application
|
15
|
+
|
16
|
+
#gem 'trinidad_jars'
|
17
|
+
#require 'trinidad/jars'
|
18
|
+
#require 'trinidad_sandbox_extension'
|
19
|
+
#require 'trinidad_sandbox_extension/sandbox_app'
|
20
|
+
|
21
|
+
#class Sinatra::Reloader < ::Rack::Reloader
|
22
|
+
# def safe_load(file, mtime, stderr)
|
23
|
+
# Sinatra::Application.reset!
|
24
|
+
# super
|
25
|
+
# end
|
26
|
+
#end
|
27
|
+
#use Sinatra::Reloader
|
28
|
+
|
29
|
+
#run Trinidad::Sandbox::App
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
begin
|
2
|
+
require 'spec'
|
3
|
+
rescue LoadError
|
4
|
+
require 'rubygems'
|
5
|
+
gem 'rspec'
|
6
|
+
require 'spec'
|
7
|
+
end
|
8
|
+
|
9
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
10
|
+
|
11
|
+
require 'java'
|
12
|
+
require 'trinidad_sandbox_extension'
|
13
|
+
require 'mocha'
|
14
|
+
|
15
|
+
Spec::Runner.configure do |config|
|
16
|
+
config.mock_with :mocha
|
17
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe Trinidad::Extensions::SandboxServerExtension do
|
4
|
+
subject { Trinidad::Extensions::SandboxServerExtension.new({}) }
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
@tomcat = Trinidad::Tomcat::Tomcat.new
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'includes a default path for the sandbox' do
|
11
|
+
opts = subject.prepare_options
|
12
|
+
opts[:context_path].should == '/sandbox'
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'allows to override the default path' do
|
16
|
+
ext = Trinidad::Extensions::SandboxServerExtension.new({
|
17
|
+
:context_path => '/trinidad'
|
18
|
+
})
|
19
|
+
|
20
|
+
ext.prepare_options[:context_path].should == '/trinidad'
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'adds a new application to the host' do
|
24
|
+
subject.configure(@tomcat)
|
25
|
+
|
26
|
+
@tomcat.host.findChildren().should have(1).children
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'gives privileges to the applications context' do
|
30
|
+
subject.configure(@tomcat)
|
31
|
+
|
32
|
+
@tomcat.host.findChildren().first.privileged.should be_true
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'adds the sandbox servlet to the application context' do
|
36
|
+
app = subject.configure(@tomcat)
|
37
|
+
app.context.findChild('SandboxServlet').should_not be_nil
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'adds provided credentials to the servlet context' do
|
41
|
+
opts = subject.prepare_options
|
42
|
+
opts[:username] = 'foo'
|
43
|
+
opts[:password] = 'bar'
|
44
|
+
|
45
|
+
ext = Trinidad::Extensions::SandboxServerExtension.new(opts)
|
46
|
+
|
47
|
+
app_ctx = ext.create_application_context(@tomcat, opts)
|
48
|
+
|
49
|
+
app_ctx.servlet_context.getAttribute('sandbox_username').should == 'foo'
|
50
|
+
app_ctx.servlet_context.getAttribute('sandbox_password').should == 'bar'
|
51
|
+
end
|
52
|
+
end
|
Binary file
|
@@ -0,0 +1,83 @@
|
|
1
|
+
## This is the rakegem gemspec template. Make sure you read and understand
|
2
|
+
## all of the comments. Some sections require modification, and others can
|
3
|
+
## be deleted if you don't need them. Once you understand the contents of
|
4
|
+
## this file, feel free to delete any comments that begin with two hash marks.
|
5
|
+
## You can find comprehensive Gem::Specification documentation, at
|
6
|
+
## http://docs.rubygems.org/read/chapter/20
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.specification_version = 2 if s.respond_to? :specification_version=
|
9
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
10
|
+
s.rubygems_version = '1.3.5'
|
11
|
+
|
12
|
+
## Leave these as is they will be modified for you by the rake gemspec task.
|
13
|
+
## If your rubyforge_project name is different, then edit it and comment out
|
14
|
+
## the sub! line in the Rakefile
|
15
|
+
s.name = 'trinidad_sandbox_extension'
|
16
|
+
s.version = '0.1.0'
|
17
|
+
s.date = '2010-05-31'
|
18
|
+
s.rubyforge_project = 'trinidad_sandbox_extension'
|
19
|
+
|
20
|
+
## Make sure your summary is short. The description may be as long
|
21
|
+
## as you like.
|
22
|
+
s.summary = "Sandbox console for Trinidad"
|
23
|
+
s.description = "Sandox console for Trinidad. It allows to manage the applications deployed on Trinidad."
|
24
|
+
|
25
|
+
## List the primary authors. If there are a bunch of authors, it's probably
|
26
|
+
## better to set the email to an email list or something. If you don't have
|
27
|
+
## a custom homepage, consider using your GitHub URL or the like.
|
28
|
+
s.authors = ["David Calavera"]
|
29
|
+
s.email = 'calavera@apache.org'
|
30
|
+
s.homepage = 'http://github.com/calavera/trinidad_sandbox_extension'
|
31
|
+
|
32
|
+
## This gets added to the $LOAD_PATH so that 'lib/NAME.rb' can be required as
|
33
|
+
## require 'NAME.rb' or'/lib/NAME/file.rb' can be as require 'NAME/file.rb'
|
34
|
+
s.require_paths = %w[lib]
|
35
|
+
|
36
|
+
## Specify any RDoc options here. You'll want to add your README and
|
37
|
+
## LICENSE files to the extra_rdoc_files list.
|
38
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
39
|
+
s.extra_rdoc_files = %w[README LICENSE]
|
40
|
+
|
41
|
+
## List your runtime dependencies here. Runtime dependencies are those
|
42
|
+
## that are needed for an end user to actually USE your code.
|
43
|
+
['sinatra', 'sinatra-authorization', 'sinatra-respond_to', 'sinatra-flash'].each do |dep|
|
44
|
+
s.add_dependency(dep)
|
45
|
+
end
|
46
|
+
|
47
|
+
## List your development dependencies here. Development dependencies are
|
48
|
+
## those that are only needed during development
|
49
|
+
s.add_development_dependency('rspec')
|
50
|
+
s.add_development_dependency('mocha')
|
51
|
+
|
52
|
+
## Leave this section as-is. It will be automatically generated from the
|
53
|
+
## contents of your Git repository via the gemspec task. DO NOT REMOVE
|
54
|
+
## THE MANIFEST COMMENTS, they are used as delimiters by the task.
|
55
|
+
# = MANIFEST =
|
56
|
+
s.files = %w[
|
57
|
+
LICENSE
|
58
|
+
README
|
59
|
+
Rakefile
|
60
|
+
lib/trinidad_sandbox_extension.rb
|
61
|
+
lib/trinidad_sandbox_extension/app/helpers/sandbox.rb
|
62
|
+
lib/trinidad_sandbox_extension/app/model/application_context.rb
|
63
|
+
lib/trinidad_sandbox_extension/app/public/css/main.css
|
64
|
+
lib/trinidad_sandbox_extension/app/sandbox.rb
|
65
|
+
lib/trinidad_sandbox_extension/app/views/actions.html.haml
|
66
|
+
lib/trinidad_sandbox_extension/app/views/app.html.haml
|
67
|
+
lib/trinidad_sandbox_extension/app/views/app.xml.haml
|
68
|
+
lib/trinidad_sandbox_extension/app/views/index.html.haml
|
69
|
+
lib/trinidad_sandbox_extension/app/views/index.xml.haml
|
70
|
+
lib/trinidad_sandbox_extension/app/views/layout.html.haml
|
71
|
+
lib/trinidad_sandbox_extension/config.ru
|
72
|
+
spec/spec.opts
|
73
|
+
spec/spec_helper.rb
|
74
|
+
spec/trinidad_sandbox_extension_spec.rb
|
75
|
+
trinidad_sandbox_extension.gemspec
|
76
|
+
trinidad-libs/trinidad-sandbox-extension.jar
|
77
|
+
]
|
78
|
+
# = MANIFEST =
|
79
|
+
|
80
|
+
## Test files will be grabbed from the file list. Make sure the path glob
|
81
|
+
## matches what you actually use.
|
82
|
+
s.test_files = s.files.select { |path| path =~ /^spec\/.*\_spec.rb/ }
|
83
|
+
end
|
metadata
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: trinidad_sandbox_extension
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- David Calavera
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-05-31 00:00:00 +02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: sinatra
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :runtime
|
31
|
+
version_requirements: *id001
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: sinatra-authorization
|
34
|
+
prerelease: false
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
segments:
|
40
|
+
- 0
|
41
|
+
version: "0"
|
42
|
+
type: :runtime
|
43
|
+
version_requirements: *id002
|
44
|
+
- !ruby/object:Gem::Dependency
|
45
|
+
name: sinatra-respond_to
|
46
|
+
prerelease: false
|
47
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
segments:
|
52
|
+
- 0
|
53
|
+
version: "0"
|
54
|
+
type: :runtime
|
55
|
+
version_requirements: *id003
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: sinatra-flash
|
58
|
+
prerelease: false
|
59
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
version: "0"
|
66
|
+
type: :runtime
|
67
|
+
version_requirements: *id004
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
name: rspec
|
70
|
+
prerelease: false
|
71
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
version: "0"
|
78
|
+
type: :development
|
79
|
+
version_requirements: *id005
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: mocha
|
82
|
+
prerelease: false
|
83
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
segments:
|
88
|
+
- 0
|
89
|
+
version: "0"
|
90
|
+
type: :development
|
91
|
+
version_requirements: *id006
|
92
|
+
description: Sandox console for Trinidad. It allows to manage the applications deployed on Trinidad.
|
93
|
+
email: calavera@apache.org
|
94
|
+
executables: []
|
95
|
+
|
96
|
+
extensions: []
|
97
|
+
|
98
|
+
extra_rdoc_files:
|
99
|
+
- README
|
100
|
+
- LICENSE
|
101
|
+
files:
|
102
|
+
- LICENSE
|
103
|
+
- README
|
104
|
+
- Rakefile
|
105
|
+
- lib/trinidad_sandbox_extension.rb
|
106
|
+
- lib/trinidad_sandbox_extension/app/helpers/sandbox.rb
|
107
|
+
- lib/trinidad_sandbox_extension/app/model/application_context.rb
|
108
|
+
- lib/trinidad_sandbox_extension/app/public/css/main.css
|
109
|
+
- lib/trinidad_sandbox_extension/app/sandbox.rb
|
110
|
+
- lib/trinidad_sandbox_extension/app/views/actions.html.haml
|
111
|
+
- lib/trinidad_sandbox_extension/app/views/app.html.haml
|
112
|
+
- lib/trinidad_sandbox_extension/app/views/app.xml.haml
|
113
|
+
- lib/trinidad_sandbox_extension/app/views/index.html.haml
|
114
|
+
- lib/trinidad_sandbox_extension/app/views/index.xml.haml
|
115
|
+
- lib/trinidad_sandbox_extension/app/views/layout.html.haml
|
116
|
+
- lib/trinidad_sandbox_extension/config.ru
|
117
|
+
- spec/spec.opts
|
118
|
+
- spec/spec_helper.rb
|
119
|
+
- spec/trinidad_sandbox_extension_spec.rb
|
120
|
+
- trinidad_sandbox_extension.gemspec
|
121
|
+
- trinidad-libs/trinidad-sandbox-extension.jar
|
122
|
+
has_rdoc: true
|
123
|
+
homepage: http://github.com/calavera/trinidad_sandbox_extension
|
124
|
+
licenses: []
|
125
|
+
|
126
|
+
post_install_message:
|
127
|
+
rdoc_options:
|
128
|
+
- --charset=UTF-8
|
129
|
+
require_paths:
|
130
|
+
- lib
|
131
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
segments:
|
136
|
+
- 0
|
137
|
+
version: "0"
|
138
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
segments:
|
143
|
+
- 0
|
144
|
+
version: "0"
|
145
|
+
requirements: []
|
146
|
+
|
147
|
+
rubyforge_project: trinidad_sandbox_extension
|
148
|
+
rubygems_version: 1.3.6
|
149
|
+
signing_key:
|
150
|
+
specification_version: 2
|
151
|
+
summary: Sandbox console for Trinidad
|
152
|
+
test_files:
|
153
|
+
- spec/trinidad_sandbox_extension_spec.rb
|