lib/condo/strata/google_cloud_storage.rb in condo-1.0.1 vs lib/condo/strata/google_cloud_storage.rb in condo-1.0.2
- old
+ new
@@ -15,19 +15,23 @@
@options = {
:name => :GoogleCloudStorage,
:location => :na, # US or Europe, set at bucket creation time
:fog => {
:provider => 'Google',
- :google_storage_access_key_id => options[:access_id],
- :google_storage_secret_access_key => options[:secret_key]
- }
+ :google_storage_access_key_id => options[:fog_access_id] || options[:access_id],
+ :google_storage_secret_access_key => options[:fog_secret_key] || options[:secret_key]
+ },
+ :api => 1
}.merge!(options)
raise ArgumentError, 'Google Access ID missing' if @options[:access_id].nil?
raise ArgumentError, 'Google Secret Key missing' if @options[:secret_key].nil?
+ if @options[:api] == 2
+ @options[:secret_key] = OpenSSL::PKey::RSA.new(@options[:secret_key])
+ end
@options[:location] = @options[:location].to_sym
end
@@ -126,11 +130,11 @@
#
# Set the access control headers
#
- options[:object_options][:headers]['x-goog-api-version'] = 1
+ options[:object_options][:headers]['x-goog-api-version'] = @options[:api]
if options[:object_options][:headers]['x-goog-acl'].nil?
options[:object_options][:headers]['x-goog-acl'] = case options[:object_options][:permissions]
when :public
:'public-read'
@@ -281,15 +285,19 @@
#
# Encode the request signature
#
- signature = Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha1'), @options[:secret_key], signature)).chomp!
+ if @options[:api] == 1
+ signature = Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha1'), @options[:secret_key], signature)).gsub("\n","")
+ options[:object_options][:headers]['Authorization'] = "GOOG1 #{@options[:access_id]}:#{signature}"
+ else
+ signature = Base64.encode64(@options[:secret_key].sign(OpenSSL::Digest::SHA256.new, signature)).gsub("\n","")
+ end
url += signed_params.present? ? '&' : '?'
url = "#{options[:object_options][:protocol]}://#{options[:bucket_name]}.storage.googleapis.com#{url}#{other_params}GoogleAccessId=#{@options[:access_id]}&Expires=#{options[:object_options][:expires]}&Signature=#{CGI::escape(signature)}"
- options[:object_options][:headers]['Authorization'] = "GOOG1 #{@options[:access_id]}:#{signature}"
#
# Finish building the request
#