[英]How do I export(to a file) all people with a certain role per project in an organization in GCP?
I have inherited a project and am basically trying to get all owners per project from the more than 100 projects into a nice little list so that I can use them for further role planning outside of GCP.我继承了一个项目,基本上是在尝试将 100 多个项目中的每个项目的所有所有者放入一个漂亮的小列表中,以便我可以使用它们在 GCP 之外进行进一步的角色规划。 There are projects that have more than 30 owners and I need to start managing roles.有超过 30 个所有者的项目,我需要开始管理角色。
They are managed in the projects directly and are not populated by CI or any other service.它们直接在项目中管理,不由 CI 或任何其他服务填充。
Thank you谢谢
What have you tried so far?你试过什么了?
There's a lot of questions I can ask for more detail and understanding but making assumptions, I'd make a script that iterates over all Projects, iterate over all People with Role.有很多问题我可以要求更多的细节和理解,但做出假设,我会制作一个遍历所有项目的脚本,遍历所有具有角色的人。
There's GUI, CLI, API, etc ways to access the information.有 GUI、CLI、API 等方式来访问信息。 For a simple script, CLI is the simplest.对于简单的脚本,CLI 是最简单的。
To show all projects: gcloud projects list
显示所有项目: gcloud projects list
To list all users in the project (with their roles) gcloud projects get-iam-policy <project_name>
列出项目中的所有用户(及其角色) gcloud projects get-iam-policy <project_name>
Hope this helps!希望这可以帮助!
for PROJECT in `gcloud projects list --format="value(projectId)"`
do
printf "Project: %s\n" ${PROJECT} >> Testfile1.txt
gcloud projects get-iam-policy ${PROJECT} --flatten="bindings[].members[]" --filter="bindings.role=roles/owner" --format="value(bindings.members)" >> Testfile1.txt
printf "\n"
printf "\n"
done
Gets the job done.完成工作。 Iterates through all projects and exports project-id and name of all "owners" to a file called "Testfile1.txt".遍历所有项目并将所有“所有者”的项目 ID 和名称导出到名为“Testfile1.txt”的文件中。 It is not pretty but it works.它不漂亮,但它有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.