Sha256: ad2ac2b9ed7cfbf5ba705e6e51a4f997729e5411bf3aa773af7cd75615779e8c

Contents?: true

Size: 1.76 KB

Versions: 80

Compression:

Stored size: 1.76 KB

Contents

# frozen_string_literal: true

module Aws
  module S3
    module Plugins

      # Amazon S3 requires DNS style addressing for buckets outside of
      # the classic region when possible.
      class BucketDns < Seahorse::Client::Plugin

        # When set to `false` DNS compatible bucket names are moved from
        # the request URI path to the host as a subdomain, unless the request
        # is using SSL and the bucket name contains a dot.
        #
        # When set to `true`, the bucket name is always forced to be part
        # of the request URI path.  This will not work with buckets outside
        # the classic region.
        option(:force_path_style,
          default: false,
          doc_type: 'Boolean',
          docstring: <<-DOCS)
When set to `true`, the bucket name is always left in the
request URI and never moved to the host as a sub-domain.
          DOCS

        # These class methods were originally used in a handler in this plugin.
        # SigV2 legacy signer needs this logic so we keep it here as utility.
        # New endpoint resolution will check this as a matcher.
        class << self
          # @param [String] bucket_name
          # @param [Boolean] ssl
          # @return [Boolean]
          def dns_compatible?(bucket_name, ssl)
            if valid_subdomain?(bucket_name)
              bucket_name.match(/\./) && ssl ? false : true
            else
              false
            end
          end

          # @param [String] bucket_name
          # @return [Boolean]
          def valid_subdomain?(bucket_name)
            bucket_name.size < 64 &&
            bucket_name =~ /^[a-z0-9][a-z0-9.-]+[a-z0-9]$/ &&
            bucket_name !~ /(\d+\.){3}\d+/ &&
            bucket_name !~ /[.-]{2}/
          end
        end
      end
    end
  end
end

Version data entries

80 entries across 80 versions & 1 rubygems

Version Path
aws-sdk-s3-1.182.0 lib/aws-sdk-s3/plugins/bucket_dns.rb
aws-sdk-s3-1.181.0 lib/aws-sdk-s3/plugins/bucket_dns.rb
aws-sdk-s3-1.180.0 lib/aws-sdk-s3/plugins/bucket_dns.rb
aws-sdk-s3-1.179.0 lib/aws-sdk-s3/plugins/bucket_dns.rb
aws-sdk-s3-1.178.0 lib/aws-sdk-s3/plugins/bucket_dns.rb
aws-sdk-s3-1.177.0 lib/aws-sdk-s3/plugins/bucket_dns.rb
aws-sdk-s3-1.176.1 lib/aws-sdk-s3/plugins/bucket_dns.rb
aws-sdk-s3-1.176.0 lib/aws-sdk-s3/plugins/bucket_dns.rb
aws-sdk-s3-1.175.0 lib/aws-sdk-s3/plugins/bucket_dns.rb
aws-sdk-s3-1.174.0 lib/aws-sdk-s3/plugins/bucket_dns.rb
aws-sdk-s3-1.173.0 lib/aws-sdk-s3/plugins/bucket_dns.rb
aws-sdk-s3-1.172.0 lib/aws-sdk-s3/plugins/bucket_dns.rb
aws-sdk-s3-1.171.0 lib/aws-sdk-s3/plugins/bucket_dns.rb
aws-sdk-s3-1.170.1 lib/aws-sdk-s3/plugins/bucket_dns.rb
aws-sdk-s3-1.170.0 lib/aws-sdk-s3/plugins/bucket_dns.rb
aws-sdk-s3-1.169.0 lib/aws-sdk-s3/plugins/bucket_dns.rb
aws-sdk-s3-1.168.0 lib/aws-sdk-s3/plugins/bucket_dns.rb
aws-sdk-s3-1.167.0 lib/aws-sdk-s3/plugins/bucket_dns.rb
aws-sdk-s3-1.166.0 lib/aws-sdk-s3/plugins/bucket_dns.rb
aws-sdk-s3-1.165.0 lib/aws-sdk-s3/plugins/bucket_dns.rb