Skip to content

Instantly share code, notes, and snippets.

@jlsherrill
Created August 29, 2023 12:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jlsherrill/880bb18c288be3916c8cda94db0efacd to your computer and use it in GitHub Desktop.
Save jlsherrill/880bb18c288be3916c8cda94db0efacd to your computer and use it in GitHub Desktop.
org_admin header script
#!/bin/bash
ORG_ID="$1"
USER_NAME="$2"
ACCOUNT_ID="$3"
function print_out_usage {
cat <<EOF
Usage: ./scripts/header.sh <org_id> [user_name]
EOF
}
function error {
local err=$?
print_out_usage >&2
printf "error: %s\n" "$*" >&2
exit $err
}
[ "${ORG_ID}" != "" ] || error "ORG_ID is required and cannot be empty"
if [ "${ACCOUNT_ID}" == "" ]; then
ACCOUNT_ID=$ORG_ID
fi
if [ "${USER_NAME}" == "" ]; then
USER_NAME="snapUser"
fi
case "$( uname -s )" in
"Darwin" )
ENC="$(echo "{\"identity\":{\"type\":\"User\",\"user\":{\"is_org_admin\":true,\"username\":\"${USER_NAME}\"},\"account_number\":\"${ACCOUNT_ID}\",\"internal\":{\"org_id\":\"${ORG_ID}\"}}}" | base64 -b 0)"
;;
"Linux" | *)
ENC="$(echo "{\"identity\":{\"type\":\"User\",\"user\":{\"is_org_admin\":true, \"username\":\"${USER_NAME}\"},\"account_number\":\"${ACCOUNT_ID}\",\"internal\":{\"org_id\":\"${ORG_ID}\"}}}" | base64 -w0)"
;;
esac
echo "x-rh-identity: $ENC"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment