cat|sed|awk|grep|cut
gcloud projects list
PROJECT_ID NAME PROJECT_NUMBERcanvas-syntax-130823 scesproject2 346904393285windy-bearing-129522 scesproject1 222844913538
gcloud projects list --format="json"
[ { "createTime": "2016-04-28T22:33:12.274Z", "labels": { "env": "test", "version": "alpha" }, "lifecycleState": "ACTIVE", "name": "scesproject1", "parent": { "id": "297814986428", "type": "organization" }, "projectId": "windy-bearing-129522", "projectNumber": "222844913538" }, { "createTime": "2016-05-11T03:08:13.359Z", "labels": { "env": "test", "version": "beta" }, "lifecycleState": "ACTIVE", "name": "scesproject2", "parent": { "id": "297814986428", "type": "organization" }, "projectId": "canvas-syntax-130823", "projectNumber": "346904393285" }]
createdTime
gcloud projects list --format="table[box,title='My Project List'](createTime:sort=1,name,projectNumber,projectId:label=ProjectID,parent.id:label=Parent)"
┌────────────────────────────────────────────────────────────────────────────────────────────────┐│ My Project List │├──────────────────────────┬──────────────┬────────────────┬──────────────────────┬──────────────┤│ CREATE_TIME │ NAME │ PROJECT_NUMBER │ ProjectID │ Parent │├──────────────────────────┼──────────────┼────────────────┼──────────────────────┼──────────────┤│ 2016-04-28T22:33:12.274Z │ scesproject1 │ 222844913538 │ windy-bearing-129522 │ 297814986428 ││ 2016-05-11T03:08:13.359Z │ scesproject2 │ 346904393285 │ canvas-syntax-130823 │ 297814986428 │└──────────────────────────┴──────────────┴────────────────┴──────────────────────┴──────────────┘
--format='flattened'
gcloud projects list --format="table(createTime.date('%Y-%m-%d'),name,projectNumber,projectId)"
CREATE_TIME NAME PROJECT_NUMBER PROJECT_ID2016-05-11 scesproject2 346904393285 canvas-syntax-1308232016-04-28 scesproject1 222844913538 windy-bearing-129522
gcloud compute zones list --format="json"
{ "creationTimestamp": "2014-05-30T18:35:16.514-07:00", "description": "us-central1-a", "id": "2000", "kind": "compute#zone", "name": "us-central1-a", "region": "us-central1", "selfLink": "https://www.googleapis.com/compute/v1/projects/windy-bearing-129522/ zones/us-central1-a", "status": "UP" },
gcloud
selfLink.scope()
gcloud compute zones list --format="value(selfLink.scope())"
us-central1-a
gcloud compute zones list --format="value(selfLink.basename())"
gcloud compute zones list --format="value(selfLink.scope(projects))"
windy-bearing-129522/zones/us-central1-a
gcloud compute instances list --format="json"
"serviceAccounts": [ { "email": "1071284184436-compute@developer.gserviceaccount.com", "scopes": [ "https://www.googleapis.com/auth/devstorage.read_only", "https://www.googleapis.com/auth/logging.write", "https://www.googleapis.com/auth/monitoring.write", "https://www.googleapis.com/auth/cloud.useraccounts.readonly" ] } ],
gcloud compute instances list --format="flattened(name,serviceAccounts[].email,serviceAccounts[].scopes[].basename())"
name: instance-1serviceAccounts[0].email: 1071284184436-compute@developer.gserviceaccount.comserviceAccounts[0].scopes[0]: devstorage.read_onlyserviceAccounts[0].scopes[1]: logging.writeserviceAccounts[0].scopes[2]: monitoring.writeserviceAccounts[0].scopes[3]: cloud.useraccounts.readonly
gcloud compute instances list --filter=name:instance-1 --flatten="serviceAccounts[].scopes[]" --format="csv(name,id,serviceAccounts.email,serviceAccounts.scopes.basename())"
name,id,email,scopesinstance-1,763097360168409044,1071284184436-compute@developer.gserviceaccount.com,devstorage.read_onlyinstance-1,763097360168409044,1071284184436-compute@developer.gserviceaccount.com,logging.writeinstance-1,763097360168409044,1071284184436-compute@developer.gserviceaccount.com,monitoring.writeinstance-1,763097360168409044,1071284184436-compute@developer.gserviceaccount.com,servicecontrolinstance-1,763097360168409044,1071284184436-compute@developer.gserviceaccount.com,service.management
gcloud compute instances list --filter=name:instance-1 --format="table[box,no-heading](name,id,serviceAccounts:format='table[box,no-heading](email,scopes:format=\"table[box,no-heading](.)\")')"
┌────────────┬────────────────────┐│ instance-1 │ 763097360168409044 │└────────────┴────────────────────┘ ┌────────────────────────────────────────────────────┐ │ 1071284184431-compute@developer.gserviceaccount.com│ └────────────────────────────────────────────────────┘ ┌──────────────────────────────────────────────────────┐ │ https://www.googleapis.com/auth/devstorage.read_only │ │ https://www.googleapis.com/auth/logging.write │ │ https://www.googleapis.com/auth/monitoring.write │ │ https://www.googleapis.com/auth/servicecontrol │ │ https://www.googleapis.com/auth/service.management │ └──────────────────────────────────────────────────────┘
gcloud beta iam service-accounts keys list --iam-account svc-2-429@mineral-minutia-820.iam.gserviceaccount.com --project mineral-minutia-820 --format="json"
[ { "name": "projects/mineral-minutia-820/serviceAccounts/svc-2-429@mineral-minutia-820.iam.gserviceaccount.com/keys/04bd2d56d0cc5746b125d17f95d4b0dd654accca", "validAfterTime": "2016-03-11T05:30:04.000Z", "validBeforeTime": "2026-03-09T05:30:04.000Z" }, { "name": "projects/mineral-minutia-820/serviceAccounts/svc-2-429@mineral-minutia-820.iam.gserviceaccount.com/keys/1deb44e2f54328fc7bb316e5a87315e3314f114f", "validAfterTime": "2016-01-02T18:54:26.000Z", "validBeforeTime": "2025-12-30T18:54:26.000Z" },....]
.scope()
segment(0)
gcloud beta iam service-accounts keys list --iam-account svc-2-429@mineral-minutia-820.iam.gserviceaccount.com --project mineral-minutia-820 --format="table(name.scope(serviceAccounts).segment(0):label='service Account',name.scope(keys):label='keyID',validAfterTime)"
label.env='test'
label.version=alpha)
gcloud projects list --format="json" --filter="labels.env=test AND labels.version=alpha"
[ { "createTime": "2016-04-28T22:33:12.274Z", "labels": { "env": "test", "version": "alpha" }, "lifecycleState": "ACTIVE", "name": "scesproject1", "parent": { "id": "297814986428", "type": "organization" }, "projectId": "windy-bearing-129522", "projectNumber": "222844913538" }]
createTime
gcloud projects list --format="table(projectNumber,projectId,createTime)" --filter="createTime.date('%Y-%m-%d', Z)='2016-05-11'"
PROJECT_NUMBER PROJECT_ID CREATE_TIME346904393285 canvas-syntax-130823 2016-05-11T03:08:13.359Z
env=test
.extract(), .scope(), .basename(), .segment()
parent.id
gcloud projects list --format="table(projectId,parent.id.yesno(yes="YES", no=”NO”):label='Has Parent':sort=2)"
PROJECT_ID Has Parentmineral-minutia-820 NOfabled-ray-104117 YESrk-test-0506 YESuser2proj1 YESuser2project2 YES
gcloud compute instances list --format="flattened(name,serviceAccounts[].email,serviceAccounts[].scopes.map().scope())"
#!/bin/bashfor project in $(gcloud projects list --format="value(projectId)")do echo "ProjectId: $project" for robot in $(gcloud beta iam service-accounts list --project $project --format="value(email)") do echo " -> Robot $robot" for key in $(gcloud beta iam service-accounts keys list --iam-account $robot --project $project --format="value(name.basename())") do echo " $key" done donedone
foreach ($project in gcloud projects list --format="value(projectId)"){ Write-Host "ProjectId: $project" foreach ($robot in gcloud beta iam service-accounts list --project $project --format="value(email)") { Write-Host " -> Robot $robot" foreach ($key in gcloud beta iam service-accounts keys list --iam-account $robot --project $project --format="value(name.basename())") { Write-Host " $key" } }}
serviceAccounts[].scope field
name,id,email,scope_1;scope_2;scope_3.
#!/bin/bashfor scopesInfo in $( gcloud compute instances list --filter=name:instance-1 \ --format="csv[no-heading](name,id,serviceAccounts[].email.list(), serviceAccounts[].scopes[].map().list(separator=;))")do IFS=',' read -r -a scopesInfoArray<<< "$scopesInfo" NAME="${scopesInfoArray[0]}" ID="${scopesInfoArray[1]}" EMAIL="${scopesInfoArray[2]}" SCOPES_LIST="${scopesInfoArray[3]}" echo "NAME: $NAME, ID: $ID, EMAIL: $EMAIL" echo "" IFS=';' read -r -a scopeListArray<<< "$SCOPES_LIST" for SCOPE in "${scopeListArray[@]}" do echo " SCOPE: $SCOPE" donedone
Use promo code NEXT1720 to save $300 off general admission
No comments :
Post a Comment