Harbor::FileStore::Mosso
Parent
Namespace
Attributes
Public Class Methods
Public Instance Methods
container()
# File lib/harbor/file_store/mosso.rb, line 123 123: def container 124: @container ||= connect! 125: end
delete(filename)
# File lib/harbor/file_store/mosso.rb, line 63 63: def delete(filename) 64: filename = strip_leading_slash(filename) 65: container.delete_object(filename) 66: end
exists?(filename)
# File lib/harbor/file_store/mosso.rb, line 68 68: def exists?(filename) 69: filename = strip_leading_slash(filename) 70: container.object_exists?(filename) 71: end
get(path)
# File lib/harbor/file_store/mosso.rb, line 16 16: def get(path) 17: path = strip_leading_slash(path) 18: Harbor::FileStore::File.new(self, path) 19: end
open(filename, mode = "r", &block)
# File lib/harbor/file_store/mosso.rb, line 73 73: def open(filename, mode = "r", &block) 74: filename = strip_leading_slash(filename) 75: url = container.connection.storagehost + container.connection.storagepath + "/#{container.name}/#{filename}" 76: token = container.connection.authtoken 77: 78: if mode == "r" 79: command = "curl -s -X \"GET\" \\\\\n-D - \\\\\n-H \"X-Auth-Token: \#{token}\" \\\\\nhttps://\#{url}\n" 80: 81: stream = IO::popen(command, "r") 82: 83: headers = [] 84: 85: while line = stream.gets 86: break if line == "\r\n" 87: headers << line 88: end 89: elsif mode =~ /w/ 90: make_path(::File.dirname(filename)) 91: 92: command = "curl -X \"PUT\" \\\\\n-T \#{\"-\"} \\\\\n-H \"X-Auth-Token: \#{token}\" \\\\\n-H \"Content-Type: text/plain\" \\\\\nhttps://\#{url}\n" 93: 94: stream = IO::popen(command, "w") 95: end 96: 97: if block_given? 98: yield stream 99: stream.close 100: else 101: stream 102: end 103: end
put(filename, file)
# File lib/harbor/file_store/mosso.rb, line 21 21: def put(filename, file) 22: filename = strip_leading_slash(filename) 23: url = container.connection.storagehost + container.connection.storagepath + "/#{container.name}/#{filename}" 24: token = container.connection.authtoken 25: 26: path = nil 27: 28: if file.is_a?(::File) 29: path = file.path 30: elsif file.is_a?(Harbor::FileStore::File) && file.store.local? 31: path = file.store.path + file.path 32: end 33: 34: make_path(::File.dirname(path)) 35: 36: command = "curl -X \"PUT\" \\\\\n-T \#{path ? Shellwords.escape(path.to_s) : \"-\"} \\\\\n-H \"X-Auth-Token: \#{token}\" \\\\\n-H \"Content-Type: text/plain\" \\\\\nhttps://\#{url}\n" 37: 38: if path 39: system(command) 40: else 41: IO::popen(command, "w") do |session| 42: case file 43: when ::File 44: while data = file.read(500_000) 45: session.write(data) 46: end 47: when Harbor::FileStore::File 48: file.read do |block| 49: session.write(block) 50: end 51: end 52: end 53: end 54: end
Private Instance Methods
connect!()
# File lib/harbor/file_store/mosso.rb, line 129 129: def connect! 130: @connection = CloudFiles::Connection.new(@username, @api_key, true) 131: @container = @connection.container(@container_name) 132: end
connected?()
# File lib/harbor/file_store/mosso.rb, line 134 134: def connected? 135: @connection && @connection.authok? 136: end
make_path(path)
# File lib/harbor/file_store/mosso.rb, line 138 138: def make_path(path) 139: if path == "." || path == "/" 140: return 141: else 142: unless @container.object_exists?(path) 143: object = @container.create_object(path) 144: object.write(nil, { 'Content-Type' => 'application/directory'} ) 145: end 146: make_path(::File.dirname(path)) 147: end 148: end