当前位置: 首页>>代码示例>>Python>>正文


Python User.get_all方法代码示例

本文整理汇总了Python中st2common.persistence.auth.User.get_all方法的典型用法代码示例。如果您正苦于以下问题:Python User.get_all方法的具体用法?Python User.get_all怎么用?Python User.get_all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在st2common.persistence.auth.User的用法示例。


在下文中一共展示了User.get_all方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: sync_users_role_assignments

# 需要导入模块: from st2common.persistence.auth import User [as 别名]
# 或者: from st2common.persistence.auth.User import get_all [as 别名]
    def sync_users_role_assignments(self, role_assignment_apis):
        """
        Synchronize role assignments for all the users in the database.

        :param role_assignment_apis: Role assignments API objects for the assignments loaded
                                      from the files.
        :type role_assignment_apis: ``list`` of :class:`UserRoleAssignmentFileFormatAPI`

        :return: Dictionary with created and removed role assignments for each user.
        :rtype: ``dict``
        """
        LOG.info("Synchronizing users role assignments...")

        username_to_role_assignment_map = dict([(api.username, api) for api in role_assignment_apis])
        user_dbs = User.get_all()

        results = {}
        for user_db in user_dbs:
            username = user_db.name
            role_assignment_api = username_to_role_assignment_map.get(username, None)
            role_assignment_dbs = rbac_services.get_role_assignments_for_user(user_db=user_db)

            result = self._sync_user_role_assignments(
                user_db=user_db, role_assignment_dbs=role_assignment_dbs, role_assignment_api=role_assignment_api
            )
            results[username] = result

        LOG.info("User role assignments synchronized")
        return results
开发者ID:alexmakarski,项目名称:st2,代码行数:31,代码来源:syncer.py

示例2: sync_users_role_assignments

# 需要导入模块: from st2common.persistence.auth import User [as 别名]
# 或者: from st2common.persistence.auth.User import get_all [as 别名]
    def sync_users_role_assignments(self, role_assignment_apis):
        """
        Synchronize role assignments for all the users in the database.

        :param role_assignment_apis: Role assignments API objects for the assignments loaded
                                      from the files.
        :type role_assignment_apis: ``list`` of :class:`UserRoleAssignmentFileFormatAPI`

        :return: Dictionary with created and removed role assignments for each user.
        :rtype: ``dict``
        """
        LOG.info('Synchronizing users role assignments...')

        user_dbs = User.get_all()
        username_to_user_db_map = dict([(user_db.name, user_db) for user_db in user_dbs])

        results = {}
        for role_assignment_api in role_assignment_apis:
            username = role_assignment_api.username
            user_db = username_to_user_db_map.get(username, None)

            if not user_db:
                LOG.debug(('Skipping role assignments for user "%s" which doesn\'t exist in the '
                           'database' % (username)))
                continue

            role_assignment_dbs = rbac_services.get_role_assignments_for_user(user_db=user_db)

            result = self._sync_user_role_assignments(user_db=user_db,
                                                      role_assignment_dbs=role_assignment_dbs,
                                                      role_assignment_api=role_assignment_api)
            results[username] = result

        LOG.info('User role assignments synchronized')
        return results
开发者ID:agilee,项目名称:st2,代码行数:37,代码来源:syncer.py

示例3: sync_users_role_assignments

