Python oslo_utils.strutils.mask_dict_password() Examples

The following are 13 code examples of oslo_utils.strutils.mask_dict_password(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module oslo_utils.strutils , or try the search function .
Example #1
Source File: volumeops.py    From compute-hyperv with Apache License 2.0 6 votes vote down vote up
def _attach_volume(self, context, connection_info, instance,
                       disk_bus=constants.CTRL_TYPE_SCSI,
                       update_device_metadata=False):
        LOG.debug(
            "Attaching volume: %(connection_info)s to %(instance_name)s",
            {'connection_info': strutils.mask_dict_password(connection_info),
             'instance_name': instance.name})
        volume_driver = self._get_volume_driver(connection_info)
        volume_driver.attach_volume(connection_info,
                                    instance.name,
                                    disk_bus)

        if update_device_metadata:
            # When attaching volumes to already existing instances,
            # the connection info passed to the driver is not saved
            # yet within the BDM table.
            self._block_dev_man.set_volume_bdm_connection_info(
                context, instance, connection_info)
            self._vmops.update_device_metadata(
                context, instance)

        qos_specs = connection_info['data'].get('qos_specs') or {}
        if qos_specs:
            volume_driver.set_disk_qos_specs(connection_info,
                                             qos_specs) 
Example #2
Source File: iscsi.py    From os-brick with Apache License 2.0 6 votes vote down vote up
def extend_volume(self, connection_properties):
        """Update the local kernel's size information.

        Try and update the local kernel's size information
        for an iSCSI volume.
        """
        LOG.info("Extend volume for %s",
                 strutils.mask_dict_password(connection_properties))

        volume_paths = self.get_volume_paths(connection_properties)
        LOG.info("Found paths for volume %s", volume_paths)
        if volume_paths:
            return self._linuxscsi.extend_volume(
                volume_paths, use_multipath=self.use_multipath)
        else:
            LOG.warning("Couldn't find any volume paths on the host to "
                        "extend volume for %(props)s",
                        {'props': strutils.mask_dict_password(
                            connection_properties)})
            raise exception.VolumePathsNotFound() 
Example #3
Source File: volumeops.py    From compute-hyperv with Apache License 2.0 5 votes vote down vote up
def detach_volume(self, context, connection_info, instance,
                      update_device_metadata=False):
        LOG.debug("Detaching volume: %(connection_info)s "
                  "from %(instance_name)s",
                  {'connection_info': strutils.mask_dict_password(
                      connection_info),
                   'instance_name': instance.name})
        volume_driver = self._get_volume_driver(connection_info)
        volume_driver.detach_volume(connection_info, instance.name)
        volume_driver.disconnect_volume(connection_info)

        if update_device_metadata:
            self._vmops.update_device_metadata(context, instance) 
Example #4
Source File: string_utils.py    From syntribos with Apache License 2.0 5 votes vote down vote up
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) 
Example #5
Source File: nfvo_db_plugin.py    From tacker with Apache License 2.0 5 votes vote down vote up
def _make_vim_dict(self, vim_db, fields=None, mask_password=True):
        res = dict((key, vim_db[key]) for key in VIM_ATTRIBUTES)
        vim_auth_db = vim_db.vim_auth
        res['auth_url'] = vim_auth_db[0].auth_url
        res['vim_project'] = vim_auth_db[0].vim_project
        res['auth_cred'] = vim_auth_db[0].auth_cred
        res['auth_cred']['password'] = vim_auth_db[0].password
        if mask_password:
            res['auth_cred'] = strutils.mask_dict_password(res['auth_cred'])
        return self._fields(res, fields) 
Example #6
Source File: test_strutils.py    From oslo.utils with Apache License 2.0 5 votes vote down vote up
def test_dictionary(self):
        payload = {'password': 'TL0EfN33'}
        expected = {'password': '***'}
        self.assertEqual(expected,
                         strutils.mask_dict_password(payload))

        payload = {'user': 'admin', 'password': 'TL0EfN33'}
        expected = {'user': 'admin', 'password': '***'}
        self.assertEqual(expected,
                         strutils.mask_dict_password(payload))

        payload = {'strval': 'somestring',
                   'dictval': {'user': 'admin', 'password': 'TL0EfN33'}}
        expected = {'strval': 'somestring',
                    'dictval': {'user': 'admin', 'password': '***'}}
        self.assertEqual(expected,
                         strutils.mask_dict_password(payload))

        payload = {'strval': '--password abc',
                   'dont_change': 'this is fine',
                   'dictval': {'user': 'admin', 'password': b'TL0EfN33'}}
        expected = {'strval': '--password ***',
                    'dont_change': 'this is fine',
                    'dictval': {'user': 'admin', 'password': '***'}}
        self.assertEqual(expected,
                         strutils.mask_dict_password(payload))

        payload = {'ipmi_password': 'KeDrahishvowphyecMornEm0or('}
        expected = {'ipmi_password': '***'}
        self.assertEqual(expected,
                         strutils.mask_dict_password(payload))

        payload = {'passwords': {'KeystoneFernetKey1': 'c5FijjS'}}
        expected = {'passwords': {'KeystoneFernetKey1': '***'}}
        self.assertEqual(expected,
                         strutils.mask_dict_password(payload))

        payload = {'passwords': {'keystonecredential0': 'c5FijjS'}}
        expected = {'passwords': {'keystonecredential0': '***'}}
        self.assertEqual(expected,
                         strutils.mask_dict_password(payload)) 
