def gen_validation_key(name=Chef::Config[:validation_client_name], key_file=Chef::Config[:validation_key], admin=false)
api_client = Chef::ApiClient.new
api_client.name(name)
api_client.admin(admin)
begin
Chef::ApiClient.cdb_load(name)
File.open(key_file, "r") do |file|
end
rescue Chef::Exceptions::CouchDBNotFound
create_validation_key(api_client, key_file)
rescue
if $!.class.name =~ /Errno::/
Chef::Log.error("Error opening validation key: #{$!} -- destroying and regenerating")
begin
api_client.cdb_destroy
rescue Bunny::ServerDownError => e
Chef::Log.fatal("Could not de-index (to rabbitmq) previous validation key - rabbitmq is down! Start rabbitmq then restart chef-server to re-generate it")
raise
end
create_validation_key(api_client, key_file)
else
raise
end
end
end