Exemple #1
0
    def test_token_cache_id(self):
        the_token = uuid.uuid4().hex
        project_name = uuid.uuid4().hex
        default_domain_id = uuid.uuid4().hex

        a = token.Token(self.TEST_URL,
                        token=the_token,
                        project_name=project_name,
                        default_domain_id=default_domain_id)

        b = token.Token(self.TEST_URL,
                        token=the_token,
                        project_name=project_name,
                        default_domain_id=default_domain_id)

        a_id = a.get_cache_id()
        b_id = b.get_cache_id()

        self.assertEqual(a_id, b_id)

        c = token.Token(
            self.TEST_URL,
            token=the_token,
            project_name=uuid.uuid4().hex,  # different
            default_domain_id=default_domain_id)

        c_id = c.get_cache_id()

        self.assertNotEqual(a_id, c_id)
Exemple #2
0
 def _get_keystone_auth(self, session, auth_url, **kwargs):
     auth_token = kwargs.pop('auth_token', None)
     if auth_token:
         return token.Token(auth_url, auth_token, **kwargs)
     else:
         return password.Password(
             auth_url,
             username=kwargs.pop('username'),
             user_id=kwargs.pop('user_id'),
             password=kwargs.pop('password'),
             user_domain_id=kwargs.pop('user_domain_id'),
             user_domain_name=kwargs.pop('user_domain_name'),
             **kwargs)
Exemple #3
0
    def get_barbican_client_user_auth(cls, context):
        # get a normal session
        ksession = keystone.KeystoneSession()
        service_auth = ksession.get_auth()

        # make our own auth and swap it in
        user_auth = token.Token(auth_url=service_auth.auth_url,
                                token=context.auth_token,
                                project_id=context.project_id)
        user_session = session.Session(auth=user_auth)

        # create a special barbican client with our user's session
        return barbican_client.Client(session=user_session)
Exemple #4
0
def openstack_connection(request, version=None):
    interface = getattr(settings, 'OPENSTACK_ENDPOINT_TYPE', 'publicURL')

    auth = token.Token(auth_url=getattr(settings, 'OPENSTACK_KEYSTONE_URL'),
                       token=request.user.token.id,
                       project_name=request.user.project_name,
                       project_id=request.user.tenant_id)
    cacert = getattr(settings, 'OPENSTACK_SSL_CACERT')
    session = ks_session.Session(auth=auth, verify=cacert or True)
    conn = connection.Connection(session=session,
                                 interface=interface,
                                 ha_api_version=version)

    return conn.instance_ha
Exemple #5
0
    def get_user_neutron_client(cls, context):
        # get a normal session
        ksession = keystone.KeystoneSession()
        service_auth = ksession.get_auth()

        # make user auth and swap it in session
        user_auth = token.Token(auth_url=service_auth.auth_url,
                                token=context.auth_token,
                                project_id=context.project_id)
        user_session = session.Session(auth=user_auth)

        kwargs = {
            'session': user_session,
            'region_name': CONF.neutron.region_name,
            'endpoint_type': CONF.neutron.endpoint_type,
            'service_name': CONF.neutron.service_name,
            'insecure': CONF.neutron.insecure,
            'ca_cert': CONF.neutron.ca_certificates_file
        }
        if CONF.neutron.endpoint:
            kwargs['endpoint_override'] = CONF.neutron.endpoint

        # create neutron client using user's session
        return neutron_client.Client(NEUTRON_VERSION, **kwargs)