Secret: handle empty stdin read, explicit dir perms

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QKxGW1raAWaqeU8WdHsMsp
This commit is contained in:
2026-08-24 20:21:13 -04:00
co-authored by Claude Fable 5
parent 28a9de1a46
commit 6cb9065dcf
+3 -2
View File
@@ -30,7 +30,7 @@ set)
read -rs -p "API key for $provider: " key
echo
else
IFS= read -r key
IFS= read -r key || true
fi
if [[ -z $key ]]; then
echo "Empty key refused" >&2
@@ -43,7 +43,8 @@ set)
printf '%s\n' "$key" | pass insert -m -f "omarchycn/ai/$provider" > /dev/null
echo "Stored in pass (omarchycn/ai/$provider)"
else
mkdir -p -m 700 "$FILE_DIR"
mkdir -p "$FILE_DIR"
chmod 700 "$FILE_DIR"
(umask 177 && printf '%s' "$key" > "$FILE_PATH")
echo "Stored in $FILE_PATH (0600 file fallback — 安装 libsecret 或 pass 可获得更安全的存储)"
fi