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