chore: move langbot n8n target defaults to yaml
This commit is contained in:
@@ -53,6 +53,7 @@ interface N8nConfig {
|
||||
version: number;
|
||||
kind: "platform-infra-n8n";
|
||||
metadata: { id: string; owner: string; relatedIssues: number[] };
|
||||
defaults: { targetId: string };
|
||||
image: { repository: string; tag: string; pullPolicy: "Always" | "IfNotPresent" | "Never" };
|
||||
dependencyImages: { postgresClient: string };
|
||||
targets: N8nTarget[];
|
||||
@@ -96,7 +97,7 @@ interface N8nTarget extends PublicServiceTarget {
|
||||
}
|
||||
|
||||
interface CommonOptions {
|
||||
targetId: string;
|
||||
targetId: string | null;
|
||||
full: boolean;
|
||||
raw: boolean;
|
||||
}
|
||||
@@ -158,7 +159,7 @@ export async function runN8nCommand(config: UniDeskConfig, args: string[]): Prom
|
||||
}
|
||||
|
||||
function parseCommonOptions(args: string[]): CommonOptions {
|
||||
let targetId = "G14";
|
||||
let targetId: string | null = null;
|
||||
let full = false;
|
||||
let raw = false;
|
||||
for (let index = 0; index < args.length; index += 1) {
|
||||
@@ -177,7 +178,7 @@ function parseCommonOptions(args: string[]): CommonOptions {
|
||||
throw new Error(`unsupported n8n option: ${arg}`);
|
||||
}
|
||||
}
|
||||
if (!/^[A-Za-z0-9._-]+$/u.test(targetId)) throw new Error("--target must be a simple target id");
|
||||
if (targetId !== null && !/^[A-Za-z0-9._-]+$/u.test(targetId)) throw new Error("--target must be a simple target id");
|
||||
return { targetId, full, raw };
|
||||
}
|
||||
|
||||
@@ -876,6 +877,7 @@ function readN8nConfig(): N8nConfig {
|
||||
const kind = stringField(root, "kind", "");
|
||||
if (kind !== "platform-infra-n8n") throw new Error(`${configLabel}.kind must be platform-infra-n8n`);
|
||||
const metadata = objectField(root, "metadata", "");
|
||||
const defaults = objectField(root, "defaults", "");
|
||||
const image = objectField(root, "image", "");
|
||||
const dependencyImages = objectField(root, "dependencyImages", "");
|
||||
const runtime = objectField(root, "runtime", "");
|
||||
@@ -893,6 +895,9 @@ function readN8nConfig(): N8nConfig {
|
||||
owner: stringField(metadata, "owner", "metadata"),
|
||||
relatedIssues: numberArrayField(metadata, "relatedIssues", "metadata"),
|
||||
},
|
||||
defaults: {
|
||||
targetId: stringField(defaults, "targetId", "defaults"),
|
||||
},
|
||||
image: {
|
||||
repository: stringField(image, "repository", "image"),
|
||||
tag: stringField(image, "tag", "image"),
|
||||
@@ -944,6 +949,7 @@ function readN8nConfig(): N8nConfig {
|
||||
if (!isImageReference(`${config.image.repository}:${config.image.tag}`)) throw new Error(`${configLabel}.image must render a valid image reference`);
|
||||
if (!isImageReference(config.dependencyImages.postgresClient)) throw new Error(`${configLabel}.dependencyImages.postgresClient must be an image reference`);
|
||||
if (config.targets.length === 0) throw new Error(`${configLabel}.targets must not be empty`);
|
||||
assertKnownEnabledTarget(config.targets, config.defaults.targetId, "defaults.targetId");
|
||||
return config;
|
||||
}
|
||||
|
||||
@@ -994,9 +1000,16 @@ function parseTarget(record: Record<string, unknown>, index: number): N8nTarget
|
||||
};
|
||||
}
|
||||
|
||||
function resolveTarget(n8n: N8nConfig, targetId: string): N8nTarget {
|
||||
const target = n8n.targets.find((item) => item.id.toLowerCase() === targetId.toLowerCase());
|
||||
if (target === undefined) throw new Error(`unknown n8n target ${targetId}; known targets: ${n8n.targets.map((item) => item.id).join(", ")}`);
|
||||
function assertKnownEnabledTarget(targets: N8nTarget[], targetId: string, path: string): void {
|
||||
const target = targets.find((item) => item.id.toLowerCase() === targetId.toLowerCase());
|
||||
if (target === undefined) throw new Error(`${configLabel}.${path} references unknown target ${targetId}; known targets: ${targets.map((item) => item.id).join(", ")}`);
|
||||
if (!target.enabled) throw new Error(`${configLabel}.${path} references disabled target ${target.id}`);
|
||||
}
|
||||
|
||||
function resolveTarget(n8n: N8nConfig, targetId: string | null): N8nTarget {
|
||||
const resolvedTargetId = targetId ?? n8n.defaults.targetId;
|
||||
const target = n8n.targets.find((item) => item.id.toLowerCase() === resolvedTargetId.toLowerCase());
|
||||
if (target === undefined) throw new Error(`unknown n8n target ${resolvedTargetId}; known targets: ${n8n.targets.map((item) => item.id).join(", ")}`);
|
||||
if (!target.enabled) throw new Error(`n8n target ${target.id} is disabled in ${configLabel}`);
|
||||
return target;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user