Skip to content

Instantly share code, notes, and snippets.

@calavera
Last active April 25, 2023 00:46
Show Gist options
  • Select an option

  • Save calavera/61b92e5d43a58be80c5582cd082e28fe to your computer and use it in GitHub Desktop.

Select an option

Save calavera/61b92e5d43a58be80c5582cd082e28fe to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
case $1 in
"store")
in=$(</dev/stdin)
server=$(echo "$in" | jq --raw-output ".ServerURL" | sha1sum - | awk '{print $1}')
username=$(echo "$in" | jq --raw-output ".Username")
password=$(echo "$in" | jq --raw-output ".Secret")
echo "{ \"Username\": \"${username}\", \"Secret\": \"${password}\" }" > $TEMP/$server
;;
"get")
in=$(</dev/stdin)
server=$(echo "$in" | sha1sum - | awk '{print $1}')
if [[ ! -f $TEMP/$server ]]; then
echo "credentials not found in native keychain"
exit 1
fi
payload=$(<$TEMP/$server)
echo "$payload"
;;
"erase")
in=$(</dev/stdin)
server=$(echo "$in" | sha1sum - | awk '{print $1}')
rm -f $TEMP/$server
;;
*)
echo "unknown credential option"
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment