Skip to content

Instantly share code, notes, and snippets.

View jay0lee's full-sized avatar

Jay Lee jay0lee

View GitHub Profile
#!/usr/bin/env bash
###
### Shell script to get an access token for a user
### using Google 3-legged OAuth.
###
### Example to show your quota usage:
###
### # first run is to authorize.
### bash --credentials-file drive-quota.json \
@jay0lee
jay0lee / delete_old_workstation_disks.py
Last active April 25, 2024 14:16
Delete old, unused Google Cloud Workstation Disks
#!/usr/bin/env python3
'''
Delete old Cloud Workstation Disks
WARNING: This script will delete disks and all data on them. It should be
considered "proof of concept" quality and should be customized to fit your
environmental needs, checked for logic errors and monitored. I am not
responsible for data loss by using this script.
@jay0lee
jay0lee / drive-upload-5tb-file.sh
Last active March 26, 2024 08:59
Upload 5tb Drive File
refresh_access_token ()
{
echo "Old access token: $access_token"
refresh_result=$(curl -s https://accounts.google.com/o/oauth2/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d refresh_token=$refresh_token \
-d client_id=$client_id \
-d client_secret=$client_secret \
-d grant_type=refresh_token)
access_token=$(echo -e "$refresh_result" | \
#!/usr/bin/env bash
###
### Shell script to use Google service account and optionally
### domain-wide delegation (DwD).
###
### This script will ultimately output an access token that can be used to
### call Google APIs as the service account or the Workspace user in DwD.
###
### Example to show a Workspace user's IMAP settings:
###
@jay0lee
jay0lee / app.yaml
Last active May 8, 2023 19:49
BCE PoC - One Active User Device
runtime: python311
handlers:
- url: /
secure: always
script: auto
redirect_http_response_code: 301
- url: /debug
secure: always
export cpucount=$(nproc --all)
cd ~
mkdir src
cd src
export LD_LIBRARY_PATH="${HOME}/ssl/lib:${HOME}/python/lib"
git clone https://github.com/openssl/openssl.git
cd openssl
@jay0lee
jay0lee / create-user.py
Created December 14, 2022 20:00
PoC script to create a new Workspace user using a GCP service account
#!/usr/bin/env python3
### This script requires a service account private key JSON credentials file.
### The service account should be granted an admin role in your domain that
### authorizes it to create users. See:
###
### https://support.google.com/a/answer/9807615?hl=en&ref_topic=9832445&fl=1#zippy=%2Cassign-a-role-to-a-service-account
###
### This script requires PyJWT and requests. Install it by running:
###
#!/usr/bin/env bash
###
### PoC to apply Context Aware Access rules (generally IP ranges or geographical regions) to Google API calls.
###
### This script will ultimately generate an access token that can be used to call Workspace APIs as a user.
###
### Example run:
###
### export access_token=$(./dwd-with-caa.sh \
### --credentials-file oauth2service.json \
@jay0lee
jay0lee / vacation.py
Last active October 31, 2022 14:39
Python script to enable a Workspace user's vacation message
#!/usr/bin/env python3
'''
Set user's Gmail vacation message
'''
import argparse
import http.client
from json import dumps
import time
@jay0lee
jay0lee / vacation.sh
Last active October 31, 2022 14:00
Bash shell script to enable a Workspace user's vacation message
#!/usr/bin/env bash
###
### Shell script to use update a user's away message for the next week.
### Utilizes Google domain-wide delegation (DwD).
###
### Example to turn on vacation message for a user:
###
### bash vacation.sh --credentials-file oauth2service.json \
### --user jdoe@acme.com \
### --autoreply 'I am out of the office this week"