2011-06-16 00:40:32 -04:00
|
|
|
require 'fog/core/collection'
|
2011-10-17 15:25:07 -04:00
|
|
|
require 'fog/hp/models/storage/directory'
|
2011-06-16 00:40:32 -04:00
|
|
|
|
|
|
|
module Fog
|
2011-10-17 15:25:07 -04:00
|
|
|
module Storage
|
|
|
|
class HP
|
2011-06-16 00:40:32 -04:00
|
|
|
|
|
|
|
class Directories < Fog::Collection
|
|
|
|
|
2011-10-17 15:25:07 -04:00
|
|
|
model Fog::Storage::HP::Directory
|
2011-06-16 00:40:32 -04:00
|
|
|
|
|
|
|
def all
|
2012-12-22 23:26:21 +00:00
|
|
|
data = service.get_containers.body
|
2011-06-16 00:40:32 -04:00
|
|
|
load(data)
|
|
|
|
end
|
|
|
|
|
2012-07-13 18:12:07 -04:00
|
|
|
def head(key, options = {})
|
2013-01-18 15:06:41 -05:00
|
|
|
data = service.head_container(key)
|
2012-10-19 01:34:14 -04:00
|
|
|
directory = create_directory(key, data)
|
2012-07-13 18:12:07 -04:00
|
|
|
# set the cdn state for the directory
|
|
|
|
directory.cdn_enabled?
|
|
|
|
|
|
|
|
directory
|
|
|
|
rescue Fog::Storage::HP::NotFound
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2011-06-16 00:40:32 -04:00
|
|
|
def get(key, options = {})
|
2013-01-18 15:06:41 -05:00
|
|
|
data = service.get_container(key, options)
|
2012-10-19 01:34:14 -04:00
|
|
|
directory = create_directory(key, data)
|
|
|
|
# set the files for the directory
|
|
|
|
directory.files.merge_attributes(options)
|
|
|
|
directory.files.instance_variable_set(:@loaded, true)
|
|
|
|
data.body.each do |file|
|
|
|
|
directory.files << directory.files.new(file)
|
|
|
|
end
|
|
|
|
# set the cdn state for the directory
|
|
|
|
directory.cdn_enabled?
|
|
|
|
|
|
|
|
directory
|
|
|
|
rescue Fog::Storage::HP::NotFound
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def create_directory(key, data)
|
2011-08-01 15:04:20 -04:00
|
|
|
read_header = nil
|
|
|
|
write_header = nil
|
2011-06-16 00:40:32 -04:00
|
|
|
directory = new(:key => key)
|
|
|
|
for key, value in data.headers
|
|
|
|
if ['X-Container-Bytes-Used', 'X-Container-Object-Count'].include?(key)
|
|
|
|
directory.merge_attributes(key => value)
|
|
|
|
end
|
2011-08-01 15:04:20 -04:00
|
|
|
if key == 'X-Container-Read'
|
|
|
|
read_header = value
|
|
|
|
elsif key == 'X-Container-Write'
|
|
|
|
write_header = value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
# set the acl on the directory based on the headers
|
|
|
|
if !(read_header.nil? && write_header.nil?)
|
2013-01-18 15:06:41 -05:00
|
|
|
read_acl, write_acl = service.header_to_perm_acl(read_header, write_header)
|
2012-10-16 21:48:50 -04:00
|
|
|
# do not want to expose the read_acl and write_acl as writable attributes
|
|
|
|
directory.instance_variable_set(:@read_acl, read_acl)
|
|
|
|
directory.instance_variable_set(:@write_acl, write_acl)
|
2011-06-16 00:40:32 -04:00
|
|
|
end
|
|
|
|
directory
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|