class Bosh::Blobstore::SimpleBlobstoreServer
Constants
- BUFFER_SIZE
Public Class Methods
new(config)
click to toggle source
Calls superclass method
# File lib/simple_blobstore_server.rb, line 17 def initialize(config) super @path = config["path"] @nginx_path = config["nginx_path"] if File.exist?(@path) raise "Invalid path" unless File.directory?(@path) else FileUtils.mkdir_p(@path) end raise "Invalid user list" unless config["users"].kind_of?(Hash) @users = Set.new config["users"].each do |username, password| @users << [username, password] end raise "Must have at least one user" if @users.empty? end
Public Instance Methods
create(params)
click to toggle source
# File lib/simple_blobstore_server.rb, line 77 def create(params) if params[:content] && params[:content][:tempfile] # Process uploads coming directly to the simple blobstore create_file(params[:id]) do |file_name| tempfile = params[:content][:tempfile] FileUtils.copy_file(tempfile.path, file_name) end elsif params["content.name"] && params["content.path"] # Process uploads arriving via nginx create_file(params[:id]) do |file_name| FileUtils.mv(params["content.path"], file_name) end else error(400) end end
create_file(object_id) { |file_name| ... }
click to toggle source
# File lib/simple_blobstore_server.rb, line 62 def create_file(object_id) object_id ||= generate_object_id file_name = get_file_name(object_id) error(409) if File.exist?(file_name) FileUtils.mkdir_p(File.dirname(file_name)) yield file_name status(200) content_type(:text) object_id end
generate_object_id()
click to toggle source
# File lib/simple_blobstore_server.rb, line 46 def generate_object_id SecureRandom.uuid end
get_file_name(object_id)
click to toggle source
# File lib/simple_blobstore_server.rb, line 36 def get_file_name(object_id) sha1 = Digest::SHA1.hexdigest(object_id) File.join(@path, sha1[0, 2], object_id) end
get_nginx_path(object_id)
click to toggle source
# File lib/simple_blobstore_server.rb, line 41 def get_nginx_path(object_id) sha1 = Digest::SHA1.hexdigest(object_id) "#{@nginx_path}/#{sha1[0, 2]}/#{object_id}" end
protected!()
click to toggle source
# File lib/simple_blobstore_server.rb, line 50 def protected! unless authorized? response['WWW-Authenticate'] = %(Basic realm="Authenticate") throw(:halt, [401, "Not authorized\n"]) end end