Skip to content

Commit 1cd73b8

Browse files
committed
feat: add login subcommand for secure API key storage
Store API keys in system keychain (macOS Keychain / Windows Credential Manager / Linux Secret Service) instead of plaintext env vars. Falls back to AES-256-GCM encrypted file on headless Linux. Supports interactive and non-interactive flows, credential listing, and deletion. Breaking: none (backwards-compatible feature addition)
1 parent b4586f1 commit 1cd73b8

6 files changed

Lines changed: 667 additions & 12 deletions

File tree

Cargo.toml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pdf-to-markdown"
3-
version = "0.4.0"
3+
version = "0.5.0"
44
edition = "2021"
55

66
[dependencies]
@@ -14,6 +14,7 @@ indicatif = "0.17"
1414
lopdf = "0.40"
1515
regex = "1.10"
1616
reqwest = { version = "0.12", default-features = false, features = ["json", "multipart", "rustls-tls"] }
17+
rpassword = "7.4"
1718
serde = { version = "1.0", features = ["derive"] }
1819
serde_json = "1.0"
1920
serde_yaml = "0.9"
@@ -23,6 +24,17 @@ tokio = { version = "1.0", features = ["rt-multi-thread", "macros", "time", "fs"
2324
walkdir = "2.5"
2425
zip = "2.1"
2526

27+
[target.'cfg(target_os = "macos")'.dependencies]
28+
security-framework = "3"
29+
30+
[target.'cfg(target_os = "windows")'.dependencies]
31+
keyring = { version = "3.6", default-features = false, features = ["windows-native"] }
32+
33+
[target.'cfg(target_os = "linux")'.dependencies]
34+
keyring = { version = "3.6", default-features = false, features = ["sync-secret-service"] }
35+
aes-gcm = "0.10"
36+
rand = "0.8"
37+
2638
[[bin]]
2739
name = "pdf-to-markdown"
2840
path = "src/main.rs"

README.md

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ A command-line tool for converting PDF documents to Markdown with support for mu
3030
## Features
3131

3232
- Multiple provider support: PaddleOCR, Zhipu AI (lite/expert/prime)
33+
- Secure API key storage in system keychain (macOS/Windows/Linux)
3334
- Complex element parsing: text, images, tables, formulas, and more
3435
- Structured JSON output, meaningful exit codes, and dry-run support
3536
- Easy installation with one-click script for Linux/macOS/Windows
@@ -63,6 +64,41 @@ For more development information, see [CONTRIBUTING.md](./CONTRIBUTING.md).
6364

6465
## API Key Configuration
6566

67+
### Secure Login (Recommended)
68+
69+
```bash
70+
# Interactive: select provider and enter API key
71+
pdf-to-markdown login
72+
73+
# Store API key for a specific provider
74+
pdf-to-markdown login --provider paddleocr
75+
pdf-to-markdown login --provider zhipu
76+
77+
# Non-interactive: specify both provider and key
78+
pdf-to-markdown login --provider paddleocr --api-key "your_api_key"
79+
80+
# List stored credentials
81+
pdf-to-markdown login --list
82+
83+
# Delete a stored credential
84+
pdf-to-markdown login --delete paddleocr
85+
```
86+
87+
API keys are stored securely in the system keychain (macOS Keychain / Windows Credential Manager / Linux Secret Service) and never saved in plaintext.
88+
89+
### Environment Variables (Alternative)
90+
91+
```bash
92+
export PADDLE_OCR_API_KEY="your_api_key"
93+
export ZHIPU_API_KEY="your_api_key"
94+
```
95+
96+
Or pass via `--api-key` / `-k` flag:
97+
98+
```bash
99+
pdf-to-markdown parse -k "your_api_key" document.pdf
100+
```
101+
66102
### PaddleOCR
67103
- Application URL: https://aistudio.baidu.com/paddleocr
68104
- Free quota: 20,000 pages per day
@@ -76,12 +112,14 @@ For more development information, see [CONTRIBUTING.md](./CONTRIBUTING.md).
76112
### Basic Usage
77113

78114
```bash
79-
# Using PaddleOCR with local file
80-
export PADDLE_OCR_API_KEY="your_api_key"
115+
# First, store your API key securely (only needed once)
116+
pdf-to-markdown login
117+
118+
# Then convert PDF to Markdown
81119
pdf-to-markdown parse document.pdf
82120

83-
# Using Zhipu AI with local file
84-
export ZHIPU_API_KEY="your_api_key"
121+
# Using Zhipu AI
122+
pdf-to-markdown login --provider zhipu
85123
pdf-to-markdown parse --provider zhipu/lite document.pdf
86124

87125
# Using URL to download PDF directly
@@ -164,6 +202,28 @@ pdf-to-markdown parse document.pdf --overwrite
164202
PDF_TO_MARKDOWN_NO_CACHE=1 pdf-to-markdown parse document.pdf
165203
```
166204

205+
#### `login` - Secure API Key Storage
206+
207+
```bash
208+
# Interactive: select provider and enter API key
209+
pdf-to-markdown login
210+
211+
# Store API key for a specific provider (interactive key input)
212+
pdf-to-markdown login --provider paddleocr
213+
214+
# Store API key non-interactively
215+
pdf-to-markdown login --provider zhipu --api-key "your_api_key"
216+
217+
# List stored credentials
218+
pdf-to-markdown login --list
219+
220+
# Delete stored credential
221+
pdf-to-markdown login --delete paddleocr
222+
223+
# JSON output
224+
pdf-to-markdown login --list --json
225+
```
226+
167227
#### `cache` - Cache Management
168228

169229
```bash

install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ REPO="Peng-YM/pdf-to-markdown"
77
REPO_BRANCH="master"
88
BINARY_NAME="pdf-to-markdown"
99
INSTALL_DIR="${HOME}/.local/bin"
10-
DEFAULT_VERSION="v0.4.0"
10+
DEFAULT_VERSION="v0.5.0"
1111

1212
# Colors for output
1313
RED='\033[0;31m'

0 commit comments

Comments
 (0)