regurgitator 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.manifest +2 -0
- data/ChangeLog +63 -0
- data/GIT-VERSION-FILE +1 -1
- data/GIT-VERSION-GEN +1 -1
- data/LATEST +4 -4
- data/NEWS +6 -0
- data/lib/regurgitator.rb +1 -5
- data/lib/regurgitator/device.rb +1 -12
- data/lib/regurgitator/domain_host.rb +1 -1
- data/lib/regurgitator/domain_path.rb +3 -2
- data/lib/regurgitator/endpoint.rb +4 -5
- data/lib/regurgitator/file_info.rb +1 -5
- data/lib/regurgitator/list_keys.rb +27 -0
- data/lib/regurgitator/one_domain.rb +1 -1
- data/pkg.mk +2 -2
- data/t/domain_host.ru +1 -0
- data/t/domain_path.ru +5 -2
- data/t/my-tap-lib.sh +4 -3
- data/t/one_domain.ru +1 -0
- data/test/test_list_keys.rb +40 -0
- metadata +9 -5
data/.manifest
CHANGED
@@ -22,6 +22,7 @@ lib/regurgitator/domain_path.rb
|
|
22
22
|
lib/regurgitator/endpoint.rb
|
23
23
|
lib/regurgitator/file_info.rb
|
24
24
|
lib/regurgitator/file_request.rb
|
25
|
+
lib/regurgitator/list_keys.rb
|
25
26
|
lib/regurgitator/local.rb
|
26
27
|
lib/regurgitator/local_file.rb
|
27
28
|
lib/regurgitator/one_domain.rb
|
@@ -42,5 +43,6 @@ t/t0001-domain_path.sh
|
|
42
43
|
t/t0002-domain_host.sh
|
43
44
|
t/t0003-one_domain.sh
|
44
45
|
t/test-lib.sh
|
46
|
+
test/test_list_keys.rb
|
45
47
|
test/test_local.rb
|
46
48
|
test/test_server_settings.rb
|
data/ChangeLog
CHANGED
@@ -1,5 +1,68 @@
|
|
1
1
|
ChangeLog from http://bogomips.org/regurgitator.git
|
2
2
|
|
3
|
+
commit 4874e7d38453a0b4b3f47d8dc8095a314083bd11
|
4
|
+
Author: Eric Wong <normalperson@yhbt.net>
|
5
|
+
Date: Thu Dec 15 18:11:02 2011 -0800
|
6
|
+
|
7
|
+
regurgitator 0.2.0
|
8
|
+
|
9
|
+
* add list_keys module for listing keys
|
10
|
+
* add :reproxy_key, overriding global REPROXY_KEY constant
|
11
|
+
* remove support for altip/altmask (hardly ever used)
|
12
|
+
|
13
|
+
commit ed9f6b55d3acbe8bf0ee8599fff466fbe9eabd5d
|
14
|
+
Author: Eric Wong <normalperson@yhbt.net>
|
15
|
+
Date: Thu Dec 15 18:16:19 2011 -0800
|
16
|
+
|
17
|
+
strip out the altmask/altip handling stuff
|
18
|
+
|
19
|
+
Hardly anyone ever uses/used it, so stop attempting to support
|
20
|
+
it to remove the risk of supporting it improperly.
|
21
|
+
|
22
|
+
commit 3052e1b0f75523b46f43ddb1163b37c12e6ed57e
|
23
|
+
Author: Eric Wong <normalperson@yhbt.net>
|
24
|
+
Date: Thu Dec 1 00:13:43 2011 -0800
|
25
|
+
|
26
|
+
list_keys: force case-sensitive key name matching for MySQL
|
27
|
+
|
28
|
+
Case-insensitivity kills millions each year...
|
29
|
+
|
30
|
+
We require Sequel 3.29+ for SQLite, so we avoid this problem
|
31
|
+
there already.
|
32
|
+
|
33
|
+
commit 045b555d7404ca5bfac5cf69a5e7ab35872602ef
|
34
|
+
Author: Eric Wong <normalperson@yhbt.net>
|
35
|
+
Date: Wed Nov 16 19:25:32 2011 -0800
|
36
|
+
|
37
|
+
add :reproxy_key, overriding global REPROXY_KEY constant
|
38
|
+
|
39
|
+
Users may never want reproxy behavior, or they may want to
|
40
|
+
use a different key, so support both use cases.
|
41
|
+
|
42
|
+
Reproxy support (for nginx) is now off now by default.
|
43
|
+
|
44
|
+
commit 80982a28eafda2b439bbb1545e649509f29e83d4
|
45
|
+
Author: Eric Wong <normalperson@yhbt.net>
|
46
|
+
Date: Wed Nov 16 19:24:59 2011 -0800
|
47
|
+
|
48
|
+
t: update my-tap-lib.sh
|
49
|
+
|
50
|
+
Fix race conditions in verbose mode
|
51
|
+
|
52
|
+
commit 530ab82be1608f6a136169aee71dc5745b9b1785
|
53
|
+
Author: Eric Wong <normalperson@yhbt.net>
|
54
|
+
Date: Wed Nov 16 18:58:47 2011 -0800
|
55
|
+
|
56
|
+
add list_keys module for listing keys
|
57
|
+
|
58
|
+
This may be useful for building directory indices.
|
59
|
+
|
60
|
+
commit 611cb7223064f99126388062c8197d4271859b92
|
61
|
+
Author: Eric Wong <normalperson@yhbt.net>
|
62
|
+
Date: Fri Nov 11 08:49:49 2011 +0000
|
63
|
+
|
64
|
+
pkg.mk: update to the latest version
|
65
|
+
|
3
66
|
commit 84e48c63074049f32660672b5a3c195d12dc3896
|
4
67
|
Author: Eric Wong <normalperson@yhbt.net>
|
5
68
|
Date: Fri Nov 11 08:46:12 2011 +0000
|
data/GIT-VERSION-FILE
CHANGED
@@ -1 +1 @@
|
|
1
|
-
GIT_VERSION = 0.
|
1
|
+
GIT_VERSION = 0.2.0
|
data/GIT-VERSION-GEN
CHANGED
data/LATEST
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
=== regurgitator 0.
|
1
|
+
=== regurgitator 0.2.0 / 2011-12-16 02:27 UTC
|
2
2
|
|
3
|
-
*
|
4
|
-
*
|
5
|
-
*
|
3
|
+
* add list_keys module for listing keys
|
4
|
+
* add :reproxy_key, overriding global REPROXY_KEY constant
|
5
|
+
* remove support for altip/altmask (hardly ever used)
|
6
6
|
|
data/NEWS
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
=== regurgitator 0.2.0 / 2011-12-16 02:27 UTC
|
2
|
+
|
3
|
+
* add list_keys module for listing keys
|
4
|
+
* add :reproxy_key, overriding global REPROXY_KEY constant
|
5
|
+
* remove support for altip/altmask (hardly ever used)
|
6
|
+
|
1
7
|
=== regurgitator 0.1.0 / 2011-11-11 08:47 UTC
|
2
8
|
|
3
9
|
* local_file: support HTTP Range: requests
|
data/lib/regurgitator.rb
CHANGED
@@ -13,10 +13,6 @@ require 'rpatricia'
|
|
13
13
|
# so just "require 'regurgitator'" in your code.
|
14
14
|
module Regurgitator
|
15
15
|
|
16
|
-
# This HTTP header is read to determine a location to reproxy to.
|
17
|
-
# Add this header in your nginx config.
|
18
|
-
REPROXY_KEY = 'HTTP_X_REPROXY_PATH'
|
19
|
-
|
20
16
|
autoload :ServerSettings, 'regurgitator/server_settings'
|
21
17
|
autoload :Domain, 'regurgitator/domain'
|
22
18
|
autoload :Device, 'regurgitator/device'
|
@@ -25,7 +21,7 @@ module Regurgitator
|
|
25
21
|
autoload :FileRequest, 'regurgitator/file_request'
|
26
22
|
autoload :Local, 'regurgitator/local'
|
27
23
|
autoload :LocalFile, 'regurgitator/local_file'
|
28
|
-
|
24
|
+
autoload :ListKeys, 'regurgitator/list_keys'
|
29
25
|
# Rack middlewares/apps
|
30
26
|
autoload :DomainPath, 'regurgitator/domain_path'
|
31
27
|
autoload :DomainHost, 'regurgitator/domain_host'
|
data/lib/regurgitator/device.rb
CHANGED
@@ -5,7 +5,7 @@ module Regurgitator::Device
|
|
5
5
|
|
6
6
|
# :stopdoc:
|
7
7
|
REFRESH_DEVICE = <<-EOS
|
8
|
-
SELECT d.devid, h.hostip, h.
|
8
|
+
SELECT d.devid, h.hostip, h.http_port, h.http_get_port
|
9
9
|
FROM device d
|
10
10
|
LEFT JOIN host h ON d.hostid = h.hostid
|
11
11
|
WHERE d.status IN ('readonly','alive','drain') AND h.status = 'alive'
|
@@ -54,18 +54,7 @@ module Regurgitator::Device
|
|
54
54
|
x[:zone] = zone_for(hostip)
|
55
55
|
devid = x[:devid]
|
56
56
|
o = { :path => "/dev#{devid}", :port => port, :host => hostip }
|
57
|
-
|
58
57
|
x[:uris] = { :pri => device_uri_pair!(o, get_port) }
|
59
|
-
x[:ipaddr][:altmask] = pat = Patricia.new
|
60
|
-
altmask = x[:altmask] and pat.add(altmask)
|
61
|
-
|
62
|
-
if altip = x[:altip]
|
63
|
-
x[:ipaddr][:altip] = altip
|
64
|
-
o[:host] = altip
|
65
|
-
o[:port] = port
|
66
|
-
x[:uris][:alt] = device_uri_pair!(o, get_port)
|
67
|
-
end
|
68
|
-
|
69
58
|
tmp[devid] = x
|
70
59
|
end
|
71
60
|
Regurgitator::Local.refresh_addrs!
|
@@ -27,7 +27,7 @@ class Regurgitator::DomainHost
|
|
27
27
|
raise TypeError, ":suffix must be a String or Regexp #{suffix.inspect}"
|
28
28
|
end
|
29
29
|
@domain_regexp = suffix
|
30
|
-
endpoint_init(app, opts[:db])
|
30
|
+
endpoint_init(app, opts[:db], opts[:reproxy_key])
|
31
31
|
end
|
32
32
|
|
33
33
|
def call(env) # :nodoc:
|
@@ -27,7 +27,8 @@ class Regurgitator::DomainPath
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
def initialize(app,
|
31
|
-
|
30
|
+
def initialize(app, opts) # :nodoc:
|
31
|
+
opts = { :db => opts } unless Hash === opts
|
32
|
+
endpoint_init(app, opts[:db], opts[:reproxy_key])
|
32
33
|
end
|
33
34
|
end
|
@@ -5,21 +5,20 @@ module Regurgitator::Endpoint
|
|
5
5
|
include Rack::Utils
|
6
6
|
include Rack::Mime
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
def endpoint_init(app, db)
|
8
|
+
def endpoint_init(app, db, reproxy_key = nil)
|
11
9
|
@app = app
|
12
10
|
@db = db
|
11
|
+
@reproxy_key = reproxy_key
|
13
12
|
file_info_init
|
14
13
|
end
|
15
14
|
|
16
15
|
def best_addr(env)
|
17
|
-
env.include?(
|
16
|
+
env.include?(@reproxy_key) ? env['REMOTE_ADDR'] : Regurgitator::Local.addr
|
18
17
|
end
|
19
18
|
|
20
19
|
# see nginx config examples for reproxy
|
21
20
|
def reproxy_path(env)
|
22
|
-
env[
|
21
|
+
env[@reproxy_key]
|
23
22
|
end
|
24
23
|
|
25
24
|
# allow users to specify desired "Save As" filenames in the query string
|
@@ -37,7 +37,7 @@ module Regurgitator::FileInfo
|
|
37
37
|
devinfo = devices[x[:devid]] or next
|
38
38
|
fid >= 10_000_000_000 and next # TODO: support larger FIDs
|
39
39
|
|
40
|
-
uris = devinfo[:uris][
|
40
|
+
uris = devinfo[:uris][:pri]
|
41
41
|
nfid = sprintf('%010u', fid)
|
42
42
|
/\A(\d)(\d{3})(\d{3})(?:\d{3})\z/ =~ nfid
|
43
43
|
fid_path = "/#$1/#$2/#$3/#{nfid}.fid"
|
@@ -51,8 +51,4 @@ module Regurgitator::FileInfo
|
|
51
51
|
uris = info[:uris] = read_uris.empty? ? drain_uris : read_uris
|
52
52
|
(uris.empty? && ! update) ? file_info(env, domain, dkey, true) : info
|
53
53
|
end
|
54
|
-
|
55
|
-
def alt_zone?(zone, devinfo)
|
56
|
-
zone == :alt || devinfo[:ipaddr][:altmask].include?(zone)
|
57
|
-
end
|
58
54
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: binary -*-
|
2
|
+
module Regurgitator::ListKeys
|
3
|
+
include Regurgitator::Domain
|
4
|
+
|
5
|
+
LIST_KEYS_MAX = 1000
|
6
|
+
|
7
|
+
def list_keys(domain, opts = {})
|
8
|
+
dmid = get_dmid(domain) or return
|
9
|
+
|
10
|
+
after, limit, prefix = opts[:after], opts[:limit], opts[:prefix]
|
11
|
+
limit ||= LIST_KEYS_MAX
|
12
|
+
|
13
|
+
Integer === limit or
|
14
|
+
raise ArgumentError, ":limit not an Integer=#{limit.inspect}"
|
15
|
+
|
16
|
+
limit = LIST_KEYS_MAX if limit > LIST_KEYS_MAX
|
17
|
+
sql = "SELECT fid,dkey,length,devcount,classid " \
|
18
|
+
"FROM file WHERE dmid = #{dmid}"
|
19
|
+
sql << " AND dkey LIKE /*! BINARY */ #{@db.literal(prefix+'%')}" if prefix
|
20
|
+
sql << " AND dkey > #{@db.literal(after)}" if after
|
21
|
+
sql << " ORDER BY dkey LIMIT #{limit}"
|
22
|
+
|
23
|
+
# we don't enforce collation here, give DBAs some freedom...
|
24
|
+
ds = @db[sql]
|
25
|
+
block_given? ? ds.each { |row| yield(row) } : ds.to_a
|
26
|
+
end
|
27
|
+
end
|
data/pkg.mk
CHANGED
@@ -69,7 +69,7 @@ doc:: .document .wrongdoc.yml $(pkg_extra)
|
|
69
69
|
$(RM) -r doc
|
70
70
|
$(WRONGDOC) all
|
71
71
|
install -m644 COPYING doc/COPYING
|
72
|
-
install -m644 $(shell grep '^[A-Z]' .document) doc/
|
72
|
+
install -m644 $(shell LC_ALL=C grep '^[A-Z]' .document) doc/
|
73
73
|
|
74
74
|
ifneq ($(VERSION),)
|
75
75
|
pkggem := pkg/$(rfpackage)-$(VERSION).gem
|
@@ -168,7 +168,7 @@ doc_gz:
|
|
168
168
|
for i in $(docs); do \
|
169
169
|
gzip --rsyncable -9 < $$i > $$i.gz; touch -r $$i $$i.gz; done
|
170
170
|
check-warnings:
|
171
|
-
@(for i in $$(git ls-files '*.rb'|grep -v '^setup\.rb$$'); \
|
171
|
+
@(for i in $$(git ls-files '*.rb'| grep -v '^setup\.rb$$'); \
|
172
172
|
do $(RUBY) -d -W2 -c $$i; done) | grep -v '^Syntax OK$$' || :
|
173
173
|
|
174
174
|
.PHONY: all .FORCE-GIT-VERSION-FILE doc test $(test_units) manifest
|
data/t/domain_host.ru
CHANGED
data/t/domain_path.ru
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
require 'regurgitator'
|
2
2
|
use Rack::ContentLength
|
3
3
|
use Rack::ContentType, 'text/plain'
|
4
|
-
|
5
|
-
|
4
|
+
o = {
|
5
|
+
:db => Sequel.connect(ENV['TEST_SEQUEL']),
|
6
|
+
:reproxy_key => "HTTP_X_REPROXY_PATH",
|
7
|
+
}
|
8
|
+
run Regurgitator::DomainPath.new(lambda { |env| [ 404, [], [] ] }, o)
|
data/t/my-tap-lib.sh
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#!/bin/sh
|
2
|
-
# Copyright (c) 2009 Eric Wong <normalperson@yhbt.net>
|
2
|
+
# Copyright (c) 2009, 2010 Eric Wong <normalperson@yhbt.net>
|
3
3
|
#
|
4
4
|
# TAP-producing shell library for POSIX-compliant Bourne shells We do
|
5
5
|
# not _rely_ on Bourne Again features, though we will use "set -o
|
@@ -188,9 +188,10 @@ then
|
|
188
188
|
|
189
189
|
(
|
190
190
|
# use a subshell so seds are not waitable
|
191
|
-
$SED -e 's/^/#: /' $t_stdout &
|
192
|
-
$SED -e 's/^/#! /' $t_stderr &
|
191
|
+
$SED -e 's/^/#: /' < $t_stdout &
|
192
|
+
$SED -e 's/^/#! /' < $t_stderr &
|
193
193
|
) &
|
194
|
+
wait
|
194
195
|
exec > $t_stdout 2> $t_stderr
|
195
196
|
else
|
196
197
|
exec > /dev/null 2> /dev/null
|
data/t/one_domain.ru
CHANGED
@@ -0,0 +1,40 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "regurgitator"
|
3
|
+
require "tempfile"
|
4
|
+
|
5
|
+
class TestListKeys < Test::Unit::TestCase
|
6
|
+
include Regurgitator::ListKeys
|
7
|
+
def setup
|
8
|
+
@tmp = Tempfile.new(%w(regurgitator_list_keys .sqlite3))
|
9
|
+
rv = system("sqlite3 #{@tmp.path} < t/fixtures.sql")
|
10
|
+
assert rv, $?.inspect
|
11
|
+
@db = Sequel.connect("sqlite://#{@tmp.path}")
|
12
|
+
domain_init
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_list_keys
|
16
|
+
a = list_keys("d", {})
|
17
|
+
assert_kind_of Array, a
|
18
|
+
row = a[0]
|
19
|
+
assert_equal "blah", row[:dkey]
|
20
|
+
[ :fid, :length, :devcount, :classid ].each do |key|
|
21
|
+
assert_kind_of Integer, row[key]
|
22
|
+
end
|
23
|
+
|
24
|
+
list_keys("d", {:prefix => "bla"})
|
25
|
+
assert_equal row, a[0]
|
26
|
+
assert_empty list_keys("d", {:prefix => "blahh"})
|
27
|
+
assert_empty list_keys("d", {:prefix => "bla", :after => "blah"})
|
28
|
+
|
29
|
+
assert_nil list_keys("afadf")
|
30
|
+
list_keys("d") { |r| assert_equal row, r }
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_list_keys_insensitive
|
34
|
+
a = list_keys("d", :prefix => "B")
|
35
|
+
assert a.empty?, a.inspect << " not empty"
|
36
|
+
a = list_keys("d", :prefix => "b")
|
37
|
+
assert_equal 1, a.size
|
38
|
+
assert_equal "blah", a[0][:dkey]
|
39
|
+
end
|
40
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: regurgitator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Regurgitators
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-12-16 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rack
|
@@ -111,6 +111,7 @@ extra_rdoc_files:
|
|
111
111
|
- lib/regurgitator/endpoint.rb
|
112
112
|
- lib/regurgitator/file_info.rb
|
113
113
|
- lib/regurgitator/file_request.rb
|
114
|
+
- lib/regurgitator/list_keys.rb
|
114
115
|
- lib/regurgitator/local.rb
|
115
116
|
- lib/regurgitator/local_file.rb
|
116
117
|
- lib/regurgitator/one_domain.rb
|
@@ -143,6 +144,7 @@ files:
|
|
143
144
|
- lib/regurgitator/endpoint.rb
|
144
145
|
- lib/regurgitator/file_info.rb
|
145
146
|
- lib/regurgitator/file_request.rb
|
147
|
+
- lib/regurgitator/list_keys.rb
|
146
148
|
- lib/regurgitator/local.rb
|
147
149
|
- lib/regurgitator/local_file.rb
|
148
150
|
- lib/regurgitator/one_domain.rb
|
@@ -163,6 +165,7 @@ files:
|
|
163
165
|
- t/t0002-domain_host.sh
|
164
166
|
- t/t0003-one_domain.sh
|
165
167
|
- t/test-lib.sh
|
168
|
+
- test/test_list_keys.rb
|
166
169
|
- test/test_local.rb
|
167
170
|
- test/test_server_settings.rb
|
168
171
|
homepage: http://bogomips.org/regurgitator/
|
@@ -197,10 +200,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
197
200
|
requirements: []
|
198
201
|
|
199
202
|
rubyforge_project: rainbows
|
200
|
-
rubygems_version: 1.8.
|
203
|
+
rubygems_version: 1.8.11
|
201
204
|
signing_key:
|
202
205
|
specification_version: 3
|
203
206
|
summary: read-only Rack endpoints for MogileFS
|
204
207
|
test_files:
|
205
208
|
- test/test_local.rb
|
206
209
|
- test/test_server_settings.rb
|
210
|
+
- test/test_list_keys.rb
|