fix(repo): add a custom key after creation with the configured hostname (#583)
Closes #456
This commit is contained in:
parent
30f237dc1f
commit
3113af8ce8
2 changed files with 49 additions and 0 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in a new issue