Support Upstash and Vercel KV environment variables for Redis authentication#57
Support Upstash and Vercel KV environment variables for Redis authentication#57
Conversation
|
After I added UPSTASH_REST_API_URL="https://full-...-12634.upstash.io" UPSTASH_REST_API_TOKEN="ATF.....MzQ"
I hate these confusion... |
- Support both UPSTASH_REDIS_REST_* and UPSTASH_REST_API_* naming conventions - Load .env file variables into os.environ while respecting OS env priority - Add --verbose flag to 'coaia tash' and 'coaia fetch' commands - Display detailed Redis connection info in verbose mode - Update error messages with both environment variable naming conventions Co-authored-by: jgwill <23141173+jgwill@users.noreply.github.com>
- Document both UPSTASH_REDIS_REST_* and UPSTASH_REST_API_* naming conventions - Explain configuration priority order (OS env > .env > config files) - Provide troubleshooting guide for common issues - Include usage examples for different scenarios - Describe verbose mode debugging capabilities Co-authored-by: jgwill <23141173+jgwill@users.noreply.github.com>
- Handle short passwords safely in verbose output (avoid IndexError) - Fix line continuation indentation for better readability - Add consistent spacing after commas in function calls - Improve password masking logic to handle edge cases Co-authored-by: jgwill <23141173+jgwill@users.noreply.github.com>
- Document that password is masked before logging - Add explanatory comments for CodeQL analysis - Password masking is intentional security measure (only shows last 4 chars) Co-authored-by: jgwill <23141173+jgwill@users.noreply.github.com>
- Document all changes made to resolve Redis authentication issues - Include root cause analysis and solutions - List all testing performed and security considerations - Provide usage examples and migration guidance - Confirm backward compatibility Co-authored-by: jgwill <23141173+jgwill@users.noreply.github.com>
- Show concrete examples of error messages before and after fix - Demonstrate verbose mode output with real examples - Include troubleshooting scenarios with solutions - Provide quick start guide for users - Create comprehensive visual comparison document Co-authored-by: jgwill <23141173+jgwill@users.noreply.github.com>
|
@copilot because we use Vercel.com, the connection with UPSTASH as storage outputs these variables :
It gives us what we need to support and whatever else exist that dont match these should be removed because it gets confusing what should be the environment variables. Remove anything else from .env and of course, we still falling back to the ./coaia.json or $HOME/coaia.json property: "jtaleconf": host,port,password,ssl |
…confusing UPSTASH_REST_API_* - Remove UPSTASH_REST_API_URL/TOKEN (non-standard, confusing) - Add support for Vercel KV variables: KV_REST_API_URL/TOKEN, KV_URL, REDIS_URL - Update priority order: UPSTASH_REDIS_REST_* > KV_* > REDIS_* > config - Parse both REST API format (https://) and connection strings (rediss://) - Update documentation to reflect correct supported variables - Update error messages with clearer guidance Co-authored-by: jgwill <23141173+jgwill@users.noreply.github.com>
... Added full support for Vercel KV variables as you specified: Supported formats:
Priority order maintained:
The code now parses both HTTPS URLs and Fixed in commit 7e3f80f
You're right - the The code now only supports standard variables:
Fixed in commit 7e3f80f |
- Create ENVIRONMENT_VARIABLES_REFERENCE.md with quick reference for all supported variables - Add UPDATE_NOTES.md explaining the correction from non-standard to standard variables - Document priority order and when to use each format - Include migration guide from old UPSTASH_REST_API_* to correct variables - Add troubleshooting section for common issues Co-authored-by: jgwill <23141173+jgwill@users.noreply.github.com>
- Document all changes made to address user feedback - List removed non-standard variables and added standard ones - Show platform compatibility matrix - Include before/after comparison for users - Provide clear next steps and verification methods Co-authored-by: jgwill <23141173+jgwill@users.noreply.github.com>
- Create ASCII art reference showing all supported variables - Clearly mark removed non-standard variables - Show priority order with visual indicators - Include testing examples and migration guide - Easy to read format for quick reference Co-authored-by: jgwill <23141173+jgwill@users.noreply.github.com>
coaia tashandcoaia fetchfailed with authentication errors because the code didn't support standard environment variables from Vercel KV and only recognized Upstash direct variables.Changes
Environment variable handling (
coaiamodule.py)UPSTASH_REDIS_REST_URLandUPSTASH_REDIS_REST_TOKENKV_REST_API_URLandKV_REST_API_TOKENKV_URLandREDIS_URL(format:rediss://default:password@host:6379)os.environwhile preserving OS environment priorityUPSTASH_REST_API_*variables that caused confusionDebugging capability (
coaiamodule.py,coaiacli.py)--verboseflag totashandfetchcommandsConfiguration priority
UPSTASH_REDIS_REST_*)KV_REST_API_*)KV_URL,REDIS_URL)REDIS_HOST,REDIS_PASSWORD)./coaia.json,~/coaia.json)Examples
Upstash Direct:
Vercel KV (REST API):
$ cat .env KV_REST_API_URL=https://my-redis.upstash.io KV_REST_API_TOKEN=my_token $ coaia tash KEY "value" --verboseVercel KV (Connection String):
$ cat .env KV_URL=rediss://default:password@host.upstash.io:6379 $ coaia tash KEY "value" --verboseDocumentation
Added comprehensive documentation:
ENVIRONMENT_VARIABLES_REFERENCE.md- Quick reference for all supported variablesUPDATE_NOTES.md- Migration guide from non-standard variablesSUPPORTED_VARIABLES.txt- Visual ASCII referenceREDIS_FIX_DOCUMENTATION.mdwith correct variable namesBackward compatible - existing configurations continue working unchanged.
Fixes #55
Original prompt
This section details on the original issue you should resolve
<issue_title>ISSUE_251107_coaia_tash_fetch.md</issue_title>
<issue_description># Issue:
coaia tashandcoaia fetchcommands failing with Redis authentication errorProblem Description
The
coaia tashandcoaia fetchcommands are currently failing to execute successfully, returning an "invalid username-password pair or user is disabled" error. This occurs even when no.envfile is explicitly present in the current working directory, suggesting a potential misconfiguration or incorrect handling of Redis connection parameters.Observed Behavior
When attempting to use
coaia tash(e.g.,coaia tash TMP -F README.md -T 33) orcoaia fetch <key>, the following error message is displayed:Despite the message indicating the key was saved, subsequent
coaia fetchcommands for the same key also fail with the same authentication error. This indicates that the operation is not completing successfully due to a Redis authentication issue.Expected Behavior
coaia tashandcoaia fetchcommands should successfully interact with the configured Redis instance.UPSTASH_REDIS_REST_URLandUPSTASH_REDIS_REST_TOKEN..envfile exists in the current working directory (/src/coaiapy/), these variables should be read from it and used for Redis authentication..envfile is present, the commands should fall back to other configured methods (e.g.,~/.coaia.jsonor other global configurations) without authentication errors.Reproduction Steps
.envfile is present in/src/coaiapy/.coaia tash TMP -F README.md -T 33.coaia fetch TMP.Relevant Environment Variables
The following environment variables are critical for Redis connection and should be correctly processed by the
coaiatool:UPSTASH_REDIS_REST_URLUPSTASH_REDIS_REST_TOKENThese variables should be looked for in the
.envfile within the current working directory (/src/coaiapy/) first.Suggested Solution/Investigation Areas for Copilot Agents
Copilot agents should investigate the following:
coaialoads and prioritizes environment variables, especially from.envfiles. Ensure thatpython-dotenvor a similar mechanism is correctly implemented and functioning.coaiacodebase to understand how the Redis client is initialized and how theUPSTASH_REDIS_REST_URLandUPSTASH_REDIS_REST_TOKENare passed to it. There might be an issue with how these credentials are being formatted or used during the connection attempt..envvariables are not present) is correctly implemented and does not lead to authentication failures..envpresent,.envabsent, invalid credentials).</issue_description><agent_instructions>It is not the first time I assign you that issue, you seems not to have fixed it.
maybe add a flag "--view-redis-url" that will show the value of the server or just a --verbose at least to 'coaia tash' and 'coaia fetch'
my .env has the environment values UPSTASH_REST_API_URL and UPSTASH_REST_API_TOKEN but the "coaia tash" dont store the values in that REDIS server but probably another one that is not desired, it should look in the ./.env for those values
I dont know what is hapenning but you have some more work todo, you closed PR #56 failed to fix that</agent_instructions>
Comments on the Issue (you are @copilot in this section)
@jgwill # Complementary Analysis: Adjustments for `coaia tash` and `coaia fetch` Redis IssueAnalysis of Likely Root Cause
The primary issue appears to stem from an incomplete or incorrect mechanism for loading and prioritizing Redis connection credentials, particularly the
UPSTASH_REDIS_REST_URLandUPSTASH_REDIS_REST_TOKENenvironment variables. The error message "invalid username-password pair or user is disabled" strongly suggests that the Redis client is either not receiving the correct credentials or is attempting to connect with default/empty credentials.Given the user's expectation that
.envfiles should...✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.