

def _get_barbican_client(self, ctxt):
    'Creates a client to connect to the Barbican service.\n\n        :param ctxt: the user context for authentication\n        :return: a Barbican Client object\n        :raises Forbidden: if the ctxt is None\n        '
    if (not ctxt):
        msg = _('User is not authorized to use key manager.')
        LOG.error(msg)
        raise exception.Forbidden(msg)
    if ((not hasattr(ctxt, 'project_id')) or (ctxt.project_id is None)):
        msg = _('Unable to create Barbican Client without project_id.')
        LOG.error(msg)
        raise exception.KeyManagerError(msg)
    if (self._barbican_client and (self._current_context == ctxt)):
        return self._barbican_client
    try:
        _SESSION = ks_loading.load_session_from_conf_options(CONF, nova.conf.barbican.barbican_group)
        auth = ctxt.get_auth_plugin()
        (service_type, service_name, interface) = CONF.barbican.catalog_info.split(':')
        region_name = CONF.barbican.os_region_name
        service_parameters = {
            'service_type': service_type,
            'service_name': service_name,
            'interface': interface,
            'region_name': region_name,
        }
        if CONF.barbican.endpoint_template:
            self._base_url = (CONF.barbican.endpoint_template % ctxt.to_dict())
        else:
            self._base_url = _SESSION.get_endpoint(auth, **service_parameters)
        self._barbican_endpoint = self._base_url.rpartition('/')[0]
        sess = session.Session(auth=ctxt)
        self._barbican_client = barbican_client.Client(session=sess, endpoint=self._barbican_endpoint)
        self._current_context = ctxt
    except Exception as e:
        with excutils.save_and_reraise_exception():
            LOG.error(_LE('Error creating Barbican client: %s'), e)
    return self._barbican_client

dataset/ETHPy150Open BU-NU-CLOUD-SP16/Trusted-Platform-Module-nova/nova/keymgr/barbican.py BarbicanKeyManager._get_barbican_client/VarMisuse@267/481 `auth`->`ctxt`