2017-02-13 14:01:54 -05:00
|
|
|
#!/usr/bin/env bash
|
2016-02-07 19:55:17 -05:00
|
|
|
|
|
|
|
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")
|
2020-03-02 22:27:49 -05:00
|
|
|
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
|
2020-03-02 22:27:49 -05:00
|
|
|
list=$(< $TEMP/$listFile)
|
2016-09-06 17:10:04 -04:00
|
|
|
echo "$list" | jq ". + {\"${server}\": \"${username}\"}" > $TEMP/$listFile
|
|
|
|
fi
|
2016-02-07 19:55:17 -05:00
|
|
|
;;
|
|
|
|
"get")
|
2020-03-02 22:27:49 -05:00
|
|
|
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
|
2020-03-02 22:27:49 -05:00
|
|
|
payload=$(< $TEMP/$serverHash)
|
2016-02-07 19:55:17 -05:00
|
|
|
echo "$payload"
|
|
|
|
;;
|
|
|
|
"erase")
|
2020-03-02 22:27:49 -05:00
|
|
|
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
|
2020-03-02 22:27:49 -05:00
|
|
|
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
|
2020-03-02 22:27:49 -05:00
|
|
|
payload=$(< $TEMP/$listFile)
|
2016-09-06 17:10:04 -04:00
|
|
|
echo "$payload"
|
|
|
|
fi
|
2016-02-07 19:55:17 -05:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "unknown credential option"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|