Skip to content

Instantly share code, notes, and snippets.

View pydevops's full-sized avatar
🏠
Working from home

Victor Yang pydevops

🏠
Working from home
View GitHub Profile
@pydevops
pydevops / markdown_html.sh
Created October 13, 2018 19:48
markdown to html
#!/bin/bash
SRC_DIR=$HOME/Desktop
DEST_DIR=$HOME/man
mkdir -p $DEST_DIR
for mdfile in ${SRC_DIR}/*.md
do
filename=${mdfile##*/}
basename=${filename%.md}
@pydevops
pydevops / ppj.go
Last active December 13, 2022 18:37
pretty print json yaml
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"os"
flatten "github.com/jeremywohl/flatten"
@pydevops
pydevops / lock-funcs.txt
Last active September 8, 2018 17:18
GCS based locking function
#! /usr/bin/env bash
set -u
# constants
PROJECT=$(gcloud info --format='value(config.project)')
LOCKS_BUCKET=$PROJECT-db2-locks
# how long do we wait for lock or condition
SLEEP=5
# Check if a lock file exists
@pydevops
pydevops / makeself-exec.sh
Last active September 6, 2018 16:35 — forked from shturm/makeself-exec.sh
Execute makeself script from anywhere (https://github.com/megastep/makeself)
MAKESELFPATH=/opt/makeself
PAYLOADFOLDER=$(readlink -e $1)
OUTPUTFILENAME=$(pwd)/$2
LABEL=$3
INSTALLER=$(readlink -e $4)
cd $MAKESELFPATH
echo "Executing: sh makeself.sh $PAYLOADFOLDER $OUTPUTFILENAME $LABEL $INSTALLER"
sh makeself.sh $PAYLOADFOLDER $OUTPUTFILENAME $LABEL $INSTALLER
@pydevops
pydevops / gcp_ca_cert.md
Last active July 14, 2023 14:12
google cloud architect cert prepare
@pydevops
pydevops / chef_gcp_bootstrap.sh
Created February 15, 2018 18:19
gcp native chef bootstrap method
#!/bin/bash
## Please set run-list and env-name as instance attributes.
### Installs chef, kicks off initial chef run using passed runlist.
CHEF_VERSION="12.21.31"
RUN_LIST=$(curl "http://metadata.google.internal/computeMetadata/v1/instance/attributes/run-list" -H "Metadata-Flavor: Google")
ENV_NAME=$(curl "http://metadata.google.internal/computeMetadata/v1/instance/attributes/env-name" -H "Metadata-Flavor: Google")
CHEF_USER=terraformci
CHEF_SERVER_URL="https://chef-server:443/organizations/org/"
NODE_NAME=$(curl "http://metadata.google.internal/computeMetadata/v1/instance/name" -H "Metadata-Flavor: Google")
@pydevops
pydevops / cloud_kms.md
Last active February 16, 2024 14:40
cloud kms

Use case

Secrets such as aws key and secret, google service account json, database id and password etc. can be easily encrypted and decrypted with https://cloud.google.com/kms/. Cloud KMS does not directly store secrets. It can encrypt secrets that you store elsewhere, i.e. the key itself is stored within KMS.

Let's illustrate with a real world example step by step. We can encrypt and decrypt a service account json file for compute instances. These instances are a part of an elasticsearch cluster. The google cloud admin creates the service account. The service account is used by the Terraform to provision the compute instances as shown in https://www.terraform.io/docs/providers/google/r/compute_instance.html. The developers want a copy of the service account 's json file so that they can develop & test with the elasticsearch cluster. The google cloud admin creates the plain text service json file, where and how to store it safely and securely? Storing on admin's laptop is not 100% safe and secur