Last active
October 10, 2019 10:04
-
-
Save ITler/e50d6b37ef56e49de1ed463c82e68520 to your computer and use it in GitHub Desktop.
Useful shell functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gh_api() { | |
local -r gh_api_auth=${GH_API_AUTH} | |
local -r method=${1:-GET} | |
local -r path=${2:-user} | |
shift 2 | |
http --auth "${gh_api_auth}" ${method} "https://api.github.com/${path}" Accept:application/vnd.github.v3+json "${@}" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
handle_sops() { | |
if [[ $(which sops) == '' ]]; then | |
echo "Mozilla sops could not be found. Make sure it is in your path [${PATH}]" | |
fi | |
# Remove duplicate file names (without sorting) and iterate over them | |
for f in $(echo $@ | tr ' ' '\n' | awk '!x[$0]++'); do | |
local FILE_NAME=$(basename ${f}) | |
if [[ $f != /* ]]; then | |
f=$(pwd)/${f} | |
fi | |
if [[ -w /tmp ]] && [[ -r ${f} ]]; then | |
echo "Processing ${f}" | |
local CREDS_RAW=/tmp/${FILE_NAME/sops/unenc} | |
sops -d ${f} >${CREDS_RAW} | |
source ${CREDS_RAW} | |
rm ${CREDS_RAW} | |
fi | |
done | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vault_api() { | |
local -r vault_token=${VAULT_TOKEN:-$(pass show my/dev/vault_token)} | |
local -r method=${1:-GET} | |
local -r path=${2:-user} | |
local -r host=${3:-${VAULT_HOST:-"http://127.0.0.1:8200"}} | |
http ${method} "${host}/v1/${path}" X-Vault-Token:${vault_token} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment