-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathheader.sh
executable file
·41 lines (31 loc) · 951 Bytes
/
header.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/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\":{\"org_id\":\"${ORG_ID}\", \"type\":\"User\",\"user\":{\"username\":\"${USER_NAME}\"},\"account_number\":\"${ACCOUNT_ID}\",\"internal\":{\"org_id\":\"${ORG_ID}\"}}}" | base64 -b 0)"
;;
"Linux" | *)
ENC="$(echo "{\"identity\":{\"org_id\":\"${ORG_ID}\", \"type\":\"User\",\"user\":{\"username\":\"${USER_NAME}\"},\"account_number\":\"${ACCOUNT_ID}\",\"internal\":{\"org_id\":\"${ORG_ID}\"}}}" | base64 -w0)"
;;
esac
echo "x-rh-identity: $ENC"