koigrid 0.17.0 → 0.19.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/CHANGELOG.md +15 -0
- package/dist/commands/backup-key.js +52 -0
- package/dist/commands/db.js +42 -3
- package/dist/manifest.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,21 @@ All notable changes to the koigrid CLI are documented here. Format: [Keep a Chan
|
|
|
4
4
|
|
|
5
5
|
## [Unreleased]
|
|
6
6
|
|
|
7
|
+
## [0.19.0] — 2026-11-29
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- `koigrid db pooler <id> set --query-wait <seconds 0-300>|default`: how long a client waits for a pooler connection before it gets an error, like `ConnectionBorrowTimeout` of RDS Proxy (`default` = 120 s, `0` = no limit). `koigrid db pooler <id>` shows it, and what each PgBouncer applies now. Backed by `PUT /databases/:id/pooler {queryWaitTimeoutS}`.
|
|
12
|
+
- `koigrid db backup-access <id> [--hours N]`: a read-only key to the backup files of a database that expires by itself (default 24 h, at most 167 h), printed as the wal-g variables. With `db backup-key` it is all you need to restore your backups outside koigrid.
|
|
13
|
+
|
|
14
|
+
## [0.18.0] — 2026-11-28
|
|
15
|
+
|
|
16
|
+
### Added
|
|
17
|
+
|
|
18
|
+
- `koigrid db events <id> [--type T] [--since ISO] [--until ISO] [--hours N] [--limit N] [--cursor C]`: what happened to a database and when (leader changes and failovers, a member's machine lost, maintenance, backups, configuration), newest first, each with a category — like RDS Events. Backed by `GET /databases/:id/events`.
|
|
19
|
+
- `koigrid db recovery-cert [--set cert.pem | --rm]`: register (or remove) your organization's backup recovery certificate. Only the public certificate: a private key is rejected.
|
|
20
|
+
- `koigrid db backup-key <id> [--out <dir>]`: download the encryption keys of a database's backups, wrapped for that certificate (one `.cms` file per key). Open each with `openssl cms -decrypt -binary -inform DER -in <file> -inkey <your private key>` and use it as `WALG_LIBSODIUM_KEY` to read your backups outside koigrid.
|
|
21
|
+
|
|
7
22
|
## [0.17.0] — 2026-11-28
|
|
8
23
|
|
|
9
24
|
### Changed
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { api } from '../api.js';
|
|
4
|
+
import { green } from '../output.js';
|
|
5
|
+
/**
|
|
6
|
+
* Las claves de las copias para restaurar FUERA de koigrid (ficha c8c10e6d):
|
|
7
|
+
* `koigrid db recovery-cert` muestra el certificado · `--set cert.pem` lo registra · `--rm` lo retira.
|
|
8
|
+
* `koigrid db backup-key <id> [--out <dir>]` baja las claves de la base envueltas (CMS) para ese certificado.
|
|
9
|
+
*/
|
|
10
|
+
export async function recoveryCert(a, json) {
|
|
11
|
+
let r;
|
|
12
|
+
if (a.flags.set)
|
|
13
|
+
r = await api('/databases/recovery-certificate', { method: 'PUT', body: { certificate: readFileSync(String(a.flags.set), 'utf8') } });
|
|
14
|
+
else if (a.flags.rm)
|
|
15
|
+
r = await api('/databases/recovery-certificate', { method: 'DELETE' });
|
|
16
|
+
else
|
|
17
|
+
r = await api('/databases/recovery-certificate');
|
|
18
|
+
if (json)
|
|
19
|
+
return console.log(JSON.stringify(r, null, 2));
|
|
20
|
+
const c = r.certificate ?? {};
|
|
21
|
+
if (!c.configured)
|
|
22
|
+
return console.log('no recovery certificate. Register one (public part only): koigrid db recovery-cert --set cert.pem');
|
|
23
|
+
const linea = `${c.algorithm} ${c.size} · sha256 ${c.fingerprint} · expires ${c.expiresAt}${c.expired ? ' (EXPIRED: register a new one)' : ''}`;
|
|
24
|
+
console.log(a.flags.set ? green(`✓ ${linea}`) : linea);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* `koigrid db backup-access <id> [--hours N]`: una llave de SÓLO LECTURA de los ficheros de las copias que caduca sola
|
|
28
|
+
* (fase 2 de c8c10e6d), con las variables listas para wal-g.
|
|
29
|
+
*/
|
|
30
|
+
export async function backupAccess(id, a, json) {
|
|
31
|
+
const r = await api(`/databases/${encodeURIComponent(id)}/backups/access`, { method: 'POST', body: a.flags.hours ? { hours: Number(a.flags.hours) } : {} });
|
|
32
|
+
if (json)
|
|
33
|
+
return console.log(JSON.stringify(r, null, 2));
|
|
34
|
+
console.log(`${green('✓')} read-only access to ${r.bucket}/${r.prefix} until ${r.expiresAt} (shown once: it is not stored)`);
|
|
35
|
+
for (const [k, v] of Object.entries(r.walg ?? {}))
|
|
36
|
+
console.log(`export ${k}=${v}`);
|
|
37
|
+
console.log('export WALG_LIBSODIUM_KEY=<key from `koigrid db backup-key`> WALG_LIBSODIUM_KEY_TRANSFORM=hex\nthen: wal-g backup-list · wal-g backup-fetch <datadir> LATEST');
|
|
38
|
+
}
|
|
39
|
+
export async function backupKey(id, a, json) {
|
|
40
|
+
const r = await api(`/databases/${encodeURIComponent(id)}/backups/encryption-key`);
|
|
41
|
+
if (json)
|
|
42
|
+
return console.log(JSON.stringify(r, null, 2));
|
|
43
|
+
const dir = String(a.flags.out ?? '.');
|
|
44
|
+
mkdirSync(dir, { recursive: true });
|
|
45
|
+
for (const k of r.keys ?? []) {
|
|
46
|
+
const f = join(dir, `${r.database}-${k.keyFingerprint}.cms`);
|
|
47
|
+
writeFileSync(f, Buffer.from(k.cms, 'base64'), { mode: 0o600 });
|
|
48
|
+
const tramo = `${k.validFrom ?? 'creation'} → ${k.validUntil ?? 'now'}`;
|
|
49
|
+
console.log(`${green('✓')} ${f}${k.current ? ' (current)' : ''} backups ${tramo}`);
|
|
50
|
+
}
|
|
51
|
+
console.log(`open each with: openssl cms -decrypt -binary -inform DER -in <file> -inkey <your private key>\nthen read the backups with wal-g: WALG_LIBSODIUM_KEY=<key> WALG_LIBSODIUM_KEY_TRANSFORM=hex`);
|
|
52
|
+
}
|
package/dist/commands/db.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { api } from '../api.js';
|
|
2
2
|
import { output, green, dim } from '../output.js';
|
|
3
3
|
import { network } from './network.js';
|
|
4
|
+
import { recoveryCert, backupKey, backupAccess } from './backup-key.js';
|
|
4
5
|
import { proyectoDeFlags } from '../proyecto.js';
|
|
5
6
|
// Tamaño legible de una copia: sirve para VER de un vistazo si la incremental está funcionando (una delta
|
|
6
7
|
// ocupa un orden de magnitud menos que la completa de la que cuelga).
|
|
@@ -127,6 +128,32 @@ export async function db(a) {
|
|
|
127
128
|
case 'metrics':
|
|
128
129
|
need();
|
|
129
130
|
return console.log(JSON.stringify(await api(`/databases/${encodeURIComponent(id)}/metrics`), null, 2));
|
|
131
|
+
// Lo que le pasó a la base y cuándo (ficha faec5dcd, como «Events» de RDS): cambios de líder, máquina perdida,
|
|
132
|
+
// mantenimiento, copias. `--type` repetible, `--since/--until` (ISO con zona), `--hours`, `--limit`, `--cursor`.
|
|
133
|
+
case 'events': {
|
|
134
|
+
need();
|
|
135
|
+
const q = new URLSearchParams();
|
|
136
|
+
for (const t of [].concat(a.flags.type ?? []))
|
|
137
|
+
q.append('type', String(t));
|
|
138
|
+
if (a.flags.since)
|
|
139
|
+
q.set('since', String(a.flags.since));
|
|
140
|
+
if (a.flags.until)
|
|
141
|
+
q.set('until', String(a.flags.until));
|
|
142
|
+
if (a.flags.hours)
|
|
143
|
+
q.set('sinceHours', String(a.flags.hours));
|
|
144
|
+
if (a.flags.limit)
|
|
145
|
+
q.set('limit', String(a.flags.limit));
|
|
146
|
+
if (a.flags.cursor)
|
|
147
|
+
q.set('cursor', String(a.flags.cursor));
|
|
148
|
+
const r = await api(`/databases/${encodeURIComponent(id)}/events${q.size ? `?${q}` : ''}`);
|
|
149
|
+
if (json)
|
|
150
|
+
return console.log(JSON.stringify(r, null, 2));
|
|
151
|
+
const l = r.events || [];
|
|
152
|
+
output(l, false, { rows: l.map((e) => ({ at: e.createdAt, category: e.category, severity: e.severity, type: e.type, message: String(e.message ?? '').slice(0, 140) })), columns: ['at', 'category', 'severity', 'type', 'message'] });
|
|
153
|
+
if (r.nextCursor)
|
|
154
|
+
console.log(`more: --cursor ${r.nextCursor}`);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
130
157
|
// Qué consultas cargan la base en una ventana (ficha 326dd9b3, como RDS Performance Insights). `notes` se imprime:
|
|
131
158
|
// dice lo que la respuesta no puede afirmar (totales por consulta = suelo; ventana sin muestras ≠ sin carga).
|
|
132
159
|
case 'top-queries': {
|
|
@@ -342,6 +369,15 @@ export async function db(a) {
|
|
|
342
369
|
need();
|
|
343
370
|
return network('databases', 'db', id, a, json);
|
|
344
371
|
}
|
|
372
|
+
case 'recovery-cert': return recoveryCert(a, json);
|
|
373
|
+
case 'backup-key': {
|
|
374
|
+
need();
|
|
375
|
+
return backupKey(id, a, json);
|
|
376
|
+
}
|
|
377
|
+
case 'backup-access': {
|
|
378
|
+
need();
|
|
379
|
+
return backupAccess(id, a, json);
|
|
380
|
+
}
|
|
345
381
|
case 'dr-copy': {
|
|
346
382
|
// Copia de desastre (ficha c21ac56a): `db dr-copy <id>` muestra · `add` la pide · `rm` la retira.
|
|
347
383
|
need();
|
|
@@ -574,11 +610,12 @@ export async function db(a) {
|
|
|
574
610
|
console.log(`pool: ${r.pools?.transaction?.poolSize} server connections (${r.mode}; automatic ${r.limits?.autoPoolSize}, max ${r.limits?.maxPoolSize})`);
|
|
575
611
|
for (const [rol, n] of Object.entries(r.pools?.transaction?.perRole || {}))
|
|
576
612
|
console.log(` role ${rol}: ${n}`);
|
|
613
|
+
console.log(`client wait for a connection: ${r.pools?.transaction?.queryWaitTimeoutS} s${r.config?.queryWaitTimeoutS === undefined ? ' (default)' : ''}`);
|
|
577
614
|
console.log(`session pooler (direct URL): ${r.pools?.session?.poolSize}`);
|
|
578
615
|
if (r.warning)
|
|
579
616
|
console.log(r.warning);
|
|
580
617
|
for (const l of r.live || [])
|
|
581
|
-
console.log(` ${l.host}:${l.port} ${l.pooler}: ${l.error ? `no answer (${l.error})` : `${l.poolSize} / ${l.maxDbConnections || 'no cap'} · ${l.serverConnections} open${l.matches === false ? ' · pending' : ''}`}`);
|
|
618
|
+
console.log(` ${l.host}:${l.port} ${l.pooler}: ${l.error ? `no answer (${l.error})` : `${l.poolSize} / ${l.maxDbConnections || 'no cap'} · ${l.serverConnections} open · wait ${l.queryWaitTimeoutS ?? '?'} s${l.matches === false ? ' · pending' : ''}`}`);
|
|
582
619
|
return;
|
|
583
620
|
}
|
|
584
621
|
if (act === 'set') {
|
|
@@ -597,16 +634,18 @@ export async function db(a) {
|
|
|
597
634
|
}
|
|
598
635
|
if (a.flags['no-roles'])
|
|
599
636
|
body.roles = null;
|
|
637
|
+
if (a.flags['query-wait'] !== undefined)
|
|
638
|
+
body.queryWaitTimeoutS = a.flags['query-wait'] === 'default' ? null : Number(a.flags['query-wait']);
|
|
600
639
|
if (a.flags['dry-run'])
|
|
601
640
|
body.dryRun = true;
|
|
602
641
|
if (!Object.keys(body).filter((k) => k !== 'dryRun').length)
|
|
603
|
-
throw new Error('usage: koigrid db pooler <id> set [--pool-size N|auto] [--role <role>=N]... [--no-roles] [--dry-run]');
|
|
642
|
+
throw new Error('usage: koigrid db pooler <id> set [--pool-size N|auto] [--role <role>=N]... [--no-roles] [--query-wait <seconds 0-300>|default] [--dry-run]');
|
|
604
643
|
const r = await api(`/databases/${encodeURIComponent(id)}/pooler`, { method: 'PUT', body });
|
|
605
644
|
if (json)
|
|
606
645
|
return console.log(JSON.stringify(r, null, 2));
|
|
607
646
|
return console.log(green(`✓ ${r.detail}`));
|
|
608
647
|
}
|
|
609
|
-
throw new Error('usage: koigrid db pooler <id> show | set [--pool-size N|auto] [--role <role>=N]... [--no-roles] [--dry-run]');
|
|
648
|
+
throw new Error('usage: koigrid db pooler <id> show | set [--pool-size N|auto] [--role <role>=N]... [--no-roles] [--query-wait <seconds 0-300>|default] [--dry-run]');
|
|
610
649
|
}
|
|
611
650
|
case 'rotation': {
|
|
612
651
|
need();
|
package/dist/manifest.js
CHANGED
|
@@ -23,7 +23,7 @@ export const CLI_COMMANDS = [
|
|
|
23
23
|
subs: ['ls', 'deploy', 'logs', 'http', 'rm', 'rename', 'health-path', 'port', 'release', 'build-settings', 'traffic-ramp', 'max-surge', 'deploy-analysis', 'scale', 'resize', 'autoscale', 'scale-out', 'env', 'domains', 'volumes', 'cdn', 'cache', 'protection', 'retention', 'github', 'github-repos', 'hooks', 'rollback', 'pause', 'resume', 'restore', 'migrate', 'deployments', 'previews', 'preview', 'rules', 'rule', 'rule-rm', 'rule-toggle', 'registry', 'loadtest'],
|
|
24
24
|
endpoints: ['apps', 'apps/[id]', 'apps/[id]/deployments', 'apps/[id]/source-upload', 'apps/[id]/logs', 'apps/[id]/http', 'apps/[id]/scale', 'apps/[id]/resources', 'apps/[id]/autoscale', 'apps/[id]/scale-out', 'apps/[id]/env', 'apps/[id]/env/verify', 'apps/[id]/domains', 'apps/[id]/domains/verify', 'apps/[id]/volumes', 'apps/[id]/volumes/[volId]', 'apps/[id]/volumes/[volId]/backups', 'apps/[id]/volumes/[volId]/backups/[backupId]/restore', 'apps/[id]/cdn', 'apps/[id]/cache', 'apps/[id]/cache/purge', 'apps/[id]/protection', 'apps/[id]/protection/evaluate', 'apps/[id]/retention', 'apps/[id]/github', 'github/repos', 'apps/[id]/deploy-hooks', 'apps/[id]/deploy-hooks/[hookId]', 'apps/[id]/rollback', 'apps/[id]/pause', 'apps/[id]/resume', 'apps/[id]/restore', 'apps/[id]/migrate', 'apps/[id]/previews', 'apps/[id]/rules', 'apps/[id]/rules/[ruleId]', 'apps/[id]/registry', 'apps/[id]/loadtest'],
|
|
25
25
|
},
|
|
26
|
-
{ name: 'db', aliases: ['databases', 'database'], product: 'databases', summary: 'Managed Postgres (HA) — incl. SQL console (db query/tables) + branching (db branch) + managed restore (db restore-dump)', subs: ['ls', 'info', 'create', 'rm', 'rename', 'pause', 'resume', 'retention', 'weekly', 'monthly', 'url', 'connect', 'metrics', 'top-queries', 'slots', 'logs', 'backups', 'restore', 'restore-dump', 'fix-ownership', 'analyze', 'import', 'restore-status', 'ext', 'replicas', 'dr-copy', 'network', 'pub', 'query', 'tables', 'branch', 'roles', 'params', 'pooler', 'rotation', 'patching', 'sync', 'slot-cap', 'resize', 'apply-config', 'maintenance', 'subs', 'data', 'rpc'], endpoints: ['databases', 'databases/[id]', 'databases/[id]/pause', 'databases/[id]/resume', 'databases/[id]/connection', 'databases/[id]/backups', 'databases/[id]/restore', 'databases/[id]/restore-dump', 'databases/[id]/restore-dump/upload-url', 'databases/[id]/restore-dump/[jobId]', 'databases/[id]/fix-ownership', 'databases/[id]/analyze', 'databases/[id]/metrics', 'databases/[id]/queries', 'databases/[id]/replication-slots', 'databases/[id]/logs', 'databases/[id]/extensions', 'databases/[id]/replicas', 'databases/[id]/dr-copy', 'databases/[id]/network', 'databases/[id]/publications', 'databases/[id]/subscriptions', 'databases/[id]/subscriptions/preflight', 'databases/[id]/subscriptions/verify', 'databases/[id]/subscriptions/verify/[verificationId]', 'databases/[id]/subscriptions/sync-sequences', 'databases/[id]/apply-config', 'databases/[id]/maintenance/apply', 'databases/[id]/maintenance/defer', 'databases/[id]/query', 'databases/[id]/branches', 'databases/[id]/branches/[branchId]', 'databases/[id]/branches/[branchId]/reset', 'databases/[id]/roles', 'databases/[id]/roles/[roleName]', 'databases/[id]/parameters', 'databases/[id]/pooler', 'databases/[id]/rotation', 'databases/[id]/rotation/rotate', 'databases/[id]/rotation/migrate', 'databases/[id]/data/[table]', 'databases/[id]/rpc/[fn]'] },
|
|
26
|
+
{ name: 'db', aliases: ['databases', 'database'], product: 'databases', summary: 'Managed Postgres (HA) — incl. SQL console (db query/tables) + branching (db branch) + managed restore (db restore-dump)', subs: ['ls', 'info', 'create', 'rm', 'rename', 'pause', 'resume', 'retention', 'weekly', 'monthly', 'url', 'connect', 'metrics', 'events', 'top-queries', 'slots', 'logs', 'backups', 'restore', 'restore-dump', 'fix-ownership', 'analyze', 'import', 'restore-status', 'ext', 'replicas', 'dr-copy', 'network', 'recovery-cert', 'backup-key', 'backup-access', 'pub', 'query', 'tables', 'branch', 'roles', 'params', 'pooler', 'rotation', 'patching', 'sync', 'slot-cap', 'resize', 'apply-config', 'maintenance', 'subs', 'data', 'rpc'], endpoints: ['databases', 'databases/[id]', 'databases/[id]/pause', 'databases/[id]/resume', 'databases/[id]/connection', 'databases/[id]/backups', 'databases/[id]/restore', 'databases/[id]/restore-dump', 'databases/[id]/restore-dump/upload-url', 'databases/[id]/restore-dump/[jobId]', 'databases/[id]/fix-ownership', 'databases/[id]/analyze', 'databases/[id]/metrics', 'databases/[id]/events', 'databases/[id]/queries', 'databases/[id]/replication-slots', 'databases/[id]/logs', 'databases/[id]/extensions', 'databases/[id]/replicas', 'databases/[id]/dr-copy', 'databases/[id]/network', 'databases/recovery-certificate', 'databases/[id]/backups/encryption-key', 'databases/[id]/backups/access', 'databases/[id]/publications', 'databases/[id]/subscriptions', 'databases/[id]/subscriptions/preflight', 'databases/[id]/subscriptions/verify', 'databases/[id]/subscriptions/verify/[verificationId]', 'databases/[id]/subscriptions/sync-sequences', 'databases/[id]/apply-config', 'databases/[id]/maintenance/apply', 'databases/[id]/maintenance/defer', 'databases/[id]/query', 'databases/[id]/branches', 'databases/[id]/branches/[branchId]', 'databases/[id]/branches/[branchId]/reset', 'databases/[id]/roles', 'databases/[id]/roles/[roleName]', 'databases/[id]/parameters', 'databases/[id]/pooler', 'databases/[id]/rotation', 'databases/[id]/rotation/rotate', 'databases/[id]/rotation/migrate', 'databases/[id]/data/[table]', 'databases/[id]/rpc/[fn]'] },
|
|
27
27
|
{ name: 'redis', aliases: ['cache'], product: 'cache', summary: 'Managed Redis (HA)', subs: ['apply-config', 'ls', 'create', 'rm', 'rename', 'resize', 'url', 'connect', 'metrics', 'backups', 'restore', 'dr-copy', 'network', 'password', 'maintenance'], endpoints: ['redis/[id]/apply-config', 'redis/[id]/maintenance/defer', 'redis/[id]/password', 'redis', 'redis/[id]', 'redis/[id]/connection', 'redis/[id]/backups', 'redis/[id]/restore', 'redis/[id]/metrics', 'redis/[id]/dr-copy', 'redis/[id]/network'] },
|
|
28
28
|
{ name: 'storage', aliases: ['buckets'], product: 'storage', summary: 'Object storage (S3): buckets, object browser (list/upload/download/delete), versioning + restore, public read (storage public)', subs: ['ls', 'create', 'rm', 'keys', 'key', 'key-scope', 'versions', 'restore', 'objects', 'upload-url', 'download-url', 'object-rm', 'replication', 'public'], endpoints: ['buckets', 'buckets/[id]', 'buckets/[id]/versions', 'buckets/[id]/objects', 'buckets/[id]/objects/upload-url', 'buckets/[id]/objects/download-url', 'buckets/[id]/public', 'storage/keys', 'storage/keys/[id]', 'storage/keys/[id]/scope'] },
|
|
29
29
|
{ name: 'jobs', aliases: ['cron'], product: 'jobs', summary: 'Cron / scheduled jobs', subs: ['ls', 'create', 'update', 'rm', 'trigger', 'runs'], endpoints: ['jobs', 'jobs/[id]', 'jobs/[id]/runs', 'jobs/[id]/trigger'] },
|