Module: Fog::Storage

Defined in:
lib/fog/storage.rb,
lib/fog/hp/storage.rb,
lib/fog/aws/storage.rb,
lib/fog/ibm/storage.rb,
lib/fog/atmos/storage.rb,
lib/fog/local/storage.rb,
lib/fog/google/storage.rb,
lib/fog/ninefold/storage.rb,
lib/fog/rackspace/storage.rb,
lib/fog/hp/models/storage/file.rb,
lib/fog/aws/models/storage/file.rb,
lib/fog/hp/models/storage/files.rb,
lib/fog/aws/models/storage/files.rb,
lib/fog/atmos/models/storage/file.rb,
lib/fog/ibm/models/storage/volume.rb,
lib/fog/local/models/storage/file.rb,
lib/fog/atmos/models/storage/files.rb,
lib/fog/aws/models/storage/version.rb,
lib/fog/google/models/storage/file.rb,
lib/fog/ibm/models/storage/volumes.rb,
lib/fog/local/models/storage/files.rb,
lib/fog/aws/models/storage/versions.rb,
lib/fog/google/models/storage/files.rb,
lib/fog/hp/models/storage/directory.rb,
lib/fog/ibm/models/storage/offering.rb,
lib/fog/aws/models/storage/directory.rb,
lib/fog/ibm/models/storage/offerings.rb,
lib/fog/hp/models/storage/directories.rb,
lib/fog/rackspace/models/storage/file.rb,
lib/fog/atmos/models/storage/directory.rb,
lib/fog/aws/models/storage/directories.rb,
lib/fog/aws/requests/storage/acl_utils.rb,
lib/fog/hp/requests/storage/get_object.rb,
lib/fog/hp/requests/storage/put_object.rb,
lib/fog/local/models/storage/directory.rb,
lib/fog/rackspace/models/storage/files.rb,
lib/fog/aws/requests/storage/get_bucket.rb,
lib/fog/aws/requests/storage/get_object.rb,
lib/fog/aws/requests/storage/list_parts.rb,
lib/fog/aws/requests/storage/put_bucket.rb,
lib/fog/aws/requests/storage/put_object.rb,
lib/fog/aws/requests/storage/sync_clock.rb,
lib/fog/google/models/storage/directory.rb,
lib/fog/hp/requests/storage/head_object.rb,
lib/fog/ibm/requests/storage/get_volume.rb,
lib/fog/atmos/models/storage/directories.rb,
lib/fog/aws/requests/storage/copy_object.rb,
lib/fog/aws/requests/storage/get_service.rb,
lib/fog/aws/requests/storage/head_object.rb,
lib/fog/aws/requests/storage/upload_part.rb,
lib/fog/local/models/storage/directories.rb,
lib/fog/google/models/storage/directories.rb,
lib/fog/hp/requests/storage/delete_object.rb,
lib/fog/hp/requests/storage/get_container.rb,
lib/fog/hp/requests/storage/put_container.rb,
lib/fog/ibm/requests/storage/list_volumes.rb,
lib/fog/aws/requests/storage/delete_bucket.rb,
lib/fog/aws/requests/storage/delete_object.rb,
lib/fog/google/requests/storage/get_bucket.rb,
lib/fog/google/requests/storage/get_object.rb,
lib/fog/google/requests/storage/put_bucket.rb,
lib/fog/google/requests/storage/put_object.rb,
lib/fog/hp/requests/storage/get_containers.rb,
lib/fog/hp/requests/storage/head_container.rb,
lib/fog/ibm/requests/storage/create_volume.rb,
lib/fog/ibm/requests/storage/delete_volume.rb,
lib/fog/rackspace/models/storage/directory.rb,
lib/fog/aws/requests/storage/get_bucket_acl.rb,
lib/fog/aws/requests/storage/get_object_acl.rb,
lib/fog/aws/requests/storage/get_object_url.rb,
lib/fog/aws/requests/storage/put_bucket_acl.rb,
lib/fog/aws/requests/storage/put_object_acl.rb,
lib/fog/aws/requests/storage/put_object_url.rb,
lib/fog/google/requests/storage/copy_object.rb,
lib/fog/google/requests/storage/get_service.rb,
lib/fog/google/requests/storage/head_object.rb,
lib/fog/hp/requests/storage/head_containers.rb,
lib/fog/ibm/requests/storage/list_offerings.rb,
lib/fog/atmos/requests/storage/get_namespace.rb,
lib/fog/atmos/requests/storage/put_namespace.rb,
lib/fog/hp/requests/storage/delete_container.rb,
lib/fog/rackspace/models/storage/directories.rb,
lib/fog/atmos/requests/storage/head_namespace.rb,
lib/fog/atmos/requests/storage/post_namespace.rb,
lib/fog/google/requests/storage/delete_bucket.rb,
lib/fog/google/requests/storage/delete_object.rb,
lib/fog/rackspace/requests/storage/get_object.rb,
lib/fog/rackspace/requests/storage/put_object.rb,
lib/fog/aws/requests/storage/get_bucket_policy.rb,
lib/fog/aws/requests/storage/put_bucket_policy.rb,
lib/fog/google/requests/storage/get_object_acl.rb,
lib/fog/google/requests/storage/get_object_url.rb,
lib/fog/google/requests/storage/put_bucket_acl.rb,
lib/fog/google/requests/storage/put_object_url.rb,
lib/fog/rackspace/requests/storage/copy_object.rb,
lib/fog/rackspace/requests/storage/head_object.rb,
lib/fog/atmos/requests/storage/delete_namespace.rb,
lib/fog/aws/requests/storage/get_bucket_logging.rb,
lib/fog/aws/requests/storage/get_bucket_website.rb,
lib/fog/aws/requests/storage/get_object_torrent.rb,
lib/fog/aws/requests/storage/put_bucket_logging.rb,
lib/fog/aws/requests/storage/put_bucket_website.rb,
lib/fog/aws/requests/storage/get_bucket_location.rb,
lib/fog/aws/requests/storage/get_object_http_url.rb,
lib/fog/aws/requests/storage/get_request_payment.rb,
lib/fog/aws/requests/storage/put_request_payment.rb,
lib/fog/rackspace/requests/storage/delete_object.rb,
lib/fog/rackspace/requests/storage/get_container.rb,
lib/fog/rackspace/requests/storage/put_container.rb,
lib/fog/aws/requests/storage/delete_bucket_policy.rb,
lib/fog/aws/requests/storage/get_bucket_lifecycle.rb,
lib/fog/aws/requests/storage/get_object_https_url.rb,
lib/fog/aws/requests/storage/put_bucket_lifecycle.rb,
lib/fog/rackspace/requests/storage/get_containers.rb,
lib/fog/rackspace/requests/storage/head_container.rb,
lib/fog/aws/requests/storage/delete_bucket_website.rb,
lib/fog/aws/requests/storage/get_bucket_versioning.rb,
lib/fog/aws/requests/storage/put_bucket_versioning.rb,
lib/fog/google/requests/storage/get_object_torrent.rb,
lib/fog/rackspace/requests/storage/head_containers.rb,
lib/fog/aws/requests/storage/abort_multipart_upload.rb,
lib/fog/aws/requests/storage/list_multipart_uploads.rb,
lib/fog/google/requests/storage/get_object_http_url.rb,
lib/fog/rackspace/requests/storage/delete_container.rb,
lib/fog/aws/requests/storage/delete_bucket_lifecycle.rb,
lib/fog/aws/requests/storage/delete_multiple_objects.rb,
lib/fog/google/requests/storage/get_object_https_url.rb,
lib/fog/aws/requests/storage/complete_multipart_upload.rb,
lib/fog/aws/requests/storage/initiate_multipart_upload.rb,
lib/fog/aws/requests/storage/post_object_hidden_fields.rb,
lib/fog/rackspace/requests/storage/put_object_manifest.rb,
lib/fog/aws/requests/storage/get_bucket_object_versions.rb,
lib/fog/rackspace/requests/storage/get_object_https_url.rb,
lib/fog/rackspace/requests/storage/post_set_meta_temp_url_key.rb

