【问题标题】:PCF: How to find the list of all the spaces where you have Developer privilegesPCF:如何找到您拥有开发人员权限的所有空间的列表
【发布时间】:2019-12-12 17:17:30
【问题描述】:

如果您不是 Pivotal Cloud Foundry 的管理员,您将如何查找或列出您拥有开发人员权限的所有组织/空间?是否有一个命令或菜单来获取它,而不是进入每个空间并验证它?

【问题讨论】:

    标签: cloud-foundry pivotal-web-services


    【解决方案1】:

    这是一个脚本,它将转储当前登录用户所属的组织和空间名称。

    快速解释。它将调用/v2/spaces api,它已经过滤为仅显示当前登录用户可以看到的空间(如果您使用具有管理员访问权限的用户运行,它将列出所有组织和空间)。然后我们遍历结果并获取空间的organization_url 字段和cf curl 以获取组织名称(有一个哈希图来缓存结果)。

    这个脚本需要 Bash 4+ 来支持 hashmap。如果你没有那个,你可以删除那个部分,它会慢一点。还有requires jq,当然还有cf cli。

    希望有帮助!

    #!/usr/bin/env bash
    #
    # List all spaces available to the current user
    #
    set -e
    
    function load_all_pages {
        URL="$1"
        DATA=""
        until [ "$URL" == "null" ]; do
            RESP=$(cf curl "$URL")
            DATA+=$(echo "$RESP" | jq .resources)
            URL=$(echo "$RESP" | jq -r .next_url)
        done
        # dump the data
        echo "$DATA" | jq .[] | jq -s
    }
    
    function load_all_spaces {
        load_all_pages "/v2/spaces"
    }
    
    function main {
        declare -A ORGS  # cache org name lookups
    
        # load all the spaces & properly paginate
        SPACES=$(load_all_spaces)
    
        # filter out the name & org_url
        SPACES_DATA=$(echo "$SPACES" | jq -rc '.[].entity | {"name": .name, "org_url": .organization_url}')
    
        printf "Org\tSpace\n"
        for SPACE_JSON in $SPACES_DATA; do
            SPACE_NAME=$(echo "$SPACE_JSON" | jq -r '.name')
            # take the org_url and look up the org name, cache responses for speed
            ORG_URL=$(echo "$SPACE_JSON" | jq -r '.org_url')
            ORG_NAME="${ORGS[$ORG_URL]}"
            if [ "$ORG_NAME" == "" ]; then
                ORG_NAME=$(cf curl "$ORG_URL" | jq -r '.entity.name')
                ORGS[$ORG_URL]="$ORG_NAME"
            fi
            printf "$ORG_NAME\t$SPACE_NAME\n"
        done
    }
    
    main "$@"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多