mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
cc69d10c89
Refactor ninefold to provide generic Atmos support. Add an additional argument, when compared to ninefold, which is the endpoint. The endpoint should be a full URL, e.g. https://storage.provider.com:1337/atmos. The API path and port are optional. If the port is not specified, it is inferred from the protocol.
48 lines
1.4 KiB
Ruby
48 lines
1.4 KiB
Ruby
require 'fog/core/collection'
|
|
require 'fog/atmos/models/storage/directory'
|
|
|
|
module Fog
|
|
module Storage
|
|
class Atmos
|
|
|
|
class Directories < Fog::Collection
|
|
|
|
attribute :directory
|
|
|
|
model Fog::Storage::Atmos::Directory
|
|
|
|
def all
|
|
directory ? ns = directory.key : ns = ''
|
|
ns = ns + '/' unless ns =~ /\/$/
|
|
data = connection.get_namespace(ns).body[:DirectoryList]
|
|
data = {:DirectoryEntry => []} if data.kind_of? String
|
|
data[:DirectoryEntry] = [data[:DirectoryEntry]] if data[:DirectoryEntry].kind_of? Hash
|
|
dirs = data[:DirectoryEntry].select {|de| de[:FileType] == 'directory'}
|
|
dirs.each do |d|
|
|
d[:Filename] = ns + d[:Filename] if directory
|
|
d[:Filename] += '/' unless d[:Filename] =~ /\/$/
|
|
end
|
|
load(dirs)
|
|
end
|
|
|
|
def get(key, options = {})
|
|
return nil if key == '' # Root dir shouldn't be retrieved like this.
|
|
key =~ /\/$/ ? ns = key : ns = key + '/'
|
|
res = connection.get_namespace ns
|
|
emc_meta = res.headers['x-emc-meta']
|
|
obj_id = emc_meta.scan(/objectid=(\w+),/).flatten[0]
|
|
new(:objectid => obj_id, :key => ns)
|
|
rescue Fog::Storage::Atmos::NotFound
|
|
nil
|
|
end
|
|
|
|
def new(attributes ={})
|
|
attributes = {:directory => directory}.merge(attributes) if directory
|
|
super(attributes)
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
end
|
|
end
|