本文整理汇总了Python中novaclient.crypto.decrypt_password函数的典型用法代码示例。如果您正苦于以下问题:Python decrypt_password函数的具体用法?Python decrypt_password怎么用?Python decrypt_password使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了decrypt_password函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_password
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 ""
示例2: test_decrypt_password
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()
示例3: get_password
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
示例4: get_password
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