def signature(params)
string_to_sign =
"\#{params[:method]}\n\#{params[:headers]['Content-MD5']}\n\#{params[:headers]['Content-Type']}\n\#{params[:headers]['Date']}\n"
google_headers, canonical_google_headers = {}, ''
for key, value in params[:headers]
if key[0..6] == 'x-goog-'
google_headers[key] = value
end
end
google_headers = google_headers.sort {|x, y| x[0] <=> y[0]}
for key, value in google_headers
canonical_google_headers << "#{key}:#{value}\n"
end
string_to_sign << "#{canonical_google_headers}"
subdomain = params[:host].split(".#{@host}").first
unless subdomain =~ /^(?:[a-z]|\d(?!\d{0,2}(?:\.\d{1,3}){3}$))(?:[a-z0-9]|\.(?![\.\-])|\-(?![\.])){1,61}[a-z0-9]$/
Formatador.display_line("[yellow][WARN] fog: the specified google storage bucket name(#{subdomain}) is not a valid dns name. See: http://code.google.com/apis/storage/docs/developer-guide.html#naming[/]")
params[:host] = params[:host].split("#{subdomain}.")[-1]
if params[:path]
params[:path] = "#{subdomain}/#{params[:path]}"
else
params[:path] = "#{subdomain}"
end
subdomain = nil
end
canonical_resource = "/"
unless subdomain.nil? || subdomain == @host
canonical_resource << "#{CGI.escape(subdomain).downcase}/"
end
canonical_resource << "#{params[:path]}"
canonical_resource << '?'
for key in (params[:query] || {}).keys
if ['acl', 'location', 'logging', 'requestPayment', 'torrent', 'versions', 'versioning'].include?(key)
canonical_resource << "#{key}&"
end
end
canonical_resource.chop!
string_to_sign << "#{canonical_resource}"
signed_string = @hmac.sign(string_to_sign)
signature = Base64.encode64(signed_string).chomp!
end