Class/Module Index [+]

Quicksearch

Fog::Storage::Rackspace::Real

Attributes

rackspace_cdn_ssl[R]

Public Class Methods

new(options={}) click to toggle source
# File lib/fog/rackspace/storage.rb, line 101
def initialize(options={})
  require 'mime/types'
  @rackspace_api_key = options[:rackspace_api_key]
  @rackspace_username = options[:rackspace_username]
  @rackspace_cdn_ssl = options[:rackspace_cdn_ssl]
  @rackspace_auth_url = options[:rackspace_auth_url]
  @rackspace_servicenet = options[:rackspace_servicenet]
  @rackspace_auth_token = options[:rackspace_auth_token]
  @rackspace_storage_url = options[:rackspace_storage_url]
  @rackspace_cdn_url = options[:rackspace_cdn_url]          
  @rackspace_region = options[:rackspace_region] || :dfw
  @rackspace_temp_url_key = options[:rackspace_temp_url_key]
  @rackspace_must_reauthenticate = false
  @connection_options     = options[:connection_options] || {}

  authenticate
  @persistent = options[:persistent] || false
  Excon.defaults[:ssl_verify_peer] = false if service_net?
  @connection = Fog::Connection.new(endpoint_uri.to_s, @persistent, @connection_options)
end

Public Instance Methods

account() click to toggle source

Return Account Details @return [Fog::Storage::Rackspace::Account] account details object

# File lib/fog/rackspace/storage.rb, line 124
def account
  account = Fog::Storage::Rackspace::Account.new(:service => self)
  account.reload
end
authenticate() click to toggle source
# File lib/fog/rackspace/storage.rb, line 179
def authenticate
  if @rackspace_must_reauthenticate || @rackspace_auth_token.nil?
    options = {
      :rackspace_api_key  => @rackspace_api_key,
      :rackspace_username => @rackspace_username,
      :rackspace_auth_url => @rackspace_auth_url
    }            
    super(options)
  else
    @auth_token = @rackspace_auth_token
    @uri = URI.parse(@rackspace_storage_url)
  end
end
copy_object(source_container_name, source_object_name, target_container_name, target_object_name, options={}) click to toggle source

Copy object

Parameters

  • source_container_name<~String> - Name of source bucket

  • source_object_name<~String> - Name of source object

  • target_container_name<~String> - Name of bucket to create copy in

  • target_object_name<~String> - Name for new copy of object

  • options<~Hash> - Additional headers

@raise [Fog::Storage::Rackspace::NotFound] - HTTP 404 @raise [Fog::Storage::Rackspace::BadRequest] - HTTP 400 @raise [Fog::Storage::Rackspace::InternalServerError] - HTTP 500 @raise [Fog::Storage::Rackspace::ServiceError]

# File lib/fog/rackspace/requests/storage/copy_object.rb, line 18
def copy_object(source_container_name, source_object_name, target_container_name, target_object_name, options={})
  headers = { 'X-Copy-From' => "/#{source_container_name}/#{source_object_name}" }.merge(options)
  request({
    :expects  => 201,
    :headers  => headers,
    :method   => 'PUT',
    :path     => "#{Fog::Rackspace.escape(target_container_name)}/#{Fog::Rackspace.escape(target_object_name)}"
  })
end
delete_container(name) click to toggle source

Delete an existing container

Parameters

  • name<~String> - Name of container to delete

@raise [Fog::Storage::Rackspace::NotFound] - HTTP 404 @raise [Fog::Storage::Rackspace::BadRequest] - HTTP 400 @raise [Fog::Storage::Rackspace::InternalServerError] - HTTP 500 @raise [Fog::Storage::Rackspace::ServiceError]

# File lib/fog/rackspace/requests/storage/delete_container.rb, line 14
def delete_container(name)
  request(
    :expects  => 204,
    :method   => 'DELETE',
    :path     => Fog::Rackspace.escape(name)
  )
end
delete_object(container, object) click to toggle source

Delete an existing object

Parameters

  • container<~String> - Name of container to delete

  • object<~String> - Name of object to delete

@raise [Fog::Storage::Rackspace::NotFound] - HTTP 404 @raise [Fog::Storage::Rackspace::BadRequest] - HTTP 400 @raise [Fog::Storage::Rackspace::InternalServerError] - HTTP 500 @raise [Fog::Storage::Rackspace::ServiceError]

# File lib/fog/rackspace/requests/storage/delete_object.rb, line 15
def delete_object(container, object)
  request(
    :expects  => 204,
    :method   => 'DELETE',
    :path     => "#{Fog::Rackspace.escape(container)}/#{Fog::Rackspace.escape(object)}"
  )
