Repository navigation
fix(clawdbot): inject cliproxy apiKey via activation script #615
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 | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -45,6 +45,23 @@ lib.mkIf (!env.isCI) { | |||||||||||||||||||||||||||||||||||||||||||||
| '' | ||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| # Inject cliproxy API key into clawdbot.json (apiKeyFile not supported upstream) | ||||||||||||||||||||||||||||||||||||||||||||||
| home.activation.clawdbotCliproxyKey = lib.mkIf (lib ? hm && lib.hm ? dag && host.isKyber) ( | ||||||||||||||||||||||||||||||||||||||||||||||
| lib.hm.dag.entryAfter [ "clawdbotSecrets" "clawdbotConfigFiles" ] '' | ||||||||||||||||||||||||||||||||||||||||||||||
| KEY_FILE="${clawdbotDir}/cliproxy-key" | ||||||||||||||||||||||||||||||||||||||||||||||
| CONFIG_FILE="${homeDir}/.clawdbot/clawdbot.json" | ||||||||||||||||||||||||||||||||||||||||||||||
| if [ -f "$KEY_FILE" ] && [ -f "$CONFIG_FILE" ]; then | ||||||||||||||||||||||||||||||||||||||||||||||
| KEY=$(${pkgs.coreutils}/bin/cat "$KEY_FILE" | ${pkgs.coreutils}/bin/tr -d '\n') | ||||||||||||||||||||||||||||||||||||||||||||||
| # Inject apiKey into models.providers.cliproxy | ||||||||||||||||||||||||||||||||||||||||||||||
| ${pkgs.jq}/bin/jq --arg key "$KEY" \ | ||||||||||||||||||||||||||||||||||||||||||||||
| '.models.providers.cliproxy.apiKey = $key' \ | ||||||||||||||||||||||||||||||||||||||||||||||
| "$CONFIG_FILE" > "$CONFIG_FILE.tmp" && \ | ||||||||||||||||||||||||||||||||||||||||||||||
| ${pkgs.coreutils}/bin/mv "$CONFIG_FILE.tmp" "$CONFIG_FILE" | ||||||||||||||||||||||||||||||||||||||||||||||
| echo "Injected cliproxy API key into clawdbot config" | ||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+53
to
+61
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. Guard against empty key + avoid false “Injected” logs. If the key file exists but is empty (or jq fails), the script will overwrite the config with an empty apiKey and still print success, which can silently break authentication. Consider requiring a non-empty key and chaining the success log to the jq/mv pipeline. 🔧 Suggested fix- if [ -f "$KEY_FILE" ] && [ -f "$CONFIG_FILE" ]; then
- KEY=$(${pkgs.coreutils}/bin/cat "$KEY_FILE" | ${pkgs.coreutils}/bin/tr -d '\n')
- # Inject apiKey into models.providers.cliproxy
- ${pkgs.jq}/bin/jq --arg key "$KEY" \
- '.models.providers.cliproxy.apiKey = $key' \
- "$CONFIG_FILE" > "$CONFIG_FILE.tmp" && \
- ${pkgs.coreutils}/bin/mv "$CONFIG_FILE.tmp" "$CONFIG_FILE"
- echo "Injected cliproxy API key into clawdbot config"
- fi
+ if [ -f "$KEY_FILE" ] && [ -f "$CONFIG_FILE" ]; then
+ KEY=$(${pkgs.coreutils}/bin/cat "$KEY_FILE" | ${pkgs.coreutils}/bin/tr -d '\n')
+ if [ -n "$KEY" ]; then
+ # Inject apiKey into models.providers.cliproxy
+ ${pkgs.jq}/bin/jq --arg key "$KEY" \
+ '.models.providers.cliproxy.apiKey = $key' \
+ "$CONFIG_FILE" > "$CONFIG_FILE.tmp" && \
+ ${pkgs.coreutils}/bin/mv "$CONFIG_FILE.tmp" "$CONFIG_FILE" && \
+ echo "Injected cliproxy API key into clawdbot config"
+ else
+ echo "cliproxy key is empty; skipping injection"
+ fi
+ fi📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||
| '' | ||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| # Inject gateway token into clawdbot.json for remote mode (tokenFile not supported upstream) | ||||||||||||||||||||||||||||||||||||||||||||||
| home.activation.clawdbotRemoteToken = lib.mkIf (lib ? hm && lib.hm ? dag && !host.isKyber) ( | ||||||||||||||||||||||||||||||||||||||||||||||
| lib.hm.dag.entryAfter [ "clawdbotSecrets" "clawdbotConfigFiles" ] '' | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
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.
This script block can be made more robust and correct. Currently, it reports success even if the
mvcommand fails, and it doesn't handle empty key files. I suggest the following improvements:[ -s "$KEY_FILE" ]instead of[ -f "$KEY_FILE" ]to prevent injecting an empty API key ifextract-secrets.shdoesn't find a key.mktemp: Create a secure temporary file to avoid issues with stale or conflicting temporary files.