diff --git a/scripts/src/platform-infra-langbot.ts b/scripts/src/platform-infra-langbot.ts index e0d61186..86c55b5e 100644 --- a/scripts/src/platform-infra-langbot.ts +++ b/scripts/src/platform-infra-langbot.ts @@ -566,7 +566,7 @@ function bootstrapApiKey(options: ApplyOptions): Record { const conn = postgresConninfo(langbot, secret); const sql = [ "INSERT INTO api_keys (name, key, description)", - "VALUES (:'name', :'api_key', :'description')", + `VALUES (${sqlLiteral(langbot.apiKey.name)}, ${sqlLiteral(secret.values.apiKey)}, ${sqlLiteral(langbot.apiKey.description)})`, "ON CONFLICT (key) DO UPDATE SET name = EXCLUDED.name, description = EXCLUDED.description, updated_at = now()", "RETURNING id, name, created_at, updated_at;", ].join("\n"); @@ -574,12 +574,6 @@ function bootstrapApiKey(options: ApplyOptions): Record { "psql", "-Atq", conn, - "-v", - `name=${langbot.apiKey.name}`, - "-v", - `api_key=${secret.values.apiKey}`, - "-v", - `description=${langbot.apiKey.description}`, "-c", sql, ], { @@ -1681,6 +1675,10 @@ function quoteEnv(value: string): string { return `'${value.replaceAll("'", "'\"'\"'")}'`; } +function sqlLiteral(value: string): string { + return `'${value.replaceAll("'", "''")}'`; +} + function requiredEnvValue(values: Record, key: string, sourceRef: string): string { const value = values[key]; if (value === undefined || value.length === 0) throw new Error(`${sourceRef} is missing required key ${key}`);