@rcpooley/concord 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +318 -0
- package/bin/concord.service +69 -0
- package/dist/age.d.ts +20 -0
- package/dist/age.d.ts.map +1 -0
- package/dist/age.js +58 -0
- package/dist/age.js.map +1 -0
- package/dist/cli/main.d.ts +3 -0
- package/dist/cli/main.d.ts.map +1 -0
- package/dist/cli/main.js +301 -0
- package/dist/cli/main.js.map +1 -0
- package/dist/daemon.d.ts +4 -0
- package/dist/daemon.d.ts.map +1 -0
- package/dist/daemon.js +394 -0
- package/dist/daemon.js.map +1 -0
- package/dist/eval-config.d.ts +2 -0
- package/dist/eval-config.d.ts.map +1 -0
- package/dist/eval-config.js +45 -0
- package/dist/eval-config.js.map +1 -0
- package/dist/exec.d.ts +168 -0
- package/dist/exec.d.ts.map +1 -0
- package/dist/exec.js +313 -0
- package/dist/exec.js.map +1 -0
- package/dist/git.d.ts +59 -0
- package/dist/git.d.ts.map +1 -0
- package/dist/git.js +265 -0
- package/dist/git.js.map +1 -0
- package/dist/hook.d.ts +37 -0
- package/dist/hook.d.ts.map +1 -0
- package/dist/hook.js +89 -0
- package/dist/hook.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/init.d.ts +76 -0
- package/dist/init.d.ts.map +1 -0
- package/dist/init.js +236 -0
- package/dist/init.js.map +1 -0
- package/dist/loader.d.ts +35 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +230 -0
- package/dist/loader.js.map +1 -0
- package/dist/module.d.ts +116 -0
- package/dist/module.d.ts.map +1 -0
- package/dist/module.js +100 -0
- package/dist/module.js.map +1 -0
- package/dist/modules/apt/index.d.ts +45 -0
- package/dist/modules/apt/index.d.ts.map +1 -0
- package/dist/modules/apt/index.js +249 -0
- package/dist/modules/apt/index.js.map +1 -0
- package/dist/modules/apt/schema.d.ts +63 -0
- package/dist/modules/apt/schema.d.ts.map +1 -0
- package/dist/modules/apt/schema.js +75 -0
- package/dist/modules/apt/schema.js.map +1 -0
- package/dist/modules/checkout/index.d.ts +88 -0
- package/dist/modules/checkout/index.d.ts.map +1 -0
- package/dist/modules/checkout/index.js +382 -0
- package/dist/modules/checkout/index.js.map +1 -0
- package/dist/modules/checkout/schema.d.ts +52 -0
- package/dist/modules/checkout/schema.d.ts.map +1 -0
- package/dist/modules/checkout/schema.js +132 -0
- package/dist/modules/checkout/schema.js.map +1 -0
- package/dist/modules/cloudflare/api.d.ts +64 -0
- package/dist/modules/cloudflare/api.d.ts.map +1 -0
- package/dist/modules/cloudflare/api.js +98 -0
- package/dist/modules/cloudflare/api.js.map +1 -0
- package/dist/modules/cloudflare/index.d.ts +74 -0
- package/dist/modules/cloudflare/index.d.ts.map +1 -0
- package/dist/modules/cloudflare/index.js +374 -0
- package/dist/modules/cloudflare/index.js.map +1 -0
- package/dist/modules/cloudflare/schema.d.ts +62 -0
- package/dist/modules/cloudflare/schema.d.ts.map +1 -0
- package/dist/modules/cloudflare/schema.js +85 -0
- package/dist/modules/cloudflare/schema.js.map +1 -0
- package/dist/modules/docker/index.d.ts +83 -0
- package/dist/modules/docker/index.d.ts.map +1 -0
- package/dist/modules/docker/index.js +470 -0
- package/dist/modules/docker/index.js.map +1 -0
- package/dist/modules/docker/registry.d.ts +35 -0
- package/dist/modules/docker/registry.d.ts.map +1 -0
- package/dist/modules/docker/registry.js +95 -0
- package/dist/modules/docker/registry.js.map +1 -0
- package/dist/modules/docker/render.d.ts +45 -0
- package/dist/modules/docker/render.d.ts.map +1 -0
- package/dist/modules/docker/render.js +162 -0
- package/dist/modules/docker/render.js.map +1 -0
- package/dist/modules/docker/schema.d.ts +231 -0
- package/dist/modules/docker/schema.d.ts.map +1 -0
- package/dist/modules/docker/schema.js +335 -0
- package/dist/modules/docker/schema.js.map +1 -0
- package/dist/modules/docker/sweeper.d.ts +64 -0
- package/dist/modules/docker/sweeper.d.ts.map +1 -0
- package/dist/modules/docker/sweeper.js +94 -0
- package/dist/modules/docker/sweeper.js.map +1 -0
- package/dist/modules/file/index.d.ts +79 -0
- package/dist/modules/file/index.d.ts.map +1 -0
- package/dist/modules/file/index.js +305 -0
- package/dist/modules/file/index.js.map +1 -0
- package/dist/modules/file/schema.d.ts +45 -0
- package/dist/modules/file/schema.d.ts.map +1 -0
- package/dist/modules/file/schema.js +114 -0
- package/dist/modules/file/schema.js.map +1 -0
- package/dist/modules/index.d.ts +20 -0
- package/dist/modules/index.d.ts.map +1 -0
- package/dist/modules/index.js +11 -0
- package/dist/modules/index.js.map +1 -0
- package/dist/modules/porkbun/api.d.ts +36 -0
- package/dist/modules/porkbun/api.d.ts.map +1 -0
- package/dist/modules/porkbun/api.js +62 -0
- package/dist/modules/porkbun/api.js.map +1 -0
- package/dist/modules/porkbun/index.d.ts +50 -0
- package/dist/modules/porkbun/index.d.ts.map +1 -0
- package/dist/modules/porkbun/index.js +236 -0
- package/dist/modules/porkbun/index.js.map +1 -0
- package/dist/modules/porkbun/schema.d.ts +38 -0
- package/dist/modules/porkbun/schema.d.ts.map +1 -0
- package/dist/modules/porkbun/schema.js +39 -0
- package/dist/modules/porkbun/schema.js.map +1 -0
- package/dist/modules/script/index.d.ts +43 -0
- package/dist/modules/script/index.d.ts.map +1 -0
- package/dist/modules/script/index.js +116 -0
- package/dist/modules/script/index.js.map +1 -0
- package/dist/modules/script/schema.d.ts +25 -0
- package/dist/modules/script/schema.d.ts.map +1 -0
- package/dist/modules/script/schema.js +63 -0
- package/dist/modules/script/schema.js.map +1 -0
- package/dist/modules/systemd/index.d.ts +93 -0
- package/dist/modules/systemd/index.d.ts.map +1 -0
- package/dist/modules/systemd/index.js +394 -0
- package/dist/modules/systemd/index.js.map +1 -0
- package/dist/modules/systemd/render.d.ts +41 -0
- package/dist/modules/systemd/render.d.ts.map +1 -0
- package/dist/modules/systemd/render.js +252 -0
- package/dist/modules/systemd/render.js.map +1 -0
- package/dist/modules/systemd/schema.d.ts +293 -0
- package/dist/modules/systemd/schema.d.ts.map +1 -0
- package/dist/modules/systemd/schema.js +302 -0
- package/dist/modules/systemd/schema.js.map +1 -0
- package/dist/modules/systemd/sweeper.d.ts +31 -0
- package/dist/modules/systemd/sweeper.d.ts.map +1 -0
- package/dist/modules/systemd/sweeper.js +77 -0
- package/dist/modules/systemd/sweeper.js.map +1 -0
- package/dist/plans.d.ts +132 -0
- package/dist/plans.d.ts.map +1 -0
- package/dist/plans.js +315 -0
- package/dist/plans.js.map +1 -0
- package/dist/records.d.ts +37 -0
- package/dist/records.d.ts.map +1 -0
- package/dist/records.js +100 -0
- package/dist/records.js.map +1 -0
- package/dist/registry.d.ts +38 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +31 -0
- package/dist/registry.js.map +1 -0
- package/dist/runner.d.ts +48 -0
- package/dist/runner.d.ts.map +1 -0
- package/dist/runner.js +150 -0
- package/dist/runner.js.map +1 -0
- package/dist/scheduler.d.ts +36 -0
- package/dist/scheduler.d.ts.map +1 -0
- package/dist/scheduler.js +77 -0
- package/dist/scheduler.js.map +1 -0
- package/dist/schema.d.ts +762 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +185 -0
- package/dist/schema.js.map +1 -0
- package/dist/secret.d.ts +24 -0
- package/dist/secret.d.ts.map +1 -0
- package/dist/secret.js +3 -0
- package/dist/secret.js.map +1 -0
- package/dist/ui.d.ts +62 -0
- package/dist/ui.d.ts.map +1 -0
- package/dist/ui.js +288 -0
- package/dist/ui.js.map +1 -0
- package/package.json +57 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/modules/porkbun/api.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,IAAI,GAAG,0CAA0C,CAAA;AAkBvD,KAAK,UAAU,IAAI,CACjB,KAAmB,EACnB,IAAY,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AAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACxD,CAAC,CAAA;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,KAAmB,EACnB,MAAc,EACd,EAAU;IAEV,MAAM,IAAI,CAAC,KAAK,EAAE,cAAc,MAAM,IAAI,EAAE,EAAE,CAAC,CAAA;AACjD,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Module, type BaseOp } from '../../module.js';
|
|
2
|
+
import { type PorkbunConfig } from './schema.js';
|
|
3
|
+
export type { PorkbunConfig, ZoneConfig } from './schema.js';
|
|
4
|
+
export interface DnsRecord {
|
|
5
|
+
/** A, CNAME, TXT, MX, … */
|
|
6
|
+
type: string;
|
|
7
|
+
/** Relative to the zone. '' = apex. Write '@' in config; it normalizes to ''. */
|
|
8
|
+
name: string;
|
|
9
|
+
content: string;
|
|
10
|
+
/** Porkbun's floor is 600. */
|
|
11
|
+
ttl: number;
|
|
12
|
+
/** MX/SRV only. null for everything else. */
|
|
13
|
+
prio?: number | null;
|
|
14
|
+
/** Present in live state only; absent in desired. Ignored by diff. */
|
|
15
|
+
id?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface PorkbunState {
|
|
18
|
+
zones: Record<string, DnsRecord[]>;
|
|
19
|
+
}
|
|
20
|
+
export interface PorkbunOp extends BaseOp {
|
|
21
|
+
zone: string;
|
|
22
|
+
record: DnsRecord;
|
|
23
|
+
/** Present on update/delete. */
|
|
24
|
+
recordId?: string;
|
|
25
|
+
before?: DnsRecord;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Creates and updates first; deletes LAST.
|
|
29
|
+
*
|
|
30
|
+
* The asymmetry is deliberate. If a run dies partway through, this ordering
|
|
31
|
+
* leaves *extra* records rather than *missing* ones — and an extra record is
|
|
32
|
+
* cleaned up by the next reconcile, while a missing one is an outage until
|
|
33
|
+
* someone notices. Same reason a rename (delete old + create new) should never
|
|
34
|
+
* be able to land the delete without the create.
|
|
35
|
+
*/
|
|
36
|
+
export declare function orderOps<T extends {
|
|
37
|
+
kind: string;
|
|
38
|
+
}>(ops: T[]): T[];
|
|
39
|
+
export declare class PorkbunModule extends Module<PorkbunState, PorkbunOp> {
|
|
40
|
+
private readonly config;
|
|
41
|
+
readonly kind = "porkbun";
|
|
42
|
+
/** Config is already schema-validated by the loader; no checks needed here. */
|
|
43
|
+
constructor(config: PorkbunConfig);
|
|
44
|
+
private creds;
|
|
45
|
+
desired(): Promise<PorkbunState>;
|
|
46
|
+
read(): Promise<PorkbunState>;
|
|
47
|
+
diff(actual: PorkbunState, desired: PorkbunState): PorkbunOp[];
|
|
48
|
+
apply(ops: PorkbunOp[]): Promise<void>;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/modules/porkbun/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAErD,OAAO,EAAe,KAAK,aAAa,EAAE,MAAM,aAAa,CAAA;AAE7D,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAI5D,MAAM,WAAW,SAAS;IACxB,2BAA2B;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,iFAAiF;IACjF,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,8BAA8B;IAC9B,GAAG,EAAE,MAAM,CAAA;IACX,6CAA6C;IAC7C,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,sEAAsE;IACtE,EAAE,CAAC,EAAE,MAAM,CAAA;CACZ;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,EAAE,CAAC,CAAA;CACnC;AAID,MAAM,WAAW,SAAU,SAAQ,MAAM;IACvC,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,SAAS,CAAA;IACjB,gCAAgC;IAChC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,SAAS,CAAA;CACnB;AAgED;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAGlE;AASD,qBAAa,aAAc,SAAQ,MAAM,CAAC,YAAY,EAAE,SAAS,CAAC;IAIpD,OAAO,CAAC,QAAQ,CAAC,MAAM;IAHnC,SAAkB,IAAI,aAAY;IAElC,+EAA+E;gBAClD,MAAM,EAAE,aAAa;YAIpC,KAAK;IAOb,OAAO,IAAI,OAAO,CAAC,YAAY,CAAC;IA8BhC,IAAI,IAAI,OAAO,CAAC,YAAY,CAAC;IAgCnC,IAAI,CAAC,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,YAAY,GAAG,SAAS,EAAE;IAmFxD,KAAK,CAAC,GAAG,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAgC7C"}
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { Module } from '../../module.js';
|
|
2
|
+
import * as api from './api.js';
|
|
3
|
+
import { DEFAULT_TTL } from './schema.js';
|
|
4
|
+
// ------------------------------------------------------------ normalize ----
|
|
5
|
+
/** Porkbun returns FQDNs; the write API takes a relative name. */
|
|
6
|
+
function toRelative(fqdn, zone) {
|
|
7
|
+
if (fqdn === zone)
|
|
8
|
+
return '';
|
|
9
|
+
const suffix = `.${zone}`;
|
|
10
|
+
return fqdn.endsWith(suffix) ? fqdn.slice(0, -suffix.length) : fqdn;
|
|
11
|
+
}
|
|
12
|
+
function normalizeName(name) {
|
|
13
|
+
const n = name.trim();
|
|
14
|
+
return n === '@' ? '' : n;
|
|
15
|
+
}
|
|
16
|
+
function normalizePrio(prio, type) {
|
|
17
|
+
// Porkbun reports prio 0 on record types that have no priority. Treat those
|
|
18
|
+
// as null so a config that omits prio doesn't diff forever against "0".
|
|
19
|
+
if (type !== 'MX' && type !== 'SRV')
|
|
20
|
+
return null;
|
|
21
|
+
if (prio === null || prio === undefined || prio === '')
|
|
22
|
+
return null;
|
|
23
|
+
const n = Number(prio);
|
|
24
|
+
return Number.isFinite(n) ? n : null;
|
|
25
|
+
}
|
|
26
|
+
function normalizeRecord(r) {
|
|
27
|
+
return {
|
|
28
|
+
type: r.type.toUpperCase(),
|
|
29
|
+
name: normalizeName(r.name),
|
|
30
|
+
content: r.content.trim(),
|
|
31
|
+
ttl: r.ttl == null ? DEFAULT_TTL : Number(r.ttl),
|
|
32
|
+
prio: normalizePrio(r.prio, r.type.toUpperCase()),
|
|
33
|
+
...(r.id ? { id: r.id } : {}),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Apex NS records are the registrar's own nameserver delegation. They are not
|
|
38
|
+
* editable through the DNS API and must never appear in a plan.
|
|
39
|
+
*/
|
|
40
|
+
function isUnmanaged(r) {
|
|
41
|
+
return r.type === 'NS' && r.name === '';
|
|
42
|
+
}
|
|
43
|
+
function toWrite(r) {
|
|
44
|
+
return {
|
|
45
|
+
name: r.name,
|
|
46
|
+
type: r.type,
|
|
47
|
+
content: r.content,
|
|
48
|
+
ttl: r.ttl,
|
|
49
|
+
...(r.prio != null ? { prio: r.prio } : {}),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Creates and updates first; deletes LAST.
|
|
54
|
+
*
|
|
55
|
+
* The asymmetry is deliberate. If a run dies partway through, this ordering
|
|
56
|
+
* leaves *extra* records rather than *missing* ones — and an extra record is
|
|
57
|
+
* cleaned up by the next reconcile, while a missing one is an outage until
|
|
58
|
+
* someone notices. Same reason a rename (delete old + create new) should never
|
|
59
|
+
* be able to land the delete without the create.
|
|
60
|
+
*/
|
|
61
|
+
export function orderOps(ops) {
|
|
62
|
+
const rank = (k) => (k === 'delete' ? 1 : 0);
|
|
63
|
+
return [...ops].sort((a, b) => rank(a.kind) - rank(b.kind));
|
|
64
|
+
}
|
|
65
|
+
const setKey = (r) => `${r.type}|${r.name}`;
|
|
66
|
+
const recKey = (r) => `${r.type}|${r.name}|${r.content}`;
|
|
67
|
+
const describe = (zone, r) => `${r.type} ${r.name === '' ? '@' : r.name}.${zone} -> ${r.content} (ttl ${r.ttl})`;
|
|
68
|
+
// --------------------------------------------------------------- module ----
|
|
69
|
+
export class PorkbunModule extends Module {
|
|
70
|
+
config;
|
|
71
|
+
kind = 'porkbun';
|
|
72
|
+
/** Config is already schema-validated by the loader; no checks needed here. */
|
|
73
|
+
constructor(config) {
|
|
74
|
+
super(config.id);
|
|
75
|
+
this.config = config;
|
|
76
|
+
}
|
|
77
|
+
async creds() {
|
|
78
|
+
return {
|
|
79
|
+
apikey: await this.secret(this.config.apiKey),
|
|
80
|
+
secretapikey: await this.secret(this.config.secretKey),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
async desired() {
|
|
84
|
+
const zones = {};
|
|
85
|
+
for (const [zone, cfg] of Object.entries(this.config.zones)) {
|
|
86
|
+
const records = cfg.records.map(normalizeRecord);
|
|
87
|
+
for (const r of records) {
|
|
88
|
+
if (isUnmanaged(r)) {
|
|
89
|
+
throw new Error(`${this.kind}:${this.id}: zone ${zone} declares an apex NS record ` +
|
|
90
|
+
`(${r.content}). Apex NS is registrar-level delegation and is not ` +
|
|
91
|
+
`manageable through the DNS API — remove it from the config.`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const seen = new Map();
|
|
95
|
+
for (const r of records) {
|
|
96
|
+
const k = recKey(r);
|
|
97
|
+
if (seen.has(k)) {
|
|
98
|
+
throw new Error(`${this.kind}:${this.id}: zone ${zone} declares ${describe(zone, r)} twice.`);
|
|
99
|
+
}
|
|
100
|
+
seen.set(k, r);
|
|
101
|
+
}
|
|
102
|
+
zones[zone] = records;
|
|
103
|
+
}
|
|
104
|
+
return { zones };
|
|
105
|
+
}
|
|
106
|
+
async read() {
|
|
107
|
+
const creds = await this.creds();
|
|
108
|
+
const zones = {};
|
|
109
|
+
let skipped = 0;
|
|
110
|
+
for (const zone of Object.keys(this.config.zones)) {
|
|
111
|
+
const raw = await api.retrieveRecords(creds, zone);
|
|
112
|
+
const records = [];
|
|
113
|
+
for (const r of raw) {
|
|
114
|
+
const rec = normalizeRecord({
|
|
115
|
+
type: r.type,
|
|
116
|
+
name: toRelative(r.name, zone),
|
|
117
|
+
content: r.content,
|
|
118
|
+
ttl: Number(r.ttl),
|
|
119
|
+
prio: r.prio,
|
|
120
|
+
id: String(r.id),
|
|
121
|
+
});
|
|
122
|
+
if (isUnmanaged(rec)) {
|
|
123
|
+
skipped++;
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
records.push(rec);
|
|
127
|
+
}
|
|
128
|
+
zones[zone] = records;
|
|
129
|
+
}
|
|
130
|
+
if (skipped > 0) {
|
|
131
|
+
this.log(`skipped ${skipped} apex NS record(s) — registrar-level, not manageable`);
|
|
132
|
+
}
|
|
133
|
+
return { zones };
|
|
134
|
+
}
|
|
135
|
+
diff(actual, desired) {
|
|
136
|
+
const ops = [];
|
|
137
|
+
for (const [zone, desiredRecords] of Object.entries(desired.zones)) {
|
|
138
|
+
const actualRecords = actual.zones[zone] ?? [];
|
|
139
|
+
const actualByRec = new Map(actualRecords.map((r) => [recKey(r), r]));
|
|
140
|
+
const desiredByRec = new Map(desiredRecords.map((r) => [recKey(r), r]));
|
|
141
|
+
// Record sets that exist on both sides let us tell "changed the IP" from
|
|
142
|
+
// "added a second IP" — a content change within a (type,name) set is an
|
|
143
|
+
// update against the existing record id, not a delete + create.
|
|
144
|
+
const actualBySet = new Map();
|
|
145
|
+
for (const r of actualRecords) {
|
|
146
|
+
const list = actualBySet.get(setKey(r)) ?? [];
|
|
147
|
+
list.push(r);
|
|
148
|
+
actualBySet.set(setKey(r), list);
|
|
149
|
+
}
|
|
150
|
+
const claimed = new Set();
|
|
151
|
+
for (const want of desiredRecords) {
|
|
152
|
+
const exact = actualByRec.get(recKey(want));
|
|
153
|
+
if (exact) {
|
|
154
|
+
claimed.add(recKey(exact));
|
|
155
|
+
if (exact.ttl !== want.ttl || (exact.prio ?? null) !== (want.prio ?? null)) {
|
|
156
|
+
ops.push({
|
|
157
|
+
kind: 'update',
|
|
158
|
+
id: `${zone}/${recKey(want)}`,
|
|
159
|
+
summary: `update ${describe(zone, want)} (was ttl ${exact.ttl})`,
|
|
160
|
+
zone,
|
|
161
|
+
record: want,
|
|
162
|
+
recordId: exact.id,
|
|
163
|
+
before: exact,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
// Same (type,name), different content, and that live record is not
|
|
169
|
+
// itself declared elsewhere -> treat as an edit in place.
|
|
170
|
+
const candidates = (actualBySet.get(setKey(want)) ?? []).filter((r) => !claimed.has(recKey(r)) && !desiredByRec.has(recKey(r)));
|
|
171
|
+
const reuse = candidates[0];
|
|
172
|
+
if (reuse) {
|
|
173
|
+
claimed.add(recKey(reuse));
|
|
174
|
+
ops.push({
|
|
175
|
+
kind: 'update',
|
|
176
|
+
id: `${zone}/${recKey(want)}`,
|
|
177
|
+
summary: `update ${describe(zone, want)} (was -> ${reuse.content})`,
|
|
178
|
+
zone,
|
|
179
|
+
record: want,
|
|
180
|
+
recordId: reuse.id,
|
|
181
|
+
before: reuse,
|
|
182
|
+
});
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
ops.push({
|
|
186
|
+
kind: 'create',
|
|
187
|
+
id: `${zone}/${recKey(want)}`,
|
|
188
|
+
summary: `create ${describe(zone, want)}`,
|
|
189
|
+
zone,
|
|
190
|
+
record: want,
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
for (const have of actualRecords) {
|
|
194
|
+
if (claimed.has(recKey(have)) || desiredByRec.has(recKey(have)))
|
|
195
|
+
continue;
|
|
196
|
+
ops.push({
|
|
197
|
+
kind: 'delete',
|
|
198
|
+
id: `${zone}/${recKey(have)}`,
|
|
199
|
+
summary: `delete ${describe(zone, have)}`,
|
|
200
|
+
zone,
|
|
201
|
+
record: have,
|
|
202
|
+
recordId: have.id,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return ops;
|
|
207
|
+
}
|
|
208
|
+
async apply(ops) {
|
|
209
|
+
const creds = await this.creds();
|
|
210
|
+
for (const op of orderOps(ops)) {
|
|
211
|
+
switch (op.kind) {
|
|
212
|
+
case 'create':
|
|
213
|
+
await api.createRecord(creds, op.zone, toWrite(op.record));
|
|
214
|
+
break;
|
|
215
|
+
case 'update':
|
|
216
|
+
if (!op.recordId) {
|
|
217
|
+
throw new Error(`update op has no recordId: ${op.summary}`);
|
|
218
|
+
}
|
|
219
|
+
await api.editRecord(creds, op.zone, op.recordId, toWrite(op.record));
|
|
220
|
+
break;
|
|
221
|
+
case 'delete':
|
|
222
|
+
if (!op.recordId) {
|
|
223
|
+
throw new Error(`delete op has no recordId: ${op.summary}`);
|
|
224
|
+
}
|
|
225
|
+
await api.deleteRecord(creds, op.zone, op.recordId);
|
|
226
|
+
break;
|
|
227
|
+
default:
|
|
228
|
+
throw new Error(`unsupported op kind "${op.kind}": ${op.summary}`);
|
|
229
|
+
}
|
|
230
|
+
// Logged per-op as it lands, so a mid-run failure leaves an accurate
|
|
231
|
+
// record of exactly how far we got.
|
|
232
|
+
this.log(` ✓ ${op.kind}: ${op.summary}`);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/modules/porkbun/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,M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CAAC,CAAC,CAAA;oBACrE,MAAK;gBAEP,KAAK,QAAQ;oBACX,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC;wBACjB,MAAM,IAAI,KAAK,CAAC,8BAA8B,EAAE,CAAC,OAAO,EAAE,CAAC,CAAA;oBAC7D,CAAC;oBACD,MAAM,GAAG,CAAC,YAAY,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAA;oBACnD,MAAK;gBAEP;oBACE,MAAM,IAAI,KAAK,CAAC,wBAAwB,EAAE,CAAC,IAAI,MAAM,EAAE,CAAC,OAAO,EAAE,CAAC,CAAA;YACtE,CAAC;YAED,qEAAqE;YACrE,oCAAoC;YACpC,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC,OAAO,EAAE,CAAC,CAAA;QAC3C,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** Porkbun's floor. Applied when a record omits `ttl`. */
|
|
3
|
+
export declare const DEFAULT_TTL = 600;
|
|
4
|
+
export declare const DnsRecordSchema: z.ZodObject<{
|
|
5
|
+
type: z.ZodString;
|
|
6
|
+
name: z.ZodString;
|
|
7
|
+
content: z.ZodString;
|
|
8
|
+
ttl: z.ZodOptional<z.ZodNumber>;
|
|
9
|
+
prio: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
10
|
+
}, z.core.$strict>;
|
|
11
|
+
export declare const ZoneConfigSchema: z.ZodObject<{
|
|
12
|
+
records: z.ZodArray<z.ZodObject<{
|
|
13
|
+
type: z.ZodString;
|
|
14
|
+
name: z.ZodString;
|
|
15
|
+
content: z.ZodString;
|
|
16
|
+
ttl: z.ZodOptional<z.ZodNumber>;
|
|
17
|
+
prio: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
18
|
+
}, z.core.$strict>>;
|
|
19
|
+
}, z.core.$strict>;
|
|
20
|
+
export declare const PorkbunConfigSchema: z.ZodObject<{
|
|
21
|
+
type: z.ZodLiteral<"porkbun">;
|
|
22
|
+
id: z.ZodString;
|
|
23
|
+
apiKey: z.ZodCustom<import("../../secret.js").Secret, import("../../secret.js").Secret>;
|
|
24
|
+
secretKey: z.ZodCustom<import("../../secret.js").Secret, import("../../secret.js").Secret>;
|
|
25
|
+
zones: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
26
|
+
records: z.ZodArray<z.ZodObject<{
|
|
27
|
+
type: z.ZodString;
|
|
28
|
+
name: z.ZodString;
|
|
29
|
+
content: z.ZodString;
|
|
30
|
+
ttl: z.ZodOptional<z.ZodNumber>;
|
|
31
|
+
prio: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
32
|
+
}, z.core.$strict>>;
|
|
33
|
+
}, z.core.$strict>>;
|
|
34
|
+
}, z.core.$strict>;
|
|
35
|
+
export type DnsRecordInput = z.output<typeof DnsRecordSchema>;
|
|
36
|
+
export type ZoneConfig = z.output<typeof ZoneConfigSchema>;
|
|
37
|
+
export type PorkbunConfig = z.output<typeof PorkbunConfigSchema>;
|
|
38
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/modules/porkbun/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAGvB,0DAA0D;AAC1D,eAAO,MAAM,WAAW,MAAM,CAAA;AAE9B,eAAO,MAAM,eAAe;;;;;;kBAWjB,CAAA;AAEX,eAAO,MAAM,gBAAgB;;;;;;;;kBASlB,CAAA;AAEX,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;kBAWrB,CAAA;AAEX,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,eAAe,CAAC,CAAA;AAC7D,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,gBAAgB,CAAC,CAAA;AAC1D,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,mBAAmB,CAAC,CAAA"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { SecretSchema } from '../../secret.js';
|
|
3
|
+
/** Porkbun's floor. Applied when a record omits `ttl`. */
|
|
4
|
+
export const DEFAULT_TTL = 600;
|
|
5
|
+
export const DnsRecordSchema = z
|
|
6
|
+
.object({
|
|
7
|
+
/** A, CNAME, TXT, MX, … */
|
|
8
|
+
type: z.string().min(1),
|
|
9
|
+
/** Relative to the zone. '@' or '' = apex. */
|
|
10
|
+
name: z.string(),
|
|
11
|
+
content: z.string().min(1),
|
|
12
|
+
ttl: z.number().int().min(60).optional(),
|
|
13
|
+
/** MX/SRV only. */
|
|
14
|
+
prio: z.number().int().min(0).nullable().optional(),
|
|
15
|
+
})
|
|
16
|
+
.strict();
|
|
17
|
+
export const ZoneConfigSchema = z
|
|
18
|
+
.object({
|
|
19
|
+
/**
|
|
20
|
+
* The complete set of records for this zone. A live record not declared
|
|
21
|
+
* here is DELETED — a declared zone is the whole truth. A zone absent from
|
|
22
|
+
* `zones` is never touched at all.
|
|
23
|
+
*/
|
|
24
|
+
records: z.array(DnsRecordSchema),
|
|
25
|
+
})
|
|
26
|
+
.strict();
|
|
27
|
+
export const PorkbunConfigSchema = z
|
|
28
|
+
.object({
|
|
29
|
+
type: z.literal('porkbun'),
|
|
30
|
+
/** Stable instance id — distinguishes two Porkbun accounts in plans/logs. */
|
|
31
|
+
id: z
|
|
32
|
+
.string()
|
|
33
|
+
.regex(/^[a-z0-9][a-z0-9-]*$/, 'must be kebab-case, starting alphanumeric'),
|
|
34
|
+
apiKey: SecretSchema,
|
|
35
|
+
secretKey: SecretSchema,
|
|
36
|
+
zones: z.record(z.string().min(1), ZoneConfigSchema),
|
|
37
|
+
})
|
|
38
|
+
.strict();
|
|
39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AAE,2CAA2C,CAAC;IAC7E,MAAM,EAAE,YAAY;IACpB,SAAS,EAAE,YAAY;IACvB,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,gBAAgB,CAAC;CACrD,CAAC;KACD,MAAM,EAAE,CAAA"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Module, type BaseOp } from '../../module.js';
|
|
2
|
+
import type { ScriptConfig } from './schema.js';
|
|
3
|
+
export type { ScriptConfig } from './schema.js';
|
|
4
|
+
export interface ScriptState {
|
|
5
|
+
name: string;
|
|
6
|
+
/** Guard exit 0. */
|
|
7
|
+
satisfied: boolean;
|
|
8
|
+
/** Guard's exit code — surfaced in the plan so a broken guard is visible. */
|
|
9
|
+
exitCode: number;
|
|
10
|
+
}
|
|
11
|
+
export interface ScriptModuleState {
|
|
12
|
+
scripts: ScriptState[];
|
|
13
|
+
}
|
|
14
|
+
export interface ScriptOp extends BaseOp {
|
|
15
|
+
entity: 'script';
|
|
16
|
+
name: string;
|
|
17
|
+
}
|
|
18
|
+
export declare class ScriptModule extends Module<ScriptModuleState, ScriptOp> {
|
|
19
|
+
private readonly config;
|
|
20
|
+
readonly kind = "script";
|
|
21
|
+
constructor(config: ScriptConfig);
|
|
22
|
+
private get scripts();
|
|
23
|
+
/**
|
|
24
|
+
* Give a script body its secrets.
|
|
25
|
+
*
|
|
26
|
+
* `secrets` become single-quoted shell assignments AHEAD of the body. They
|
|
27
|
+
* used to be spliced into the text itself, which made bash parse every
|
|
28
|
+
* decrypted value as source: a `'` in a secret broke the quoting its author
|
|
29
|
+
* wrapped it in, and a `$(…)` inside one would have run. A variable's value
|
|
30
|
+
* is never re-parsed, so the body refers to `"$NAME"` like any other variable.
|
|
31
|
+
*
|
|
32
|
+
* The result is NEVER logged. Anything non-secret should be a TypeScript
|
|
33
|
+
* template literal in the config instead — this exists only because
|
|
34
|
+
* `secrets['x']` is ciphertext at author time.
|
|
35
|
+
*/
|
|
36
|
+
private resolve;
|
|
37
|
+
desired(): Promise<ScriptModuleState>;
|
|
38
|
+
read(): Promise<ScriptModuleState>;
|
|
39
|
+
private checkGuard;
|
|
40
|
+
diff(actual: ScriptModuleState, desired: ScriptModuleState): ScriptOp[];
|
|
41
|
+
apply(ops: ScriptOp[]): Promise<void>;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/modules/script/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,KAAK,EAAE,YAAY,EAAe,MAAM,aAAa,CAAA;AAE5D,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAQ/C,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,oBAAoB;IACpB,SAAS,EAAE,OAAO,CAAA;IAClB,6EAA6E;IAC7E,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,WAAW,EAAE,CAAA;CACvB;AAED,MAAM,WAAW,QAAS,SAAQ,MAAM;IACtC,MAAM,EAAE,QAAQ,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;CACb;AAID,qBAAa,YAAa,SAAQ,MAAM,CAAC,iBAAiB,EAAE,QAAQ,CAAC;IAGvD,OAAO,CAAC,QAAQ,CAAC,MAAM;IAFnC,SAAkB,IAAI,YAAW;gBAEJ,MAAM,EAAE,YAAY;IAIjD,OAAO,KAAK,OAAO,GAElB;IAED;;;;;;;;;;;;OAYG;YACW,OAAO;IASf,OAAO,IAAI,OAAO,CAAC,iBAAiB,CAAC;IAYrC,IAAI,IAAI,OAAO,CAAC,iBAAiB,CAAC;YAQ1B,UAAU;IAcxB,IAAI,CAAC,MAAM,EAAE,iBAAiB,EAAE,OAAO,EAAE,iBAAiB,GAAG,QAAQ,EAAE;IAqBjE,KAAK,CAAC,GAAG,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CA4B5C"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { Module } from '../../module.js';
|
|
2
|
+
/** Guards run on every reconcile, including plans, so they must stay cheap. */
|
|
3
|
+
const GUARD_TIMEOUT_MS = 30_000;
|
|
4
|
+
const DEFAULT_RUN_TIMEOUT_S = 600;
|
|
5
|
+
// --------------------------------------------------------------- module ----
|
|
6
|
+
export class ScriptModule extends Module {
|
|
7
|
+
config;
|
|
8
|
+
kind = 'script';
|
|
9
|
+
constructor(config) {
|
|
10
|
+
super(config.id, config.host);
|
|
11
|
+
this.config = config;
|
|
12
|
+
}
|
|
13
|
+
get scripts() {
|
|
14
|
+
return this.config.scripts ?? [];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Give a script body its secrets.
|
|
18
|
+
*
|
|
19
|
+
* `secrets` become single-quoted shell assignments AHEAD of the body. They
|
|
20
|
+
* used to be spliced into the text itself, which made bash parse every
|
|
21
|
+
* decrypted value as source: a `'` in a secret broke the quoting its author
|
|
22
|
+
* wrapped it in, and a `$(…)` inside one would have run. A variable's value
|
|
23
|
+
* is never re-parsed, so the body refers to `"$NAME"` like any other variable.
|
|
24
|
+
*
|
|
25
|
+
* The result is NEVER logged. Anything non-secret should be a TypeScript
|
|
26
|
+
* template literal in the config instead — this exists only because
|
|
27
|
+
* `secrets['x']` is ciphertext at author time.
|
|
28
|
+
*/
|
|
29
|
+
async resolve(text, s) {
|
|
30
|
+
if (!s.secrets)
|
|
31
|
+
return text;
|
|
32
|
+
const lines = [];
|
|
33
|
+
for (const [name, ref] of Object.entries(s.secrets)) {
|
|
34
|
+
lines.push(`${name}=${singleQuoted(await this.secret(ref))}`);
|
|
35
|
+
}
|
|
36
|
+
return `${lines.join('\n')}\n${text}`;
|
|
37
|
+
}
|
|
38
|
+
async desired() {
|
|
39
|
+
const seen = new Set();
|
|
40
|
+
for (const s of this.scripts) {
|
|
41
|
+
if (seen.has(s.name)) {
|
|
42
|
+
throw new Error(`${this.kind}:${this.id}: script "${s.name}" declared twice`);
|
|
43
|
+
}
|
|
44
|
+
seen.add(s.name);
|
|
45
|
+
}
|
|
46
|
+
// Desired is simply "every guard passes".
|
|
47
|
+
return { scripts: this.scripts.map((s) => ({ name: s.name, satisfied: true, exitCode: 0 })) };
|
|
48
|
+
}
|
|
49
|
+
async read() {
|
|
50
|
+
const scripts = [];
|
|
51
|
+
for (const s of this.scripts) {
|
|
52
|
+
scripts.push({ name: s.name, ...(await this.checkGuard(s)) });
|
|
53
|
+
}
|
|
54
|
+
return { scripts };
|
|
55
|
+
}
|
|
56
|
+
async checkGuard(s) {
|
|
57
|
+
const r = this.exec.runScript(await this.resolve(s.unless, s), {
|
|
58
|
+
sudo: s.sudo,
|
|
59
|
+
timeoutMs: GUARD_TIMEOUT_MS,
|
|
60
|
+
});
|
|
61
|
+
if (r.status === 124) {
|
|
62
|
+
throw new Error(`${this.kind}:${this.id}: guard for "${s.name}" timed out after ${GUARD_TIMEOUT_MS / 1000}s. ` +
|
|
63
|
+
`Guards run on every reconcile — keep them cheap.`);
|
|
64
|
+
}
|
|
65
|
+
return { satisfied: r.status === 0, exitCode: r.status };
|
|
66
|
+
}
|
|
67
|
+
diff(actual, desired) {
|
|
68
|
+
const byName = new Map(actual.scripts.map((s) => [s.name, s]));
|
|
69
|
+
const ops = [];
|
|
70
|
+
for (const want of desired.scripts) {
|
|
71
|
+
const have = byName.get(want.name);
|
|
72
|
+
if (have && !have.satisfied) {
|
|
73
|
+
ops.push({
|
|
74
|
+
kind: 'custom',
|
|
75
|
+
entity: 'script',
|
|
76
|
+
id: `script/${want.name}`,
|
|
77
|
+
// The exit code is in the summary on purpose: a guard that is simply
|
|
78
|
+
// broken looks identical to real work otherwise.
|
|
79
|
+
summary: `run ${want.name} (guard exited ${have.exitCode})`,
|
|
80
|
+
name: want.name,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return ops;
|
|
85
|
+
}
|
|
86
|
+
async apply(ops) {
|
|
87
|
+
for (const op of ops) {
|
|
88
|
+
const s = this.scripts.find((x) => x.name === op.name);
|
|
89
|
+
const timeoutMs = (s.timeout ?? DEFAULT_RUN_TIMEOUT_S) * 1000;
|
|
90
|
+
const r = this.exec.runScript(await this.resolve(s.run, s), { sudo: s.sudo, timeoutMs });
|
|
91
|
+
if (r.status !== 0) {
|
|
92
|
+
throw new Error(`${this.kind}:${this.id}: script "${s.name}" failed (exit ${r.status}):\n` +
|
|
93
|
+
tail(r.output));
|
|
94
|
+
}
|
|
95
|
+
// Re-check the guard. A script that exits 0 without achieving its goal
|
|
96
|
+
// would otherwise be planned and "applied" on every run forever — the
|
|
97
|
+
// non-convergence trap. Verifying here turns that into one loud failure.
|
|
98
|
+
const after = await this.checkGuard(s);
|
|
99
|
+
if (!after.satisfied) {
|
|
100
|
+
throw new Error(`${this.kind}:${this.id}: script "${s.name}" reported success but its guard still ` +
|
|
101
|
+
`fails (exit ${after.exitCode}). Either the script did not do what the guard ` +
|
|
102
|
+
`checks, or the guard is wrong.\n${tail(r.output)}`);
|
|
103
|
+
}
|
|
104
|
+
this.log(` ✓ ran ${s.name}`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* A bash single-quoted word: nothing inside is special except the quote itself,
|
|
110
|
+
* which closes, emits an escaped quote, and reopens. The callback matters — a
|
|
111
|
+
* replacement STRING would have its own `$` patterns interpreted.
|
|
112
|
+
*/
|
|
113
|
+
const singleQuoted = (v) => `'${v.replace(/'/g, () => `'\\''`)}'`;
|
|
114
|
+
/** Output may contain anything the script printed — keep it short. */
|
|
115
|
+
const tail = (s, n = 20) => s.trim().split('\n').slice(-n).join('\n');
|
|
116
|
+
//# sourceMappingURL=index.js.map
|
|
@@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AS,EAAE,CAAC,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const ScriptSchema: z.ZodObject<{
|
|
3
|
+
name: z.ZodString;
|
|
4
|
+
unless: z.ZodString;
|
|
5
|
+
run: z.ZodString;
|
|
6
|
+
sudo: z.ZodOptional<z.ZodBoolean>;
|
|
7
|
+
secrets: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodCustom<import("../../secret.js").Secret, import("../../secret.js").Secret>>>;
|
|
8
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
9
|
+
}, z.core.$strict>;
|
|
10
|
+
export declare const ScriptConfigSchema: z.ZodObject<{
|
|
11
|
+
type: z.ZodLiteral<"script">;
|
|
12
|
+
id: z.ZodString;
|
|
13
|
+
host: z.ZodString;
|
|
14
|
+
scripts: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
15
|
+
name: z.ZodString;
|
|
16
|
+
unless: z.ZodString;
|
|
17
|
+
run: z.ZodString;
|
|
18
|
+
sudo: z.ZodOptional<z.ZodBoolean>;
|
|
19
|
+
secrets: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodCustom<import("../../secret.js").Secret, import("../../secret.js").Secret>>>;
|
|
20
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
21
|
+
}, z.core.$strict>>>;
|
|
22
|
+
}, z.core.$strict>;
|
|
23
|
+
export type ScriptEntry = z.output<typeof ScriptSchema>;
|
|
24
|
+
export type ScriptConfig = z.output<typeof ScriptConfigSchema>;
|
|
25
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/modules/script/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAGvB,eAAO,MAAM,YAAY;;;;;;;kBA2Cd,CAAA;AAEX,eAAO,MAAM,kBAAkB;;;;;;;;;;;;kBAsBpB,CAAA;AAEX,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,YAAY,CAAC,CAAA;AACvD,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,kBAAkB,CAAC,CAAA"}
|