    # File lib/chef/certificate.rb, line 131
          def gen_validation_key(name=Chef::Config[:validation_client_name], key_file=Chef::Config[:validation_key], admin=false)
            # Create the validation key
            api_client = Chef::ApiClient.new
            api_client.name(name)
            api_client.admin(admin)

            begin
              # If both the couch record and file exist, don't do anything. Otherwise,
              # re-generate the validation key.
              Chef::ApiClient.cdb_load(name)

              # The couch document was loaded successfully if we got to here; if we
              # can't also load the file on the filesystem, we'll regenerate it all.
              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
                  # create_validation_key is gonna fail anyway, so let's just bail out.
                  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