'Extract the identity from the Keystone auth component.'

def _keystone_identity(self, environ):

    if ((environ.get('HTTP_X_IDENTITY_STATUS') != 'Confirmed') or (environ.get('HTTP_X_SERVICE_IDENTITY_STATUS') not in (None, 'Confirmed'))):
        return
    roles = list_from_csv(environ.get('HTTP_X_ROLES', ''))
    service_roles = list_from_csv(environ.get('HTTP_X_SERVICE_ROLES', ''))
    identity = {'user': (environ.get('HTTP_X_USER_ID'), environ.get('HTTP_X_USER_NAME')), 'tenant': (environ.get('HTTP_X_PROJECT_ID', environ.get('HTTP_X_TENANT_ID')), environ.get('HTTP_X_PROJECT_NAME', environ.get('HTTP_X_TENANT_NAME'))), 'roles': roles, 'service_roles': service_roles}
    token_info = environ.get('keystone.token_info', {})
    auth_version = 0
    user_domain = project_domain = (None, None)
    if ('access' in token_info):
        auth_version = 2
    elif ('token' in token_info):
        auth_version = 3
        user_domain = (environ.get('HTTP_X_USER_DOMAIN_ID'), environ.get('HTTP_X_USER_DOMAIN_NAME'))
        project_domain = (environ.get('HTTP_X_PROJECT_DOMAIN_ID'), environ.get('HTTP_X_PROJECT_DOMAIN_NAME'))
    identity['user_domain'] = user_domain
    identity['project_domain'] = project_domain
    identity['auth_version'] = auth_version
    return identity
