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

Version Path
ridley-0.7.0.beta lib/ridley/middleware/chef_auth.rb
ridley-0.6.3 lib/ridley/middleware/chef_auth.rb
ridley-0.6.2 lib/ridley/middleware/chef_auth.rb
ridley-0.6.1 lib/ridley/middleware/chef_auth.rb
ridley-0.6.0 lib/ridley/middleware/chef_auth.rb
ridley-0.5.2 lib/ridley/middleware/chef_auth.rb
ridley-0.5.1 lib/ridley/middleware/chef_auth.rb
ridley-0.5.0 lib/ridley/middleware/chef_auth.rb
ridley-0.4.1 lib/ridley/middleware/chef_auth.rb
ridley-0.4.0 lib/ridley/middleware/chef_auth.rb
ridley-0.3.2 lib/ridley/middleware/chef_auth.rb
ridley-0.3.1 lib/ridley/middleware/chef_auth.rb
ridley-0.3.0 lib/ridley/middleware/chef_auth.rb
ridley-0.2.2 lib/ridley/middleware/chef_auth.rb
ridley-0.2.1 lib/ridley/middleware/chef_auth.rb
ridley-0.2.0 lib/ridley/middleware/chef_auth.rb
ridley-0.1.0 lib/ridley/middleware/chef_auth.rb
ridley-0.0.6 lib/ridley/middleware/chef_auth.rb
ridley-0.0.5 lib/ridley/middleware/chef_auth.rb
ridley-0.0.4 lib/ridley/middleware/chef_auth.rb