class Chef::HTTP::AuthCredentials

Attributes

client_name[R]
key[R]

Public Class Methods

new(client_name=nil, key=nil) click to toggle source
# File lib/chef/http/auth_credentials.rb, line 31
def initialize(client_name=nil, key=nil)
  @client_name, @key = client_name, key
end

Public Instance Methods

sign_requests?() click to toggle source
# File lib/chef/http/auth_credentials.rb, line 35
def sign_requests?
  !!key
end
signature_headers(request_params={}) click to toggle source
# File lib/chef/http/auth_credentials.rb, line 39
def signature_headers(request_params={})
  raise ArgumentError, "Cannot sign the request without a client name, check that :node_name is assigned" if client_name.nil?
  Chef::Log.debug("Signing the request as #{client_name}")

  # params_in = {:http_method => :GET, :path => "/clients", :body => "", :host => "localhost"}
  request_params                 = request_params.dup
  request_params[:timestamp]     = Time.now.utc.iso8601
  request_params[:user_id]       = client_name
  request_params[:proto_version] = Chef::Config[:authentication_protocol_version]
  host = request_params.delete(:host) || "localhost"

  sign_obj = Mixlib::Authentication::SignedHeaderAuth.signing_object(request_params)
  signed =  sign_obj.sign(key).merge({:host => host})
  signed.inject({}){|memo, kv| memo["#{kv[0].to_s.upcase}"] = kv[1];memo}
end