Defined Under Namespace

Classes: AWS, Atmos, Google, HP, IBM, Local, Ninefold, Rackspace

Class Method Summary collapse

Class Method Details

.[](provider) ⇒ Object



4
5
6
# File 'lib/fog/storage.rb', line 4

def self.[](provider)
  self.new(:provider => provider)
end

.directoriesObject



40
41
42
43
44
45
46
47
48
49
# File 'lib/fog/storage.rb', line 40

def self.directories
  directories = []
  for provider in self.providers
    begin
      directories.concat(self[provider].directories)
    rescue # ignore any missing credentials/etc
    end
  end
  directories
end

.get_body_size(body) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/fog/storage.rb', line 51

def self.get_body_size(body)
  if body.respond_to?(:force_encoding)
    body.force_encoding('BINARY')
  end
  if body.respond_to?(:bytesize)
    body.bytesize
  elsif body.respond_to?(:size)
    body.size
  elsif body.respond_to?(:stat)
    body.stat.size
  else
    0
  end
end

.get_content_type(data) ⇒ Object



66
67
68
69
70
71
72
73
# File 'lib/fog/storage.rb', line 66

def self.get_content_type(data)
  if data.respond_to?(:path) and !data.path.nil?
    filename = ::File.basename(data.path)
    unless (mime_types = MIME::Types.of(filename)).empty?
      mime_types.first.content_type
    end
  end
end

.new(attributes) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fog/storage.rb', line 8

def self.new(attributes)
  attributes = attributes.dup # prevent delete from having side effects
  case provider = attributes.delete(:provider).to_s.downcase.to_sym
  when :atmos
    require 'fog/atmos/storage'
    Fog::Storage::Atmos.new(attributes)
  when :aws
    require 'fog/aws/storage'
    Fog::Storage::AWS.new(attributes)
  when :google
    require 'fog/google/storage'
    Fog::Storage::Google.new(attributes)
  when :hp
    require 'fog/hp/storage'
    Fog::Storage::HP.new(attributes)
  when :ibm
    require 'fog/ibm/storage'
    Fog::Storage::IBM.new(attributes)
  when :local
    require 'fog/local/storage'
    Fog::Storage::Local.new(attributes)
  when :ninefold
    require 'fog/ninefold/storage'
    Fog::Storage::Ninefold.new(attributes)
  when :rackspace
    require 'fog/rackspace/storage'
    Fog::Storage::Rackspace.new(attributes)
  else
    raise ArgumentError.new("#{provider} is not a recognized storage provider")
  end
end

.parse_data(data) ⇒ Object



75
76
77
78
79
80
81
82
83
84
# File 'lib/fog/storage.rb', line 75

def self.parse_data(data)
  {
    :body     => data,
    :headers  => {
      'Content-Length'  => get_body_size(data),
      'Content-Type'    => get_content_type(data)
      #'Content-MD5' => Base64.encode64(Digest::MD5.digest(metadata[:body])).strip
    }
  }
end

.providersObject



86
87
88
# File 'lib/fog/storage.rb', line 86

def self.providers
  Fog.services[:storage]
end