Module: Spice::Authentication

Included in:
Connection
Defined in:
lib/spice/authentication.rb

Instance Method Summary collapse

Instance Method Details

#signature_headers(method, path, json_body = nil) ⇒ Object


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/spice/authentication.rb', line 8

def signature_headers(method, path, json_body=nil)
  uri = URI(server_url)
  
  params = {
    :http_method => method, 
    :path        => path,
    :body        => json_body || "", 
    :host        => "#{uri.host}:#{uri.port}",
    :timestamp   => Time.now.utc.iso8601,
    :user_id     => client_name
  }

  signing_object = Mixlib::Authentication::SignedHeaderAuth.signing_object(params)
  signed_headers = signing_object.sign(client_key)

  # Platform requires X-Chef-Version header
  signed_headers['X-Chef-Version'] = chef_version
  # signed_headers['Content-Length'] = json_body.bytesize.to_s if json_body
  signed_headers
end