Use directory backend config from redis instead of config file
This commit is contained in:
parent
16dcc56fba
commit
a4673e9661
@ -20,7 +20,6 @@ development: &defaults
|
||||
# redis:
|
||||
# host: localhost
|
||||
# port: 6379
|
||||
# use_redis_dir_listing: true
|
||||
|
||||
test:
|
||||
<<: *defaults
|
||||
|
||||
@ -75,7 +75,7 @@ module RemoteStorage
|
||||
end
|
||||
|
||||
def get_directory_listing(user, directory)
|
||||
if settings.use_redis_dir_listing
|
||||
if directory_backend(user).match /new/
|
||||
get_directory_listing_from_redis(user, directory)
|
||||
else
|
||||
get_directory_listing_from_swift(user, directory)
|
||||
@ -289,7 +289,7 @@ module RemoteStorage
|
||||
end
|
||||
|
||||
def has_name_collision?(user, directory, key)
|
||||
if settings.use_redis_dir_listing
|
||||
if directory_backend(user).match /new/
|
||||
has_name_collision_via_redis?(user, directory, key)
|
||||
else
|
||||
has_name_collision_via_swift?(user, directory, key)
|
||||
@ -518,6 +518,10 @@ module RemoteStorage
|
||||
@redis ||= Redis.new(host: settings.redis["host"], port: settings.redis["port"])
|
||||
end
|
||||
|
||||
def directory_backend(user)
|
||||
@directory_backend ||= redis.get("rs_config:dir_backend:#{user}") || "legacy"
|
||||
end
|
||||
|
||||
def etag_for(body)
|
||||
objects = JSON.parse(body)
|
||||
|
||||
|
||||
@ -38,7 +38,7 @@ def redis
|
||||
end
|
||||
|
||||
def purge_redis
|
||||
redis.keys("*").each do |key|
|
||||
redis.keys("rs_*").each do |key|
|
||||
redis.del key
|
||||
end
|
||||
end
|
||||
|
||||
@ -16,6 +16,7 @@ describe "App" do
|
||||
|
||||
before do
|
||||
purge_redis
|
||||
redis.set "rs_config:dir_backend:phil", "new"
|
||||
end
|
||||
|
||||
context "authorized" do
|
||||
@ -107,6 +108,7 @@ describe "App" do
|
||||
|
||||
before do
|
||||
purge_redis
|
||||
redis.set "rs_config:dir_backend:phil", "new"
|
||||
end
|
||||
|
||||
context "authorized" do
|
||||
@ -191,9 +193,11 @@ describe "App" do
|
||||
|
||||
before do
|
||||
purge_redis
|
||||
redis.set "rs_config:dir_backend:phil", "new"
|
||||
end
|
||||
|
||||
context "authorized" do
|
||||
|
||||
before do
|
||||
redis.sadd "authorizations:phil:amarillo", [":rw"]
|
||||
header "Authorization", "Bearer amarillo"
|
||||
@ -255,6 +259,33 @@ describe "App" do
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
context "with legacy directory backend" do
|
||||
|
||||
before do
|
||||
redis.sadd "authorizations:phil:amarillo", [":rw"]
|
||||
header "Authorization", "Bearer amarillo"
|
||||
|
||||
put_stub = OpenStruct.new(headers: {etag: "bla"})
|
||||
RestClient.stub :put, put_stub do
|
||||
put "/phil/food/aguacate", "si"
|
||||
put "/phil/food/camaron", "yummi"
|
||||
end
|
||||
|
||||
redis.set "rs_config:dir_backend:phil", "legacy"
|
||||
end
|
||||
|
||||
it "serves directory listing from Swift backend" do
|
||||
RemoteStorage::Swift.stub_any_instance :get_directory_listing_from_swift, "directory listing" do
|
||||
get "/phil/food/"
|
||||
end
|
||||
|
||||
last_response.status.must_equal 200
|
||||
last_response.body.must_equal "directory listing"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user