本文整理汇总了Python中oslo_utils.strutils.mask_password方法的典型用法代码示例。如果您正苦于以下问题:Python strutils.mask_password方法的具体用法?Python strutils.mask_password怎么用?Python strutils.mask_password使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oslo_utils.strutils
的用法示例。
在下文中一共展示了strutils.mask_password方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_encryption_metadata
# 需要导入模块: from oslo_utils import strutils [as 别名]
# 或者: from oslo_utils.strutils import mask_password [as 别名]
def get_encryption_metadata(context, volume_api, volume_id, connection_info):
metadata = {}
if ('data' in connection_info and
connection_info['data'].get('encrypted', False)):
try:
metadata = volume_api.get_volume_encryption_metadata(context,
volume_id)
if not metadata:
LOG.warning('Volume %s should be encrypted but there is no '
'encryption metadata.', volume_id)
except Exception as e:
LOG.error("Failed to retrieve encryption metadata for "
"volume %(volume_id)s: %(exception)s",
{'volume_id': volume_id, 'exception': e})
raise
if metadata:
msg = ("Using volume encryption metadata '%(metadata)s' for "
"connection: %(connection_info)s" %
{'metadata': metadata, 'connection_info': connection_info})
LOG.debug(strutils.mask_password(msg))
return metadata
示例2: _run_iscsiadm
# 需要导入模块: from oslo_utils import strutils [as 别名]
# 或者: from oslo_utils.strutils import mask_password [as 别名]
def _run_iscsiadm(self, connection_properties, iscsi_command, **kwargs):
check_exit_code = kwargs.pop('check_exit_code', 0)
attempts = kwargs.pop('attempts', 1)
delay_on_retry = kwargs.pop('delay_on_retry', True)
(out, err) = self._execute('iscsiadm', '-m', 'node', '-T',
connection_properties['target_iqn'],
'-p',
connection_properties['target_portal'],
*iscsi_command, run_as_root=True,
root_helper=self._root_helper,
check_exit_code=check_exit_code,
attempts=attempts,
delay_on_retry=delay_on_retry)
msg = ("iscsiadm %(iscsi_command)s: stdout=%(out)s stderr=%(err)s" %
{'iscsi_command': iscsi_command, 'out': out, 'err': err})
# don't let passwords be shown in log output
LOG.debug(strutils.mask_password(msg))
return (out, err)
示例3: test_json_message
# 需要导入模块: from oslo_utils import strutils [as 别名]
# 或者: from oslo_utils.strutils import mask_password [as 别名]
def test_json_message(self):
payload = """body: {"changePassword": {"adminPass": "1234567"}}"""
expected = """body: {"changePassword": {"adminPass": "***"}}"""
self.assertEqual(expected, strutils.mask_password(payload))
payload = """body: {"rescue": {"admin_pass": "1234567"}}"""
expected = """body: {"rescue": {"admin_pass": "***"}}"""
self.assertEqual(expected, strutils.mask_password(payload))
payload = """body: {"rescue": {"admin_password": "1234567"}}"""
expected = """body: {"rescue": {"admin_password": "***"}}"""
self.assertEqual(expected, strutils.mask_password(payload))
payload = """body: {"rescue": {"password": "1234567"}}"""
expected = """body: {"rescue": {"password": "***"}}"""
self.assertEqual(expected, strutils.mask_password(payload))
payload = """body: {"rescue": {"encryption_key_id": "1234567"}}"""
expected = """body: {"rescue": {"encryption_key_id": "***"}}"""
self.assertEqual(expected, strutils.mask_password(payload))
示例4: custom_execute
# 需要导入模块: from oslo_utils import strutils [as 别名]
# 或者: from oslo_utils.strutils import mask_password [as 别名]
def custom_execute(*cmd, **kwargs):
try:
return processutils.execute(*cmd, **kwargs)
except processutils.ProcessExecutionError as e:
sanitized_cmd = strutils.mask_password(' '.join(cmd))
raise exception.CommandError(cmd=sanitized_cmd,
error=str(e))
示例5: create_vim
# 需要导入模块: from oslo_utils import strutils [as 别名]
# 或者: from oslo_utils.strutils import mask_password [as 别名]
def create_vim(request, vim_arg):
LOG.debug("create_vim(): vim_arg=%s", strutils.mask_password(vim_arg))
vim_instance = tackerclient(request).create_vim(body=vim_arg)
return vim_instance
示例6: execute
# 需要导入模块: from oslo_utils import strutils [as 别名]
# 或者: from oslo_utils.strutils import mask_password [as 别名]
def execute(*cmd, **kwargs):
"""NB: Raises processutils.ProcessExecutionError on failure."""
run_as_root = kwargs.pop('run_as_root', False)
kwargs.pop('root_helper', None)
try:
if run_as_root:
return execute_root(*cmd, **kwargs)
else:
return custom_execute(*cmd, **kwargs)
except OSError as e:
# Note:
# putils.execute('bogus', run_as_root=True)
# raises ProcessExecutionError(exit_code=1) (because there's a
# "sh -c bogus" involved in there somewhere, but:
# putils.execute('bogus', run_as_root=False)
# raises OSError(not found).
#
# Lots of code in os-brick catches only ProcessExecutionError
# and never encountered the latter when using rootwrap.
# Rather than fix all the callers, we just always raise
# ProcessExecutionError here :(
sanitized_cmd = strutils.mask_password(' '.join(cmd))
raise putils.ProcessExecutionError(
cmd=sanitized_cmd, description=six.text_type(e))
# See comment on `execute`
示例7: _gpfs_ssh_execute
# 需要导入模块: from oslo_utils import strutils [as 别名]
# 或者: from oslo_utils.strutils import mask_password [as 别名]
def _gpfs_ssh_execute(self, ssh, cmd, ignore_exit_code=None,
check_exit_code=True):
sanitized_cmd = strutils.mask_password(cmd)
LOG.debug('Running cmd (SSH): %s', sanitized_cmd)
stdin_stream, stdout_stream, stderr_stream = ssh.exec_command(cmd)
channel = stdout_stream.channel
stdout = stdout_stream.read()
sanitized_stdout = strutils.mask_password(stdout)
stderr = stderr_stream.read()
sanitized_stderr = strutils.mask_password(stderr)
stdin_stream.close()
exit_status = channel.recv_exit_status()
# exit_status == -1 if no exit code was returned
if exit_status != -1:
LOG.debug('Result was %s', exit_status)
if ((check_exit_code and exit_status != 0)
and
(ignore_exit_code is None or
exit_status not in ignore_exit_code)):
raise exception.ProcessExecutionError(exit_code=exit_status,
stdout=sanitized_stdout,
stderr=sanitized_stderr,
cmd=sanitized_cmd)
return (sanitized_stdout, sanitized_stderr)
示例8: execute
# 需要导入模块: from oslo_utils import strutils [as 别名]
# 或者: from oslo_utils.strutils import mask_password [as 别名]
def execute(self, server, command, check_exit_code=True,
retry=True):
retries = self._config.winrm_retry_count if retry else 1
conn = self._get_conn(server)
@utils.retry(exception=Exception,
interval=self._config.winrm_retry_interval,
retries=retries)
def _execute():
parsed_cmd, sanitized_cmd = self._parse_command(command)
LOG.debug("Executing command: %s", sanitized_cmd)
(stdout, stderr, exit_code) = conn.execute(parsed_cmd)
sanitized_stdout = strutils.mask_password(stdout)
sanitized_stderr = strutils.mask_password(stderr)
LOG.debug("Executed command: %(cmd)s. Stdout: %(stdout)s. "
"Stderr: %(stderr)s. Exit code %(exit_code)s",
dict(cmd=sanitized_cmd, stdout=sanitized_stdout,
stderr=sanitized_stderr, exit_code=exit_code))
if check_exit_code and exit_code != 0:
raise processutils.ProcessExecutionError(
stdout=sanitized_stdout,
stderr=sanitized_stderr,
exit_code=exit_code,
cmd=sanitized_cmd)
return (stdout, stderr)
return _execute()
示例9: _parse_command
# 需要导入模块: from oslo_utils import strutils [as 别名]
# 或者: from oslo_utils.strutils import mask_password [as 别名]
def _parse_command(self, command):
if isinstance(command, list) or isinstance(command, tuple):
command = " ".join([six.text_type(c) for c in command])
sanitized_cmd = strutils.mask_password(command)
b64_command = base64.b64encode(command.encode("utf_16_le"))
command = ("powershell.exe -ExecutionPolicy RemoteSigned "
"-NonInteractive -EncodedCommand %s" % b64_command)
return command, sanitized_cmd
示例10: stringify
# 需要导入模块: from oslo_utils import strutils [as 别名]
# 或者: from oslo_utils.strutils import mask_password [as 别名]
def stringify(self, value):
return super(SensitiveString, self).stringify(
strutils.mask_password(value))
示例11: sanitize_secrets
# 需要导入模块: from oslo_utils import strutils [as 别名]
# 或者: from oslo_utils.strutils import mask_password [as 别名]
def sanitize_secrets(content, mask="****"):
"""Extends oslo_utils strutils to make mask passwords more robust."""
def mask_dict_password(dictionary, secret="***"):
"""Overriding strutils.mask_dict_password.
Overriding mask_dict_password to accept CaseInsenstiveDict as well.
"""
out = deepcopy(dictionary)
for k, v in dictionary.items():
if is_dict(v):
out[k] = mask_dict_password(v, secret=secret)
continue
for sani_key in strutils._SANITIZE_KEYS:
if sani_key in k:
out[k] = secret
break
else:
if isinstance(v, six.string_types):
out[k] = strutils.mask_password(v, secret=secret)
return out
strutils.mask_dict_password = mask_dict_password
if is_dict(content):
return strutils.mask_dict_password(content, mask)
if is_string(content):
return strutils.mask_password(content, mask)
示例12: create_vim
# 需要导入模块: from oslo_utils import strutils [as 别名]
# 或者: from oslo_utils.strutils import mask_password [as 别名]
def create_vim(self, context, vim):
LOG.debug('Create vim called with parameters %s',
strutils.mask_password(vim))
vim_obj = vim['vim']
vim_type = vim_obj['type']
if vim_type == 'openstack':
vim_obj['auth_url'] = utils.get_auth_url_v3(vim_obj['auth_url'])
vim_obj['id'] = uuidutils.generate_uuid()
vim_obj['status'] = 'PENDING'
try:
self._vim_drivers.invoke(vim_type,
'register_vim',
vim_obj=vim_obj)
res = super(NfvoPlugin, self).create_vim(context, vim_obj)
except Exception:
with excutils.save_and_reraise_exception():
self._vim_drivers.invoke(vim_type,
'delete_vim_auth',
vim_id=vim_obj['id'],
auth=vim_obj['auth_cred'])
try:
self.monitor_vim(context, vim_obj)
except Exception:
LOG.warning("Failed to set up vim monitoring")
return res
示例13: _get_vim
# 需要导入模块: from oslo_utils import strutils [as 别名]
# 或者: from oslo_utils.strutils import mask_password [as 别名]
def _get_vim(self, context, vim_id):
if not self.is_vim_still_in_use(context, vim_id):
return self.get_vim(context, vim_id, mask_password=False)
示例14: _get_vim_from_vnf
# 需要导入模块: from oslo_utils import strutils [as 别名]
# 或者: from oslo_utils.strutils import mask_password [as 别名]
def _get_vim_from_vnf(self, context, vnf_id):
"""Figures out VIM based on a VNF
:param context: SQL Session Context
:param vnf_id: VNF ID
:return: VIM or VIM properties if fields are provided
"""
vnfm_plugin = manager.TackerManager.get_service_plugins()['VNFM']
vim_id = vnfm_plugin.get_vnf(context, vnf_id, fields=['vim_id'])
vim_obj = self.get_vim(context, vim_id['vim_id'], mask_password=False)
if vim_obj is None:
raise nfvo.VimFromVnfNotFoundException(vnf_id=vnf_id)
self._build_vim_auth(vim_obj)
return vim_obj
示例15: log
# 需要导入模块: from oslo_utils import strutils [as 别名]
# 或者: from oslo_utils.strutils import mask_password [as 别名]
def log(method):
"""Decorator helping to log method calls."""
def wrapper(*args, **kwargs):
instance = args[0]
data = {"class_name": (instance.__class__.__module__ + '.'
+ instance.__class__.__name__),
"method_name": method.__name__,
"args": strutils.mask_password(args[1:]),
"kwargs": strutils.mask_password(kwargs)}
LOG.debug('%(class_name)s method %(method_name)s'
' called with arguments %(args)s %(kwargs)s', data)
return method(*args, **kwargs)
return wrapper