end
endpoint_uri(service_endpoint_url=nil) click to toggle source
# File lib/fog/rackspace/storage.rb, line 201
def endpoint_uri(service_endpoint_url=nil)
  return @uri if @uri

  @uri = super(@rackspace_storage_url || service_endpoint_url, :rackspace_storage_url)
  @uri.host = "snet-#{@uri.host}" if service_net?
  @uri
end
get_container(container, options = {}) click to toggle source

Get details for container and total bytes stored

Parameters

  • container<~String> - Name of container to retrieve info for

  • options<~String>:

    • 'limit'<~String> - Maximum number of objects to return

    • 'marker'<~String> - Only return objects whose name is greater than marker

    • 'prefix'<~String> - Limits results to those starting with prefix

    • 'path'<~String> - Return objects nested in the pseudo path

Returns

  • response<~Excon::Response>:

    • headers<~Hash>:

      • 'X-Account-Container-Count'<~String> - Count of containers

      • 'X-Account-Bytes-Used'<~String> - Bytes used

    • body<~Array>:

      • 'bytes'<~Integer> - Number of bytes used by container

      • 'count'<~Integer> - Number of items in container

      • 'name'<~String> - Name of container

      • item<~Hash>:

        • 'bytes'<~String> - Size of object

        • 'content_type'<~String> Content-Type of object

        • 'hash'<~String> - Hash of object (etag?)

        • 'last_modified'<~String> - Last modified timestamp

        • 'name'<~String> - Name of object

@raise [Fog::Storage::Rackspace::NotFound] - HTTP 404 @raise [Fog::Storage::Rackspace::BadRequest] - HTTP 400 @raise [Fog::Storage::Rackspace::InternalServerError] - HTTP 500 @raise [Fog::Storage::Rackspace::ServiceError]

# File lib/fog/rackspace/requests/storage/get_container.rb, line 35
def get_container(container, options = {})
  options = options.reject {|key, value| value.nil?}
  request(
    :expects  => 200,
    :method   => 'GET',
    :path     => Fog::Rackspace.escape(container),
    :query    => {'format' => 'json'}.merge!(options)
  )
end
get_containers(options = {}) click to toggle source

List existing storage containers

Parameters

  • options<~Hash>:

    • 'limit'<~Integer> - Upper limit to number of results returned

    • 'marker'<~String> - Only return objects with name greater than this value

Returns

  • response<~Excon::Response>:

    • body<~Array>:

      • container<~Hash>:

        • 'bytes'<~Integer>: - Number of bytes used by container

        • 'count'<~Integer>: - Number of items in container

        • 'name'<~String>: - Name of container

@raise [Fog::Storage::Rackspace::NotFound] - HTTP 404 @raise [Fog::Storage::Rackspace::BadRequest] - HTTP 400 @raise [Fog::Storage::Rackspace::InternalServerError] - HTTP 500 @raise [Fog::Storage::Rackspace::ServiceError]

# File lib/fog/rackspace/requests/storage/get_containers.rb, line 24
def get_containers(options = {})
  options = options.reject {|key, value| value.nil?}
  request(
    :expects  => [200, 204],
    :method   => 'GET',
    :path     => '',
    :query    => {'format' => 'json'}.merge!(options)
  )
end
get_object(container, object, &block) click to toggle source

Get details for object

Parameters

  • container<~String> - Name of container to look in

  • object<~String> - Name of object to look for

@raise [Fog::Storage::Rackspace::NotFound] - HTTP 404 @raise [Fog::Storage::Rackspace::BadRequest] - HTTP 400 @raise [Fog::Storage::Rackspace::InternalServerError] - HTTP 500 @raise [Fog::Storage::Rackspace::ServiceError]

# File lib/fog/rackspace/requests/storage/get_object.rb, line 15
def get_object(container, object, &block)
  params = {}

  if block_given?
    params[:response_block] = Proc.new
  end

  request(params.merge!({
    :expects  => 200,
    :method   => 'GET',
    :path     => "#{Fog::Rackspace.escape(container)}/#{Fog::Rackspace.escape(object)}"
  }), false)
end
get_object_https_url(container, object, expires, options = {}) click to toggle source

Get an expiring object https url from Cloud Files

Parameters

  • container<~String> - Name of container containing object

  • object<~String> - Name of object to get expiring url for

  • expires<~Time> - An expiry time for this url

Returns

  • response<~Excon::Response>:

    • body<~String> - url for object

@raise [Fog::Storage::Rackspace::NotFound] - HTTP 404 @raise [Fog::Storage::Rackspace::BadRequest] - HTTP 400 @raise [Fog::Storage::Rackspace::InternalServerError] - HTTP 500 @raise [Fog::Storage::Rackspace::ServiceError]

See Also

docs.rackspace.com/files/api/v1/cf-devguide/content/Create_TempURL-d1a444.html

