aurora 0.1.10 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/aurora +44 -55
- data/lib/aurora.rb +1 -1
- data/lib/aurora/client.rb +47 -0
- data/lib/aurora/server.rb +4 -3
- metadata +2 -2
data/bin/aurora
CHANGED
@@ -18,6 +18,7 @@ $:.unshift(File.join(File.dirname(__FILE__),'lib'))
|
|
18
18
|
|
19
19
|
$debug = false
|
20
20
|
$test = false
|
21
|
+
$daemonize = false
|
21
22
|
options = Halcyon::Server::DEFAULT_OPTIONS
|
22
23
|
|
23
24
|
#--
|
@@ -148,7 +149,6 @@ options[:app] = ARGV.shift
|
|
148
149
|
#--
|
149
150
|
# load app
|
150
151
|
#++
|
151
|
-
|
152
152
|
begin
|
153
153
|
# go ahead and try to require since it could be a gem
|
154
154
|
require options[:app]
|
@@ -169,66 +169,47 @@ end
|
|
169
169
|
# prepare server
|
170
170
|
#++
|
171
171
|
begin
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
use Rack::CommonLogger, STDERR unless server.name =~ /CGI/
|
202
|
-
use Rack::ShowExceptions
|
203
|
-
use Rack::Reloader
|
204
|
-
use Rack::Lint
|
205
|
-
run app.new(options)
|
206
|
-
}.to_app
|
207
|
-
when "deployment"
|
208
|
-
app = Rack::Builder.new {
|
209
|
-
use Rack::CommonLogger, STDERR unless server.name =~ /CGI/
|
210
|
-
run app.new(options)
|
211
|
-
}.to_app
|
212
|
-
else
|
213
|
-
app = app.new(options)
|
214
|
-
end
|
215
|
-
|
216
|
-
#--
|
217
|
-
# start server
|
218
|
-
#++
|
219
|
-
|
220
|
-
server.run app, :Port => options[:port]
|
172
|
+
case options[:server]
|
173
|
+
when 'swift-thin'
|
174
|
+
require 'thin'
|
175
|
+
server = Rack::Handler::Thin
|
176
|
+
server = Controllers::Controller.new({
|
177
|
+
:swiftiply => '',
|
178
|
+
:chdir => Dir.pwd,
|
179
|
+
:log => options[:log_file],
|
180
|
+
:pid => options[:pid_file],
|
181
|
+
:environment => 'development',
|
182
|
+
:timeout => 30,
|
183
|
+
:max_conns => 1024,
|
184
|
+
:max_persistent_conns => 512
|
185
|
+
})
|
186
|
+
when 'swift-mongrel'
|
187
|
+
require 'swiftcore/swiftiplied_mongrel'
|
188
|
+
require 'mongrel'
|
189
|
+
server = Rack::Handler::Mongrel
|
190
|
+
else
|
191
|
+
warn 'Aurora is not running behind an SSL connection-capable server. Authenticate at your own risk.'
|
192
|
+
servers = {
|
193
|
+
'cgi' => 'CGI',
|
194
|
+
'fastcgi' => 'FastCGI',
|
195
|
+
'lsws' => 'LSWS',
|
196
|
+
'mongrel' => 'Mongrel',
|
197
|
+
'webrick' => 'WEBrick',
|
198
|
+
'thin' => 'Thin'
|
199
|
+
}
|
200
|
+
server = Rack::Handler.const_get(servers[options[:server]].to_sym)
|
221
201
|
end
|
202
|
+
rescue NameError
|
203
|
+
abort "Unsupported server (missing Rack Handler). Did you mean to specify #{options[:server]}?"
|
222
204
|
end
|
223
205
|
|
224
206
|
#--
|
225
207
|
# prepare app environment
|
226
208
|
#++
|
227
|
-
|
228
209
|
case options[:environment]
|
229
210
|
when "development"
|
230
211
|
app = Rack::Builder.new {
|
231
|
-
use Rack::CommonLogger, STDERR
|
212
|
+
use Rack::CommonLogger, STDERR unless server.name =~ /CGI/
|
232
213
|
use Rack::ShowExceptions
|
233
214
|
use Rack::Reloader
|
234
215
|
use Rack::Lint
|
@@ -236,7 +217,7 @@ when "development"
|
|
236
217
|
}.to_app
|
237
218
|
when "deployment"
|
238
219
|
app = Rack::Builder.new {
|
239
|
-
use Rack::CommonLogger, STDERR
|
220
|
+
use Rack::CommonLogger, STDERR unless server.name =~ /CGI/
|
240
221
|
run app.new(options)
|
241
222
|
}.to_app
|
242
223
|
else
|
@@ -246,5 +227,13 @@ end
|
|
246
227
|
#--
|
247
228
|
# start server
|
248
229
|
#++
|
249
|
-
|
250
|
-
server.run app, :Port => options[:port]
|
230
|
+
unless $daemonize
|
231
|
+
server.run app, :Port => options[:port].to_i
|
232
|
+
else
|
233
|
+
fork do
|
234
|
+
require 'daemons'
|
235
|
+
Daemonize.daemonize
|
236
|
+
|
237
|
+
server.run app, :Port => options[:port].to_i
|
238
|
+
end
|
239
|
+
end
|
data/lib/aurora.rb
CHANGED
data/lib/aurora/client.rb
CHANGED
@@ -69,3 +69,50 @@ module Aurora
|
|
69
69
|
end
|
70
70
|
|
71
71
|
end
|
72
|
+
|
73
|
+
require 'net/https'
|
74
|
+
|
75
|
+
module Halcyon
|
76
|
+
class Client
|
77
|
+
|
78
|
+
class Base
|
79
|
+
|
80
|
+
private
|
81
|
+
|
82
|
+
def request(req, headers={})
|
83
|
+
# define essential headers for Halcyon::Server's picky requirements
|
84
|
+
req["Content-Type"] = CONTENT_TYPE
|
85
|
+
req["User-Agent"] = USER_AGENT
|
86
|
+
|
87
|
+
# apply provided headers
|
88
|
+
headers.each do |pair|
|
89
|
+
header, value = pair
|
90
|
+
req[header] = value
|
91
|
+
end
|
92
|
+
|
93
|
+
# provide hook for modifying the headers
|
94
|
+
req = headers(req) if respond_to? :headers
|
95
|
+
|
96
|
+
# prepare and send HTTP request
|
97
|
+
serv = Net::HTTP.new(@uri.host, @uri.port)
|
98
|
+
serv.use_ssl = true if @uri.scheme == 'https'
|
99
|
+
res = serv.start {|http|http.request(req)}
|
100
|
+
|
101
|
+
# parse response
|
102
|
+
body = JSON.parse(res.body)
|
103
|
+
body.symbolize_keys!
|
104
|
+
|
105
|
+
# handle non-successes
|
106
|
+
raise Halcyon::Client::Base::Exceptions.lookup(body[:status]).new unless res.kind_of? Net::HTTPSuccess
|
107
|
+
|
108
|
+
# return response
|
109
|
+
body
|
110
|
+
rescue Halcyon::Exceptions::Base => e
|
111
|
+
# log exception if logger is in place
|
112
|
+
raise
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
end
|
data/lib/aurora/server.rb
CHANGED
@@ -77,6 +77,7 @@ module Aurora
|
|
77
77
|
host = "#{@config[:db][:host]}/" unless @config[:db][:host].nil?
|
78
78
|
credentials = "#{@config[:db][:username]}:#{@config[:db][:password]}@" unless @config[:db][:username].nil?
|
79
79
|
@db = Sequel("#{@config[:db][:adapter]}://#{credentials}#{host}#{@config[:db][:database]}")
|
80
|
+
@db.logger = @logger if $debug
|
80
81
|
@logger.info 'Connected to Database.'
|
81
82
|
|
82
83
|
# run migrations if version is outdated
|
@@ -115,7 +116,7 @@ module Aurora
|
|
115
116
|
@db[:tokens] << {:username => username, :token => token, :expires_at => expiration}
|
116
117
|
|
117
118
|
# create the user if not already in the DB
|
118
|
-
if @db[:users].filter(:username => username).empty?
|
119
|
+
if @db[:users].filter(:username => username).all.empty?
|
119
120
|
# retrieve the new user permissions
|
120
121
|
permissions = initialize_permissions(username)
|
121
122
|
|
@@ -217,11 +218,11 @@ module Aurora
|
|
217
218
|
# Authenticates the token.
|
218
219
|
def auth
|
219
220
|
# expire_tokens # TODO: investigate how much of a performance hit checking (and deleting) is
|
220
|
-
unless @db[:tokens].filter('token = ? AND expires_at > ?', params[:token], Time.now).empty?
|
221
|
+
unless @db[:tokens].filter('token = ? AND expires_at > ?', params[:token], Time.now).all.empty?
|
221
222
|
# authenticated
|
222
223
|
|
223
224
|
# update the expiration date if close to expiring
|
224
|
-
unless @db[:tokens].filter('token = ? AND expires_at <= ?', params[:token], generate_expiration(15)).empty?
|
225
|
+
unless @db[:tokens].filter('token = ? AND expires_at <= ?', params[:token], generate_expiration(15)).all.empty?
|
225
226
|
@db[:tokens].filter(:token => params[:token]).update(:expires_at => generate_expiration)
|
226
227
|
end
|
227
228
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aurora
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Todd
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-02-
|
12
|
+
date: 2008-02-28 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|