How to use the keystoneauth1.identity.Token function in keystoneauth1

To help you get started, we’ve selected a few keystoneauth1 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openstack / tacker / tacker / keymgr / barbican_key_manager.py View on Github external
auth_url=self._auth_url,
                username=context.username,
                password=context.password,
                user_id=context.user_id,
                user_domain_id=context.user_domain_id,
                user_domain_name=context.user_domain_name,
                trust_id=context.trust_id,
                domain_id=context.domain_id,
                domain_name=context.domain_name,
                project_id=context.project_id,
                project_name=context.project_name,
                project_domain_id=context.project_domain_id,
                project_domain_name=context.project_domain_name,
                reauthenticate=context.reauthenticate)
        elif context.__class__.__name__ == 'KeystoneToken':
            return identity.Token(
                auth_url=self._auth_url,
                token=context.token,
                trust_id=context.trust_id,
                domain_id=context.domain_id,
                domain_name=context.domain_name,
                project_id=context.project_id,
                project_name=context.project_name,
                project_domain_id=context.project_domain_id,
                project_domain_name=context.project_domain_name,
                reauthenticate=context.reauthenticate)
        # this will be kept for oslo.context compatibility until
        # projects begin to use utils.credential_factory
        elif (context.__class__.__name__ == 'RequestContext' or
              context.__class__.__name__ == 'Context'):
            return identity.Token(
                auth_url=self._auth_url,
github openstack / cinder / cinder / compute / nova.py View on Github external
Number of seconds to wait for an answer before raising a
        Timeout exception (None to disable)
    @param api_version:
        api version of nova
    """

    if privileged_user and CONF[NOVA_GROUP].auth_type:
        LOG.debug('Creating Keystone auth plugin from conf')
        n_auth = ks_loading.load_auth_from_conf_options(CONF, NOVA_GROUP)
    else:
        if CONF[NOVA_GROUP].token_auth_url:
            url = CONF[NOVA_GROUP].token_auth_url
        else:
            url = _get_identity_endpoint_from_sc(context)
        LOG.debug('Creating Keystone token plugin using URL: %s', url)
        n_auth = identity.Token(auth_url=url,
                                token=context.auth_token,
                                project_name=context.project_name,
                                project_domain_id=context.project_domain_id)

    if CONF.auth_strategy == 'keystone':
        n_auth = service_auth.get_auth_plugin(context, auth=n_auth)

    keystone_session = ks_loading.load_session_from_conf_options(
        CONF,
        NOVA_GROUP,
        auth=n_auth)

    c = nova_client.Client(
        api_versions.APIVersion(api_version or NOVA_API_VERSION),
        session=keystone_session,
        insecure=CONF[NOVA_GROUP].insecure,
github openstack / murano / murano / common / auth_utils.py View on Github external
def get_token_client_session(token=None, project_id=None, conf=None):
    www_authenticate_uri = \
        cfg.CONF[CFG_MURANO_AUTH_GROUP].www_authenticate_uri
    if not www_authenticate_uri:
        versionutils.report_deprecated_feature(
            LOG, 'Please configure www_authenticate_uri in ' +
            CFG_MURANO_AUTH_GROUP + 'group')
        www_authenticate_uri = \
            cfg.CONF[CFG_KEYSTONE_GROUP].www_authenticate_uri
    auth_url = www_authenticate_uri.replace('v2.0', 'v3')
    if token is None or project_id is None:
        execution_session = helpers.get_execution_session()
        token = execution_session.token
        project_id = execution_session.project_id
    token_auth = identity.Token(
        auth_url,
        token=token,
        project_id=project_id)
    session = _get_session(auth=token_auth, conf_section=conf)
    return session
github openstack / tacker / tacker / keymgr / barbican_key_manager.py View on Github external
return identity.Token(
                auth_url=self._auth_url,
                token=context.token,
                trust_id=context.trust_id,
                domain_id=context.domain_id,
                domain_name=context.domain_name,
                project_id=context.project_id,
                project_name=context.project_name,
                project_domain_id=context.project_domain_id,
                project_domain_name=context.project_domain_name,
                reauthenticate=context.reauthenticate)
        # this will be kept for oslo.context compatibility until
        # projects begin to use utils.credential_factory
        elif (context.__class__.__name__ == 'RequestContext' or
              context.__class__.__name__ == 'Context'):
            return identity.Token(
                auth_url=self._auth_url,
                token=context.auth_token,
                project_id=context.tenant)
        else:
            msg = _("context must be of type KeystonePassword, "
                    "KeystoneToken, RequestContext, or Context, got type "
                    "%s") % context.__class__.__name__
            LOG.error(msg)
            raise exception.Forbidden(reason=msg)
github openstack / sahara-dashboard / sahara_dashboard / api / sahara.py View on Github external
def client(request):
    insecure = getattr(settings, 'OPENSTACK_SSL_NO_VERIFY', False)
    cacert = getattr(settings, 'OPENSTACK_SSL_CACERT', None)
    auth = identity.Token(auth_url=request.user.endpoint,
                          token=request.user.token.id,
                          project_id=request.user.project_id)
    verify = False
    if cacert:
        verify = cacert
    elif not insecure:
        verify = True
    sess = session.Session(auth=auth, verify=verify)
    return api_client.Client(VERSIONS.get_active_version()["version"],
                             service_type=SAHARA_SERVICE,
                             session=sess)
github openstack / solum / solum / common / solum_keystoneclient.py View on Github external
'endpoint': self.endpoint
        }
        # Note try trust_id first, as we can't reuse auth_token in that case
        if self.context.trust_id is not None:
            # We got a trust_id, so we use the admin credentials
            # to authenticate with the trust_id so we can use the
            # trust impersonating the trustor user.
            kwargs.update(self._service_admin_creds())
            kwargs['trust_id'] = self.context.trust_id
            kwargs.pop('project_name')
            auth = ka_loading.load_auth_from_conf_options(
                cfg.CONF, 'keystone_authtoken', **kwargs)
        elif self.context.auth_token is not None:
            kwargs['token'] = self.context.auth_token
            kwargs['project_id'] = self.context.tenant
            auth = identity.Token(
                auth_url=kwargs['auth_url'],
                token=kwargs['token'],
                project_id=kwargs['project_id'])
        else:
            LOG.error(_("Keystone v3 API connection failed, no password "
                        "trust or auth_token!"))
            raise exception.AuthorizationFailure()
        session = ks_session.Session(auth=auth)
        client = kc_v3.Client(session=session)
        client.auth_ref = client.session.auth.get_access(client.session)
        # If we are authenticating with a trust set the context auth_token
        # with the trust scoped token
        if 'trust_id' in kwargs:
            # Sanity check
            if not client.auth_ref.trust_scoped:
                LOG.error(_("trust token re-scoping failed!"))
github openstack / castellan / castellan / key_manager / barbican_key_manager.py View on Github external
token=context.token,
                trust_id=context.trust_id,
                domain_id=context.domain_id,
                domain_name=context.domain_name,
                project_id=context.project_id,
                project_name=context.project_name,
                project_domain_id=context.project_domain_id,
                project_domain_name=context.project_domain_name,
                reauthenticate=context.reauthenticate)
        # this will be kept for oslo.context compatibility until
        # projects begin to use utils.credential_factory
        elif context.__class__.__name__ == 'RequestContext':
            if getattr(context, 'get_auth_plugin', None):
                return context.get_auth_plugin()
            else:
                return identity.Token(
                    auth_url=self.conf.barbican.auth_endpoint,
                    token=context.auth_token,
                    project_id=context.project_id,
                    project_name=context.project_name,
                    project_domain_id=context.project_domain_id,
                    project_domain_name=context.project_domain_name)
        else:
            msg = _("context must be of type KeystonePassword, "
                    "KeystoneToken, or RequestContext.")
            LOG.error(msg)
            raise exception.Forbidden(reason=msg)