# File lib/fog/rackspace/requests/storage/get_object_https_url.rb, line 23
def get_object_https_url(container, object, expires, options = {})
  if @rackspace_temp_url_key.nil?
    raise ArgumentError, "Storage must my instantiated with the :rackspace_temp_url_key option"
  end

  method         = 'GET'
  expires        = expires.to_i
  object_path_escaped   = "#{@uri.path}/#{Fog::Rackspace.escape(container)}/#{Fog::Rackspace.escape(object,"/")}"
  object_path_unescaped = "#{@uri.path}/#{Fog::Rackspace.escape(container)}/#{object}"
  string_to_sign = "#{method}\n#{expires}\n#{object_path_unescaped}"

  hmac = Fog::HMAC.new('sha1', @rackspace_temp_url_key)
  sig  = sig_to_hex(hmac.sign(string_to_sign))

  "https://#{@uri.host}#{object_path_escaped}?temp_url_sig=#{sig}&temp_url_expires=#{expires}"
end
head_container(container) click to toggle source

List number of objects and total bytes stored

Parameters

  • container<~String> - Name of container to retrieve info for

Returns

  • response<~Excon::Response>:

    • headers<~Hash>:

      • 'X-Container-Object-Count'<~String> - Count of containers

      • 'X-Container-Bytes-Used'<~String> - Bytes used

@raise [Fog::Storage::Rackspace::NotFound] - HTTP 404 @raise [Fog::Storage::Rackspace::BadRequest] - HTTP 400 @raise [Fog::Storage::Rackspace::InternalServerError] - HTTP 500 @raise [Fog::Storage::Rackspace::ServiceError]

# File lib/fog/rackspace/requests/storage/head_container.rb, line 20
def head_container(container)
  request(
    :expects  => 204,
    :method   => 'HEAD',
    :path     => Fog::Rackspace.escape(container),
    :query    => {'format' => 'json'}
  )
end
head_containers() click to toggle source

List number of containers and total bytes stored

Returns

  • response<~Excon::Response>:

    • headers<~Hash>:

      • 'X-Account-Container-Count'<~String> - Count of containers

      • 'X-Account-Bytes-Used'<~String> - Bytes used

@raise [Fog::Storage::Rackspace::NotFound] - HTTP 404 @raise [Fog::Storage::Rackspace::BadRequest] - HTTP 400 @raise [Fog::Storage::Rackspace::InternalServerError] - HTTP 500 @raise [Fog::Storage::Rackspace::ServiceError]

# File lib/fog/rackspace/requests/storage/head_containers.rb, line 17
def head_containers
  request(
    :expects  => 204,
    :method   => 'HEAD',
    :path     => '',
    :query    => {'format' => 'json'}
  )
end
head_object(container, object) click to toggle source

Get headers for object

Parameters

  • container<~String> - Name of container to look in

  • object<~String> - Name of object to look for

@raise [Fog::Storage::Rackspace::NotFound] - HTTP 404 @raise [Fog::Storage::Rackspace::BadRequest] - HTTP 400 @raise [Fog::Storage::Rackspace::InternalServerError] - HTTP 500 @raise [Fog::Storage::Rackspace::ServiceError]

# File lib/fog/rackspace/requests/storage/head_object.rb, line 15
def head_object(container, object)
  request({
    :expects  => 200,
    :method   => 'HEAD',
    :path     => "#{Fog::Rackspace.escape(container)}/#{Fog::Rackspace.escape(object)}"
  }, false)
end
post_set_meta_temp_url_key(key) click to toggle source

Set the account wide Temp URL Key. This is a secret key that's used to generate signed expiring URLs.

Once the key has been set with this request you should create new Storage objects with the :rackspace_temp_url_key option then use the get_object_https_url method to generate expiring URLs.

*** CAUTION *** changing this secret key will invalidate any expiring URLS generated with old keys.

Parameters

  • key<~String> - The new Temp URL Key

Returns

  • response<~Excon::Response>

@raise [Fog::Storage::Rackspace::NotFound] - HTTP 404 @raise [Fog::Storage::Rackspace::BadRequest] - HTTP 400 @raise [Fog::Storage::Rackspace::InternalServerError] - HTTP 500 @raise [Fog::Storage::Rackspace::ServiceError]

See Also

docs.rackspace.com/files/api/v1/cf-devguide/content/Set_Account_Metadata-d1a4460.html

# File lib/fog/rackspace/requests/storage/post_set_meta_temp_url_key.rb, line 28
def post_set_meta_temp_url_key(key)
  request(
    :expects  => [201, 202, 204],
    :method   => 'POST',
    :headers  => {'X-Account-Meta-Temp-Url-Key' => key}
  )
