Make config settable from outside the app

This commit is contained in:
2012-02-29 14:07:51 +01:00
parent 064b8dc06a
commit 64698b8503
2 changed files with 16 additions and 8 deletions

View File

@@ -3,10 +3,14 @@ require "riak"
module RemoteStorage
module Riak
def client
return @client if @client
@client = ::Riak::Client.new(LiquorCabinet.config['riak'].symbolize_keys)
end
def authorize_request(user, category, token)
return true if category == "public" && env["REQUEST_METHOD"] == "GET"
client = ::Riak::Client.new(settings.riak_config)
categories = client.bucket("authorizations").get("#{user}:#{token}").data
halt 403 unless categories.include?(category)
@@ -15,14 +19,12 @@ module RemoteStorage
end
def get_data(user, category, key)
client = ::Riak::Client.new(settings.riak_config)
client.bucket("user_data").get("#{user}:#{category}:#{key}").data
rescue ::Riak::HTTPFailedRequest
halt 404
end
def put_data(user, category, key, data)
client = ::Riak::Client.new(settings.riak_config)
object = client.bucket("user_data").new("#{user}:#{category}:#{key}")
object.content_type = "text/plain"
object.data = data
@@ -32,7 +34,6 @@ module RemoteStorage
end
def delete_data(user, category, key)
client = ::Riak::Client.new(settings.riak_config)
riak_response = client.bucket("user_data").delete("#{user}:#{category}:#{key}")
halt riak_response[:code]
rescue ::Riak::HTTPFailedRequest