Returns true if the given bucket_name
is DNS compatible.
DNS compatible bucket names may be accessed like:
http://dns.compat.bucket.name.s3.amazonaws.com/
Whereas non-dns compatible bucket names must place the bucket name in the url path, like:
http://s3.amazonaws.com/dns_incompat_bucket_name/
@return [Boolean] Returns true if the given bucket name may be
is dns compatible. this bucket n
# File lib/aws/s3/client.rb, line 1432 def dns_compatible_bucket_name?(bucket_name) return false if !valid_bucket_name?(bucket_name) or # Bucket names should not contain underscores (_) bucket_name["_"] or # Bucket names should be between 3 and 63 characters long bucket_name.size > 63 or # Bucket names should not end with a dash bucket_name[-1,1] == '-' or # Bucket names cannot contain two, adjacent periods bucket_name['..'] or # Bucket names cannot contain dashes next to periods # (e.g., "my-.bucket.com" and "my.-bucket" are invalid) (bucket_name['-.'] || bucket_name['.-']) true end
# File lib/aws/s3/client.rb, line 1593 def json_validation_message(obj) if obj.respond_to?(:to_str) obj = obj.to_str elsif obj.respond_to?(:to_json) obj = obj.to_json end error = nil begin JSON.parse(obj) rescue => e error = e end "contains invalid JSON: #{error}" if error end
Returns true if the bucket name must be used in the request path instead of as a sub-domain when making requests against S3.
This can be an issue if the bucket name is DNS compatible but contains '.' (periods). These cause the SSL certificate to become invalid when making authenticated requets over SSL to the bucket name. The solution is to send this as a path argument instead.
@return [Boolean] Returns true if the bucket name should be used
as a path segement instead of dns prefix when making requests against s3.
# File lib/aws/s3/client.rb, line 1469 def path_style_bucket_name? bucket_name if dns_compatible_bucket_name?(bucket_name) bucket_name =~ %r\./ ? true : false else true end end
# File lib/aws/s3/client.rb, line 1532 def require_acl! options acl_options = [ :acl, :grant_read, :grant_write, :grant_read_acp, :grant_write_acp, :grant_full_control, :access_control_policy, ] unless options.keys.any?{|opt| acl_options.include?(opt) } msg = "missing a required ACL option, must provide an ACL " + "via :acl, :grant_* or :access_control_policy" raise ArgumentError, msg end end
# File lib/aws/s3/client.rb, line 1493 def require_bucket_name! bucket_name if [nil, ''].include?(bucket_name) raise ArgumentError, "bucket_name may not be blank" end end
# File lib/aws/s3/client.rb, line 1569 def require_part_number! part_number validate!("part_number", part_number) do "must not be blank" if part_number.to_s.empty? end end
# File lib/aws/s3/client.rb, line 1521 def require_policy!(policy) validate!('policy', policy) do case when policy.nil? || policy == '' 'may not be blank' else json_validation_message(policy) end end end
# File lib/aws/s3/client.rb, line 1563 def require_upload_id!(upload_id) validate!("upload_id", upload_id) do "must not be blank" if upload_id.to_s.empty? end end
# File lib/aws/s3/client.rb, line 1549 def set_body_stream_and_content_length request, options unless options[:content_length] msg = "S3 requires a content-length header, unable to determine " msg << "the content length of the data provided, please set " msg << ":content_length" raise ArgumentError, msg end request.headers['content-length'] = options[:content_length] request.body_stream = options[:data] end
@return [Boolean] Returns true if the given bucket name is valid.
# File lib/aws/s3/client.rb, line 1413 def valid_bucket_name?(bucket_name) validate_bucket_name!(bucket_name) rescue false end
# File lib/aws/s3/client.rb, line 1477 def validate! name, value, &block if error_msg = yield raise ArgumentError, "#{name} #{error_msg}" end value end
Returns true if the given bucket name is valid. If the name is invalid, an ArgumentError is raised.
# File lib/aws/s3/client.rb, line 1501 def validate_bucket_name!(bucket_name) validate!('bucket_name', bucket_name) do case when bucket_name.nil? || bucket_name == '' 'may not be blank' when bucket_name !~ %r^[a-z0-9._\-]+$/ 'may only contain lowercase letters, numbers, periods (.), ' + 'underscores (_), and dashes (-)' when bucket_name !~ %r^[a-z0-9]/ 'must start with a letter or a number' when !(3..255).include?(bucket_name.size) 'must be between 3 and 255 characters long' when bucket_name =~ %r(\d+\.){3}\d+/ 'must not be formatted like an IP address (e.g., 192.168.5.4)' when bucket_name =~ %r\n/ 'must not contain a newline character' end end end
# File lib/aws/s3/client.rb, line 1484 def validate_key!(key) validate!('key', key) do case when key.nil? || key == '' 'may not be blank' end end end
# File lib/aws/s3/client.rb, line 1575 def validate_parts!(parts) validate!("parts", parts) do if !parts.kind_of?(Array) "must not be blank" elsif parts.empty? "must contain at least one entry" elsif !parts.all? { |p| p.kind_of?(Hash) } "must be an array of hashes" elsif !parts.all? { |p| p[:part_number] } "must contain part_number for each part" elsif !parts.all? { |p| p[:etag] } "must contain etag for each part" elsif parts.any? { |p| p[:part_number].to_i < 1 } "must not have part numbers less than 1" end end end