fix(repo): add a custom key after creation with the configured hostname (#583)

Closes #456
This commit is contained in:
Nico 2026-02-26 19:46:25 +01:00 committed by GitHub
parent 30f237dc1f
commit 3113af8ce8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 49 additions and 0 deletions

View file

@ -6,6 +6,7 @@
- If you realize an automated migration is incorrect, make sure to remove all the associated entries from the `_journal.json` and the newly created files located in `app/drizzle/` before re-generating the migration
- The dev server is running at http://localhost:3000. Username is `admin` and password is `password`
- The repo is https://github.com/nicotsx/zerobyte
- If you need to run a specific restic command on a repository, you can open and use the dev panel with `Meta+Shift+D`
## Project Overview

View file

@ -235,6 +235,41 @@ export const buildEnv = async (config: RepositoryConfig, organizationId: string)
return env;
};
const keyAdd = async (
config: RepositoryConfig,
organizationId: string,
options: { host: string; timeoutMs?: number },
) => {
const repoUrl = buildRepoUrl(config);
logger.info(`Adding restic key with host "${options.host}" for repository at ${repoUrl}...`);
const env = await buildEnv(config, organizationId);
const args = [
"key",
"add",
"--repo",
repoUrl,
"--host",
options.host,
"--new-password-file",
env.RESTIC_PASSWORD_FILE,
];
addCommonArgs(args, env, config);
const res = await safeExec({ command: "restic", args, env, timeout: options.timeoutMs ?? 60000 });
await cleanupTemporaryKeys(env);
if (res.exitCode !== 0) {
logger.error(`Restic key add failed: ${res.stderr}`);
return { success: false, error: res.stderr };
}
logger.info(`Restic key added with host "${options.host}" for repository: ${repoUrl}`);
return { success: true, error: null };
};
const init = async (config: RepositoryConfig, organizationId: string, options?: { timeoutMs?: number }) => {
const repoUrl = buildRepoUrl(config);
@ -254,6 +289,18 @@ const init = async (config: RepositoryConfig, organizationId: string, options?:
}
logger.info(`Restic repository initialized: ${repoUrl}`);
if (appConfig.resticHostname) {
const keyResult = await keyAdd(config, organizationId, {
host: appConfig.resticHostname,
timeoutMs: options?.timeoutMs,
});
if (!keyResult.success) {
logger.warn(`Repository initialized but failed to add key with hostname: ${keyResult.error}`);
}
}
return { success: true, error: null };
};
@ -1248,6 +1295,7 @@ export const addCommonArgs = (
export const restic = {
init,
keyAdd,
backup,
restore,
dump,