Merge branch 'master' into stable
This commit is contained in:
commit
031ce9453c
@ -4,7 +4,7 @@ require "cgi"
|
||||
require "active_support/core_ext/time/conversions"
|
||||
require "active_support/core_ext/numeric/time"
|
||||
require "redis"
|
||||
require 'digest/md5'
|
||||
require "digest/md5"
|
||||
|
||||
module RemoteStorage
|
||||
class Swift
|
||||
@ -12,8 +12,8 @@ module RemoteStorage
|
||||
attr_accessor :settings, :server
|
||||
|
||||
def initialize(settings, server)
|
||||
self.settings = settings
|
||||
self.server = server
|
||||
@settings = settings
|
||||
@server = server
|
||||
end
|
||||
|
||||
def authorize_request(user, directory, token, listing=false)
|
||||
@ -313,7 +313,7 @@ module RemoteStorage
|
||||
end
|
||||
|
||||
def default_headers
|
||||
@default_headers ||= {"x-auth-token" => settings.swift["token"]}
|
||||
{"x-auth-token" => swift_token}
|
||||
end
|
||||
|
||||
def do_put_request(url, data, content_type)
|
||||
@ -350,5 +350,22 @@ module RemoteStorage
|
||||
Digest::MD5.hexdigest objects.map { |o| o["hash"] }.join
|
||||
end
|
||||
end
|
||||
|
||||
def reload_swift_token
|
||||
server.logger.debug "Reloading swift token. Old token: #{settings.swift_token}"
|
||||
settings.swift_token = File.read(swift_token_path)
|
||||
settings.swift_token_loaded_at = Time.now
|
||||
server.logger.debug "Reloaded swift token. New token: #{settings.swift_token}"
|
||||
end
|
||||
|
||||
def swift_token_path
|
||||
"tmp/swift_token.txt"
|
||||
end
|
||||
|
||||
def swift_token
|
||||
reload_swift_token if Time.now - settings.swift_token_loaded_at > 3600
|
||||
|
||||
settings.swift_token
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -20,16 +20,24 @@ class LiquorCabinet < Sinatra::Base
|
||||
register Sinatra::ConfigFile
|
||||
set :environments, %w{development test production staging}
|
||||
config_file 'config.yml'
|
||||
if settings.respond_to? :swift
|
||||
set :swift_token, File.read("tmp/swift_token.txt")
|
||||
set :swift_token_loaded_at, Time.now
|
||||
end
|
||||
end
|
||||
|
||||
configure :development do
|
||||
register Sinatra::Reloader
|
||||
also_reload "lib/remote_storage/*.rb"
|
||||
enable :logging
|
||||
set :logging, Logger::DEBUG
|
||||
end
|
||||
|
||||
configure :production do
|
||||
# Disable logging
|
||||
require "rack/common_logger"
|
||||
end
|
||||
|
||||
configure :production, :staging do
|
||||
require "rack/common_logger"
|
||||
if ENV['SENTRY_DSN']
|
||||
require "raven"
|
||||
|
||||
@ -43,6 +51,10 @@ class LiquorCabinet < Sinatra::Base
|
||||
end
|
||||
end
|
||||
|
||||
configure :staging do
|
||||
set :logging, Logger::DEBUG
|
||||
end
|
||||
|
||||
#
|
||||
# Cabinet doors
|
||||
#
|
||||
@ -120,7 +132,6 @@ class LiquorCabinet < Sinatra::Base
|
||||
if settings.respond_to? :riak
|
||||
RemoteStorage::Riak.new(settings, self)
|
||||
elsif settings.respond_to? :swift
|
||||
settings.swift["token"] = File.read("tmp/swift_token.txt")
|
||||
RemoteStorage::Swift.new(settings, self)
|
||||
else
|
||||
puts <<-EOF
|
||||
|
Loading…
x
Reference in New Issue
Block a user