Example #7
Source File: test_strutils.py    From oslo.utils with Apache License 2.0 5 votes vote down vote up
def test_do_no_harm(self):
        payload = {}
        expected = {}
        self.assertEqual(expected,
                         strutils.mask_dict_password(payload))

        payload = {'somekey': 'somevalue',
                   'anotherkey': 'anothervalue'}
        expected = {'somekey': 'somevalue',
                    'anotherkey': 'anothervalue'}
        self.assertEqual(expected,
                         strutils.mask_dict_password(payload)) 
Example #8
Source File: test_strutils.py    From oslo.utils with Apache License 2.0 5 votes vote down vote up
def test_do_an_int(self):
        payload = {}
        payload[1] = 2
        expected = payload.copy()
        self.assertEqual(expected,
                         strutils.mask_dict_password(payload)) 
Example #9
Source File: test_strutils.py    From oslo.utils with Apache License 2.0 5 votes vote down vote up
def test_mask_values(self):
        payload = {'somekey': 'test = cmd --password my\xe9\x80\x80pass'}
        expected = {'somekey': 'test = cmd --password ***'}
        self.assertEqual(expected,
                         strutils.mask_dict_password(payload)) 
Example #10
Source File: test_strutils.py    From oslo.utils with Apache License 2.0 5 votes vote down vote up
def test_other_non_str_values(self):
        payload = {'password': 'DK0PK1AK3', 'bool': True,
                   'dict': {'cat': 'meow', 'password': "*aa38skdjf"},
                   'float': 0.1, 'int': 123, 'list': [1, 2], 'none': None,
                   'str': 'foo'}
        expected = {'password': '***', 'bool': True,
                    'dict': {'cat': 'meow', 'password': '***'},
                    'float': 0.1, 'int': 123, 'list': [1, 2], 'none': None,
                    'str': 'foo'}
        self.assertEqual(expected,
                         strutils.mask_dict_password(payload)) 
Example #11
Source File: test_strutils.py    From oslo.utils with Apache License 2.0 5 votes vote down vote up
def test_non_dict(self):
        expected = {'password': '***',
                    'foo': 'bar',
                    }
        payload = TestMapping()
        self.assertEqual(expected, strutils.mask_dict_password(payload)) 
Example #12
Source File: test_strutils.py    From oslo.utils with Apache License 2.0 5 votes vote down vote up
def test_nested_non_dict(self):
        expected = {'nested': {'password': '***',
                               'foo': 'bar',
                               }
                    }
        payload = NestedMapping()
        self.assertEqual(expected, strutils.mask_dict_password(payload)) 
Example #13
Source File: volumeops.py    From compute-hyperv with Apache License 2.0 4 votes vote down vote up
def attach_volume(self, context, connection_info, instance,
                      disk_bus=constants.CTRL_TYPE_SCSI,
                      update_device_metadata=False):
        tries_left = CONF.hyperv.volume_attach_retry_count + 1

        while tries_left:
            try:
                self._attach_volume(context,
                                    connection_info,
                                    instance,
                                    disk_bus,
                                    update_device_metadata)
                break
            except Exception as ex:
                tries_left -= 1
                if not tries_left:
                    LOG.exception(
                        "Failed to attach volume %(connection_info)s "
                        "to instance %(instance_name)s. ",
                        {'connection_info': strutils.mask_dict_password(
                             connection_info),
                         'instance_name': instance.name})

                    # We're requesting a detach as the disk may have
                    # been attached to the instance but one of the
                    # post-attach operations failed.
                    self.detach_volume(context,
                                       connection_info,
                                       instance,
                                       update_device_metadata)
                    raise exception.VolumeAttachFailed(
                        volume_id=connection_info['serial'],
                        reason=ex)
                else:
                    LOG.warning(
                        "Failed to attach volume %(connection_info)s "
                        "to instance %(instance_name)s. "
                        "Tries left: %(tries_left)s.",
                        {'connection_info': strutils.mask_dict_password(
                             connection_info),
                         'instance_name': instance.name,
                         'tries_left': tries_left})

                    time.sleep(CONF.hyperv.volume_attach_retry_interval)