Sha256: 172058ff2220e69c3b06227e1f23c0a7beae44761aed10f8ce0587c2082e2aae
Contents?: true
Size: 1.39 KB
Versions: 1
Compression:
Stored size: 1.39 KB
Contents
require 'mixlib/authentication/signedheaderauth' module Ridley module Middleware # @author Jamie Winsor <jamie@vialstudios.com> class ChefAuth < Faraday::Middleware include Ridley::Logging 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] log.debug { "Performing Authenticated Chef Request: "} 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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ridley-0.7.0.rc1 | lib/ridley/middleware/chef_auth.rb |