本文整理汇总了Python中st2common.persistence.rbac.PermissionGrant.get_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python PermissionGrant.get_by_id方法的具体用法?Python PermissionGrant.get_by_id怎么用?Python PermissionGrant.get_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类st2common.persistence.rbac.PermissionGrant
的用法示例。
在下文中一共展示了PermissionGrant.get_by_id方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_sync_roles_single_role_definition_three_grants
# 需要导入模块: from st2common.persistence.rbac import PermissionGrant [as 别名]
# 或者: from st2common.persistence.rbac.PermissionGrant import get_by_id [as 别名]
def test_sync_roles_single_role_definition_three_grants(self):
syncer = RBACDefinitionsDBSyncer()
# One role with two grants
permission_grants = [
{
'resource_uid': 'pack:mapack1',
'permission_types': ['pack_all']
},
{
'resource_uid': 'pack:mapack2',
'permission_types': ['rule_view', 'action_view']
},
{
'permission_types': ['sensor_list', 'action_list']
}
]
api = RoleDefinitionFileFormatAPI(name='test_role_2', description='test description 2',
permission_grants=permission_grants)
created_role_dbs, deleted_role_dbs = syncer.sync_roles(role_definition_apis=[api])
self.assertEqual(len(created_role_dbs), 1)
self.assertItemsEqual(deleted_role_dbs, [])
self.assertEqual(created_role_dbs[0].name, 'test_role_2')
self.assertEqual(created_role_dbs[0].description, 'test description 2')
self.assertEqual(len(created_role_dbs[0].permission_grants), 3)
# Assert role and grants have been created in the DB
self.assertRoleDBObjectExists(role_db=created_role_dbs[0])
for permission_grant_id in created_role_dbs[0].permission_grants:
self.assertGrantDBObjectExists(permission_grant_id)
grant_db = PermissionGrant.get_by_id(str(created_role_dbs[0].permission_grants[0]))
self.assertEqual(grant_db.resource_uid, permission_grants[0]['resource_uid'])
self.assertEqual(grant_db.resource_type, 'pack')
self.assertEqual(grant_db.permission_types, permission_grants[0]['permission_types'])
grant_db = PermissionGrant.get_by_id(str(created_role_dbs[0].permission_grants[2]))
self.assertEqual(grant_db.resource_uid, None)
self.assertEqual(grant_db.resource_type, None)
self.assertEqual(grant_db.permission_types, permission_grants[2]['permission_types'])
示例2: assertGrantDBObjectExists
# 需要导入模块: from st2common.persistence.rbac import PermissionGrant [as 别名]
# 或者: from st2common.persistence.rbac.PermissionGrant import get_by_id [as 别名]
def assertGrantDBObjectExists(self, permission_grant_id):
result = PermissionGrant.get_by_id(str(permission_grant_id))
self.assertTrue(result)
self.assertEqual(permission_grant_id, str(result.id))