Skip to content

Instantly share code, notes, and snippets.

@m-richo
Last active December 12, 2017 22:15
Show Gist options
  • Select an option

  • Save m-richo/67fc0fae82c8fda484d3dfeabc5899be to your computer and use it in GitHub Desktop.

Select an option

Save m-richo/67fc0fae82c8fda484d3dfeabc5899be to your computer and use it in GitHub Desktop.

Revisions

  1. m-richo revised this gist Oct 4, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion cf-app-audit.sh
    Original file line number Diff line number Diff line change
    @@ -25,8 +25,8 @@ do
    do
    SPACE_NAME=$(cf curl /v2/spaces/$SPACE_GUID |jq -r '.entity.name')
    SPACE_APP_NUMBER=$(cf curl /v2/spaces/$SPACE_GUID/apps |jq -r '.total_results')

    DEVELOPERS=$(cf curl /v2/spaces/$SPACE_GUID/developers | jq -r '.resources[] .entity.username' |tr '\n' ' ')

    echo "CF SPACE = $SPACE_NAME - $SPACE_APP_NUMBER app(s)"

    # Iterate through all the CF apps in this CF space
  2. m-richo created this gist Oct 4, 2017.
    41 changes: 41 additions & 0 deletions cf-app-audit.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    #!/bin/bash

    set -eu
    set -o pipefail

    API_ENDPOINT=$(cf api |grep "endpoint" |awk -F "https://" '{print $2}')
    rm -f $API_ENDPOINT.csv

    echo "Running audit for $API_ENDPOINT"
    echo "Output is in $API_ENDPOINT.csv"
    echo "ORG_NAME,SPACE_NAME,APP_NAME,DEVELOPERS" > $API_ENDPOINT.csv

    # List of all CF Orgs and then iterate through them
    ORG_GUIDS=$(cf curl /v2/organizations | jq -r '.resources[] .metadata.guid')

    for ORG_GUID in $ORG_GUIDS
    do
    ORG_NAME=$(cf curl /v2/organizations/$ORG_GUID |jq -r '.entity.name')
    echo "CF ORG = $ORG_NAME"

    # Iterate through all the CF spaces in this CF ORG
    SPACE_GUIDS=$(cf curl /v2/organizations/$ORG_GUID/spaces |jq -r '.resources[] .metadata.guid')

    for SPACE_GUID in $SPACE_GUIDS
    do
    SPACE_NAME=$(cf curl /v2/spaces/$SPACE_GUID |jq -r '.entity.name')
    SPACE_APP_NUMBER=$(cf curl /v2/spaces/$SPACE_GUID/apps |jq -r '.total_results')

    DEVELOPERS=$(cf curl /v2/spaces/$SPACE_GUID/developers | jq -r '.resources[] .entity.username' |tr '\n' ' ')
    echo "CF SPACE = $SPACE_NAME - $SPACE_APP_NUMBER app(s)"

    # Iterate through all the CF apps in this CF space
    APP_GUIDS=$(cf curl /v2/spaces/$SPACE_GUID/apps | jq -r '.resources[] .metadata.guid')
    for APP_GUID in $APP_GUIDS
    do
    APP_NAME=$(cf curl /v2/apps/$APP_GUID |jq -r '.entity.name')
    echo "$ORG_NAME,$SPACE_NAME,$APP_NAME,$DEVELOPERS" >> $API_ENDPOINT.csv
    done
    done
    echo ""
    done