lib/aws/s3/s3_object.rb in aws-sdk-1.6.9 vs lib/aws/s3/s3_object.rb in aws-sdk-1.7.0

- old
+ new

@@ -118,11 +118,11 @@ # == Server Side Encryption # # Amazon S3 provides server side encryption for an additional cost. # You can specify to use server side encryption when writing an object. # - # obj.write('data', :server_size_encryption => :aes256) + # obj.write('data', :server_side_encryption => :aes256) # # You can also make this the default behavior. # # AWS.config(:s3_server_side_encryption => :aes256) # @@ -359,13 +359,16 @@ # # @option [Boolean] :delete_instruction_file (false) Set this to +true+ # if you use client-side encryption and the encryption materials # were stored in a separate object in S3 (key.instruction). # + # @option [String] :mfa The serial number and current token code of + # the Multi-Factor Authentication (MFA) device for the user. Format + # is "SERIAL TOKEN" - with a space between the serial and token. + # # @return [nil] def delete options = {} - client.delete_object(options.merge( :bucket_name => bucket.name, :key => key)) if options[:delete_instruction_file] @@ -1112,10 +1115,20 @@ # This option defaults to one hour after the current time. # # @option options [Boolean] :secure (true) Whether to generate a # secure (HTTPS) URL or a plain HTTP url. # + # @option options [String] :endpoint Sets the hostname of the + # endpoint (overrides config.s3_endpoint). + # + # @option options [Integer] :port Sets the port of the + # endpoint (overrides config.s3_port). + # + # @option options [Boolean] :force_path_style (false) Indicates + # whether the generated URL should place the bucket name in + # the path (true) or as a subdomain (false). + # # @option options [String] :response_content_type Sets the # Content-Type header of the response when performing an # HTTP GET on the returned URL. # # @option options [String] :response_content_language Sets the @@ -1137,10 +1150,13 @@ # @option options [String] :response_content_encoding Sets the # Content-Encoding header of the response when performing an # HTTP GET on the returned URL. # @return [URI::HTTP, URI::HTTPS] def url_for(method, options = {}) + + options[:secure] = config.use_ssl? unless options.key?(:secure) + req = request_for_signing(options) method = http_method(method) expires = expiration_timestamp(options[:expires]) req.add_param("AWSAccessKeyId", @@ -1150,11 +1166,12 @@ req.add_param("Expires", expires) req.add_param("x-amz-security-token", config.credential_provider.session_token) if config.credential_provider.session_token - build_uri(options[:secure] != false, req) + secure = options.fetch(:secure, config.use_ssl?) + build_uri(req, options) end # Generates a public (not authenticated) URL for the object. # # @param [Hash] options Options for generating the URL. @@ -1163,12 +1180,12 @@ # secure (HTTPS) URL or a plain HTTP url. # # @return [URI::HTTP, URI::HTTPS] # def public_url(options = {}) - req = request_for_signing(options) - build_uri(options[:secure] != false, req) + options[:secure] = config.use_ssl? unless options.key?(:secure) + build_uri(request_for_signing(options), options) end # Generates fields for a presigned POST to this object. This # method adds a constraint that the key must match the key of # this object. All options are sent to the PresignedPost @@ -1263,13 +1280,14 @@ raise ArgumentError, msg end estimate end - def build_uri(secure, request) - uri_class = secure ? URI::HTTPS : URI::HTTP + def build_uri(request, options) + uri_class = options[:secure] ? URI::HTTPS : URI::HTTP uri_class.build(:host => request.host, + :port => request.port, :path => request.path, :query => request.querystring) end def signature(method, expires, request) @@ -1277,13 +1295,12 @@ parts = [] parts << method parts << "" parts << "" parts << expires - if config.credential_provider.session_token - parts << "x-amz-security-token:" - parts << "#{config.credential_provider.session_token}" + if token = config.credential_provider.session_token + parts << "x-amz-security-token:#{token}" end parts << request.canonicalized_resource string_to_sign = parts.join("\n") @@ -1316,14 +1333,21 @@ end symbol.to_s.upcase end def request_for_signing(options) + + port = [443, 80].include?(config.s3_port) ? + (options[:secure] ? 443 : 80) : + config.s3_port + req = Request.new req.bucket = bucket.name req.key = key - req.host = config.s3_endpoint + req.host = options.fetch(:endpoint, config.s3_endpoint) + req.port = options.fetch(:port, port) + req.force_path_style = options.fetch(:force_path_style, config.s3_force_path_style) REQUEST_PARAMETERS.each do |param| req.add_param(param.to_s.tr("_","-"), options[param]) if options.key?(param) end