Make bucket names configurable by environment (refs #16)
This commit is contained in:
parent
d1acfe88e8
commit
84c1f419be
@ -1,11 +1,21 @@
|
|||||||
development:
|
defaults: &defaults
|
||||||
riak:
|
riak:
|
||||||
host: localhost
|
host: localhost
|
||||||
http_port: 8098
|
http_port: 8098
|
||||||
|
buckets:
|
||||||
|
data: "user_data"
|
||||||
|
directories: "rs_directories"
|
||||||
|
authorizations: "authorizations"
|
||||||
|
|
||||||
|
development:
|
||||||
|
<<: *defaults
|
||||||
|
|
||||||
test:
|
test:
|
||||||
riak:
|
<<: *defaults
|
||||||
host: localhost
|
buckets:
|
||||||
http_port: 8098
|
data: "user_data_test"
|
||||||
|
directories: "rs_directories_test"
|
||||||
|
authorizations: "authorizations_test"
|
||||||
|
|
||||||
production:
|
production:
|
||||||
|
<<: *defaults
|
||||||
|
@ -12,18 +12,22 @@ module RemoteStorage
|
|||||||
end
|
end
|
||||||
|
|
||||||
def data_bucket
|
def data_bucket
|
||||||
@data_bucket ||= client.bucket("user_data")
|
@data_bucket ||= client.bucket(LiquorCabinet.config['buckets']['data'])
|
||||||
end
|
end
|
||||||
|
|
||||||
def directory_bucket
|
def directory_bucket
|
||||||
@directory_bucket ||= client.bucket("rs_directories")
|
@directory_bucket ||= client.bucket(LiquorCabinet.config['buckets']['directories'])
|
||||||
|
end
|
||||||
|
|
||||||
|
def auth_bucket
|
||||||
|
@auth_bucket ||= client.bucket(LiquorCabinet.config['buckets']['authorizations'])
|
||||||
end
|
end
|
||||||
|
|
||||||
def authorize_request(user, directory, token)
|
def authorize_request(user, directory, token)
|
||||||
request_method = env["REQUEST_METHOD"]
|
request_method = env["REQUEST_METHOD"]
|
||||||
return true if directory.split("/").first == "public" && request_method == "GET"
|
return true if directory.split("/").first == "public" && request_method == "GET"
|
||||||
|
|
||||||
authorizations = client.bucket("authorizations").get("#{user}:#{token}").data
|
authorizations = auth_bucket.get("#{user}:#{token}").data
|
||||||
permission = directory_permission(authorizations, directory)
|
permission = directory_permission(authorizations, directory)
|
||||||
|
|
||||||
halt 403 unless permission
|
halt 403 unless permission
|
||||||
@ -181,7 +185,7 @@ module RemoteStorage
|
|||||||
|
|
||||||
map_reduce = ::Riak::MapReduce.new(client)
|
map_reduce = ::Riak::MapReduce.new(client)
|
||||||
all_keys.each do |key|
|
all_keys.each do |key|
|
||||||
map_reduce.add("user_data", key)
|
map_reduce.add(data_bucket.name, key)
|
||||||
end
|
end
|
||||||
|
|
||||||
map_reduce.
|
map_reduce.
|
||||||
@ -212,7 +216,7 @@ module RemoteStorage
|
|||||||
|
|
||||||
map_reduce = ::Riak::MapReduce.new(client)
|
map_reduce = ::Riak::MapReduce.new(client)
|
||||||
all_keys.each do |key|
|
all_keys.each do |key|
|
||||||
map_reduce.add("rs_directories", key)
|
map_reduce.add(directory_bucket.name, key)
|
||||||
end
|
end
|
||||||
|
|
||||||
map_reduce.
|
map_reduce.
|
||||||
|
@ -11,9 +11,10 @@ require 'riak'
|
|||||||
set :environment, :test
|
set :environment, :test
|
||||||
ENV["RACK_ENV"] = "test"
|
ENV["RACK_ENV"] = "test"
|
||||||
|
|
||||||
config = File.read(File.expand_path('../config.yml', File.dirname(__FILE__)))
|
config_file = File.read(File.expand_path('../config.yml', File.dirname(__FILE__)))
|
||||||
riak_config = YAML.load(config)[ENV['RACK_ENV']]['riak'].symbolize_keys
|
config = YAML.load(config_file)[ENV['RACK_ENV']]
|
||||||
set :riak_config, riak_config
|
set :riak_config, config['riak'].symbolize_keys
|
||||||
|
set :bucket_config, config['buckets']
|
||||||
|
|
||||||
::Riak.disable_list_keys_warnings = true
|
::Riak.disable_list_keys_warnings = true
|
||||||
|
|
||||||
@ -26,15 +27,15 @@ def storage_client
|
|||||||
end
|
end
|
||||||
|
|
||||||
def data_bucket
|
def data_bucket
|
||||||
@data_bucket ||= storage_client.bucket("user_data")
|
@data_bucket ||= storage_client.bucket(settings.bucket_config['data'])
|
||||||
end
|
end
|
||||||
|
|
||||||
def auth_bucket
|
def auth_bucket
|
||||||
@auth_bucket ||= storage_client.bucket("authorizations")
|
@auth_bucket ||= storage_client.bucket(settings.bucket_config['authorizations'])
|
||||||
end
|
end
|
||||||
|
|
||||||
def directory_bucket
|
def directory_bucket
|
||||||
@directory_bucket ||= storage_client.bucket("rs_directories")
|
@directory_bucket ||= storage_client.bucket(settings.bucket_config['directories'])
|
||||||
end
|
end
|
||||||
|
|
||||||
def purge_all_buckets
|
def purge_all_buckets
|
||||||
|
Loading…
x
Reference in New Issue
Block a user