Skip to content

Commit 2e90173

Browse files
authored
Merge pull request #57 from jgwill/copilot/fix-redis-authentication-error
Support Upstash and Vercel KV environment variables for Redis authentication
2 parents 6277afd + 9def56b commit 2e90173

File tree

9 files changed

+1303
-21
lines changed

9 files changed

+1303
-21
lines changed

CHANGES_SUMMARY.md

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
# Summary of Changes - Redis Environment Variable Fix
2+
3+
## Issue Addressed
4+
User comments #3504737289 and #3504805230 pointed out:
5+
1. Confusion about which environment variables to use
6+
2. Non-standard `UPSTASH_REST_API_*` variables were added but aren't provided by any platform
7+
3. Need to support Vercel KV variables: `KV_REST_API_URL`, `KV_URL`, `REDIS_URL`
8+
4. Maintain fallback to `./coaia.json` and `~/coaia.json`
9+
10+
## Changes Made
11+
12+
### Code Changes (`coaiapy/coaiamodule.py`)
13+
14+
#### Removed
15+
-`UPSTASH_REST_API_URL` support (non-standard, confusing)
16+
-`UPSTASH_REST_API_TOKEN` support (non-standard, confusing)
17+
18+
#### Added
19+
-`KV_REST_API_URL` support (Vercel KV REST API)
20+
-`KV_REST_API_TOKEN` support (Vercel KV REST API)
21+
-`KV_URL` support (Vercel connection string parsing)
22+
-`REDIS_URL` support (Vercel connection string parsing)
23+
- ✅ Connection string parsing for `rediss://` format
24+
25+
#### Kept (Already Working)
26+
-`UPSTASH_REDIS_REST_URL` (Upstash direct)
27+
-`UPSTASH_REDIS_REST_TOKEN` (Upstash direct)
28+
-`REDIS_HOST`, `REDIS_PORT`, `REDIS_PASSWORD` (traditional)
29+
- ✅ Config file support (`./coaia.json`, `~/coaia.json`)
30+
-`--verbose` flag for debugging
31+
32+
### Priority Order (Updated)
33+
1. **Upstash Direct** - `UPSTASH_REDIS_REST_*`
34+
2. **Vercel KV REST** - `KV_REST_API_*`
35+
3. **Vercel Connection Strings** - `KV_URL` or `REDIS_URL`
36+
4. **Traditional Redis** - `REDIS_HOST`/`REDIS_PASSWORD`
37+
5. **Config Files** - `./coaia.json` or `~/coaia.json`
38+
39+
### Documentation Changes
40+
41+
#### New Files
42+
1. **`ENVIRONMENT_VARIABLES_REFERENCE.md`**
43+
- Quick reference for all supported variables
44+
- Examples for each platform (Upstash, Vercel)
45+
- Priority order explanation
46+
- Troubleshooting guide
47+
- Migration guide
48+
49+
2. **`UPDATE_NOTES.md`**
50+
- Explains the correction from non-standard to standard variables
51+
- Why the change was needed
52+
- Migration instructions
53+
54+
#### Updated Files
55+
1. **`REDIS_FIX_DOCUMENTATION.md`**
56+
- Removed references to `UPSTASH_REST_API_*`
57+
- Added Vercel KV variables
58+
- Updated examples to show correct variable names
59+
60+
2. **Error Messages in `coaiamodule.py`**
61+
- Updated to mention correct variables
62+
- Added clearer troubleshooting steps
63+
64+
## Verification
65+
66+
### Tests Performed
67+
✅ All syntax checks pass
68+
✅ Help text shows `--verbose` flag
69+
✅ Code compiles without errors
70+
✅ Tested all variable formats:
71+
- Upstash direct variables
72+
- Vercel KV REST API variables
73+
- Vercel connection strings (KV_URL, REDIS_URL)
74+
- Priority order works correctly
75+
76+
### Platform Compatibility
77+
78+
| Platform | Variables | Status |
79+
|----------|-----------|--------|
80+
| Upstash Direct | `UPSTASH_REDIS_REST_*` | ✅ Supported |
81+
| Vercel KV | `KV_REST_API_*` | ✅ Supported |
82+
| Vercel KV | `KV_URL`, `REDIS_URL` | ✅ Supported |
83+
| Traditional Redis | `REDIS_HOST`, etc. | ✅ Supported |
84+
| Config Files | `coaia.json` | ✅ Supported |
85+
86+
## User Impact
87+
88+
### Before This Fix
89+
- ❌ Confusing `UPSTASH_REST_API_*` variables that don't match any platform
90+
- ❌ Vercel KV variables not supported
91+
- ❌ Users had to manually figure out which variables to use
92+
93+
### After This Fix
94+
- ✅ Only standard platform-provided variables supported
95+
- ✅ All Vercel KV variable formats work
96+
- ✅ Clear documentation showing which variables to use for each platform
97+
- ✅ Easy to debug with `--verbose` flag
98+
99+
## How Users Should Configure
100+
101+
### Upstash Direct Users
102+
```bash
103+
# .env
104+
UPSTASH_REDIS_REST_URL=https://your-instance.upstash.io
105+
UPSTASH_REDIS_REST_TOKEN=your_token
106+
```
107+
108+
### Vercel Users (Option 1: REST API)
109+
```bash
110+
# .env (from Vercel dashboard)
111+
KV_REST_API_URL=https://your-instance.upstash.io
112+
KV_REST_API_TOKEN=your_token
113+
```
114+
115+
### Vercel Users (Option 2: Connection String)
116+
```bash
117+
# .env (from Vercel dashboard)
118+
KV_URL=rediss://default:password@host.upstash.io:6379
119+
```
120+
121+
### Testing
122+
```bash
123+
# Verify configuration with verbose mode
124+
coaia tash TEST_KEY "test" --verbose
125+
126+
# Expected output shows:
127+
# - Connecting to Redis server:
128+
# Host: your-host.upstash.io
129+
# Port: 6379
130+
# SSL: True
131+
# Password: ***word
132+
# Status: Connection established successfully
133+
```
134+
135+
## Commits
136+
137+
1. **7e3f80f** - Fix environment variable naming: Support Vercel KV variables, remove confusing UPSTASH_REST_API_*
138+
2. **0373dfa** - Add comprehensive environment variables reference and update notes
139+
140+
## Next Steps for Users
141+
142+
1. ✅ Update .env files to use correct variable names for your platform
143+
2. ✅ Test with `--verbose` flag to verify configuration
144+
3. ✅ See `ENVIRONMENT_VARIABLES_REFERENCE.md` for complete reference
145+
4. ✅ See `UPDATE_NOTES.md` for migration guide
146+
147+
## Resolution
148+
149+
Both user comments have been addressed:
150+
-#3504737289 - Removed confusing `UPSTASH_REST_API_*` variables
151+
-#3504805230 - Added full Vercel KV support, maintained config file fallback

