2016-02-07 19:55:17 -05:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2016-09-06 17:10:04 -04:00
|
|
|
listFile=shell_test_list.json
|
|
|
|
|
2016-02-07 19:55:17 -05:00
|
|
|
case $1 in
|
|
|
|
"store")
|
|
|
|
in=$(</dev/stdin)
|
2016-09-06 17:10:04 -04:00
|
|
|
server=$(echo "$in" | jq --raw-output ".ServerURL")
|
|
|
|
serverHash=$(echo "$server" | sha1sum - | awk '{print $1}')
|
2016-02-07 19:55:17 -05:00
|
|
|
|
|
|
|
username=$(echo "$in" | jq --raw-output ".Username")
|
2016-03-04 15:00:18 -05:00
|
|
|
password=$(echo "$in" | jq --raw-output ".Secret")
|
2016-09-06 17:10:04 -04:00
|
|
|
echo "{ \"Username\": \"${username}\", \"Secret\": \"${password}\" }" > $TEMP/$serverHash
|
|
|
|
# add the server to the list file
|
|
|
|
if [[ ! -f $TEMP/$listFile ]]; then
|
|
|
|
echo "{ \"${server}\": \"${username}\" }" > $TEMP/$listFile
|
|
|
|
else
|
|
|
|
list=$(<$TEMP/$listFile)
|
|
|
|
echo "$list" | jq ". + {\"${server}\": \"${username}\"}" > $TEMP/$listFile
|
|
|
|
fi
|
2016-02-07 19:55:17 -05:00
|
|
|
;;
|
|
|
|
"get")
|
|
|
|
in=$(</dev/stdin)
|
2016-09-06 17:10:04 -04:00
|
|
|
serverHash=$(echo "$in" | sha1sum - | awk '{print $1}')
|
|
|
|
if [[ ! -f $TEMP/$serverHash ]]; then
|
2016-02-07 19:55:17 -05:00
|
|
|
echo "credentials not found in native keychain"
|
|
|
|
exit 1
|
|
|
|
fi
|
2016-09-06 17:10:04 -04:00
|
|
|
payload=$(<$TEMP/$serverHash)
|
2016-02-07 19:55:17 -05:00
|
|
|
echo "$payload"
|
|
|
|
;;
|
|
|
|
"erase")
|
|
|
|
in=$(</dev/stdin)
|
2016-09-06 17:10:04 -04:00
|
|
|
serverHash=$(echo "$in" | sha1sum - | awk '{print $1}')
|
|
|
|
rm -f $TEMP/$serverHash
|
|
|
|
|
|
|
|
# Remove the server from the list
|
|
|
|
list=$(<$TEMP/$listFile)
|
2016-11-04 18:51:35 -04:00
|
|
|
echo "$list" | jq "del(.[\"${in}\"])" > $TEMP/$listFile
|
2016-09-06 17:10:04 -04:00
|
|
|
;;
|
|
|
|
"list")
|
|
|
|
if [[ ! -f $TEMP/$listFile ]]; then
|
|
|
|
echo "{}"
|
|
|
|
else
|
|
|
|
payload=$(<$TEMP/$listFile)
|
|
|
|
echo "$payload"
|
|
|
|
fi
|
2016-02-07 19:55:17 -05:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "unknown credential option"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|