Module: SensuPluginsHttp::AwsV4
- Defined in:
- lib/sensu-plugins-http/aws-v4.rb
Instance Method Summary collapse
-
#apply_v4_signature(http, req, options = {}) ⇒ Object
Returns a modified request object with AWS v4 signature headers and authentication options (if any).
Instance Method Details
#apply_v4_signature(http, req, options = {}) ⇒ Object
Returns a modified request object with AWS v4 signature headers and authentication options (if any)
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/sensu-plugins-http/aws-v4.rb', line 18 def apply_v4_signature(http, req, = {}) require 'aws-sdk' fake_seahorse = Struct.new(:endpoint, :body, :headers, :http_method) headers = {} req.each_name { |name| headers[name] = req[name] } protocol = http.use_ssl? ? 'https' : 'http' uri = URI.parse("#{protocol}://#{http.address}:#{http.port}#{req.path}") fake_req = fake_seahorse.new(uri, req.body || '', headers, req.method) credentials = Aws::CredentialProviderChain.new.resolve service = [:aws_v4_service] || 'execute-api' region = [:aws_v4_region] || ENV['AWS_REGION'] || ENV['AWS_DEFAULT_REGION'] signer = Aws::Signers::V4.new(credentials, service, region) signed_req = signer.sign(fake_req) signed_req.headers.each { |key, value| req[key] = value } req end |