@imenam/mcp-dependabot-tracker 1.0.24 → 1.0.26
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/README.md +187 -77
- package/dist/shared/schemas/agent-token.schema.d.ts +47 -0
- package/dist/shared/schemas/agent-token.schema.js +18 -0
- package/dist/shared/schemas/api.schema.d.ts +23 -23
- package/dist/shared/schemas/api.schema.js +8 -8
- package/dist/shared/schemas/deploy.schema.d.ts +174 -0
- package/dist/shared/schemas/deploy.schema.js +72 -0
- package/dist/shared/schemas/model.schema.d.ts +9 -26
- package/dist/shared/schemas/model.schema.js +7 -15
- package/dist/src/cli/setup-mcp.d.ts +19 -16
- package/dist/src/cli/setup-mcp.js +35 -82
- package/dist/src/cli/users.d.ts +5 -0
- package/dist/src/cli/users.js +164 -0
- package/dist/src/core/agent-tokens.d.ts +15 -0
- package/dist/src/core/agent-tokens.js +96 -0
- package/dist/src/core/auth.d.ts +774 -0
- package/dist/src/core/auth.js +191 -0
- package/dist/src/core/commands.d.ts +1 -1
- package/dist/src/core/commands.js +47 -4
- package/dist/src/core/config.d.ts +2 -3
- package/dist/src/core/config.js +2 -9
- package/dist/src/core/data-dir.d.ts +6 -8
- package/dist/src/core/data-dir.js +18 -16
- package/dist/src/core/deploy-servers.d.ts +77 -0
- package/dist/src/core/deploy-servers.js +480 -0
- package/dist/src/core/deployments.d.ts +75 -0
- package/dist/src/core/deployments.js +387 -0
- package/dist/src/core/github.d.ts +2 -0
- package/dist/src/core/github.js +8 -0
- package/dist/src/core/log-dir.d.ts +2 -6
- package/dist/src/core/log-dir.js +3 -8
- package/dist/src/core/npm-sandbox.d.ts +19 -3
- package/dist/src/core/npm-sandbox.js +87 -17
- package/dist/src/core/operations.d.ts +20 -18
- package/dist/src/core/operations.js +86 -70
- package/dist/src/core/repair.d.ts +0 -7
- package/dist/src/core/repair.js +10 -33
- package/dist/src/core/repos.d.ts +2 -3
- package/dist/src/core/repos.js +4 -7
- package/dist/src/core/server-config.d.ts +29 -0
- package/dist/src/core/server-config.js +85 -0
- package/dist/src/core/settings.d.ts +9 -3
- package/dist/src/core/settings.js +49 -10
- package/dist/src/core/ssh.d.ts +31 -0
- package/dist/src/core/ssh.js +82 -0
- package/dist/src/core/store.d.ts +5 -12
- package/dist/src/core/store.js +82 -160
- package/dist/src/core/vault.d.ts +10 -0
- package/dist/src/core/vault.js +50 -0
- package/dist/src/index.d.ts +9 -0
- package/dist/src/index.js +46 -455
- package/dist/src/mcp.d.ts +6 -0
- package/dist/src/mcp.js +59 -0
- package/dist/src/server/app.d.ts +47 -0
- package/dist/src/server/app.js +273 -0
- package/dist/src/server/serve.d.ts +7 -0
- package/dist/src/server/serve.js +185 -0
- package/dist/src/tools/client.d.ts +15 -0
- package/dist/src/tools/client.js +62 -0
- package/dist/src/tools/format.d.ts +4 -5
- package/dist/src/tools/format.js +39 -16
- package/dist/src/tools/tools.d.ts +101 -15
- package/dist/src/tools/tools.js +91 -62
- package/gui/dist/assets/index-FrRzRTkV.js +71 -0
- package/gui/dist/assets/index-o3l3BAZD.css +1 -0
- package/gui/dist/index.html +2 -2
- package/package.json +11 -4
- package/dist/shared/schemas/ipc.schema.d.ts +0 -26
- package/dist/shared/schemas/ipc.schema.js +0 -53
- package/dist/src/gui-worker.d.ts +0 -1
- package/dist/src/gui-worker.js +0 -379
- package/gui/dist/assets/index-BFMdldjC.css +0 -1
- package/gui/dist/assets/index-BFWRvPPl.js +0 -64
|
@@ -4,17 +4,20 @@ import path from "path";
|
|
|
4
4
|
import { DEFAULT_SETTINGS, SettingsSchema } from "../../shared/schemas/settings.schema.js";
|
|
5
5
|
import { TrackerError } from "./errors.js";
|
|
6
6
|
import { organizerUrl } from "./organizer.js";
|
|
7
|
+
import { decryptSecret, encryptSecret, isEncrypted } from "./vault.js";
|
|
7
8
|
/**
|
|
8
9
|
* Réglages des corrections par Claude, dans `<données>/settings.json`, lisible par
|
|
9
10
|
* le seul compte du serveur : ils portent le token de l'organizer et celui de
|
|
10
|
-
* Claude, que la GUI ne reçoit jamais
|
|
11
|
+
* Claude, chiffrés avec VAULT_KEY dans le fichier, que la GUI ne reçoit jamais
|
|
12
|
+
* en entier.
|
|
11
13
|
*/
|
|
12
14
|
/** Durée de validité d'un token créé par `claude setup-token`. */
|
|
13
15
|
const CLAUDE_TOKEN_VALIDITY_MS = 365 * 24 * 3600_000;
|
|
14
16
|
function settingsPath(dataDir) {
|
|
15
17
|
return path.join(dataDir, "settings.json");
|
|
16
18
|
}
|
|
17
|
-
|
|
19
|
+
/** Contenu de `settings.json` tel qu'il est écrit, tokens compris ; null sans fichier. */
|
|
20
|
+
function readSettingsFile(dataDir) {
|
|
18
21
|
const file = settingsPath(dataDir);
|
|
19
22
|
let raw;
|
|
20
23
|
try {
|
|
@@ -22,7 +25,7 @@ export function readSettings(dataDir) {
|
|
|
22
25
|
}
|
|
23
26
|
catch (err) {
|
|
24
27
|
if (err.code === "ENOENT")
|
|
25
|
-
return
|
|
28
|
+
return null;
|
|
26
29
|
throw err;
|
|
27
30
|
}
|
|
28
31
|
const parsed = SettingsSchema.safeParse(JSON.parse(raw));
|
|
@@ -30,7 +33,43 @@ export function readSettings(dataDir) {
|
|
|
30
33
|
throw new TrackerError(`${file} is invalid: ${parsed.error.message}`);
|
|
31
34
|
return parsed.data;
|
|
32
35
|
}
|
|
33
|
-
|
|
36
|
+
/** Applique `fn` à chaque token des réglages, null laissé tel quel. */
|
|
37
|
+
function mapTokens(settings, fn) {
|
|
38
|
+
const map = (token) => (token === null ? null : fn(token));
|
|
39
|
+
return { ...settings, organizer: { ...settings.organizer, token: map(settings.organizer.token) }, claude: { ...settings.claude, token: map(settings.claude.token) } };
|
|
40
|
+
}
|
|
41
|
+
/** Réglages, tokens déchiffrés avec `vaultKey` ; un token que la clé ne déchiffre pas lève une erreur. */
|
|
42
|
+
export function readSettings(dataDir, vaultKey) {
|
|
43
|
+
const stored = readSettingsFile(dataDir);
|
|
44
|
+
if (stored === null)
|
|
45
|
+
return DEFAULT_SETTINGS;
|
|
46
|
+
return mapTokens(stored, (token) => {
|
|
47
|
+
try {
|
|
48
|
+
return decryptSecret(token, vaultKey);
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
throw new TrackerError(`A token of ${settingsPath(dataDir)} cannot be read: ${err.message}`);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Chiffre avec `vaultKey` les tokens de `settings.json` écrits en clair par une
|
|
57
|
+
* version antérieure ; rend vrai si le fichier a été réécrit.
|
|
58
|
+
*/
|
|
59
|
+
export function encryptStoredTokens(dataDir, vaultKey) {
|
|
60
|
+
const stored = readSettingsFile(dataDir);
|
|
61
|
+
if (stored === null)
|
|
62
|
+
return false;
|
|
63
|
+
const tokens = [stored.organizer.token, stored.claude.token].filter((token) => token !== null);
|
|
64
|
+
if (tokens.every(isEncrypted))
|
|
65
|
+
return false;
|
|
66
|
+
writeSettingsFile(dataDir, mapTokens(stored, (token) => (isEncrypted(token) ? token : encryptSecret(token, vaultKey))));
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
function writeSettings(dataDir, vaultKey, settings) {
|
|
70
|
+
writeSettingsFile(dataDir, mapTokens(settings, (token) => encryptSecret(token, vaultKey)));
|
|
71
|
+
}
|
|
72
|
+
function writeSettingsFile(dataDir, settings) {
|
|
34
73
|
const file = settingsPath(dataDir);
|
|
35
74
|
const tmp = `${file}.${process.pid}.${crypto.randomBytes(4).toString("hex")}.tmp`;
|
|
36
75
|
try {
|
|
@@ -79,8 +118,8 @@ async function checkedOrganizer(organizer, checks) {
|
|
|
79
118
|
* testée, un nouveau token Claude vérifié : un échec refuse tout
|
|
80
119
|
* l'enregistrement.
|
|
81
120
|
*/
|
|
82
|
-
export async function saveSettings(dataDir, body, checks) {
|
|
83
|
-
const current = readSettings(dataDir);
|
|
121
|
+
export async function saveSettings(dataDir, vaultKey, body, checks) {
|
|
122
|
+
const current = readSettings(dataDir, vaultKey);
|
|
84
123
|
const url = body.organizerUrl === "" ? null : organizerUrl(body.organizerUrl);
|
|
85
124
|
const token = body.organizerToken ?? current.organizer.token;
|
|
86
125
|
const organizerChanged = url !== current.organizer.url || token !== current.organizer.token;
|
|
@@ -91,15 +130,15 @@ export async function saveSettings(dataDir, body, checks) {
|
|
|
91
130
|
claude = { token: body.claudeToken, savedAt: new Date().toISOString() };
|
|
92
131
|
}
|
|
93
132
|
const next = { organizer, claude, analysis: body.analysis };
|
|
94
|
-
writeSettings(dataDir, next);
|
|
133
|
+
writeSettings(dataDir, vaultKey, next);
|
|
95
134
|
return settingsView(next);
|
|
96
135
|
}
|
|
97
136
|
/** Teste la connexion enregistrée à l'organizer et relève son espace et son propriétaire. */
|
|
98
|
-
export async function testOrganizer(dataDir, checks) {
|
|
99
|
-
const current = readSettings(dataDir);
|
|
137
|
+
export async function testOrganizer(dataDir, vaultKey, checks) {
|
|
138
|
+
const current = readSettings(dataDir, vaultKey);
|
|
100
139
|
if (!organizerConnection(current))
|
|
101
140
|
throw new TrackerError("Set the organizer address and token first.");
|
|
102
141
|
const next = { ...current, organizer: await checkedOrganizer(current.organizer, checks) };
|
|
103
|
-
writeSettings(dataDir, next);
|
|
142
|
+
writeSettings(dataDir, vaultKey, next);
|
|
104
143
|
return settingsView(next);
|
|
105
144
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type Client, type ClientChannel } from "ssh2";
|
|
2
|
+
import { TrackerError } from "./errors.js";
|
|
3
|
+
/** Connexion SSH refusée à l'authentification : le serveur n'accepte pas la clé du tracker. */
|
|
4
|
+
export declare class AuthRefusedError extends TrackerError {
|
|
5
|
+
constructor(message: string);
|
|
6
|
+
}
|
|
7
|
+
export interface SshTarget {
|
|
8
|
+
host: string;
|
|
9
|
+
port: number;
|
|
10
|
+
username: string;
|
|
11
|
+
privateKey: string;
|
|
12
|
+
/** Empreinte attendue de la clé d'hôte ; null au premier test de connexion. */
|
|
13
|
+
expectedFingerprint: string | null;
|
|
14
|
+
}
|
|
15
|
+
/** Empreinte au format d'OpenSSH : `SHA256:<base64 sans remplissage>`. */
|
|
16
|
+
export declare function fingerprintOf(key: Buffer): string;
|
|
17
|
+
/**
|
|
18
|
+
* Ouvre une connexion SSH authentifiée. Avec une empreinte attendue, une clé
|
|
19
|
+
* d'hôte différente la fait échouer ; l'empreinte vue est renvoyée.
|
|
20
|
+
*/
|
|
21
|
+
export declare function connectSsh(target: SshTarget): Promise<{
|
|
22
|
+
client: Client;
|
|
23
|
+
fingerprint: string;
|
|
24
|
+
}>;
|
|
25
|
+
/** Ouvre un canal qui exécute `command` sur le serveur. */
|
|
26
|
+
export declare function openExec(client: Client, command: string): Promise<ClientChannel>;
|
|
27
|
+
/** Exécute un script sh transmis sur l'entrée standard ; renvoie son code de retour et sa sortie fusionnée. */
|
|
28
|
+
export declare function execScript(client: Client, script: string): Promise<{
|
|
29
|
+
code: number | null;
|
|
30
|
+
output: string;
|
|
31
|
+
}>;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { createHash } from "crypto";
|
|
2
|
+
import ssh2 from "ssh2";
|
|
3
|
+
import { TrackerError } from "./errors.js";
|
|
4
|
+
const CONNECT_TIMEOUT_MS = 15_000;
|
|
5
|
+
/** Connexion SSH refusée à l'authentification : le serveur n'accepte pas la clé du tracker. */
|
|
6
|
+
export class AuthRefusedError extends TrackerError {
|
|
7
|
+
constructor(message) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = "AuthRefusedError";
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
/** Empreinte au format d'OpenSSH : `SHA256:<base64 sans remplissage>`. */
|
|
13
|
+
export function fingerprintOf(key) {
|
|
14
|
+
return `SHA256:${createHash("sha256").update(key).digest("base64").replace(/=+$/, "")}`;
|
|
15
|
+
}
|
|
16
|
+
function connectionErrorMessage(err, target) {
|
|
17
|
+
if (err?.level === "client-authentication") {
|
|
18
|
+
return `Authentification refusée pour ${target.username}@${target.host} : le serveur n'accepte pas la clé du tracker. Colle la commande d'installation sur le serveur, puis teste à nouveau.`;
|
|
19
|
+
}
|
|
20
|
+
if (err?.level === "client-timeout")
|
|
21
|
+
return `Le serveur ${target.host}:${target.port} n'a pas répondu dans les ${CONNECT_TIMEOUT_MS / 1000} s.`;
|
|
22
|
+
return `Connexion SSH impossible à ${target.host}:${target.port} : ${err?.message ?? err}`;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Ouvre une connexion SSH authentifiée. Avec une empreinte attendue, une clé
|
|
26
|
+
* d'hôte différente la fait échouer ; l'empreinte vue est renvoyée.
|
|
27
|
+
*/
|
|
28
|
+
export function connectSsh(target) {
|
|
29
|
+
return new Promise((resolve, reject) => {
|
|
30
|
+
const client = new ssh2.Client();
|
|
31
|
+
let seenFingerprint = null;
|
|
32
|
+
let settled = false;
|
|
33
|
+
const fail = (message, authRefused = false) => {
|
|
34
|
+
if (settled)
|
|
35
|
+
return;
|
|
36
|
+
settled = true;
|
|
37
|
+
client.end();
|
|
38
|
+
reject(authRefused ? new AuthRefusedError(message) : new TrackerError(message));
|
|
39
|
+
};
|
|
40
|
+
client.on("ready", () => {
|
|
41
|
+
if (settled)
|
|
42
|
+
return;
|
|
43
|
+
settled = true;
|
|
44
|
+
resolve({ client, fingerprint: seenFingerprint });
|
|
45
|
+
});
|
|
46
|
+
client.on("error", (err) => {
|
|
47
|
+
if (target.expectedFingerprint && seenFingerprint && seenFingerprint !== target.expectedFingerprint) {
|
|
48
|
+
return fail(`La clé d'hôte de ${target.host} a changé (${seenFingerprint}, attendue ${target.expectedFingerprint}). Connexion refusée : vérifie le serveur, puis modifie-le dans l'interface pour enregistrer la nouvelle empreinte.`);
|
|
49
|
+
}
|
|
50
|
+
fail(connectionErrorMessage(err, target), err?.level === "client-authentication");
|
|
51
|
+
});
|
|
52
|
+
client.connect({
|
|
53
|
+
host: target.host,
|
|
54
|
+
port: target.port,
|
|
55
|
+
username: target.username,
|
|
56
|
+
privateKey: target.privateKey,
|
|
57
|
+
readyTimeout: CONNECT_TIMEOUT_MS,
|
|
58
|
+
keepaliveInterval: 30_000,
|
|
59
|
+
hostVerifier: (key) => {
|
|
60
|
+
seenFingerprint = fingerprintOf(key);
|
|
61
|
+
return target.expectedFingerprint === null || seenFingerprint === target.expectedFingerprint;
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/** Ouvre un canal qui exécute `command` sur le serveur. */
|
|
67
|
+
export function openExec(client, command) {
|
|
68
|
+
return new Promise((resolve, reject) => {
|
|
69
|
+
client.exec(command, (err, channel) => (err ? reject(new TrackerError(`Exécution impossible sur le serveur : ${err.message}`)) : resolve(channel)));
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/** Exécute un script sh transmis sur l'entrée standard ; renvoie son code de retour et sa sortie fusionnée. */
|
|
73
|
+
export async function execScript(client, script) {
|
|
74
|
+
const channel = await openExec(client, "sh -s");
|
|
75
|
+
return new Promise((resolve) => {
|
|
76
|
+
let output = "";
|
|
77
|
+
channel.on("data", (chunk) => (output += chunk.toString("utf8")));
|
|
78
|
+
channel.stderr.on("data", (chunk) => (output += chunk.toString("utf8")));
|
|
79
|
+
channel.on("close", (code) => resolve({ code, output }));
|
|
80
|
+
channel.end(script);
|
|
81
|
+
});
|
|
82
|
+
}
|
package/dist/src/core/store.d.ts
CHANGED
|
@@ -1,23 +1,17 @@
|
|
|
1
1
|
import { type Category, type Operation, type Repo } from "../../shared/schemas/model.schema.js";
|
|
2
|
-
/** Vrai si le processus `pid` existe encore. */
|
|
3
|
-
export declare function processAlive(pid: number): boolean;
|
|
4
2
|
export declare function isActive(operation: Operation): boolean;
|
|
5
3
|
/** Refuse toute lecture GitHub ou opération sur un dépôt déprécié. */
|
|
6
4
|
export declare function assertNotDeprecated(repo: Repo): void;
|
|
7
5
|
/**
|
|
8
6
|
* Persistance : `<dataDir>/repos.json` pour les dépôts suivis et
|
|
9
|
-
* `<dataDir>/operations/<id>.json` pour chaque opération.
|
|
10
|
-
*
|
|
11
|
-
* chaque écriture passe par le verrou `<dataDir>/data.lock`.
|
|
7
|
+
* `<dataDir>/operations/<id>.json` pour chaque opération. Le serveur est le
|
|
8
|
+
* seul processus qui les écrit ; chaque écriture est atomique.
|
|
12
9
|
*/
|
|
13
10
|
export declare class Store {
|
|
14
11
|
readonly dataDir: string;
|
|
15
12
|
private readonly reposPath;
|
|
16
13
|
private readonly operationsDir;
|
|
17
|
-
private readonly lockPath;
|
|
18
14
|
constructor(dataDir: string);
|
|
19
|
-
/** Sérialise les écritures entre processus : `wx` échoue si le verrou existe déjà. Non réentrant. */
|
|
20
|
-
private withLock;
|
|
21
15
|
private readReposFile;
|
|
22
16
|
private writeReposFile;
|
|
23
17
|
listRepos(): Repo[];
|
|
@@ -55,9 +49,8 @@ export declare class Store {
|
|
|
55
49
|
createOperation(operation: Operation): Operation;
|
|
56
50
|
updateOperation(id: string, fn: (operation: Operation) => Operation): Operation;
|
|
57
51
|
/**
|
|
58
|
-
* Opérations `running`
|
|
59
|
-
*
|
|
60
|
-
* dépendent d'aucun processus et restent en l'état.
|
|
52
|
+
* Opérations encore `running` au démarrage du serveur, que son arrêt a
|
|
53
|
+
* interrompues : elles passent en échec et leur clone est supprimé.
|
|
61
54
|
*/
|
|
62
|
-
|
|
55
|
+
failInterruptedOperations(): Operation[];
|
|
63
56
|
}
|
package/dist/src/core/store.js
CHANGED
|
@@ -3,21 +3,14 @@ import fs from "fs";
|
|
|
3
3
|
import path from "path";
|
|
4
4
|
import { ACTIVE_STATUSES, OperationSchema, ReposFileSchema, } from "../../shared/schemas/model.schema.js";
|
|
5
5
|
import { ConflictError, NotFoundError, TrackerError } from "./errors.js";
|
|
6
|
-
const LOCK_STALE_MS = 10_000;
|
|
7
|
-
const LOCK_RETRY_MS = 25;
|
|
8
|
-
const LOCK_TIMEOUT_MS = 5_000;
|
|
9
6
|
/** Opérations terminées conservées par dépôt ; les plus anciennes sont supprimées. */
|
|
10
7
|
const KEPT_OPERATIONS_PER_REPO = 20;
|
|
11
8
|
const OPERATION_ID_PATTERN = /^[a-z0-9-]+$/;
|
|
12
|
-
/**
|
|
13
|
-
function sleepSync(ms) {
|
|
14
|
-
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
15
|
-
}
|
|
16
|
-
/** Écriture atomique : fichier temporaire unique puis `rename`, JSON indenté. */
|
|
9
|
+
/** Écriture atomique : fichier temporaire unique puis `rename`, JSON indenté, lisible par le seul compte du serveur. */
|
|
17
10
|
function writeJsonAtomic(target, value) {
|
|
18
|
-
const tmp = `${target}.${
|
|
11
|
+
const tmp = `${target}.${crypto.randomBytes(4).toString("hex")}.tmp`;
|
|
19
12
|
try {
|
|
20
|
-
fs.writeFileSync(tmp, JSON.stringify(value, null, 2), "utf-8");
|
|
13
|
+
fs.writeFileSync(tmp, JSON.stringify(value, null, 2), { encoding: "utf-8", mode: 0o600 });
|
|
21
14
|
fs.renameSync(tmp, target);
|
|
22
15
|
}
|
|
23
16
|
catch (err) {
|
|
@@ -25,16 +18,6 @@ function writeJsonAtomic(target, value) {
|
|
|
25
18
|
throw err;
|
|
26
19
|
}
|
|
27
20
|
}
|
|
28
|
-
/** Vrai si le processus `pid` existe encore. */
|
|
29
|
-
export function processAlive(pid) {
|
|
30
|
-
try {
|
|
31
|
-
process.kill(pid, 0);
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
catch (err) {
|
|
35
|
-
return err.code === "EPERM";
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
21
|
/**
|
|
39
22
|
* Complète un fichier écrit par une version antérieure : un dépôt sans branche
|
|
40
23
|
* choisie analyse sa branche par défaut, un dépôt sans catégorie n'est rangé
|
|
@@ -42,7 +25,8 @@ export function processAlive(pid) {
|
|
|
42
25
|
* corrigée à la main n'en a aucune, un dépôt sans pull request en attente n'en
|
|
43
26
|
* a aucune jusqu'à sa lecture suivante, un dépôt sans date de dépréciation
|
|
44
27
|
* n'est pas déprécié, un dépôt sans date d'entrée dans la file n'y est pas, un
|
|
45
|
-
dépôt sans date de marque « à déployer » ne l'est pas
|
|
28
|
+
dépôt sans date de marque « à déployer » ne l'est pas, un dépôt sans serveur
|
|
29
|
+
* de déploiement n'en a aucun ni de script. Une alerte sans date
|
|
46
30
|
* d'émission prend celle de la lecture qui l'a rapportée, une alerte sans
|
|
47
31
|
* portée n'en a aucune ; la lecture suivante les remplace par les vraies.
|
|
48
32
|
*/
|
|
@@ -61,6 +45,8 @@ function normalizeReposFile(file) {
|
|
|
61
45
|
deprecatedAt: repo?.deprecatedAt ?? null,
|
|
62
46
|
queuedAt: repo?.queuedAt ?? null,
|
|
63
47
|
deployPendingAt: repo?.deployPendingAt ?? null,
|
|
48
|
+
deployServerId: repo?.deployServerId ?? null,
|
|
49
|
+
deployScript: typeof repo?.deployScript === "string" ? repo.deployScript : "",
|
|
64
50
|
alerts: Array.isArray(repo?.alerts)
|
|
65
51
|
? repo.alerts.map((alert) => ({ ...alert, createdAt: alert?.createdAt ?? repo.syncedAt ?? repo.addedAt, scope: alert?.scope ?? null }))
|
|
66
52
|
: repo?.alerts,
|
|
@@ -115,60 +101,18 @@ export function assertNotDeprecated(repo) {
|
|
|
115
101
|
}
|
|
116
102
|
/**
|
|
117
103
|
* Persistance : `<dataDir>/repos.json` pour les dépôts suivis et
|
|
118
|
-
* `<dataDir>/operations/<id>.json` pour chaque opération.
|
|
119
|
-
*
|
|
120
|
-
* chaque écriture passe par le verrou `<dataDir>/data.lock`.
|
|
104
|
+
* `<dataDir>/operations/<id>.json` pour chaque opération. Le serveur est le
|
|
105
|
+
* seul processus qui les écrit ; chaque écriture est atomique.
|
|
121
106
|
*/
|
|
122
107
|
export class Store {
|
|
123
108
|
dataDir;
|
|
124
109
|
reposPath;
|
|
125
110
|
operationsDir;
|
|
126
|
-
lockPath;
|
|
127
111
|
constructor(dataDir) {
|
|
128
112
|
this.dataDir = dataDir;
|
|
129
113
|
this.reposPath = path.join(dataDir, "repos.json");
|
|
130
114
|
this.operationsDir = path.join(dataDir, "operations");
|
|
131
|
-
this.
|
|
132
|
-
fs.mkdirSync(this.operationsDir, { recursive: true });
|
|
133
|
-
}
|
|
134
|
-
/** Sérialise les écritures entre processus : `wx` échoue si le verrou existe déjà. Non réentrant. */
|
|
135
|
-
withLock(fn) {
|
|
136
|
-
const deadline = Date.now() + LOCK_TIMEOUT_MS;
|
|
137
|
-
let fd;
|
|
138
|
-
for (;;) {
|
|
139
|
-
try {
|
|
140
|
-
fd = fs.openSync(this.lockPath, "wx");
|
|
141
|
-
break;
|
|
142
|
-
}
|
|
143
|
-
catch (err) {
|
|
144
|
-
if (err.code !== "EEXIST")
|
|
145
|
-
throw err;
|
|
146
|
-
let mtimeMs;
|
|
147
|
-
try {
|
|
148
|
-
mtimeMs = fs.statSync(this.lockPath).mtimeMs;
|
|
149
|
-
}
|
|
150
|
-
catch (statErr) {
|
|
151
|
-
if (statErr.code === "ENOENT")
|
|
152
|
-
continue;
|
|
153
|
-
throw statErr;
|
|
154
|
-
}
|
|
155
|
-
if (Date.now() - mtimeMs > LOCK_STALE_MS) {
|
|
156
|
-
fs.rmSync(this.lockPath, { force: true });
|
|
157
|
-
continue;
|
|
158
|
-
}
|
|
159
|
-
if (Date.now() > deadline) {
|
|
160
|
-
throw new TrackerError(`The tracker data is being written by another process and did not free up in ${LOCK_TIMEOUT_MS} ms. Try again in a moment.`);
|
|
161
|
-
}
|
|
162
|
-
sleepSync(LOCK_RETRY_MS);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
try {
|
|
166
|
-
return fn();
|
|
167
|
-
}
|
|
168
|
-
finally {
|
|
169
|
-
fs.closeSync(fd);
|
|
170
|
-
fs.rmSync(this.lockPath, { force: true });
|
|
171
|
-
}
|
|
115
|
+
fs.mkdirSync(this.operationsDir, { recursive: true, mode: 0o700 });
|
|
172
116
|
}
|
|
173
117
|
// --- Dépôts et catégories ----------------------------------------------------
|
|
174
118
|
readReposFile() {
|
|
@@ -205,47 +149,41 @@ export class Store {
|
|
|
205
149
|
}
|
|
206
150
|
/** Ajoute un dépôt ; sa catégorie, s'il en a une, doit exister. */
|
|
207
151
|
addRepo(repo) {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
return repo;
|
|
217
|
-
});
|
|
152
|
+
const file = this.readReposFile();
|
|
153
|
+
if (file.repos.some((existing) => existing.id.toLowerCase() === repo.id.toLowerCase())) {
|
|
154
|
+
throw new ConflictError(`Repository ${repo.id} is already tracked.`);
|
|
155
|
+
}
|
|
156
|
+
if (repo.categoryId !== null)
|
|
157
|
+
findCategoryIn(file, repo.categoryId);
|
|
158
|
+
this.writeReposFile({ ...file, repos: [...file.repos, repo] });
|
|
159
|
+
return repo;
|
|
218
160
|
}
|
|
219
161
|
/** Modifie un dépôt ; une catégorie qui lui est attribuée doit exister. */
|
|
220
162
|
updateRepo(repoId, fn) {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
return updated;
|
|
233
|
-
});
|
|
163
|
+
const file = this.readReposFile();
|
|
164
|
+
const index = file.repos.findIndex((repo) => repo.id.toLowerCase() === repoId.toLowerCase());
|
|
165
|
+
if (index === -1)
|
|
166
|
+
throw new NotFoundError(`Repository "${repoId}" is not tracked.`);
|
|
167
|
+
const updated = fn(file.repos[index]);
|
|
168
|
+
if (updated.categoryId !== null)
|
|
169
|
+
findCategoryIn(file, updated.categoryId);
|
|
170
|
+
const repos = [...file.repos];
|
|
171
|
+
repos[index] = updated;
|
|
172
|
+
this.writeReposFile({ ...file, repos });
|
|
173
|
+
return updated;
|
|
234
174
|
}
|
|
235
175
|
/** Retire un dépôt et ses opérations ; refusé pendant une opération en cours. */
|
|
236
176
|
removeRepo(repoId) {
|
|
237
|
-
this.
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
this.writeReposFile({ ...file, repos: file.repos.filter((candidate) => candidate !== repo) });
|
|
248
|
-
});
|
|
177
|
+
const file = this.readReposFile();
|
|
178
|
+
const repo = file.repos.find((candidate) => candidate.id.toLowerCase() === repoId.toLowerCase());
|
|
179
|
+
if (!repo)
|
|
180
|
+
throw new NotFoundError(`Repository "${repoId}" is not tracked.`);
|
|
181
|
+
const operations = this.readOperationsOf(repo.id);
|
|
182
|
+
if (operations.some(isActive))
|
|
183
|
+
throw new ConflictError(`An operation is in progress on ${repo.id}: cancel it before removing the repository.`);
|
|
184
|
+
for (const operation of operations)
|
|
185
|
+
fs.rmSync(this.operationPath(operation.id), { force: true });
|
|
186
|
+
this.writeReposFile({ ...file, repos: file.repos.filter((candidate) => candidate !== repo) });
|
|
249
187
|
}
|
|
250
188
|
/** Catégories dans l'ordre alphabétique. */
|
|
251
189
|
listCategories() {
|
|
@@ -256,33 +194,27 @@ export class Store {
|
|
|
256
194
|
}
|
|
257
195
|
/** Crée une catégorie ; deux catégories ne portent pas le même nom, sans tenir compte de la casse. */
|
|
258
196
|
createCategory(name) {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
return category;
|
|
265
|
-
});
|
|
197
|
+
const file = this.readReposFile();
|
|
198
|
+
assertNameFree(file, name, null);
|
|
199
|
+
const category = { id: crypto.randomBytes(6).toString("hex"), name: name.trim() };
|
|
200
|
+
this.writeReposFile({ ...file, categories: [...file.categories, category] });
|
|
201
|
+
return category;
|
|
266
202
|
}
|
|
267
203
|
renameCategory(categoryId, name) {
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
return renamed;
|
|
275
|
-
});
|
|
204
|
+
const file = this.readReposFile();
|
|
205
|
+
findCategoryIn(file, categoryId);
|
|
206
|
+
assertNameFree(file, name, categoryId);
|
|
207
|
+
const renamed = { id: categoryId, name: name.trim() };
|
|
208
|
+
this.writeReposFile({ ...file, categories: file.categories.map((category) => (category.id === categoryId ? renamed : category)) });
|
|
209
|
+
return renamed;
|
|
276
210
|
}
|
|
277
211
|
/** Supprime une catégorie ; ses dépôts restent suivis, sans catégorie. */
|
|
278
212
|
deleteCategory(categoryId) {
|
|
279
|
-
this.
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
repos: file.repos.map((repo) => (repo.categoryId === categoryId ? { ...repo, categoryId: null } : repo)),
|
|
285
|
-
});
|
|
213
|
+
const file = this.readReposFile();
|
|
214
|
+
findCategoryIn(file, categoryId);
|
|
215
|
+
this.writeReposFile({
|
|
216
|
+
categories: file.categories.filter((category) => category.id !== categoryId),
|
|
217
|
+
repos: file.repos.map((repo) => (repo.categoryId === categoryId ? { ...repo, categoryId: null } : repo)),
|
|
286
218
|
});
|
|
287
219
|
}
|
|
288
220
|
// --- Opérations ---------------------------------------------------------------
|
|
@@ -343,48 +275,38 @@ export class Store {
|
|
|
343
275
|
* même dépôt. Les opérations terminées au-delà des 20 plus récentes sont supprimées.
|
|
344
276
|
*/
|
|
345
277
|
createOperation(operation) {
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
return operation;
|
|
356
|
-
});
|
|
278
|
+
const existing = this.readOperationsOf(operation.repoId);
|
|
279
|
+
const active = existing.find(isActive);
|
|
280
|
+
if (active) {
|
|
281
|
+
throw new ConflictError(`An operation is already in progress on ${operation.repoId} (${active.id}, ${active.status}). Wait for it to finish or cancel it.`);
|
|
282
|
+
}
|
|
283
|
+
writeJsonAtomic(this.operationPath(operation.id), OperationSchema.parse(operation));
|
|
284
|
+
for (const old of existing.slice(KEPT_OPERATIONS_PER_REPO - 1))
|
|
285
|
+
fs.rmSync(this.operationPath(old.id), { force: true });
|
|
286
|
+
return operation;
|
|
357
287
|
}
|
|
358
288
|
updateOperation(id, fn) {
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
return updated;
|
|
364
|
-
});
|
|
289
|
+
const current = this.getOperation(id);
|
|
290
|
+
const updated = OperationSchema.parse({ ...fn(current), updatedAt: new Date().toISOString() });
|
|
291
|
+
writeJsonAtomic(this.operationPath(id), updated);
|
|
292
|
+
return updated;
|
|
365
293
|
}
|
|
366
294
|
/**
|
|
367
|
-
* Opérations `running`
|
|
368
|
-
*
|
|
369
|
-
* dépendent d'aucun processus et restent en l'état.
|
|
295
|
+
* Opérations encore `running` au démarrage du serveur, que son arrêt a
|
|
296
|
+
* interrompues : elles passent en échec et leur clone est supprimé.
|
|
370
297
|
*/
|
|
371
|
-
|
|
372
|
-
const
|
|
373
|
-
return
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
};
|
|
384
|
-
});
|
|
385
|
-
if (orphan.workDir)
|
|
386
|
-
fs.rmSync(orphan.workDir, { recursive: true, force: true });
|
|
387
|
-
return failed;
|
|
298
|
+
failInterruptedOperations() {
|
|
299
|
+
const interrupted = this.readAllOperations().filter((operation) => operation.status === "running");
|
|
300
|
+
return interrupted.map((operation) => {
|
|
301
|
+
if (operation.workDir)
|
|
302
|
+
fs.rmSync(operation.workDir, { recursive: true, force: true });
|
|
303
|
+
return this.updateOperation(operation.id, (current) => ({
|
|
304
|
+
...current,
|
|
305
|
+
status: "failed",
|
|
306
|
+
error: "Interrupted: the server stopped while this operation ran.",
|
|
307
|
+
steps: Object.fromEntries(Object.entries(current.steps).map(([name, state]) => [name, state === "running" ? "failed" : state])),
|
|
308
|
+
workDir: null,
|
|
309
|
+
}));
|
|
388
310
|
});
|
|
389
311
|
}
|
|
390
312
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Nouvelle clé de coffre : 32 octets aléatoires, en base64. */
|
|
2
|
+
export declare function generateVaultKey(): string;
|
|
3
|
+
/** Décode VAULT_KEY ; lève une erreur qui dit comment en obtenir une valide. */
|
|
4
|
+
export declare function parseVaultKey(raw: string | undefined): Buffer;
|
|
5
|
+
/** Chiffre en AES-256-GCM : `v1:<iv>:<tag>:<chiffré>`, chaque partie en base64. */
|
|
6
|
+
export declare function encryptSecret(plaintext: string, key: Buffer): string;
|
|
7
|
+
/** Vrai pour une valeur au format de `encryptSecret`. */
|
|
8
|
+
export declare function isEncrypted(value: string): boolean;
|
|
9
|
+
/** Déchiffre un secret produit par `encryptSecret` ; échoue si la clé n'est pas la bonne. */
|
|
10
|
+
export declare function decryptSecret(payload: string, key: Buffer): string;
|