def get_password(self, server, private_key): """ Get password for an instance Requires that openssl in installed and in the path :param server: The :class:`Server` (or its ID) to add an IP to. :param private_key: The private key to decrypt password """ _resp, body = self.api.client.get("/servers/%s/os-server-password" % base.getid(server)) if body and body.get("password"): try: return crypto.decrypt_password(private_key, body["password"]) except Exception as exc: return "%sFailed to decrypt:\n%s" % (exc, body["password"]) return ""
def get_password(self, server, private_key): """ Get password for an instance Requires that openssl is installed and in the path :param server: The :class:`Server` (or its ID) to add an IP to. :param private_key: The private key to decrypt password """ _resp, body = self.api.client.get("/servers/%s/os-server-password" % base.getid(server)) if body and body.get('password'): try: return crypto.decrypt_password(private_key, body['password']) except Exception as exc: return '%sFailed to decrypt:\n%s' % (exc, body['password']) return ''
def test_decrypt_password(self, mock_open): mocked_proc = mock.Mock() mock_open.return_value = mocked_proc mocked_proc.returncode = 0 mocked_proc.communicate.return_value = (self.decrypt_password, '') decrypt_password = crypto.decrypt_password(self.private_key, self.password_string) # The return value is 'str' in both python 2 and python 3 self.assertIsInstance(decrypt_password, str) self.assertEqual('Decrypt Password', decrypt_password) mock_open.assert_called_once_with( ['openssl', 'rsautl', '-decrypt', '-inkey', self.private_key], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) mocked_proc.communicate.assert_called_once_with( base64.b64decode(self.password_string)) mocked_proc.stdin.close.assert_called_once_with()
def get_password(self, server, private_key=None): """ Get password for an instance Returns the clear password of an instance if private_key is provided, returns the ciphered password otherwise. Requires that openssl is installed and in the path :param server: The :class:`Server` (or its ID) to add an IP to. :param private_key: The private key to decrypt password (optional) """ _resp, body = self.api.client.get("/servers/%s/os-server-password" % base.getid(server)) ciphered_pw = body.get("password", "") if body else "" if private_key and ciphered_pw: try: return crypto.decrypt_password(private_key, ciphered_pw) except Exception as exc: return "%sFailed to decrypt:\n%s" % (exc, ciphered_pw) return ciphered_pw
def get_password(self, server, private_key=None): """ Get password for an instance Returns the clear password of an instance if private_key is provided, returns the ciphered password otherwise. Requires that openssl is installed and in the path :param server: The :class:`Server` (or its ID) to add an IP to. :param private_key: The private key to decrypt password (optional) """ _resp, body = self.api.client.get("/servers/%s/os-server-password" % base.getid(server)) ciphered_pw = body.get('password', '') if body else '' if private_key and ciphered_pw: try: return crypto.decrypt_password(private_key, ciphered_pw) except Exception as exc: return '%sFailed to decrypt:\n%s' % (exc, ciphered_pw) return ciphered_pw
def get_password(self, server, private_key=None): """ Get admin password of an instance Returns the admin password of an instance in the clear if private_key is provided, returns the ciphered password otherwise. Requires that openssl is installed and in the path :param server: The :class:`Server` (or its ID) for which the admin password is to be returned :param private_key: The private key to decrypt password (optional) """ _resp, body = self.api.client.get("/servers/%s/os-server-password" % base.getid(server)) ciphered_pw = body.get('password', '') if body else '' if private_key and ciphered_pw: try: return crypto.decrypt_password(private_key, ciphered_pw) except Exception as exc: return '%sFailed to decrypt:\n%s' % (exc, ciphered_pw) return ciphered_pw