appengine-rack 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -10,7 +10,7 @@ EOF
10
10
 
11
11
  spec = Gem::Specification.new do |s|
12
12
  s.name = "appengine-rack"
13
- s.version = "0.0.3"
13
+ s.version = "0.0.4"
14
14
  s.author = "Ryan Brown"
15
15
  s.email = "ribrdb@google.com"
16
16
  s.homepage = "http://code.google.com/p/appengine-jruby"
@@ -15,6 +15,11 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
 
18
+ begin
19
+ require 'bundler_gems/environment'
20
+ rescue LoadError
21
+ end
22
+
18
23
  begin
19
24
  require 'appengine-apis/urlfetch'
20
25
  require 'appengine-apis/tempfile'
@@ -75,7 +80,7 @@ module AppEngine
75
80
  sys = xml.add_element('system-properties')
76
81
  each do |name, value|
77
82
  sys.add_element('property').
78
- add_attributes( { "name" => name, "value" => value } )
83
+ add_attributes( { "name" => name, "value" => value.to_s } )
79
84
  end
80
85
  end
81
86
  end
@@ -87,14 +92,14 @@ module AppEngine
87
92
  env = xml.add_element('env-variables')
88
93
  each do |name, value|
89
94
  env.add_element('env-var').
90
- add_attributes( { "name" => name, "value" => value } )
95
+ add_attributes( { "name" => name, "value" => value.to_s } )
91
96
  end
92
97
  end
93
98
  end
94
99
  end
95
100
 
96
101
  class RackApplication
97
- attr_accessor :application, :inbound_services
102
+ attr_accessor :application, :inbound_services, :precompilation_enabled
98
103
  attr_reader :version, :static_files, :resource_files, :public_root
99
104
  attr_reader :system_properties, :environment_variables
100
105
  attr_writer :ssl_enabled, :sessions_enabled
@@ -102,8 +107,10 @@ module AppEngine
102
107
  def initialize
103
108
  @version = '1'
104
109
  @system_properties = PropertyMap[ 'os.arch' => '',
105
- 'jruby.management.enabled' => false,
106
- 'jruby.rack.input.rewindable' => false ]
110
+ 'jruby.jit.threshold' => 99,
111
+ 'jruby.native.enabled' => false,
112
+ 'jruby.management.enabled' => false,
113
+ 'jruby.rack.input.rewindable' => false ]
107
114
  @environment_variables = EnvVarMap.new
108
115
  @static_files = Resources.new
109
116
  @resource_files = Resources.new
@@ -121,6 +128,10 @@ module AppEngine
121
128
  @ssl_enabled
122
129
  end
123
130
 
131
+ def precompilation_enabled?
132
+ @precompilation_enabled
133
+ end
134
+
124
135
  def public_root=(root)
125
136
  root = "/#{root}".squeeze '/'
126
137
  root = nil if root.eql? '/'
@@ -156,6 +167,9 @@ module AppEngine
156
167
  if ssl_enabled?
157
168
  xml.add_element('ssl-enabled').add_text('true')
158
169
  end
170
+ if precompilation_enabled?
171
+ xml.add_element('precompilation-enabled').add_text('true')
172
+ end
159
173
  unless @inbound_services.empty?
160
174
  services = xml.add_element('inbound-services')
161
175
  @inbound_services.each do |service|
