如何使用gcloud从组织获取所有GCP文件夹? [英] How to get ALL the GCP folders from an Organization with `gcloud`?

查看:67
本文介绍了如何使用gcloud从组织获取所有GCP文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道您是否可以找到组织中的所有项目/文件夹.当前,gcloud允许将文件夹和项目都指定给父级,从而将递归操作委托给CLIENT.

I was wondering if you have a way to find all projects/folders in an organization. Currently gcloud allows to get both folders and projects given the parent, delegating the recursive action to the CLIENT.

看起来很像一种通过资源管理器API进行搜索的方法,尽管不幸的是,没有等效的 gcloud 命令.确实可行:

It looks like there is a way to Search via Resource Manager APIs, although unfortunately there's no gcloud equivalent command. This does work:

$ alias curl-oauth='curl -H "Authorization: Bearer $(gcloud auth print-access-token)"'
$ curl-oauth -X POST https://cloudresourcemanager.googleapis.com/v2/folders:search '{}'

感谢您提供任何帮助或指向现有代码的指针,以实现此客户端或通过 gcloud .

Thanks for any help or pointer to existing code to implement this client side or via gcloud.

推荐答案

我终于能够获得递归的红宝石版本(感谢Daz的提示!).

I was finally able to get a recursive ruby version (thanks Daz for the Hint!).

我很快会将代码移至github,但仍然希望为您提供代码,以防您想玩它.

I'll move code to github soon, but still want to give you the code in case you want to play with it.

  • 它确实填充了所有组织(您可以使用 maxlevel ).
  • IT创建一个graphviz点并对其进行图形绘制(很酷!)

只需确保在运行之前创建out/目录即可.

Just make sure to create out/ directory before running.

我将组织的结果附加到 maxlevel = 2 (看起来像3-需要对其进行修复).

I'm attaching the result of my org with maxlevel=2 (which looks like 3 - need to fix it).

github上的Ruby代码: https://github.com/palladius/org-folder-projects-graph/blob/master/recurse_folders.rb

Ruby code on github: https://github.com/palladius/org-folder-projects-graph/blob/master/recurse_folders.rb

这篇关于如何使用gcloud从组织获取所有GCP文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