Sha256: c8256753b7965a886094b6e50d094f009f7042ed60016513d7dedc8066a6cb37

Contents?: true

Size: 1.12 KB

Versions: 16

Compression:

Stored size: 1.12 KB

Contents

require 'aws-sdk-core'
require 'faraday'


class AwsV4Signer < Faraday::Middleware
  class Request
    def initialize(env)
      @env = env
    end

    def headers
      @env.request_headers
    end

    def set_header(header)
      @env.request_headers = header
    end

    def body
      @env.body || ''
    end

    def endpoint
      @env.url
    end

    def http_method
      @env.method.to_s.upcase
    end
  end

  def signer
    credentials = @options.fetch(:credentials)
    service_name = @options.fetch(:service_name)
    region = @options.fetch(:region)
    Aws::Signers::V4.new(credentials, service_name, region)
  end

 def initialize(app, options = nil)
    super(app)
    @options = options
    @net_http = app.is_a?(Faraday::Adapter::NetHttp)
  end

  def call(env)
    normalize_for_net_http!(env)
    req = Request.new(env)
    signer().sign(req)
    @app.call(env)
  end

  private
  def normalize_for_net_http!(env)
    return unless @net_http

    if Net::HTTP::HAVE_ZLIB
      env.request_headers['Accept-Encoding'] ||= 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3'
    end

    env.request_headers['Accept'] ||= '*/*'
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
logstash-output-amazon_es-6.0.0 lib/logstash/outputs/amazon_es/aws_v4_signer_impl.rb
logstash-output-amazon_es-2.0.1-java lib/logstash/outputs/amazon_es/aws_v4_signer_impl.rb
logstash-output-amazon_es-2.0.1 lib/logstash/outputs/amazon_es/aws_v4_signer_impl.rb
logstash-output-amazon_es-1.1.0 lib/logstash/outputs/amazon_es/aws_v4_signer_impl.rb
logstash-output-amazon_es-1.1.0-java lib/logstash/outputs/amazon_es/aws_v4_signer_impl.rb
logstash-output-amazon_es-1.0-java lib/logstash/outputs/amazon_es/aws_v4_signer_impl.rb
logstash-output-amazon_es-1.0 lib/logstash/outputs/amazon_es/aws_v4_signer_impl.rb
logstash-output-amazon_es-0.3-java lib/logstash/outputs/amazon_es/aws_v4_signer_impl.rb
logstash-output-amazon_es-0.3 lib/logstash/outputs/amazon_es/aws_v4_signer_impl.rb
logstash-output-amazon_es-0.2.0-java lib/logstash/outputs/amazon_es/aws_v4_signer_impl.rb
logstash-output-amazon_es-0.2.0 lib/logstash/outputs/amazon_es/aws_v4_signer_impl.rb
aws-es-transport-0.1.3 lib/aws_v4_signer_impl.rb
logstash-output-amazon_es-0.1.3-java lib/logstash/outputs/amazon_es/aws_v4_signer_impl.rb
logstash-output-amazon_es-0.1.3 lib/logstash/outputs/amazon_es/aws_v4_signer_impl.rb
logstash-output-amazon_es-0.1.2 lib/logstash/outputs/amazon_es/aws_v4_signer_impl.rb
logstash-output-amazon_es-0.1.2-java lib/logstash/outputs/amazon_es/aws_v4_signer_impl.rb