Prefer env vars over secret store for API credentials

All scripts now check GLM_API_KEY / TK_AI_API_TOKEN environment
variables first, falling back to Keychain/libsecret only when unset.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-04 11:55:05 +07:00
co-authored by Claude Opus 4.7
parent 062597252a
commit 11485e08d9
5 changed files with 82 additions and 21 deletions
+15 -11
View File
@@ -43,17 +43,21 @@ while [[ $# -gt 0 ]]; do
done
# ===== LOAD TOKEN =====
case "$OS" in
macos)
API_TOKEN=$(security find-generic-password -a "$USER" -s "$KEY_NAME" -w 2>/dev/null | tr -d '\n')
;;
arch)
API_TOKEN=$(secret-tool lookup service "$KEY_NAME" 2>/dev/null | tr -d '\n')
;;
*)
API_TOKEN=$(secret-tool lookup service "$KEY_NAME" 2>/dev/null | tr -d '\n')
;;
esac
if [ -n "${!KEY_NAME}" ]; then
API_TOKEN="${!KEY_NAME}"
else
case "$OS" in
macos)
API_TOKEN=$(security find-generic-password -a "$USER" -s "$KEY_NAME" -w 2>/dev/null | tr -d '\n')
;;
arch)
API_TOKEN=$(secret-tool lookup service "$KEY_NAME" 2>/dev/null | tr -d '\n')
;;
*)
API_TOKEN=$(secret-tool lookup service "$KEY_NAME" 2>/dev/null | tr -d '\n')
;;
esac
fi
if [ -z "$API_TOKEN" ]; then
echo -e "${RED}❌ API token not found ($KEY_NAME)${RESET}" >&2
exit 1