* feat: file-based provisionning of volumes and repos docs: provisioning example chore: ui improvements * chore: ci issues
47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
import type { BackendConfig } from "~/schemas/volumes";
|
|
import { cryptoUtils } from "~/server/utils/crypto";
|
|
|
|
type SecretTransformer = (value: string) => Promise<string>;
|
|
|
|
const transformOptionalSecret = async (
|
|
value: string | undefined,
|
|
transformSecret: SecretTransformer,
|
|
): Promise<string | undefined> => {
|
|
if (!value) {
|
|
return value;
|
|
}
|
|
|
|
return await transformSecret(value);
|
|
};
|
|
|
|
export const mapVolumeConfigSecrets = async (
|
|
config: BackendConfig,
|
|
transformSecret: SecretTransformer,
|
|
): Promise<BackendConfig> => {
|
|
switch (config.backend) {
|
|
case "smb":
|
|
return {
|
|
...config,
|
|
password: await transformOptionalSecret(config.password, transformSecret),
|
|
};
|
|
case "webdav":
|
|
return {
|
|
...config,
|
|
password: await transformOptionalSecret(config.password, transformSecret),
|
|
};
|
|
case "sftp":
|
|
return {
|
|
...config,
|
|
password: await transformOptionalSecret(config.password, transformSecret),
|
|
privateKey: await transformOptionalSecret(config.privateKey, transformSecret),
|
|
};
|
|
case "nfs":
|
|
case "directory":
|
|
case "rclone":
|
|
return config;
|
|
}
|
|
};
|
|
|
|
export const encryptVolumeConfig = async (config: BackendConfig): Promise<BackendConfig> => {
|
|
return await mapVolumeConfigSecrets(config, cryptoUtils.sealSecret);
|
|
};
|