mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[ninefold|storage] Directories Functionality
This commit is contained in:
parent
af404bb5ef
commit
c69e231c10
6 changed files with 138 additions and 3 deletions
33
lib/fog/storage/models/ninefold/directories.rb
Normal file
33
lib/fog/storage/models/ninefold/directories.rb
Normal file
|
@ -0,0 +1,33 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/storage/models/ninefold/directory'
|
||||
|
||||
module Fog
|
||||
module Storage
|
||||
class Ninefold
|
||||
|
||||
class Directories < Fog::Collection
|
||||
|
||||
model Fog::Storage::Ninefold::Directory
|
||||
|
||||
def all
|
||||
data = connection.get_namespace.body[:DirectoryList]
|
||||
data = {:DirectoryEntry => []} if data.kind_of? String
|
||||
data[:DirectoryEntry] = [data[:DirectoryEntry]] if data[:DirectoryEntry].kind_of? Hash
|
||||
load(data[:DirectoryEntry])
|
||||
end
|
||||
|
||||
def get(key, options = {})
|
||||
return nil if key == '' # Root dir shouldn't be retrieved like this.
|
||||
res = connection.get_namespace key
|
||||
emc_meta = res.headers['x-emc-meta']
|
||||
obj_id = emc_meta.scan(/objectid=(\w+),/).flatten[0]
|
||||
new(:id => obj_id, :filename => key, :type => 'directory')
|
||||
rescue Fog::Storage::Ninefold::NotFound
|
||||
nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
27
lib/fog/storage/models/ninefold/directory.rb
Normal file
27
lib/fog/storage/models/ninefold/directory.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module Storage
|
||||
class Ninefold
|
||||
|
||||
class Directory < Fog::Model
|
||||
|
||||
identity :filename, :aliases => [:'Filename', :'key']
|
||||
attribute :id, :aliases => :'ObjectID'
|
||||
attribute :type, :aliases => :'FileType'
|
||||
|
||||
def save
|
||||
res = connection.post_namespace filename
|
||||
reload
|
||||
end
|
||||
|
||||
def destroy
|
||||
connection.delete_namespace filename
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -12,13 +12,16 @@ module Fog
|
|||
requires :ninefold_storage_token, :ninefold_storage_secret
|
||||
|
||||
model_path 'fog/storage/models/ninefold'
|
||||
# model :directory
|
||||
# collection :directories
|
||||
model :directory
|
||||
collection :directories
|
||||
# model :file
|
||||
# collection :files
|
||||
|
||||
request_path 'fog/storage/requests/ninefold'
|
||||
# request :delete_container
|
||||
request :get_namespace
|
||||
request :post_namespace
|
||||
request :delete_namespace
|
||||
|
||||
module Utils
|
||||
end
|
||||
|
@ -85,7 +88,8 @@ module Fog
|
|||
signstring += "\n"
|
||||
|
||||
signstring += "/rest/" + URI.unescape( req_path ).downcase
|
||||
signstring += params[:query] if params[:query]
|
||||
query_str = params[:query].map{|k,v| "#{k}=#{v}"}.join('&')
|
||||
signstring += '?' + params[:query] unless query_str.empty?
|
||||
signstring += "\n"
|
||||
|
||||
customheaders = {}
|
||||
|
@ -117,6 +121,15 @@ module Fog
|
|||
error
|
||||
end
|
||||
end
|
||||
unless response.body.empty?
|
||||
if params[:parse]
|
||||
document = Fog::ToHashDocument.new
|
||||
parser = Nokogiri::XML::SAX::PushParser.new(document)
|
||||
parser << response.body
|
||||
parser.finish
|
||||
response.body = document.body
|
||||
end
|
||||
end
|
||||
response
|
||||
end
|
||||
|
||||
|
|
20
lib/fog/storage/requests/ninefold/delete_namespace.rb
Normal file
20
lib/fog/storage/requests/ninefold/delete_namespace.rb
Normal file
|
@ -0,0 +1,20 @@
|
|||
module Fog
|
||||
module Storage
|
||||
class Ninefold
|
||||
class Real
|
||||
|
||||
def delete_namespace(namespace = '', options = {})
|
||||
namespace = namespace + '/' unless namespace =~ /\/$/
|
||||
options = options.reject {|key, value| value.nil?}
|
||||
request(
|
||||
:expects => 204,
|
||||
:method => 'DELETE',
|
||||
:path => "namespace/" + namespace,
|
||||
:query => options
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
21
lib/fog/storage/requests/ninefold/get_namespace.rb
Normal file
21
lib/fog/storage/requests/ninefold/get_namespace.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
module Fog
|
||||
module Storage
|
||||
class Ninefold
|
||||
class Real
|
||||
|
||||
def get_namespace(namespace = '', options = {})
|
||||
namespace = namespace + '/' unless namespace =~ /\/$/
|
||||
options = options.reject {|key, value| value.nil?}
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => "namespace/" + namespace,
|
||||
:query => options,
|
||||
:parse => true
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
21
lib/fog/storage/requests/ninefold/post_namespace.rb
Normal file
21
lib/fog/storage/requests/ninefold/post_namespace.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
module Fog
|
||||
module Storage
|
||||
class Ninefold
|
||||
class Real
|
||||
|
||||
def post_namespace(namespace = '', options = {})
|
||||
namespace = namespace + '/' unless namespace =~ /\/$/
|
||||
options = options.reject {|key, value| value.nil?}
|
||||
request(
|
||||
:expects => 201,
|
||||
:method => 'POST',
|
||||
:path => "namespace/" + namespace,
|
||||
:query => options,
|
||||
:parse => true
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue