Make config settable from outside the app
This commit is contained in:
parent
064b8dc06a
commit
64698b8503
@ -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
|
||||
|
@ -9,15 +9,22 @@ class LiquorCabinet < Sinatra::Base
|
||||
|
||||
include RemoteStorage::Riak
|
||||
|
||||
def self.config=(config)
|
||||
@config = config
|
||||
end
|
||||
|
||||
def self.config
|
||||
return @config if @config
|
||||
config = File.read(File.expand_path('config.yml', File.dirname(__FILE__)))
|
||||
@config = YAML.load(config)[ENV['RACK_ENV']]
|
||||
end
|
||||
|
||||
configure :development do
|
||||
register Sinatra::Reloader
|
||||
enable :logging
|
||||
end
|
||||
|
||||
configure :development, :test, :production do
|
||||
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
|
||||
configure do
|
||||
end
|
||||
|
||||
before "/:user/:category/:key" do
|
||||
|
Loading…
x
Reference in New Issue
Block a user