Sha256: 44075202838fa302567b066a1b12c2a42aa52c43ace89d09403c166c26ca305a
Contents?: true
Size: 1.3 KB
Versions: 21
Compression:
Stored size: 1.3 KB
Contents
require 'mixlib/authentication/signedheaderauth' module Ridley module Middleware # @author Jamie Winsor <jamie@vialstudios.com> class ChefAuth < Faraday::Middleware attr_reader :client_name attr_reader :client_key def initialize(app, client_name, client_key) super(app) @client_name = client_name @client_key = OpenSSL::PKey::RSA.new(File.read(client_key)) end def call(env) sign_obj = Mixlib::Authentication::SignedHeaderAuth.signing_object( http_method: env[:method], host: env[:url].host, path: env[:url].path, body: env[:body] || '', timestamp: Time.now.utc.iso8601, user_id: client_name ) authentication_headers = sign_obj.sign(client_key) env[:request_headers] = default_headers.merge(env[:request_headers]).merge(authentication_headers) env[:request_headers] = env[:request_headers].merge('Content-Length' => env[:body].bytesize.to_s) if env[:body] Ridley.log.debug(env) @app.call(env) end private def default_headers { 'Accept' => 'application/json', 'Content-Type' => 'application/json', 'X-Chef-Version' => Ridley::CHEF_VERSION } end end end end
Version data entries
21 entries across 21 versions & 1 rubygems