建立及搜尋識別資訊對應群組

本頁說明如何建立及搜尋識別資訊對應群組。識別資訊對應群組是一種群組類型,可複製外部身分來源 (例如 Active Directory 群組) 中的群組。建立 Google Cloud Search 的 ID 連接器時,會使用已對應 ID 的群組。

如要進一步瞭解已對應身分識別資訊的群組,請參閱 Groups API 總覽

以下各節將說明如何管理識別資訊對應群組。

事前準備

請先執行下列工作,再繼續瞭解本頁資訊:

建立識別資訊對應群組

REST

如要建立已對應身分的群組,請使用新群組的例項呼叫 groups.create()。群組例項必須包含 groupKeyParentlabel,並設為 system/groups/externalgroupKeynamespacegroupId 的組合,可用於識別群組。

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

後續步驟

群組建立後,您可以為其建立會員資格。如要為識別資訊對應群組建立成員資格,請參閱「管理識別資訊對應群組的成員資格」。