lib/ridley/middleware/chef_auth.rb in ridley-0.12.1 vs lib/ridley/middleware/chef_auth.rb in ridley-0.12.2
- old
+ new
@@ -9,16 +9,19 @@
# Generate authentication headers for a request to a Chef Server
#
# @param [String] client_name
# @param [String] client_key
+ # the path OR actual client key
#
# @option options [String] :host
#
# @see {#signing_object} for options
def authentication_headers(client_name, client_key, options = {})
- rsa_key = OpenSSL::PKey::RSA.new(File.read(client_key))
+ contents = File.exists?(client_key) ? File.read(client_key) : client_key.to_s
+ rsa_key = OpenSSL::PKey::RSA.new(contents)
+
headers = signing_object(client_name, options).sign(rsa_key).merge(host: options[:host])
headers.inject({}) { |memo, kv| memo["#{kv[0].to_s.upcase}"] = kv[1];memo }
end
# Create a signing object for a Request to a Chef Server
@@ -55,10 +58,10 @@
end
def call(env)
signing_options = {
http_method: env[:method],
- host: env[:url].host || "localhost",
+ host: "#{env[:url].host}:#{env[:url].port}",
path: env[:url].path,
body: env[:body] || ''
}
authentication_headers = self.class.authentication_headers(client_name, client_key, signing_options)