Sha256: 385458a2b141455d58d03eae38d461167c235e4794dd6c59003ed57641c9bd0e

Contents?: true

Size: 1.3 KB

Versions: 129

Compression:

Stored size: 1.3 KB

Contents

module Aws
  module Plugins

    # Provide support for `api_key` parameter for `api-gateway` protocol
    # specific `api-gateway` protocol gems' user-agent
    class ApiKey < Seahorse::Client::Plugin

      option(:api_key,
        default: nil,
        doc_type: 'String',
        docstring: <<-DOCS)
When provided, `x-api-key` header will be injected with the value provided.
        DOCS

      def add_handlers(handlers, config)
        handlers.add(OptionHandler, step: :initialize)
        handlers.add(ApiKeyHandler, step: :build, priority: 0)
      end

      # @api private
      class OptionHandler < Seahorse::Client::Handler
        def call(context)
          if context.operation.require_apikey
            api_key = context.params.delete(:api_key)
            api_key = context.config.api_key if api_key.nil?
            context[:api_key] = api_key
          end

          @handler.call(context)
        end

      end

      # @api private
      class ApiKeyHandler < Seahorse::Client::Handler

        def call(context)
          if context[:api_key]
            apply_api_key(context)
          end
          @handler.call(context)
        end

        private

        def apply_api_key(context)
          context.http_request.headers['x-api-key'] = context[:api_key]
        end
      end
    end
  end
end

Version data entries

129 entries across 129 versions & 1 rubygems

Version Path
aws-sdk-core-3.100.0 lib/aws-sdk-core/plugins/api_key.rb
aws-sdk-core-3.99.2 lib/aws-sdk-core/plugins/api_key.rb
aws-sdk-core-3.99.1 lib/aws-sdk-core/plugins/api_key.rb
aws-sdk-core-3.99.0 lib/aws-sdk-core/plugins/api_key.rb
aws-sdk-core-3.98.0 lib/aws-sdk-core/plugins/api_key.rb
aws-sdk-core-3.97.1 lib/aws-sdk-core/plugins/api_key.rb
aws-sdk-core-3.97.0 lib/aws-sdk-core/plugins/api_key.rb
aws-sdk-core-3.96.1 lib/aws-sdk-core/plugins/api_key.rb
aws-sdk-core-3.96.0 lib/aws-sdk-core/plugins/api_key.rb
aws-sdk-core-3.95.0 lib/aws-sdk-core/plugins/api_key.rb
aws-sdk-core-3.94.1 lib/aws-sdk-core/plugins/api_key.rb
aws-sdk-core-3.94.0 lib/aws-sdk-core/plugins/api_key.rb
aws-sdk-core-3.93.0 lib/aws-sdk-core/plugins/api_key.rb
aws-sdk-core-3.92.0 lib/aws-sdk-core/plugins/api_key.rb
aws-sdk-core-3.91.1 lib/aws-sdk-core/plugins/api_key.rb
aws-sdk-core-3.91.0 lib/aws-sdk-core/plugins/api_key.rb
aws-sdk-core-3.90.1 lib/aws-sdk-core/plugins/api_key.rb
aws-sdk-core-3.90.0 lib/aws-sdk-core/plugins/api_key.rb
aws-sdk-core-3.89.1 lib/aws-sdk-core/plugins/api_key.rb
aws-sdk-core-3.89.0 lib/aws-sdk-core/plugins/api_key.rb