ENVIRONMENT_VARIABLES_REFERENCE.md

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
# Supported Environment Variables - Quick Reference
2+
3+
## Redis/Upstash Connection Variables
4+
5+
### Priority Order (Highest to Lowest)
6+
7+
1. **Upstash Direct (REST API)**
8+
```bash
9+
UPSTASH_REDIS_REST_URL=https://your-instance.upstash.io
10+
UPSTASH_REDIS_REST_TOKEN=your_token_here
11+
```
12+
13+
2. **Vercel KV (REST API)**
14+
```bash
15+
KV_REST_API_URL=https://your-instance.upstash.io
16+
KV_REST_API_TOKEN=your_token_here
17+
```
18+
19+
3. **Vercel KV (Connection String)**
20+
```bash
21+
KV_URL=rediss://default:your_password@your-host.upstash.io:6379
22+
# OR
23+
REDIS_URL=rediss://default:your_password@your-host.upstash.io:6379
24+
```
25+
26+
4. **Traditional Redis**
27+
```bash
28+
REDIS_HOST=your-host.upstash.io
29+
REDIS_PORT=6379
30+
REDIS_PASSWORD=your_password
31+
REDIS_SSL=true
32+
```
33+
34+
5. **Config Files** (lowest priority)
35+
- `./coaia.json` (current directory)
36+
- `~/coaia.json` (home directory)
37+
38+
```json
39+
{
40+
"jtaleconf": {
41+
"host": "your-host.upstash.io",
42+
"port": 6379,
43+
"password": "your_password",
44+
"ssl": true
45+
}
46+
}
47+
```
48+
49+
## When to Use Each Format
50+
51+
### Use Upstash Direct Format When:
52+
- You're using Upstash directly (not through Vercel)
53+
- You have the Upstash dashboard credentials
54+
55+
### Use Vercel KV Format When:
56+
- You're deploying on Vercel
57+
- Vercel automatically sets these variables
58+
- You're using Vercel's KV storage integration
59+
60+
### Use Config Files When:
61+
- You want to commit configuration (without secrets)
62+
- You need project-specific defaults
63+
- Environment variables aren't available
64+
65+
## Example .env Files
66+
67+
### For Upstash Direct Users
68+
```bash
69+
# .env
70+
UPSTASH_REDIS_REST_URL=https://talented-aardvark-12345.upstash.io
71+
UPSTASH_REDIS_REST_TOKEN=AaBbCcDdEeFf123456
72+
```
73+
74+
### For Vercel Users (REST API)
75+
```bash
76+
# .env (copied from Vercel dashboard)
77+
KV_REST_API_URL=https://full-alpaca-12634.upstash.io
78+
KV_REST_API_TOKEN=AaBbCcDdEeFf123456
79+
KV_REST_API_READ_ONLY_TOKEN=XxYyZz789012
80+
```
81+
82+
### For Vercel Users (Connection String)
83+
```bash
84+
# .env (copied from Vercel dashboard)
85+
KV_URL=rediss://default:AaBbCcDdEeFf123456@full-alpaca-12634.upstash.io:6379
86+
REDIS_URL=rediss://default:AaBbCcDdEeFf123456@full-alpaca-12634.upstash.io:6379
87+
```
88+
89+
## Testing Your Configuration
90+
91+
```bash
92+
# Test with verbose mode to see which configuration is being used
93+
coaia tash TEST_KEY "test value" --verbose
94+
95+
# Expected output:
96+
# Connecting to Redis server:
97+
# Host: your-host.upstash.io
98+
# Port: 6379
99+
# SSL: True
100+
# Password: ***3456
101+
# Status: Connection established successfully
102+
# Key: TEST_KEY was just saved to memory.
103+
```
104+
105+
## Troubleshooting
106+
107+
### Wrong Redis Server Being Used?
108+
Run with `--verbose` to see which host is being connected to:
109+
```bash
110+
coaia tash KEY "value" --verbose
111+
```
112+
113+
Check the priority order - OS environment variables override .env file, which overrides config files.
114+
115+
### "Invalid username-password pair" Error?
116+
1. Verify your credentials are correct
117+
2. Check which variables you're setting match your provider:
118+
- Upstash direct → Use `UPSTASH_REDIS_REST_*`
119+
- Vercel → Use `KV_*` variables
120+
3. Use `--verbose` to see the masked password and verify it's correct
121+
122+
### Variables Not Being Loaded from .env?
123+
1. Ensure `.env` file is in your current working directory
124+
2. Check for typos in variable names
125+
3. OS environment variables take priority over .env file
126+
4. Use `--verbose` to confirm which configuration is active
127+
128+
## Migration Guide
129+
130+
### Migrating from Old UPSTASH_REST_API_* Variables
131+
If you were using the non-standard `UPSTASH_REST_API_*` variables, update to standard names:
132+
133+
**Old (no longer supported):**
134+
```bash
135+
UPSTASH_REST_API_URL=...
136+
UPSTASH_REST_API_TOKEN=...
137+
```
138+
139+
**New (choose based on your provider):**
140+
```bash
141+
# For Upstash direct:
142+
UPSTASH_REDIS_REST_URL=...
143+
UPSTASH_REDIS_REST_TOKEN=...
144+
145+
# For Vercel KV:
146+
KV_REST_API_URL=...
147+
KV_REST_API_TOKEN=...
148+
```
149+
150+
## Summary Table
151+
152+
| Variable | Provider | Format | Priority |
153+
|----------|----------|--------|----------|
154+
| `UPSTASH_REDIS_REST_URL` | Upstash | HTTPS | 1 (Highest) |
155+
| `UPSTASH_REDIS_REST_TOKEN` | Upstash | Token | 1 |
156+
| `KV_REST_API_URL` | Vercel | HTTPS | 2 |
157+
| `KV_REST_API_TOKEN` | Vercel | Token | 2 |
158+
| `KV_URL` | Vercel | Connection String | 3 |
159+
| `REDIS_URL` | Vercel | Connection String | 3 |
160+
| `REDIS_HOST` | Generic | Hostname | 4 |
161+
| `REDIS_PASSWORD` | Generic | Password | 4 |
162+
| Config files | Any | JSON | 5 (Lowest) |

0 commit comments

Comments
 (0)