storage manager: add rclone backend.

This commit is contained in:
evazion
2019-12-11 01:44:23 -06:00
parent 2e6486ab5f
commit afea704b55

View File

@@ -0,0 +1,34 @@
class StorageManager::Rclone < StorageManager
class Error < StandardError; end
attr_reader :remote, :bucket, :rclone_options
def initialize(remote:, bucket:, rclone_options: {}, **options)
@remote = remote
@bucket = bucket
@rclone_options = rclone_options
super(**options)
end
def store(file, path)
rclone "copyto", file.path, key(path)
end
def delete(path)
rclone "delete", key(path)
end
def open(path)
file = Tempfile.new(binmode: true)
rclone "copyto", key(path), file.path
file
end
def rclone(*args)
success = system("rclone", *rclone_options, *args)
raise Error, "rclone #{$?}" if !success
end
def key(path)
":#{remote}:#{bucket}#{path}"
end
end