fix: repair langbot api key bootstrap
This commit is contained in:
@@ -566,7 +566,7 @@ function bootstrapApiKey(options: ApplyOptions): Record<string, unknown> {
|
||||
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<string, unknown> {
|
||||
"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<string, string>, key: string, sourceRef: string): string {
|
||||
const value = values[key];
|
||||
if (value === undefined || value.length === 0) throw new Error(`${sourceRef} is missing required key ${key}`);
|
||||
|
||||
Reference in New Issue
Block a user