Skip to content

Instantly share code, notes, and snippets.

@databus23
Created January 27, 2012 14:38
Show Gist options
  • Save databus23/1689076 to your computer and use it in GitHub Desktop.
Save databus23/1689076 to your computer and use it in GitHub Desktop.
Monkey patch Chef::REST::AuthCredentials to support keys directly
#Chef::REST::AuthCredentials accepts only filenames by default
#this extends the Chef::REST::AuthCredentials so that the key can be provided directly
require 'chef/rest/auth_credentials'
class Chef
class REST
class AuthCredentials
alias :original_load_signing_key :load_signing_key
def load_signing_key
if key_file.start_with?("-----BEGIN RSA PRIVATE KEY-----")
@raw_key = key_file.strip
begin
@key = OpenSSL::PKey::RSA.new(@raw_key)
rescue OpenSSL::PKey::RSAError
msg = "The key is not a correctly formatted private key.\n"
msg << "The key should begin with '-----BEGIN RSA PRIVATE KEY-----' and end with '-----END RSA PRIVATE KEY-----'"
raise Chef::Exceptions::InvalidPrivateKey, msg
end
else
original_load_signing_key
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment