Module: Fog::Storage::Rackspace::Common

Included in:
Mock, Real
Defined in:
lib/fog/rackspace/storage.rb,
lib/fog/rackspace/requests/storage/get_object_http_url.rb,
lib/fog/rackspace/requests/storage/put_object_manifest.rb,
lib/fog/rackspace/requests/storage/get_object_https_url.rb

Instance Method Summary collapse

Instance Method Details

#accountFog::Storage::Rackspace::Account

Return Account Details

Returns:



120
121
122
123
# File 'lib/fog/rackspace/storage.rb', line 120

def 
   = Fog::Storage::Rackspace::Account.new(:service => self)
  .reload
end

#apply_options(options) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/fog/rackspace/storage.rb', line 46

def apply_options(options)
  @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]
  @rackspace_temp_url_key = options[:rackspace_temp_url_key]
  @rackspace_must_reauthenticate = false
  @connection_options = options[:connection_options] || {}

  unless @rackspace_region || (@rackspace_storage_url && @rackspace_cdn_url)
    Fog::Logger.deprecation("Default region support will be removed in an upcoming release. Please switch to manually setting your endpoint. This requires settng the :rackspace_region option.")
  end

  @rackspace_region ||= :dfw
end

#authenticateObject



86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/fog/rackspace/storage.rb', line 86

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,
      :connection_options => @connection_options
    }
    super(options)
  else
    @auth_token = @rackspace_auth_token
    @uri = URI.parse(@rackspace_storage_url)
  end
end

#cdnObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/fog/rackspace/storage.rb', line 67

def cdn
  @cdn ||= Fog::CDN.new(
    :provider           => 'Rackspace',
    :rackspace_api_key  => @rackspace_api_key,
    :rackspace_auth_url => @rackspace_auth_url,
    :rackspace_cdn_url => @rackspace_cdn_url,
    :rackspace_username => @rackspace_username,
    :rackspace_region => @rackspace_region,
    :rackspace_cdn_ssl => @rackspace_cdn_ssl
  )
  if @cdn.enabled?
    @cdn
  end
end

#endpoint_uri(service_endpoint_url = nil) ⇒ Object



113
114
115
116
# File 'lib/fog/rackspace/storage.rb', line 113

def endpoint_uri(service_endpoint_url=nil)
  return @uri if @uri
  super(@rackspace_storage_url || service_endpoint_url, :rackspace_storage_url)
end

#get_object_http_url(container, object, expires, options = {}) ⇒ Object

Get an expiring object http 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

See Also

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

Raises:



21
22
23
# File 'lib/fog/rackspace/requests/storage/get_object_http_url.rb', line 21

def get_object_http_url(container, object, expires, options = {})
  get_object_https_url(container, object, expires, options.merge(:scheme => 'http'))
end

#get_object_https_url(container, object, expires, options = {}) ⇒ Object

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

  • options<~Hash> - Options to override the method or scheme

Returns

  • response<~Excon::Response>:

    • body<~String> - url for object

See Also

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

Raises:



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/fog/rackspace/requests/storage/get_object_https_url.rb', line 22

def get_object_https_url(container, object, expires, options = {})
  if @rackspace_temp_url_key.nil?
    raise ArgumentError, "Storage must be instantiated with the :rackspace_temp_url_key option"
  end

  method         = options[: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))

  temp_url_query = {
      :temp_url_sig => sig,
      :temp_url_expires => expires
  }
  temp_url_query.merge!(:inline => true) if options[:inline]
  temp_url_query.merge!(:filename => options[:filename]) if options[:filename]
  temp_url_options = {
      :scheme => options[:scheme] || @uri.scheme,
      :host => @uri.host,
      :path => object_path_escaped,
      :query => temp_url_query.map { |param, val| "#{CGI.escape(param.to_s)}=#{CGI.escape(val.to_s)}" }.join('&')
  }
  URI::Generic.build(temp_url_options).to_s
end

#put_object_manifest(container, object, options = {}) ⇒ Object

Create a new dynamic large object manifest

This is an alias for #put_dynamic_obj_manifest for backward compatibility.



8
9
10
# File 'lib/fog/rackspace/requests/storage/put_object_manifest.rb', line 8

def put_object_manifest(container, object, options = {})
  put_dynamic_obj_manifest(container, object, options)
end

#regionObject



109
110
111
# File 'lib/fog/rackspace/storage.rb', line 109

def region
  @rackspace_region
end

#request_id_headerObject



105
106
107
# File 'lib/fog/rackspace/storage.rb', line 105

def request_id_header
  "X-Trans-Id"
end

#service_nameObject



101
102
103
# File 'lib/fog/rackspace/storage.rb', line 101

def service_name
  :cloudFiles
end

#service_net?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/fog/rackspace/storage.rb', line 82

def service_net?
  @rackspace_servicenet == true
end