Created
May 5, 2023 07:25
-
-
Save pessom/c56fd66cd269661975e12b61b975e403 to your computer and use it in GitHub Desktop.
keychain storage for ENV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Как быстро и безопасно управлять переменными окружения на macOS с помощью keychain. | |
По сути там уже все есть, нужно только добавить обертку. | |
Делаем раз: | |
tee ~/keychain-env.sh <<'EOF' | |
function keychain-env-read () { | |
security find-generic-password -w -a ${USER} -D "environment variable" -s "${1}" | |
} | |
function keychain-env-add () { | |
[ -n "$1" ] || print "Missing environment variable name" | |
read -s "?Enter Value for ${1}: " secret | |
( [ -n "$1" ] && [ -n "$secret" ] ) || return 1 | |
security add-generic-password -U -a ${USER} -D "environment variable" -s "${1}" -w "${secret}" | |
} | |
EOF | |
Два: | |
echo -n 'source ~/keychain-env.sh' >> ~/.zshrc | |
Три: | |
source ~/.zshrc | |
Теперь взмахом руки можно добавлять переменные окружения в ваш keychain и вычитывать их оттуда. | |
keychain-env-add AWS_ACCESS_KEY_ID | |
export AWS_ACCESS_KEY_ID=$(keychain-env-get AWS_ACCESS_KEY_ID); | |
полный снипет тут - https://gist.github.com/kmgnd/e04a346a59bcc865f7c2fc60f7e892a3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment