-
Notifications
You must be signed in to change notification settings - Fork 0
fix(cliproxyapi): read API key from .env and skip dotfiles sync on Linux #462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| # Example environment secrets consumed by home-manager/modules/secret | ||
| # Copy to home-manager/.env and provide real values. The .env file stays local. | ||
| # Copy to .env and provide real values. The .env file stays local. | ||
| MY_SECRET=replace-me | ||
| # GITHUB_TOKEN=ghp_your_token_here | ||
| CLIPROXY_API_KEY=your-api-key-here | ||
| CLIPROXY_MANAGEMENT_PASSWORD=your-management-key-here |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -156,10 +156,41 @@ End | |
| It 'script has Linux-specific api-keys uncommenting logic' | ||
| When run bash -c "grep -A 6 'Linux: uncomment and enable api-keys' '$SCRIPT'" | ||
| # shellcheck disable=SC2016 | ||
| The output should include 'if [ "$(uname)" = "Linux" ]' | ||
| The output should include 'if [ "$(uname)" = "Linux" ] && [ -n "${CLIPROXY_API_KEY:-}" ]' | ||
| The output should include 's|^# api-keys:|api-keys:|' | ||
| The output should include 'CLIPROXY_API_KEY' | ||
| End | ||
|
|
||
| It 'keeps api-keys commented on Linux when CLIPROXY_API_KEY is empty' | ||
| # Create test script that simulates Linux behavior with empty key | ||
| cat >"$TEMP_HOME/test_linux_empty_apikey.sh" <<'EOF' | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
| CONFIG_DIR="$HOME/.cli-proxy-api" | ||
| TEMPLATE="$CONFIG_DIR/config.template.yaml" | ||
| CONFIG="$CONFIG_DIR/config.yaml" | ||
| CLIPROXY_API_KEY="" | ||
|
|
||
| # Copy template to config | ||
| cp "$TEMPLATE" "$CONFIG" | ||
|
|
||
| # Simulate Linux behavior with empty key (should NOT uncomment) | ||
| if [ -n "${CLIPROXY_API_KEY:-}" ]; then | ||
| sed \ | ||
| -e "s|^# api-keys:|api-keys:|" \ | ||
| -e "s|^# - \"__CLIPROXY_API_KEY__\"| - \"${CLIPROXY_API_KEY}\"|" \ | ||
| "$CONFIG" > "$CONFIG.tmp" && mv "$CONFIG.tmp" "$CONFIG" | ||
| fi | ||
|
|
||
| cat "$CONFIG" | ||
| EOF | ||
| chmod +x "$TEMP_HOME/test_linux_empty_apikey.sh" | ||
|
|
||
| When run bash -c "HOME='$TEMP_HOME' bash '$TEMP_HOME/test_linux_empty_apikey.sh'" | ||
| The output should include '# api-keys:' | ||
| The output should include '# - "__CLIPROXY_API_KEY__"' | ||
| The status should be success | ||
| End | ||
|
Comment on lines
+164
to
+193
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a great test for the empty API key case! To make the tests more robust, consider adding another test case for when |
||
| End | ||
|
|
||
| Describe 'binary detection logic' | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
CLIPROXY_API_KEYvariable is used directly in asedreplacement string. If the API key contains special characters forsed(like&,\, or the|delimiter), it can break the substitution command or lead to unexpected results. It's safer to escape the variable before using it.For example, if
CLIPROXY_API_KEYwasfoo&bar, the&in the replacement part would be substituted with the entire matched pattern (# - "__CLIPROXY_API_KEY__"), which is not the desired behavior.