Skip to content

Instantly share code, notes, and snippets.

@simonswine
Created March 5, 2019 18:26
Show Gist options
  • Save simonswine/5abc33ac4e1be6e5dcc6622bd59929a5 to your computer and use it in GitHub Desktop.
Save simonswine/5abc33ac4e1be6e5dcc6622bd59929a5 to your computer and use it in GitHub Desktop.
Using oauth2 google tokens with gcloud (those can be acquired through: `gcloud auth print-access-token`)
#!/bin/bash
set -o errexit
set -o nounset
set -o pipefail
account_id=temp
mkdir -p ~/.config/gcloud/configurations/
cat > ~/.config/gcloud/configurations/config_default <<EOF
[core]
project = my-project
account = ${account_id}
[compute]
zone = europe-west1-d
region = europe-west1
EOF
sqlite3 ~/.config/gcloud/access_tokens.db <<EOF
CREATE TABLE IF NOT EXISTS "access_tokens" (account_id TEXT PRIMARY KEY, access_token TEXT, token_expiry TIMESTAMP, rapt_token TEXT, id_token TEXT);
INSERT INTO access_tokens VALUES('${account_id}','${GCP_ACCESS_TOKEN}','2100-01-01 00:00:00',NULL,NULL);
EOF
sqlite3 ~/.config/gcloud/credentials.db <<EOF
CREATE TABLE IF NOT EXISTS "credentials" (account_id TEXT PRIMARY KEY, value BLOB);
INSERT INTO credentials VALUES('${account_id}','{
"client_id": "",
"client_secret": "",
"id_token": {},
"refresh_token": "",
"revoke_uri": "",
"token_response": {
"access_token": "",
"expires_in": 3600,
"id_token": "",
"token_type": "Bearer"
},
"token_uri": "https://accounts.google.com/o/oauth2/token",
"type": "authorized_user",
"user_agent": "google-cloud-sdk"
}');
EOF
gcloud compute instances list
gcloud container clusters list
gcloud container clusters get-credentials kube-virt
kubectl get nodes
kubectl get pods --all-namespaces
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment