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:
|
||||
host: localhost
|
||||
http_port: 8098
|
||||
buckets:
|
||||
data: "user_data"
|
||||
directories: "rs_directories"
|
||||
authorizations: "authorizations"
|
||||
|
||||
development:
|
||||
<<: *defaults
|
||||
|
||||
test:
|
||||
riak:
|
||||
host: localhost
|
||||
http_port: 8098
|
||||
<<: *defaults
|
||||
buckets:
|
||||
data: "user_data_test"
|
||||
directories: "rs_directories_test"
|
||||
authorizations: "authorizations_test"
|
||||
|
||||
production:
|
||||
<<: *defaults
|
||||
|
@ -12,18 +12,22 @@ module RemoteStorage
|
||||
end
|
||||
|
||||
def data_bucket
|
||||
@data_bucket ||= client.bucket("user_data")
|
||||
@data_bucket ||= client.bucket(LiquorCabinet.config['buckets']['data'])
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
def authorize_request(user, directory, token)
|
||||
request_method = env["REQUEST_METHOD"]
|
||||
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)
|
||||
|
||||
halt 403 unless permission
|
||||
@ -181,7 +185,7 @@ module RemoteStorage
|
||||
|
||||
map_reduce = ::Riak::MapReduce.new(client)
|
||||
all_keys.each do |key|
|
||||
map_reduce.add("user_data", key)
|
||||
map_reduce.add(data_bucket.name, key)
|
||||
end
|
||||
|
||||
map_reduce.
|
||||
@ -212,7 +216,7 @@ module RemoteStorage
|
||||
|
||||
map_reduce = ::Riak::MapReduce.new(client)
|
||||
all_keys.each do |key|
|
||||
map_reduce.add("rs_directories", key)
|
||||
map_reduce.add(directory_bucket.name, key)
|
||||
end
|
||||
|
||||
map_reduce.
|
||||
|
@ -11,9 +11,10 @@ require 'riak'
|
||||
set :environment, :test
|
||||
ENV["RACK_ENV"] = "test"
|
||||
|
||||
config = File.read(File.expand_path('../config.yml', File.dirname(__FILE__)))
|
||||
riak_config = YAML.load(config)[ENV['RACK_ENV']]['riak'].symbolize_keys
|
||||
set :riak_config, riak_config
|
||||
config_file = File.read(File.expand_path('../config.yml', File.dirname(__FILE__)))
|
||||
config = YAML.load(config_file)[ENV['RACK_ENV']]
|
||||
set :riak_config, config['riak'].symbolize_keys
|
||||
set :bucket_config, config['buckets']
|
||||
|
||||
::Riak.disable_list_keys_warnings = true
|
||||
|
||||
@ -26,15 +27,15 @@ def storage_client
|
||||
end
|
||||
|
||||
def data_bucket
|
||||
@data_bucket ||= storage_client.bucket("user_data")
|
||||
@data_bucket ||= storage_client.bucket(settings.bucket_config['data'])
|
||||
end
|
||||
|
||||
def auth_bucket
|
||||
@auth_bucket ||= storage_client.bucket("authorizations")
|
||||
@auth_bucket ||= storage_client.bucket(settings.bucket_config['authorizations'])
|
||||
end
|
||||
|
||||
def directory_bucket
|
||||
@directory_bucket ||= storage_client.bucket("rs_directories")
|
||||
@directory_bucket ||= storage_client.bucket(settings.bucket_config['directories'])
|
||||
end
|
||||
|
||||
def purge_all_buckets
|
||||
|
Loading…
x
Reference in New Issue
Block a user