removed duplicate isencrypted check as its handled inside encrypt already
This commit is contained in:
parent
1de82fa863
commit
abe6eb79d8
3 changed files with 11 additions and 26 deletions
|
|
@ -38,42 +38,42 @@ async function encryptSensitiveFields(config: NotificationConfig): Promise<Notif
|
||||||
case "email":
|
case "email":
|
||||||
return {
|
return {
|
||||||
...config,
|
...config,
|
||||||
password: cryptoUtils.isEncrypted(config.password) ? config.password : await cryptoUtils.encrypt(config.password),
|
password: await cryptoUtils.encrypt(config.password),
|
||||||
};
|
};
|
||||||
case "slack":
|
case "slack":
|
||||||
return {
|
return {
|
||||||
...config,
|
...config,
|
||||||
webhookUrl: cryptoUtils.isEncrypted(config.webhookUrl) ? config.webhookUrl : await cryptoUtils.encrypt(config.webhookUrl),
|
webhookUrl: await cryptoUtils.encrypt(config.webhookUrl),
|
||||||
};
|
};
|
||||||
case "discord":
|
case "discord":
|
||||||
return {
|
return {
|
||||||
...config,
|
...config,
|
||||||
webhookUrl: cryptoUtils.isEncrypted(config.webhookUrl) ? config.webhookUrl : await cryptoUtils.encrypt(config.webhookUrl),
|
webhookUrl: await cryptoUtils.encrypt(config.webhookUrl),
|
||||||
};
|
};
|
||||||
case "gotify":
|
case "gotify":
|
||||||
return {
|
return {
|
||||||
...config,
|
...config,
|
||||||
token: cryptoUtils.isEncrypted(config.token) ? config.token : await cryptoUtils.encrypt(config.token),
|
token: await cryptoUtils.encrypt(config.token),
|
||||||
};
|
};
|
||||||
case "ntfy":
|
case "ntfy":
|
||||||
return {
|
return {
|
||||||
...config,
|
...config,
|
||||||
password: config.password ? (cryptoUtils.isEncrypted(config.password) ? config.password : await cryptoUtils.encrypt(config.password)) : undefined,
|
password: config.password ? await cryptoUtils.encrypt(config.password) : undefined,
|
||||||
};
|
};
|
||||||
case "pushover":
|
case "pushover":
|
||||||
return {
|
return {
|
||||||
...config,
|
...config,
|
||||||
apiToken: cryptoUtils.isEncrypted(config.apiToken) ? config.apiToken : await cryptoUtils.encrypt(config.apiToken),
|
apiToken: await cryptoUtils.encrypt(config.apiToken),
|
||||||
};
|
};
|
||||||
case "telegram":
|
case "telegram":
|
||||||
return {
|
return {
|
||||||
...config,
|
...config,
|
||||||
botToken: cryptoUtils.isEncrypted(config.botToken) ? config.botToken : await cryptoUtils.encrypt(config.botToken),
|
botToken: await cryptoUtils.encrypt(config.botToken),
|
||||||
};
|
};
|
||||||
case "custom":
|
case "custom":
|
||||||
return {
|
return {
|
||||||
...config,
|
...config,
|
||||||
shoutrrrUrl: cryptoUtils.isEncrypted(config.shoutrrrUrl) ? config.shoutrrrUrl : await cryptoUtils.encrypt(config.shoutrrrUrl),
|
shoutrrrUrl: await cryptoUtils.encrypt(config.shoutrrrUrl),
|
||||||
};
|
};
|
||||||
default:
|
default:
|
||||||
return config;
|
return config;
|
||||||
|
|
|
||||||
|
|
@ -18,42 +18,32 @@ const listRepositories = async () => {
|
||||||
const encryptConfig = async (config: RepositoryConfig): Promise<RepositoryConfig> => {
|
const encryptConfig = async (config: RepositoryConfig): Promise<RepositoryConfig> => {
|
||||||
const encryptedConfig: Record<string, string | boolean | number> = { ...config };
|
const encryptedConfig: Record<string, string | boolean | number> = { ...config };
|
||||||
|
|
||||||
if (config.customPassword && !cryptoUtils.isEncrypted(config.customPassword)) {
|
if (config.customPassword) {
|
||||||
encryptedConfig.customPassword = await cryptoUtils.encrypt(config.customPassword);
|
encryptedConfig.customPassword = await cryptoUtils.encrypt(config.customPassword);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (config.backend) {
|
switch (config.backend) {
|
||||||
case "s3":
|
case "s3":
|
||||||
case "r2":
|
case "r2":
|
||||||
if (!cryptoUtils.isEncrypted(config.accessKeyId)) {
|
|
||||||
encryptedConfig.accessKeyId = await cryptoUtils.encrypt(config.accessKeyId);
|
encryptedConfig.accessKeyId = await cryptoUtils.encrypt(config.accessKeyId);
|
||||||
}
|
|
||||||
if (!cryptoUtils.isEncrypted(config.secretAccessKey)) {
|
|
||||||
encryptedConfig.secretAccessKey = await cryptoUtils.encrypt(config.secretAccessKey);
|
encryptedConfig.secretAccessKey = await cryptoUtils.encrypt(config.secretAccessKey);
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case "gcs":
|
case "gcs":
|
||||||
if (!cryptoUtils.isEncrypted(config.credentialsJson)) {
|
|
||||||
encryptedConfig.credentialsJson = await cryptoUtils.encrypt(config.credentialsJson);
|
encryptedConfig.credentialsJson = await cryptoUtils.encrypt(config.credentialsJson);
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case "azure":
|
case "azure":
|
||||||
if (!cryptoUtils.isEncrypted(config.accountKey)) {
|
|
||||||
encryptedConfig.accountKey = await cryptoUtils.encrypt(config.accountKey);
|
encryptedConfig.accountKey = await cryptoUtils.encrypt(config.accountKey);
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case "rest":
|
case "rest":
|
||||||
if (config.username && !cryptoUtils.isEncrypted(config.username)) {
|
if (config.username) {
|
||||||
encryptedConfig.username = await cryptoUtils.encrypt(config.username);
|
encryptedConfig.username = await cryptoUtils.encrypt(config.username);
|
||||||
}
|
}
|
||||||
if (config.password && !cryptoUtils.isEncrypted(config.password)) {
|
if (config.password) {
|
||||||
encryptedConfig.password = await cryptoUtils.encrypt(config.password);
|
encryptedConfig.password = await cryptoUtils.encrypt(config.password);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "sftp":
|
case "sftp":
|
||||||
if (!cryptoUtils.isEncrypted(config.privateKey)) {
|
|
||||||
encryptedConfig.privateKey = await cryptoUtils.encrypt(config.privateKey);
|
encryptedConfig.privateKey = await cryptoUtils.encrypt(config.privateKey);
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,6 @@ const algorithm = "aes-256-gcm" as const;
|
||||||
const keyLength = 32;
|
const keyLength = 32;
|
||||||
const encryptionPrefix = "encv1";
|
const encryptionPrefix = "encv1";
|
||||||
|
|
||||||
const isEncrypted = (val?: string): boolean => {
|
|
||||||
return typeof val === "string" && val.startsWith(encryptionPrefix);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given a string, encrypts it using a randomly generated salt
|
* Given a string, encrypts it using a randomly generated salt
|
||||||
*/
|
*/
|
||||||
|
|
@ -62,5 +58,4 @@ const decrypt = async (encryptedData: string) => {
|
||||||
export const cryptoUtils = {
|
export const cryptoUtils = {
|
||||||
encrypt,
|
encrypt,
|
||||||
decrypt,
|
decrypt,
|
||||||
isEncrypted,
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue