koigrid 0.17.0 → 0.18.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 CHANGED
@@ -4,6 +4,14 @@ All notable changes to the koigrid CLI are documented here. Format: [Keep a Chan
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [0.18.0] — 2026-11-28
8
+
9
+ ### Added
10
+
11
+ - `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`.
12
+ - `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.
13
+ - `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.
14
+
7
15
  ## [0.17.0] — 2026-11-28
8
16
 
9
17
  ### Changed
@@ -0,0 +1,39 @@
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
+ export async function backupKey(id, a, json) {
27
+ const r = await api(`/databases/${encodeURIComponent(id)}/backups/encryption-key`);
28
+ if (json)
29
+ return console.log(JSON.stringify(r, null, 2));
30
+ const dir = String(a.flags.out ?? '.');
31
+ mkdirSync(dir, { recursive: true });
32
+ for (const k of r.keys ?? []) {
33
+ const f = join(dir, `${r.database}-${k.keyFingerprint}.cms`);
34
+ writeFileSync(f, Buffer.from(k.cms, 'base64'), { mode: 0o600 });
35
+ const tramo = `${k.validFrom ?? 'creation'} → ${k.validUntil ?? 'now'}`;
36
+ console.log(`${green('✓')} ${f}${k.current ? ' (current)' : ''} backups ${tramo}`);
37
+ }
38
+ 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`);
39
+ }
@@ -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 } 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,11 @@ 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
+ }
345
377
  case 'dr-copy': {
346
378
  // Copia de desastre (ficha c21ac56a): `db dr-copy <id>` muestra · `add` la pide · `rm` la retira.
347
379
  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', '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]/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'] },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koigrid",
3
- "version": "0.17.0",
3
+ "version": "0.18.0",
4
4
  "description": "koigrid CLI — deploy apps, databases, redis, storage and more from your terminal (or your AI agent).",
5
5
  "bin": {
6
6
  "koigrid": "dist/index.js"