end
put_container(name, options={}) click to toggle source

Create a new container

Parameters

  • name<~String> - Name for container, should be < 256 bytes and must not contain '/'

@raise [Fog::Storage::Rackspace::NotFound] - HTTP 404 @raise [Fog::Storage::Rackspace::BadRequest] - HTTP 400 @raise [Fog::Storage::Rackspace::InternalServerError] - HTTP 500 @raise [Fog::Storage::Rackspace::ServiceError]

# File lib/fog/rackspace/requests/storage/put_container.rb, line 14
def put_container(name, options={})
  request(
    :expects  => [201, 202],
    :method   => 'PUT',
    :headers => options,
    :path     => Fog::Rackspace.escape(name)
  )
end
put_object(container, object, data, options = {}) click to toggle source

Create a new object

Parameters

  • container<~String> - Name for container, should be < 256 bytes and must not contain '/'

  • object<~String> - Name for object

  • data<~String|File> - data to upload

  • options<~Hash> - config headers for object. Defaults to {}.

@raise [Fog::Storage::Rackspace::NotFound] - HTTP 404 @raise [Fog::Storage::Rackspace::BadRequest] - HTTP 400 @raise [Fog::Storage::Rackspace::InternalServerError] - HTTP 500 @raise [Fog::Storage::Rackspace::ServiceError]

# File lib/fog/rackspace/requests/storage/put_object.rb, line 17
def put_object(container, object, data, options = {})
  data = Fog::Storage.parse_data(data)
  headers = data[:headers].merge!(options)
  request(
    :body       => data[:body],
    :expects    => 201,
    :idempotent => true,
    :headers    => headers,
    :method     => 'PUT',
    :path       => "#{Fog::Rackspace.escape(container)}/#{Fog::Rackspace.escape(object)}"
  )
end
put_object_manifest(container, object) click to toggle source

Create a new object

Parameters

  • container<~String> - Name for container, should be < 256 bytes and must not contain '/'

  • object<~String> - Name for object

@raise [Fog::Storage::Rackspace::NotFound] - HTTP 404 @raise [Fog::Storage::Rackspace::BadRequest] - HTTP 400 @raise [Fog::Storage::Rackspace::InternalServerError] - HTTP 500 @raise [Fog::Storage::Rackspace::ServiceError]

# File lib/fog/rackspace/requests/storage/put_object_manifest.rb, line 15
def put_object_manifest(container, object)
  path = "#{Fog::Rackspace.escape(container)}/#{Fog::Rackspace.escape(object)}"
  request(
    :expects  => 201,
    :headers  => {'X-Object-Manifest' => path},
    :method   => 'PUT',
    :path     => path
  )
end
region() click to toggle source
# File lib/fog/rackspace/storage.rb, line 197
def region
  @rackspace_region
end
reload() click to toggle source

Resets presistent service connections

# File lib/fog/rackspace/storage.rb, line 137
def reload
  @connection.reset
end
request(params, parse_json = true, &block) click to toggle source
# File lib/fog/rackspace/storage.rb, line 141
def request(params, parse_json = true, &block)
  begin
    response = @connection.request(params.merge({
      :headers  => {
        'Content-Type' => 'application/json',
        'Accept' => 'application/json',
        'X-Auth-Token' => auth_token
      }.merge!(params[:headers] || {}),
      :host     => endpoint_uri.host,
      :path     => "#{endpoint_uri.path}/#{params[:path]}",
    }), &block)
  rescue Excon::Errors::Unauthorized => error
    if error.response.body != 'Bad username or password' # token expiration
      @rackspace_must_reauthenticate = true
      authenticate
      retry
    else # bad credentials
      raise error
    end
  rescue Excon::Errors::NotFound => error
    raise NotFound.slurp(error, region)
  rescue Excon::Errors::BadRequest => error
    raise BadRequest.slurp error
  rescue Excon::Errors::InternalServerError => error
    raise InternalServerError.slurp error
  rescue Excon::Errors::HTTPStatusError => error
    raise ServiceError.slurp error
  end
  if !response.body.empty? && parse_json && response.headers['Content-Type'] =~ %{application/json}
    response.body = Fog::JSON.decode(response.body)
  end
  response
end
service_name() click to toggle source
# File lib/fog/rackspace/storage.rb, line 193
def service_name
  :cloudFiles
end
service_net?() click to toggle source
# File lib/fog/rackspace/storage.rb, line 175
def service_net?
  @rackspace_servicenet == true
end
ssl?() click to toggle source

Using SSL? @return [Boolean] return true if service is returning SSL-Secured URLs in public_url methods @see Directory#public_url

# File lib/fog/rackspace/storage.rb, line 132
def ssl?
  !rackspace_cdn_ssl.nil?
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.