@@ -0,0 +1,259 @@
1
+ #!/usr/bin/ruby1.8 -w
2
+ #
3
+ # Copyright:: Copyright 2009 Google Inc.
4
+ # Original Author:: Ryan Brown (mailto:ribrdb@google.com)
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ begin
19
+ require 'bundler_gems/environment'
20
+ rescue LoadError
21
+ end
22
+
23
+ begin
24
+ require 'appengine-apis/urlfetch'
25
+ require 'appengine-apis/tempfile'
26
+ rescue Exception
27
+ end
28
+
29
+ module AppEngine
30
+ module Rack
31
+ ROOT = File.expand_path(File.dirname(__FILE__))
32
+
33
+ class Resources
34
+ COMMON_EXCLUDES = {
35
+ :rails_excludes => %w(README Rakefile db/** doc/**
36
+ log/** script/** test/** tmp/**),
37
+ :merb_excludes => %w(Rakefile autotest/** doc/** gems/** spec/**) }
38
+
39
+ def initialize
40
+ @includes = []
41
+ @excludes = []
42
+ end
43
+
44
+ def include(glob, expiration=nil)
45
+ if glob.is_a? Array
46
+ glob.each do |g|
47
+ @includes << [g, expiration]
48
+ end
49
+ else
50
+ @includes << [glob, expiration]
51
+ end
52
+ end
53
+
54
+ def exclude(glob)
55
+ if glob.is_a? Array
56
+ @excludes += glob
57
+ elsif glob.is_a? Symbol
58
+ @excludes += COMMON_EXCLUDES[glob]
59
+ else
60
+ @excludes << glob
61
+ end
62
+ end
63
+
64
+ def append_to(xml, type)
65
+ resources = xml.add_element(type)
66
+ @includes.each do |path, expiration|
67
+ element = resources.add_element('include')
68
+ element.add_attribute('path', path)
69
+ element.add_attribute('expiration', expiration) if expiration
70
+ end
71
+ @excludes.each do |path|
72
+ resources.add_element('exclude').add_attribute('path', path)
73
+ end
74
+ end
75
+ end
76
+
77
+ class PropertyMap < Hash
78
+ def append_to(xml)
79
+ unless empty?
80
+ sys = xml.add_element('system-properties')
81
+ each do |name, value|
82
+ sys.add_element('property').
83
+ add_attributes( { "name" => name, "value" => value.to_s } )
84
+ end
85
+ end
86
+ end
87
+ end
88
+
89
+ class EnvVarMap < Hash
90
+ def append_to(xml)
91
+ unless empty?
92
+ env = xml.add_element('env-variables')
93
+ each do |name, value|
94
+ env.add_element('env-var').
95
+ add_attributes( { "name" => name, "value" => value.to_s } )
96
+ end
97
+ end
98
+ end
99
+ end
100
+
101
+ class RackApplication
102
+ attr_accessor :application, :precompilation_enabled
103
+ attr_accessor :inbound_services, :mime_mapping
104
+ attr_reader :version, :static_files, :resource_files, :public_root
105
+ attr_reader :system_properties, :environment_variables
106
+ attr_writer :ssl_enabled, :sessions_enabled
107
+
108
+ def initialize
109
+ @version = '1'
110
+ @system_properties = PropertyMap[ 'os.arch' => '',
111
+ 'jruby.jit.threshold' => 99,
112
+ 'jruby.native.enabled' => false,
113
+ 'jruby.management.enabled' => false,
114
+ 'jruby.rack.input.rewindable' => false ]
115
+ @environment_variables = EnvVarMap.new
116
+ @static_files = Resources.new
117
+ @resource_files = Resources.new
118
+ @public_root = '/public'
119
+ @inbound_services = []
120
+ @mime_mapping = {}
121
+ end
122
+
123
+ alias id application
124
+
125
+ def sessions_enabled?
126
+ @sessions_enabled
127
+ end
128
+
129
+ def ssl_enabled?
130
+ @ssl_enabled
131
+ end
132
+
133
+ def precompilation_enabled?
134
+ @precompilation_enabled
135
+ end
136
+
137
+ def public_root=(root)
138
+ root = "/#{root}".squeeze '/'
139
+ root = nil if root.eql? '/'
140
+ @public_root = root
141
+ end
142
+
143
+ def version=(version)
144
+ @version = version.to_s
145
+ end
146
+
147
+ def configure(options={})
148
+ [:system_properties, :environment_variables].each do |key|
149
+ self.send(key).merge!(options.delete(key)) if options[key]
150
+ end
151
+ options.each { |k,v| self.send("#{k}=", v) }
152
+ end
153
+
154
+ def to_xml
155
+ require 'rexml/document'
156
+
157
+ xml = REXML::Document.new.add_element('appengine-web-app')
158
+ xml.add_attribute('xmlns','http://appengine.google.com/ns/1.0')
159
+ xml.add_element('application').add_text(application)
160
+ xml.add_element('version').add_text(version)
161
+ xml.add_element('public-root').add_text(@public_root) if @public_root
162
+ static_files.append_to(xml, 'static-files')
163
+ resource_files.append_to(xml, 'resource-files')
164
+ system_properties.append_to(xml)
165
+ environment_variables.append_to(xml)
166
+ if sessions_enabled?
167
+ xml.add_element('sessions-enabled').add_text('true')
168
+ end
169
+ if ssl_enabled?
170
+ xml.add_element('ssl-enabled').add_text('true')
171
+ end
172
+ if precompilation_enabled?
173
+ xml.add_element('precompilation-enabled').add_text('true')
174
+ end
175
+ unless @inbound_services.empty?
176
+ services = xml.add_element('inbound-services')
177
+ @inbound_services.each do |service|
178
+ services.add_element('service').add_text(service.to_s)
179
+ end
180
+ end
181
+ @mime_mapping.each_pair do |key,val|
182
+ mime = xml.add_element('mime-mapping')
183
+ mime.add_element('extension').add_text(key.to_s)
184
+ mime.add_element('mime-type').add_text(val)
185
+ end
186
+ return xml
187
+ end
188
+ end
189
+
190
+ class SecurityMiddleware
191
+ def self.append_xml(doc, pattern)
192
+ security = doc.add_element('security-constraint')
193
+ collection = security.add_element('web-resource-collection')
194
+ collection.add_element('url-pattern').add_text(pattern)
195
+ collection.add_element('url-pattern').add_text(
196
+ AppEngine::Rack.make_wildcard(pattern))
197
+ yield security
198
+ end
199
+
200
+ def self.new(app, *args, &block)
201
+ app
202
+ end
203
+
204
+ end
205
+
206
+ class AdminRequired < SecurityMiddleware
207
+ def self.append_xml(doc, pattern)
208
+ super(doc, pattern) do |security|
209
+ auth = security.add_element('auth-constraint')
210
+ auth.add_element('role-name').add_text('admin')
211
+ end
212
+ end
213
+ end
214
+
215
+ class LoginRequired < SecurityMiddleware
216
+ def self.append_xml(doc, pattern)
217
+ super(doc, pattern) do |security|
218
+ auth = security.add_element('auth-constraint')
219
+ auth.add_element('role-name').add_text('*')
220
+ end
221
+ end
222
+ end
223
+
224
+ class SSLRequired < SecurityMiddleware
225
+ def self.append_xml(doc, pattern)
226
+ super(doc, pattern) do |security|
227
+ udc = security.add_element('user-data-constraint')
228
+ udc.add_element('transport-guarantee').add_text('CONFIDENTIAL')
229
+ end
230
+ end
231
+ end
232
+
233
+ class << self
234
+ def app
235
+ @app ||= RackApplication.new
236
+ end
237
+
238
+ def configure_app(options={})
239
+ @app = RackApplication.new
240
+ @app.configure(options)
241
+ end
242
+
243
+ def environment
244
+ if $servlet_context
245
+ if $servlet_context.server_info =~ %r{^Google App Engine Development/}
246
+ "development"
247
+ elsif $servlet_context.server_info =~ %r{^Google App Engine/}
248
+ "production"
249
+ end
250
+ end
251
+ end
252
+
253
+
254
+ def make_wildcard(pattern)
255
+ "#{pattern}/*".squeeze('/')
256
+ end
257
+ end
258
+ end
259
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appengine-rack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Brown
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-03 00:00:00 -07:00
12
+ date: 2009-11-02 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -26,8 +26,9 @@ extra_rdoc_files: []
26
26
  files:
27
27
  - LICENSE
28
28
  - Rakefile
29
- - lib/appengine-rack/java.rb
30
29
  - lib/appengine-rack.rb
30
+ - lib/appengine-rack.rb.orig
31
+ - lib/appengine-rack/java.rb
31
32
  has_rdoc: true
32
33
  homepage: http://code.google.com/p/appengine-jruby
33
34
  licenses: []