创建和搜索身份映射群组
本页面介绍如何创建和搜索身份映射群组。身份映射群组是一种群组类型,可镜像外部身份源中的群组(例如 Active Directory 群组)。为 Google Cloud Search 创建身份连接器时会使用身份映射群组。
如需详细了解身份映射群组,请参阅 Groups API 概览。
以下部分演示了如何管理身份映射群组。
准备工作
在继续此页面的信息之前,请先执行以下任务:
在 Google 管理控制台中创建身份源。
阅读 Groups API 概览。
创建身份映射群组
REST
如需创建身份映射群组,请使用新群组的实例调用 groups.create()。群组实例必须包含 groupKey、Parent 和设置为 system/groups/external 的 label。groupKey 是唯一标识群组的 namespace 和 groupId 的组合。
Python
以下示例展示了使用 Python 客户端库创建身份群组的辅助函数。使用在 Google 管理控制台中创建身份源时获取的身份源 ID 调用辅助函数并创建群组:
def create_identity_group(service, identity_source_id, group_id, group_display_name,
  group_description):
  namespace = "identitysources/" + identity_source_id
  group_key = {"id": group_id, "namespace": namespace}
  group = {
    "parent": namespace,
    "description": group_description,
    "displayName": group_display_name,
    "groupKey": group_key,
    "labels": {
      # Set the label to specify creation of an identity group.
      "system/groups/external": ""
    }
  }
  try:
    response = service.groups().create(body=group).execute()
    print response
  except Exception, e:
    print e
  myNewGroup = create_identity_group(
    idSvc,
    "ABC1234",
    "zebra",
    "Zebra external group",
    "The Zebra group is an identity group representing the Zooland
      external identity"
  )
提供命名空间可确保您不会遇到任何命名冲突,并会将身份映射群组放到来自相同外部身份源的其他群组的适当上下文中。
搜索身份映射群组
REST
如需搜索身份映射群组,请使用查询字符串调用 groups.search()。如需搜索所有群组,您只需提供标签 system/groups/external。
Python
以下示例展示了使用 Python 客户端库搜索身份映射群组的辅助函数:
def search_identity_groups(service, identity_source_id, pageSize, view):
  # Set the label to search for all identity groups
  searchQuery = "&query=namespace=identitysources/" + identity_source_id \
    + "%20AND%20" + "labels:system/groups/external" \
    + "&pageSize=" + pageSize + "&view=" + view
  try:
    searchGroupsRequest = service.groups().search()
    searchGroupsRequest.uri += searchQuery
    response = searchGroupsRequest.execute()
    print response
  except Exception, e:
    print e
后续步骤
群组存在后,可以为它创建成员资格。如需为身份映射群组创建成员资格,请参阅管理身份映射群组的成员资格。