Skip to content

Instantly share code, notes, and snippets.

View jay0lee's full-sized avatar

Jay Lee jay0lee

View GitHub Profile
@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.
# create your own client id/secret
# https://developers.google.com/identity/protocols/OAuth2InstalledApp#creatingcred
client_id='978969553067-73svibj9j7d5sbq6c5587qorl7qouesh.apps.googleusercontent.com'
client_secret='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'
token_endpoint="https://oauth2.googleapis.com/token"
# WARNING - DOES NOT VALIDATE AUTHENTICITY OF JWT
decode_jwt() {
local jwt_body=$(echo -n $1 | cut -d "." -f 2 | tr '_-' '/+')
echo $(echo "$jwt_body" | openssl enc -d -base64)
@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
@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:
###
@jay0lee
jay0lee / app.yaml
Last active October 28, 2022 17:57
App Engine Workspace Service Account Example
runtime: python310
handlers:
- url: /.*
script: auto
function myFunction() {
// connect to sheet
var ss = SpreadsheetApp.openById("1_6HeCZ_KEFyJIRD73joTYBwj6xKdJHXudaAfH-Apwto");
var sheet = ss.getSheets()[0];
// determine if weekly auto-reply is enabled
var range = sheet.getRange(11,2);
var weekly_autoreply_enabled = range.getValue();
if (! weekly_autoreply_enabled) {
Logger.log("Weekly auto-reply is disabled");
@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"
function onFormSubmit(e) {
var response = e.response;
var user = response.getRespondentEmail();
var manager = getManagerEmail(user);
// New title is our first (and only) form response
new_title = response.getItemResponses()[0].getResponse();
emailManager(manager, user, new_title);
}
function getManagerEmail(user) {
#!/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:
###