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 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:
###
powerd_status=$(initctl status powerd)
if [ ! "$powerd_status" = "powerd stop/waiting" ]; then
echo -e "Stopping powerd to keep display from timing out..."
initctl stop powerd
fi
setterm -blank 0
if [ "$3" != "" ]; then
target_disk=$3
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
#!/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 / pico_morse_temperature.py
Last active July 17, 2022 15:50
CircuitPython script for the Raspberry Pi Pico that reads the CPU temperature and displays it in morse code.
# Simple CircuitPython script for the Raspberry Pi Pico that reads the CPU's
# temperature and displays it in morse code https://en.wikipedia.org/wiki/Morse_code
import board
import digitalio
import microcontroller
import time
convert_to_fahrenheit = True
dot = 0.5 # time length of a dot in morse
@jay0lee
jay0lee / alert_pull.py
Last active June 10, 2022 13:47
Pulls Google Workspace Alert Center Alerts via pub/sub and runs a command for each.
#!/usr/bin/env python3
'''
Pull alerts via pubsub
Setup:
1. Create a GCP project for the script.
2. Enable PubSub and Alert Center APIs.
3. Create a service account in the project and give it "Pub/Sub Admin" role
on the project.
4. Create a JSON private key for the service account and save it to the same
@jay0lee
jay0lee / app.yaml
Created November 30, 2020 14:23
Very small Python 3 standard AppEngine app to update device user client state
runtime: python37
handlers:
- url: /patch
secure: always
script: auto
@jay0lee
jay0lee / popimap.sh
Last active August 30, 2021 18:54
Shell script that can do OAuth, domain-wide delegation or password based IMAP/POP/SMTP authentication
#!/bin/bash
#
# This script should be run from Linux and uses basic tools like grep, awk, date and openssl.
# You need to populate the client_id and client_secret variables below
# with your own GCP project values. Sample command lines:
#
# Use 3-legged IMAP OAuth (default):
# bash popimap.sh --email myaccount@example.com --protocol imap
#
# Use a service account and domain-wide delegation:
#!/usr/bin/env python3
### This script requires requests. Install it by running:
###
### pip3 install requests
###
### Example usage (where 86.0.4240.75 is a Chrome version):
###
### python3 get-policy-csv.py 86.0.4240.75
@jay0lee
jay0lee / gen-jwt.sh
Last active September 2, 2022 18:10
#!/usr/bin/env bash
### Bash script that can generate a JWT token suitable for authorizing a Service Account for Google APIS.
### As described at:
###
### https://developers.google.com/identity/protocols/oauth2/service-account#jwt-auth
###
### Script requires only basic *nix tools like cat, grep and openssl. Example usage on Linux
### with curl to call Admin SDK Directory API users.list()
###
### JWT=$(bash ~/gen-jwt.sh --credentials-file ./oauth2service.json --audience https://admin.googleapis.com/)