Skip to content

Commit a4b5873

Browse files
ImTotemclaude
andcommitted
fix(infra): use python3 for n8n credential JSON generation
Private key \n escapes broke JSON parsing in heredoc. Use python3 json.dump to properly serialize the service account credential. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent b9bf50c commit a4b5873

1 file changed

Lines changed: 15 additions & 11 deletions

File tree

infra/scripts/init_n8n.sh

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,25 +52,29 @@ activate_workflow() {
5252
}
5353

5454
setup_credential() {
55-
local sa_path="/credentials/sa.json"
5655
local existing
5756
existing=$($COMPOSE exec -T n8n n8n list:credential 2>/dev/null | grep -c "Google Sheets SA" || true)
5857
if [ "$existing" -gt 0 ]; then
5958
echo " Google Sheets credential already exists — skipping"
6059
return 0
6160
fi
6261
echo " Creating Google Sheets service account credential..."
63-
$COMPOSE exec -T n8n n8n import:credentials --input=/dev/stdin <<CRED_EOF
64-
[{
65-
"name": "Google Sheets SA",
66-
"type": "googleApi",
67-
"data": {
68-
"email": "$(grep client_email "$GOOGLE_SERVICE_ACCOUNT_FILE" | cut -d'"' -f4)",
69-
"privateKey": "$(grep private_key "$GOOGLE_SERVICE_ACCOUNT_FILE" | cut -d'"' -f4)",
70-
"impersonateUser": ""
71-
}
62+
local cred_json
63+
cred_json=$(python3 -c "
64+
import json, sys
65+
sa = json.load(open('$GOOGLE_SERVICE_ACCOUNT_FILE'))
66+
cred = [{
67+
'name': 'Google Sheets SA',
68+
'type': 'googleApi',
69+
'data': {
70+
'email': sa['client_email'],
71+
'privateKey': sa['private_key'],
72+
'impersonateUser': ''
73+
}
7274
}]
73-
CRED_EOF
75+
json.dump(cred, sys.stdout)
76+
")
77+
echo "$cred_json" | $COMPOSE exec -T n8n n8n import:credentials --input=/dev/stdin
7478
}
7579

7680
echo "=== n8n Init ==="

0 commit comments

Comments
 (0)