英文:
How to get all groups from google cloud identity using gcloud command
问题
I am using the gcloud beta command to search the groups in GCP.
The problem is I have 1700 groups, and after x number of groups, the command generates a nextpagetoken and I have to enter it manually to rerun the command. Is there any way I can automate it? i.e., store the next page token in a variable and pass it to the following command.
gcloud beta identity groups search --organization="5487965215" --labels="cloudidentity.googleapis.com/groups.discussion_forum" --page-size=3
英文:
I am using the gcloud beta command to search the groups in GCP.
The problem is I have 1700 groups, and after x number of groups command generates nextpagetoken and I have to enter it manually to rerun the command. Is there any way I can automate it? i.e, store the next page token in a variable and pass it to the following command.
gcloud beta identity groups search --organization="5487965215" --labels="cloudidentity.googleapis.com/groups.discussion_forum" --page-size=3
答案1
得分: 1
实施可以以不同的方式进行,其中之一是使用一个循环来从响应中获取nextPageToken
。
您可以在Cloud Shell上运行此脚本并更改组织ID。组名称将保存在group.txt文件中。
# 设置
ORGANIZATION_ID="..."
# 获取组列表
echo -n > groups.txt
GCLOUD_ARG_PAGE_TOKEN=""
RUN=1
while [ $RUN == 1 ] ; do
gcloud beta identity groups search \
--organization="${ORGANIZATION_ID}" \
--labels="cloudidentity.googleapis.com/groups.discussion_forum" \
--format=json \
--page-size=1000 \
${GCLOUD_ARG_PAGE_TOKEN} \
> response.json < response.json jq -r "[0].groups[].groupKey.id" >> groups.txt NEXT_PAGE_TOKEN="$(<response.json jq -r '[0].nextPageToken')"
if [ "$NEXT_PAGE_TOKEN" == "null" ] ; then
GCLOUD_ARG_PAGE_TOKEN=""
RUN=0
else
GCLOUD_ARG_PAGE_TOKEN="--page-token=$NEXT_PAGE_TOKEN"
fi
done
这是您提供的代码部分的翻译。
英文:
Implementation can be done in different ways, one of them using a while loop that retrieves nextPageToken
from response.
You can run this script on the Cloud Shell and change the Org ID. Group names will be saved on group.txt file
# setup
ORGANIZATION_ID="..."
# get groups list
echo -n > groups.txt
GCLOUD_ARG_PAGE_TOKEN=""
RUN=1
while [ $RUN == 1 ] ; do
  gcloud beta identity groups search \
    --organization="${ORGANIZATION_ID}" \
    --labels="cloudidentity.googleapis.com/groups.discussion_forum" \
    --format=json \
    --page-size=1000 \
    ${GCLOUD_ARG_PAGE_TOKEN} \
  > response.json   <response.json jq -r ".[0].groups[].groupKey.id" >> groups.txt   NEXT_PAGE_TOKEN="$(<response.json jq -r '.[0].nextPageToken')"
  if [ "$NEXT_PAGE_TOKEN" == "null" ] ; then
    GCLOUD_ARG_PAGE_TOKEN=""
    RUN=0
  else
    GCLOUD_ARG_PAGE_TOKEN="--page-token=$NEXT_PAGE_TOKEN"
  fi
done
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论