Sha256: de768a0d3ae6b4450d26987895c3b84b55eb9213510659b8c9a365c14106c678

Contents?: true

Size: 1.83 KB

Versions: 91

Compression:

Stored size: 1.83 KB

Contents

module Aws
  module Plugins
    # @api private
    class EndpointPattern < Seahorse::Client::Plugin

      option(:disable_host_prefix_injection,
        default: false,
        doc_type: 'Boolean',
        docstring: <<-DOCS
Set to true to disable SDK automatically adding host prefix
to default service endpoint when available.
        DOCS
      )

      def add_handlers(handlers, config)
        if config.regional_endpoint && !config.disable_host_prefix_injection
          handlers.add(Handler, priority: 90)
        end
      end

      class Handler < Seahorse::Client::Handler

        def call(context)
          endpoint_trait = context.operation.endpoint_pattern
          if endpoint_trait && !endpoint_trait.empty?
            _apply_endpoint_trait(context, endpoint_trait)
          end
          @handler.call(context)
        end

        private

        def _apply_endpoint_trait(context, trait)
          # currently only support host pattern
          ori_host = context.http_request.endpoint.host
          if pattern = trait['hostPrefix']
            host_prefix = pattern.gsub(/\{.+?\}/) do |label|
              label = label.delete("{}")
              _replace_label_value(
                ori_host, label, context.operation.input, context.params)
            end
            context.http_request.endpoint.host = host_prefix + context.http_request.endpoint.host
          end
        end

        def _replace_label_value(ori, label, input_ref, params)
          name = nil
          input_ref.shape.members.each do |m_name, ref|
            if ref['hostLabel'] && ref['hostLabelName'] == label
              name = m_name
            end
          end
          if name.nil? || params[name].nil?
            raise Errors::MissingEndpointHostLabelValue.new(name)
          end
          params[name]
        end

      end

    end
  end
end

Version data entries

91 entries across 91 versions & 1 rubygems

Version Path
aws-sdk-core-3.70.0 lib/aws-sdk-core/plugins/endpoint_pattern.rb
aws-sdk-core-3.69.1 lib/aws-sdk-core/plugins/endpoint_pattern.rb
aws-sdk-core-3.69.0 lib/aws-sdk-core/plugins/endpoint_pattern.rb
aws-sdk-core-3.68.1 lib/aws-sdk-core/plugins/endpoint_pattern.rb
aws-sdk-core-3.68.0 lib/aws-sdk-core/plugins/endpoint_pattern.rb
aws-sdk-core-3.67.0 lib/aws-sdk-core/plugins/endpoint_pattern.rb
aws-sdk-core-3.66.0 lib/aws-sdk-core/plugins/endpoint_pattern.rb
aws-sdk-core-3.65.1 lib/aws-sdk-core/plugins/endpoint_pattern.rb
aws-sdk-core-3.65.0 lib/aws-sdk-core/plugins/endpoint_pattern.rb
aws-sdk-core-3.64.0 lib/aws-sdk-core/plugins/endpoint_pattern.rb
aws-sdk-core-3.63.0 lib/aws-sdk-core/plugins/endpoint_pattern.rb
aws-sdk-core-3.62.0 lib/aws-sdk-core/plugins/endpoint_pattern.rb
aws-sdk-core-3.61.2 lib/aws-sdk-core/plugins/endpoint_pattern.rb
aws-sdk-core-3.61.1 lib/aws-sdk-core/plugins/endpoint_pattern.rb
aws-sdk-core-3.61.0 lib/aws-sdk-core/plugins/endpoint_pattern.rb
aws-sdk-core-3.60.0 lib/aws-sdk-core/plugins/endpoint_pattern.rb
aws-sdk-core-3.59.0 lib/aws-sdk-core/plugins/endpoint_pattern.rb
aws-sdk-core-3.58.0 lib/aws-sdk-core/plugins/endpoint_pattern.rb
aws-sdk-core-3.57.0 lib/aws-sdk-core/plugins/endpoint_pattern.rb
aws-sdk-core-3.56.0 lib/aws-sdk-core/plugins/endpoint_pattern.rb