From bbc92cc53d381a79fa58480f779d7454302ee805 Mon Sep 17 00:00:00 2001 From: Rupak Ganguly Date: Thu, 4 Oct 2012 16:50:51 -0400 Subject: [PATCH] Update the get_windows_password to return the encrypted password instead of the decrypted one. --- lib/fog/hp/models/compute/server.rb | 4 +- .../requests/compute/get_windows_password.rb | 48 +++++++------------ 2 files changed, 18 insertions(+), 34 deletions(-) diff --git a/lib/fog/hp/models/compute/server.rb b/lib/fog/hp/models/compute/server.rb index 95cc78cf9..e74711379 100644 --- a/lib/fog/hp/models/compute/server.rb +++ b/lib/fog/hp/models/compute/server.rb @@ -158,9 +158,7 @@ module Fog def windows_password() requires :id - if self.private_key - connection.get_windows_password(id, self.private_key) - end + connection.get_windows_password(id) end def reboot(type = 'SOFT') diff --git a/lib/fog/hp/requests/compute/get_windows_password.rb b/lib/fog/hp/requests/compute/get_windows_password.rb index 8c13a5acb..564b4efb7 100644 --- a/lib/fog/hp/requests/compute/get_windows_password.rb +++ b/lib/fog/hp/requests/compute/get_windows_password.rb @@ -3,29 +3,26 @@ module Fog class HP class Real - def get_windows_password(server_id, private_key_data) - begin - # get console output assuming that the server is already in active state - log_output = get_console_output(server_id, 400).body['output'] - # decrypt the log output to extract the password - encrypted_text = extract_password_from_log(log_output) - if encrypted_text - password = decrypt_using_private_key(encrypted_text, private_key_data) - else - raise "Error in extracting encrypted password from the log." - end - rescue OpenSSL::PKey::RSAError => error - raise "Error in decrypting password. Exception: #{error}" - end - # return the password - password + # Retrieves the encrypted administrator password for a server running Windows. + # + # ==== Parameters + # * server_id<~Integer> - Id of server + # + # ==== Returns + # * password_data<~string>: Encrypted password for a server running Windows + # + def get_windows_password(server_id) + # get console output assuming that the server is already in active state + log_output = get_console_output(server_id, 400).body['output'] + # decrypt the log output to extract the encrypted, base64-encoded password + encrypted_password = extract_password_from_log(log_output) end end class Mock - def get_windows_password(server_id, private_key_data) + def get_windows_password(server_id) # need to mock out the private key as well private_key = OpenSSL::PKey::RSA.generate(1024) public_key = private_key.public_key @@ -33,20 +30,9 @@ module Fog encoded_password = encrypt_using_public_key("Passw0rd", public_key) if list_servers_detail.body['servers'].detect {|_| _['id'] == server_id} - begin - # mock output for this call get_console_output(server_id, 400).body['output'] - log_output = "start junk [cloud-init] Encrypt random password\n-----BEGIN BASE64-ENCODED ENCRYPTED PASSWORD-----\n#{encoded_password}-----END BASE64-ENCODED ENCRYPTED PASSWORD-----\nend junk [cloud-init] Done\n" - encrypted_text = extract_password_from_log(log_output) - if encrypted_text - password = decrypt_using_private_key(encrypted_text, private_key) - else - raise "Error in extracting encrypted password from the log." - end - rescue OpenSSL::PKey::RSAError => error - raise "Error in decrypting password. Exception: #{error}" - end - # return the password should match Passw0rd - password + # mock output for this call get_console_output(server_id, 400).body['output'] + log_output = "start junk [cloud-init] Encrypt random password\n-----BEGIN BASE64-ENCODED ENCRYPTED PASSWORD-----\n#{encoded_password}-----END BASE64-ENCODED ENCRYPTED PASSWORD-----\nend junk [cloud-init] Done\n" + encrypted_password = extract_password_from_log(log_output) else raise Fog::Compute::HP::NotFound end