# 需要导入模块: from st2common.persistence.auth import User [as 别名]
# 或者: from st2common.persistence.auth.User import get_all [as 别名]
    def sync_users_role_assignments(self, role_assignment_apis):
        """
        Synchronize role assignments for all the users in the database.

        :param role_assignment_apis: Role assignments API objects for the assignments loaded
                                      from the files.
        :type role_assignment_apis: ``list`` of :class:`UserRoleAssignmentFileFormatAPI`

        :return: Dictionary with created and removed role assignments for each user.
        :rtype: ``dict``
        """
        LOG.info('Synchronizing users role assignments...')

        user_dbs = User.get_all()
        username_to_user_db_map = dict([(user_db.name, user_db) for user_db in user_dbs])

        results = {}
        for role_assignment_api in role_assignment_apis:
            username = role_assignment_api.username
            user_db = username_to_user_db_map.get(username, None)

            if not user_db:
                # Note: We allow assignments to be created for the users which don't exist in the
                # DB yet because user creation in StackStorm is lazy (we only create UserDB) object
                # when user first logs in.
                user_db = UserDB(name=username)
                LOG.debug(('User "%s" doesn\'t exist in the DB, creating assignment anyway' %
                          (username)))

            role_assignment_dbs = rbac_services.get_role_assignments_for_user(user_db=user_db)

            result = self._sync_user_role_assignments(user_db=user_db,
                                                      role_assignment_dbs=role_assignment_dbs,
                                                      role_assignment_api=role_assignment_api)
            results[username] = result

        LOG.info('User role assignments synchronized')
        return results
开发者ID:jspittman,项目名称:st2,代码行数:40,代码来源:syncer.py

示例4: sync_users_role_assignments

# 需要导入模块: from st2common.persistence.auth import User [as 别名]
# 或者: from st2common.persistence.auth.User import get_all [as 别名]
    def sync_users_role_assignments(self, role_assignment_apis):
        """
        Synchronize role assignments for all the users in the database.

        :param role_assignment_apis: Role assignments API objects for the assignments loaded
                                      from the files.
        :type role_assignment_apis: ``list`` of :class:`UserRoleAssignmentFileFormatAPI`

        :return: Dictionary with created and removed role assignments for each user.
        :rtype: ``dict``
        """
        assert isinstance(role_assignment_apis, (list, tuple))

        LOG.info('Synchronizing users role assignments...')

        # Note: We exclude remote assignments because sync tool is not supposed to manipulate
        # remote assignments
        role_assignment_dbs = rbac_services.get_all_role_assignments(include_remote=False)

        user_dbs = User.get_all()

        username_to_user_db_map = dict([(user_db.name, user_db) for user_db in user_dbs])
        username_to_role_assignment_apis_map = defaultdict(list)
        username_to_role_assignment_dbs_map = defaultdict(list)

        for role_assignment_api in role_assignment_apis:
            username = role_assignment_api.username
            username_to_role_assignment_apis_map[username].append(role_assignment_api)

        for role_assignment_db in role_assignment_dbs:
            username = role_assignment_db.user
            username_to_role_assignment_dbs_map[username].append(role_assignment_db)

        # Note: We process assignments for all the users (ones specified in the assignment files
        # and ones which are in the database). We want to make sure assignments are correctly
        # deleted from the database for users which existing in the database, but have no
        # assignment file on disk and for assignments for users which don't exist in the database.
        all_usernames = (list(username_to_user_db_map.keys()) +
                         list(username_to_role_assignment_apis_map.keys()) +
                         list(username_to_role_assignment_dbs_map.keys()))
        all_usernames = list(set(all_usernames))

        results = {}
        for username in all_usernames:
            user_db = username_to_user_db_map.get(username, None)

            if not user_db:
                # Note: We allow assignments to be created for the users which don't exist in the
                # DB yet because user creation in StackStorm is lazy (we only create UserDB) object
                # when user first logs in.
                user_db = UserDB(name=username)
                LOG.debug(('User "%s" doesn\'t exist in the DB, creating assignment anyway' %
                          (username)))

            role_assignment_apis = username_to_role_assignment_apis_map.get(username, [])
            role_assignment_dbs = username_to_role_assignment_dbs_map.get(username, [])

            # Additional safety assert to ensure we don't accidentally manipulate remote
            # assignments
            for role_assignment_db in role_assignment_dbs:
                assert role_assignment_db.is_remote is False

            result = self._sync_user_role_assignments(
                user_db=user_db, role_assignment_dbs=role_assignment_dbs,
                role_assignment_apis=role_assignment_apis)

            results[username] = result

        LOG.info('User role assignments synchronized')
        return results
开发者ID:lyandut,项目名称:st2,代码行数:72,代码来源:syncer.py


注:本文中的st2common.persistence.auth.User.get_all方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。