poad 2.78.0 → 2.78.2
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/global/start.js +13 -2
- package/package.json +1 -1
- package/test/project-sync.test.js +25 -0
- package/utils/help-details.js +4 -3
- package/utils/project-sync/plan.js +27 -1
- package/utils/project-sync/run.js +12 -2
package/global/start.js
CHANGED
|
@@ -59,7 +59,16 @@ module.exports = async (args = {}) => {
|
|
|
59
59
|
};
|
|
60
60
|
|
|
61
61
|
// Services optionnels à lancer, puis l'état complet du projet
|
|
62
|
-
|
|
62
|
+
// Engine qui vient d'être lancé : l'état (« structure changed outside the journal »…) n'est lu qu'une fois ses
|
|
63
|
+
// migrations jouées (migrate-upgrade.sh, avant auth et storage) ; sinon une montée était lue à moitié faite
|
|
64
|
+
let engineReady = false;
|
|
65
|
+
const finish = async (justStarted = false) => {
|
|
66
|
+
if (justStarted && !engineReady) {
|
|
67
|
+
const migrations = require('../utils/migrations');
|
|
68
|
+
const waiting = ora('Waiting for the engine').start();
|
|
69
|
+
engineReady = (await migrations.waitForDb(config)) && (await migrations.waitForServices(config));
|
|
70
|
+
waiting.stop();
|
|
71
|
+
}
|
|
63
72
|
const targets = bare ? [] : all ? SERVICES.filter((s) => s.optional && s.configured(config)) : autostartServices(config, root);
|
|
64
73
|
// Groupe « Services » de la console (Mailpit, Keycloak) : ports de cette machine, après leur réattribution
|
|
65
74
|
require('../utils/console-services').write(root);
|
|
@@ -248,6 +257,7 @@ module.exports = async (args = {}) => {
|
|
|
248
257
|
if (migrate || seed || hasReference) {
|
|
249
258
|
const waiting = ora(fresh ? 'Waiting for the new database' : 'Waiting for the database to apply migrations').start();
|
|
250
259
|
const ready = (await migrations.waitForDb(config)) && (await migrations.waitForServices(config));
|
|
260
|
+
engineReady = ready;
|
|
251
261
|
if (!ready) {
|
|
252
262
|
waiting.fail(chalk.redBright('The engine does not answer: migrations and seed not applied (poad migrate, poad db seed later).'));
|
|
253
263
|
process.exitCode = 1;
|
|
@@ -266,8 +276,9 @@ module.exports = async (args = {}) => {
|
|
|
266
276
|
const transforms = require('../utils/transforms');
|
|
267
277
|
if (transforms.hasModels(root) && !process.exitCode) {
|
|
268
278
|
const ready = migrate || seed || hasReference || ((await migrations.waitForDb(config)) && (await migrations.waitForServices(config)));
|
|
279
|
+
engineReady = engineReady || ready;
|
|
269
280
|
if (ready && !(await transforms.build(root, config, { fresh }))) process.exitCode = 1;
|
|
270
281
|
}
|
|
271
282
|
|
|
272
|
-
await finish();
|
|
283
|
+
await finish(true);
|
|
273
284
|
};
|
package/package.json
CHANGED
|
@@ -122,6 +122,31 @@ test('secretsSql: storage credentials kept on both sides, nothing read from the
|
|
|
122
122
|
assert.match(sh, /src -v ON_ERROR_STOP=1 -tA -c 'select 1' 2> \/dev\/null \| dst -v ON_ERROR_STOP=1 > \/dev\/null 2>&1/);
|
|
123
123
|
});
|
|
124
124
|
|
|
125
|
+
test('OAuth authorizations: never copied (base, secrets, auth), named in the plan', () => {
|
|
126
|
+
// Rien ne lit ni n'écrit _poad.oauth_tokens ni les secrets oauth.* : _poad est système, --with-secrets ne prend que credential.%
|
|
127
|
+
assert.ok(P.SYSTEM_SCHEMAS.includes('_poad') && P.SYSTEM_SCHEMAS.includes('vault'));
|
|
128
|
+
const q = P.secretsSql({ variables: true, credentials: true, vault: true, oauth: true }, { targetStorage: [] }).join('\n');
|
|
129
|
+
assert.doesNotMatch(q, /oauth/i);
|
|
130
|
+
assert.match(q, /name like 'credential\.%'/);
|
|
131
|
+
assert.doesNotMatch(P.secretsDigestSql({ variables: true, credentials: true, vault: true, oauth: true }), /oauth/i);
|
|
132
|
+
// L'inventaire n'en lit que des noms et des nombres
|
|
133
|
+
const inv = P.inventorySql({ oauth: true, auth: [] });
|
|
134
|
+
assert.match(inv, /'oauth', \(select coalesce\(json_agg\(json_build_object\('connection', connection, 'project', project, 'users', users\)/);
|
|
135
|
+
assert.doesNotMatch(inv, /decrypted_secret|oauth_get|vault\./);
|
|
136
|
+
assert.match(P.inventorySql({}), /'oauth', '\[\]'::json/);
|
|
137
|
+
const lines = P.oauthPlan(
|
|
138
|
+
[{ connection: 'todoist', project: true, users: 2 }, { connection: 'agenda', project: true, users: 0 }, { connection: 'notion@mcp', project: false, users: 1 }],
|
|
139
|
+
[{ connection: 'agenda', project: true, users: 0 }, { connection: 'todoist', project: false, users: 5 }],
|
|
140
|
+
);
|
|
141
|
+
assert.deepStrictEqual(lines.map((l) => l.text), [
|
|
142
|
+
'OAuth connection todoist: authorize again on the target',
|
|
143
|
+
'OAuth connection todoist: 2 user account(s) connected here, never copied: each user connects again on the target',
|
|
144
|
+
'OAuth connection agenda: the target keeps its own authorization (never copied)',
|
|
145
|
+
'OAuth connection notion (MCP server): 1 user account(s) connected here, never copied: each user connects again on the target',
|
|
146
|
+
]);
|
|
147
|
+
assert.deepStrictEqual(P.oauthPlan([], [{ connection: 'x', project: true, users: 1 }]), []);
|
|
148
|
+
});
|
|
149
|
+
|
|
125
150
|
test('parseMarkers and errorLine: timings, exit code, the ERROR line only (never CONTEXT, which quotes rows)', () => {
|
|
126
151
|
const m = P.parseMarkers('@@poad start 0 1000\n@@poad start 1 1500\npsql:<stdin>:9: ERROR: duplicate key value\nCONTEXT: COPY t, line 1: "secret row"\n@@poad done 2000 3\n');
|
|
127
152
|
assert.deepStrictEqual(m.tables, { 0: { start: 1000 }, 1: { start: 1500 } });
|
package/utils/help-details.js
CHANGED
|
@@ -533,6 +533,7 @@ Object.assign(sheets, {
|
|
|
533
533
|
'A preview always comes first, part by part and table by table: rows added (+), replaced (~), deleted (-) and identical, compared row by row with fingerprints of the primary key and of each row (never a value; above 200,000 rows a table is compared by counts only), sizes, room left on the target. An identical table is not rewritten.',
|
|
534
534
|
'Base and auth go in ONE transaction, through the direct database access of poad.io (db.poad.io), run by the PostgreSQL tools of the local engine: the source is read in one consistent snapshot, the target is written with triggers and foreign keys paused during the load (nothing cascades), sequences are set as on the source; any error and nothing changes. Sessions and refresh tokens of the target are closed (accounts sign in again there), confirmation and recovery tokens are emptied. The structure must match first: a table missing or different on the target stops the base part before anything is written, and the code part (when chosen) runs first and is checked again after it.',
|
|
535
535
|
'Secrets only with --with-secrets, after a confirmation of their own: the values of the variables of the engine and the credentials (fields, uses, vault values), except those of the storage, which each environment keeps. Values are never shown, written to a file or logged; keys of the engine, auth provider secrets and MCP tokens are never copied.',
|
|
536
|
+
'OAuth authorizations are never copied, not even with --with-secrets: neither the authorization of the project (an OAuth connection authorized from the console) nor the accounts that end users connected (per_user connections). An authorization is given to one environment: the preview names each OAuth connection ("OAuth connection todoist: authorize again on the target"), and each user connects their account again on the target. With the auth part, accounts that leave the target take their connected OAuth accounts with them (engine 0.83+).',
|
|
536
537
|
'Files: compared by name, size and checksum (MD5): what is already there is not sent again, a truncated or different object is. Above 6 MiB a file goes in resumable chunks (read from the source by ranges): an upload cut by the network, or by the end of the command, goes on from where the target is at the next run. The timeout is one of inactivity (an upload that moves is never cut); a passing error (network, timeout, 5xx, 429) is tried again after 1 s, 2 s, 4 s… and the number of transfers at once halves while errors come, then goes back up. Each file sent is read back on the target (size and checksum).',
|
|
537
538
|
'Run again: poad push resumes. Code is deployed again (idempotent), identical tables and accounts are not rewritten (and production is not backed up again when the base has nothing to write), files already there are skipped. Failed files are summed up at the end (the first 5; all of them in --json and in the logs), with the command to run again; exit code 5.',
|
|
538
539
|
],
|
|
@@ -542,7 +543,7 @@ Object.assign(sheets, {
|
|
|
542
543
|
['--only <parts>', 'only these parts: code, base, auth, s3, refs (comma separated)'],
|
|
543
544
|
['--skip <parts>', 'all parts but these'],
|
|
544
545
|
['--tables <a,b>', 'only these tables of the base part (table or schema.table)'],
|
|
545
|
-
['--with-secrets', 'also the values of variables and credentials (asks separately)'],
|
|
546
|
+
['--with-secrets', 'also the values of variables and credentials (asks separately); never OAuth authorizations'],
|
|
546
547
|
['--clean', 'free the room first: the tables to rewrite are emptied (TRUNCATE, in a transaction of its own) and the files to replace removed before the copy; identical ones are kept. Not all or nothing any more: a failure leaves them empty until the next run'],
|
|
547
548
|
['--allow-destructive', 'passed to poad deploy (alias --accept-data-loss): migrations that lose data are applied on production without asking'],
|
|
548
549
|
['--yes', 'no question (required outside a terminal)'],
|
|
@@ -562,7 +563,7 @@ Object.assign(sheets, {
|
|
|
562
563
|
text: [
|
|
563
564
|
'The other way of poad push: make the local project the mirror of an environment of poad.io, part by part: code (the migrations written there, by poad migration pull, then the deployed files of queries, auth, storage, functions, flows, api, reference, sources, transforms, connections, variables and seed.sql, then poad migrate), base, auth, refs (the reference tables of the store, loaded into the local engine), s3 (files of the storage).',
|
|
564
565
|
'A local file is replaced or removed only when git tracks it without uncommitted change; otherwise it is kept and named (commit or stash it, then pull again). Migrations are never overwritten (a version used here under another name is a conflict, said and left alone).',
|
|
565
|
-
'Same preview, same single transaction for base and auth, same structure check and same --with-secrets as poad push. Before writing a local database that holds rows, a backup: poad/backups/<timestamp>-pre-pull.dump (pg_dump custom format, outside git; pg_restore brings it back).',
|
|
566
|
+
'Same preview, same single transaction for base and auth, same structure check and same --with-secrets as poad push; OAuth authorizations are never copied either (authorize again locally, users connect again). Before writing a local database that holds rows, a backup: poad/backups/<timestamp>-pre-pull.dump (pg_dump custom format, outside git; pg_restore brings it back).',
|
|
566
567
|
],
|
|
567
568
|
options: [
|
|
568
569
|
['--env <name>', 'the environment to read (default: the current git branch if it exists on poad.io, else main); never written'],
|
|
@@ -570,7 +571,7 @@ Object.assign(sheets, {
|
|
|
570
571
|
['--only <parts>', 'only these parts: code, base, auth, s3, refs'],
|
|
571
572
|
['--skip <parts>', 'all parts but these'],
|
|
572
573
|
['--tables <a,b>', 'only these tables of the base part'],
|
|
573
|
-
['--with-secrets', 'also the values of variables and credentials (asks separately)'],
|
|
574
|
+
['--with-secrets', 'also the values of variables and credentials (asks separately); never OAuth authorizations'],
|
|
574
575
|
['--clean', 'free the room first (as for poad push)'],
|
|
575
576
|
['--yes', 'no question (required outside a terminal)'],
|
|
576
577
|
PROJECT_OPT,
|
|
@@ -80,6 +80,7 @@ const PROBE_SQL = `select json_build_object(
|
|
|
80
80
|
'variables', to_regclass('_poad.variables') is not null,
|
|
81
81
|
'credentials', to_regclass('_poad.credentials') is not null and to_regclass('_poad.credential_uses') is not null,
|
|
82
82
|
'vault', to_regclass('vault.decrypted_secrets') is not null,
|
|
83
|
+
'oauth', to_regclass('_poad.oauth_tokens') is not null,
|
|
83
84
|
'auth', (select coalesce(json_agg(c.relname order by c.relname), '[]') from pg_class c join pg_namespace n on n.oid = c.relnamespace where n.nspname = 'auth' and c.relkind = 'r')
|
|
84
85
|
)`;
|
|
85
86
|
|
|
@@ -111,7 +112,8 @@ function inventorySql(probe = {}) {
|
|
|
111
112
|
'auth', json_build_object(${auth.length ? auth.map((t) => `${lit(t)}, json_build_object('rows', (select count(*) from auth.${ident(t)}), 'bytes', pg_total_relation_size('auth.${ident(t)}'), 'columns', ${columnsJson(`'auth.${ident(t)}'::regclass`)}, 'pk', (select json_agg(a.attname order by array_position(i.indkey::int2[], a.attnum)) from pg_index i join pg_attribute a on a.attrelid = i.indrelid and a.attnum = any(i.indkey) where i.indrelid = 'auth.${ident(t)}'::regclass and i.indisprimary))`).join(', ') : ''}),
|
|
112
113
|
'variables', ${probe.variables ? `(select coalesce(json_agg(name || case when app = '' then '' else '@' || app end order by name, app), '[]') from _poad.variables where value is not null)` : `'[]'::json`},
|
|
113
114
|
'credentials', ${probe.credentials ? `(select coalesce(json_agg(c.name order by c.name), '[]') from _poad.credentials c where not exists (select 1 from _poad.credential_uses u where u.credential = c.name and u.slot like 'storage.%'))` : `'[]'::json`},
|
|
114
|
-
'storage_credentials', ${probe.credentials ? `(select coalesce(json_agg(distinct u.credential), '[]') from _poad.credential_uses u where u.slot like 'storage.%')` : `'[]'::json`}
|
|
115
|
+
'storage_credentials', ${probe.credentials ? `(select coalesce(json_agg(distinct u.credential), '[]') from _poad.credential_uses u where u.slot like 'storage.%')` : `'[]'::json`},
|
|
116
|
+
'oauth', ${probe.oauth ? `(select coalesce(json_agg(json_build_object('connection', connection, 'project', project, 'users', users) order by connection), '[]') from (select connection, bool_or(subject = '') as project, count(*) filter (where subject <> '') as users from _poad.oauth_tokens group by connection) o)` : `'[]'::json`}
|
|
115
117
|
)`;
|
|
116
118
|
}
|
|
117
119
|
|
|
@@ -465,6 +467,29 @@ function authPlan(src = {}, dst = {}) {
|
|
|
465
467
|
return { tables, dropped, clear, after, closed: AUTH_CLOSED.filter((t) => dst[t]) };
|
|
466
468
|
}
|
|
467
469
|
|
|
470
|
+
/**
|
|
471
|
+
* Autorisations OAuth (engine 0.70+, _poad.oauth_tokens) : JAMAIS copiées, ni par la partie base (_poad est un schéma
|
|
472
|
+
* système), ni par --with-secrets (seulement credential.%), ni par la partie auth. Une autorisation est donnée à un
|
|
473
|
+
* environnement : celle du projet (subject '') est à refaire sur la cible ; celles des utilisateurs finaux (per_user)
|
|
474
|
+
* aussi, par chaque utilisateur. Des comptes de la cible qui disparaissent avec la partie auth emportent leurs jetons
|
|
475
|
+
* (déclencheur de l’engine 0.83+ sur auth.users). Ce que le plan en dit : une ligne par connexion. Pure.
|
|
476
|
+
* src, dst : [{ connection, project, users }] de l'inventaire (connection « nom@mcp » : serveur MCP du service)
|
|
477
|
+
*/
|
|
478
|
+
function oauthPlan(src = [], dst = []) {
|
|
479
|
+
const there = new Map((dst || []).map((o) => [o.connection, o]));
|
|
480
|
+
const lines = [];
|
|
481
|
+
for (const o of src || []) {
|
|
482
|
+
const d = there.get(o.connection) || { project: false, users: 0 };
|
|
483
|
+
const mcp = /@mcp$/.test(o.connection);
|
|
484
|
+
const name = o.connection.replace(/@mcp$/, '');
|
|
485
|
+
const what = `OAuth connection ${name}${mcp ? ' (MCP server)' : ''}`;
|
|
486
|
+
if (o.project) lines.push({ connection: name, mcp, kind: 'project', target_has: Boolean(d.project), text: d.project ? `${what}: the target keeps its own authorization (never copied)` : `${what}: authorize again on the target` });
|
|
487
|
+
const users = Number(o.users) || 0;
|
|
488
|
+
if (users) lines.push({ connection: name, mcp, kind: 'users', users, target_users: Number(d.users) || 0, text: `${what}: ${users} user account(s) connected here, never copied: each user connects again on the target` });
|
|
489
|
+
}
|
|
490
|
+
return lines;
|
|
491
|
+
}
|
|
492
|
+
|
|
468
493
|
/**
|
|
469
494
|
* Secrets : requête lue à la source qui écrit les instructions à rejouer dans la cible, en une transaction.
|
|
470
495
|
* Variables : la valeur propre de l'engine (value) ; les défauts viennent du code. Credentials : tous sauf ceux du
|
|
@@ -574,6 +599,7 @@ module.exports = {
|
|
|
574
599
|
sequencesSql,
|
|
575
600
|
sequencesFor,
|
|
576
601
|
authPlan,
|
|
602
|
+
oauthPlan,
|
|
577
603
|
secretsSql,
|
|
578
604
|
secretsScript,
|
|
579
605
|
size,
|
|
@@ -112,7 +112,7 @@ function run(direction, raw, deps = {}) {
|
|
|
112
112
|
out.log(chalk.grey(` parts: ${sel.parts.join(', ')}${sel.tables ? ` tables: ${sel.tables.join(', ')}` : ''}${clean ? ' --clean: what is replaced is emptied first' : ''}`));
|
|
113
113
|
|
|
114
114
|
// --- Aperçu (rien ne change) -------------------------------------------------------------------
|
|
115
|
-
const preview = { code: null, base: null, auth: null, refs: null, s3: null, secrets: null, space: null };
|
|
115
|
+
const preview = { code: null, base: null, auth: null, refs: null, s3: null, secrets: null, oauth: null, space: null };
|
|
116
116
|
const needDb = has('base') || has('auth') || has('secrets');
|
|
117
117
|
let local = null;
|
|
118
118
|
let cloud = null;
|
|
@@ -176,6 +176,10 @@ function run(direction, raw, deps = {}) {
|
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
+
// Autorisations OAuth : jamais copiées (une autorisation est donnée à un environnement) ; le plan le dit
|
|
180
|
+
preview.oauth = inv ? P.oauthPlan(inv.src.oauth, inv.dst.oauth) : null;
|
|
181
|
+
if (preview.auth && inv) preview.auth.oauth_target_users = (inv.dst.oauth || []).reduce((x, o) => x + (Number(o.users) || 0), 0);
|
|
182
|
+
|
|
179
183
|
// Place sur la cible : ce qui sera écrit (base et comptes, fichiers) et ce qui sera libéré
|
|
180
184
|
const amounts = spaceAmounts(preview, { clean });
|
|
181
185
|
if (amounts.need.base + amounts.need.files > 0) preview.space = await spaceCheck(id, env, poadDir, push, amounts, P);
|
|
@@ -948,8 +952,13 @@ function printPreview(out, P, pv, { push, env, sel }) {
|
|
|
948
952
|
const d = u.diff;
|
|
949
953
|
out.log(` ${pad('auth')}${n(d.rows)} account(s): ${a.changed ? `${chalk.greenBright(`+${n(d.added)}`)} ${chalk.yellowBright(`~${n(d.replaced)}`)} ${chalk.redBright(`-${n(d.deleted)}`)}${a.closed.length ? chalk.grey(', sessions of the target closed') : ''}` : 'identical'}`);
|
|
950
954
|
if (a.dropped.length) out.log(chalk.yellowBright(` ⚠ not on the target, left out: ${a.dropped.join(', ')}`));
|
|
955
|
+
if (a.changed && a.oauth_target_users) out.log(chalk.grey(` accounts that leave the target take their connected OAuth accounts with them (engine 0.83+)`));
|
|
951
956
|
}
|
|
952
957
|
}
|
|
958
|
+
if (pv.oauth && pv.oauth.length) {
|
|
959
|
+
out.log(` ${pad('oauth')}${pv.oauth[0].text}`);
|
|
960
|
+
for (const l of pv.oauth.slice(1)) out.log(` ${l.text}`);
|
|
961
|
+
}
|
|
953
962
|
if (pv.refs) {
|
|
954
963
|
const r = pv.refs;
|
|
955
964
|
// Une ligne par table, lue dans la base de l'autre côté : déjà chargée (lignes, empreinte) / à charger (pourquoi)
|
|
@@ -969,7 +978,7 @@ function printPreview(out, P, pv, { push, env, sel }) {
|
|
|
969
978
|
const s = pv.secrets;
|
|
970
979
|
if (s.same) out.log(` ${pad('secrets')}identical: ${s.variables.length} variable value(s), ${s.credentials.length} credential(s) ${chalk.grey('(compared by a digest, never shown)')}`);
|
|
971
980
|
else out.log(` ${pad('secrets')}${s.variables.length} variable value(s), ${s.credentials.length} credential(s)${s.credentials.length ? chalk.grey(` (${s.credentials.slice(0, 8).join(', ')})`) : ''}${s.target_storage.length ? chalk.grey(`; storage credentials of the target kept (${s.target_storage.join(', ')})`) : ''}`);
|
|
972
|
-
} else out.log(chalk.grey(` ${'secrets'.padEnd(8)}left out (--with-secrets to copy variable values and credentials)`));
|
|
981
|
+
} else out.log(chalk.grey(` ${'secrets'.padEnd(8)}left out (--with-secrets to copy variable values and credentials; OAuth authorizations never)`));
|
|
973
982
|
if (pv.space) for (const [i, l] of roomLines(P, pv.space).entries()) out.log(i === 0 ? ` ${pad('room')}${l}` : ` ${l}`);
|
|
974
983
|
}
|
|
975
984
|
|
|
@@ -1008,6 +1017,7 @@ function resultOf({ direction, id, env, sel, dry, preview, blocking, events, sta
|
|
|
1008
1017
|
refs: pv.refs,
|
|
1009
1018
|
s3: pv.s3,
|
|
1010
1019
|
secrets: pv.secrets ? { variables: pv.secrets.variables.length, credentials: pv.secrets.credentials, same: Boolean(pv.secrets.same) } : null,
|
|
1020
|
+
oauth: pv.oauth ? pv.oauth.map(({ text, ...o }) => ({ ...o, message: text, copied: false })) : null,
|
|
1011
1021
|
space: pv.space,
|
|
1012
1022
|
},
|
|
1013
1023
|
blocking,
|