diff --git a/config.yml.example b/config.yml.example index 6e90101..a4069e4 100644 --- a/config.yml.example +++ b/config.yml.example @@ -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 diff --git a/lib/remote_storage/riak.rb b/lib/remote_storage/riak.rb index ec06e6d..5f19c9e 100644 --- a/lib/remote_storage/riak.rb +++ b/lib/remote_storage/riak.rb @@ -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. diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ac20b62..23b086f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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