2022-10-13 21:54:29 +02:00
|
|
|
import { Logger } from '@nestjs/common';
|
2022-02-03 17:06:44 +01:00
|
|
|
import { ConfigModuleOptions } from '@nestjs/config';
|
|
|
|
import Joi from 'joi';
|
2022-10-23 23:54:54 +02:00
|
|
|
import { createSecretKey, generateKeySync } from 'node:crypto';
|
2022-10-13 21:54:29 +02:00
|
|
|
|
2022-10-23 23:54:54 +02:00
|
|
|
const jwtSecretValidator: Joi.CustomValidator<string> = (value) => {
|
|
|
|
const key = createSecretKey(value, 'base64');
|
|
|
|
const keySizeBits = (key.symmetricKeySize ?? 0) * 8;
|
2022-10-13 21:54:29 +02:00
|
|
|
|
|
|
|
if (keySizeBits < 128) {
|
2022-10-23 23:54:54 +02:00
|
|
|
const newKey = generateKeySync('hmac', { length: 256 }).export().toString('base64');
|
|
|
|
Logger.warn('The current JWT_SECRET key is insecure. It should be at least 128 bits long!');
|
|
|
|
Logger.warn(`Here is a new, securely generated key that you can use instead: ${newKey}`);
|
2022-10-13 21:54:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
2022-10-23 23:54:54 +02:00
|
|
|
};
|
2022-02-03 17:06:44 +01:00
|
|
|
|
2023-01-20 21:27:01 +01:00
|
|
|
const WHEN_DB_URL_SET = Joi.when('DB_URL', {
|
|
|
|
is: Joi.exist(),
|
|
|
|
then: Joi.string().optional(),
|
|
|
|
otherwise: Joi.string().required(),
|
|
|
|
});
|
|
|
|
|
2022-02-03 17:06:44 +01:00
|
|
|
export const immichAppConfig: ConfigModuleOptions = {
|
|
|
|
envFilePath: '.env',
|
|
|
|
isGlobal: true,
|
|
|
|
validationSchema: Joi.object({
|
|
|
|
NODE_ENV: Joi.string().required().valid('development', 'production', 'staging').default('development'),
|
2023-01-20 21:27:01 +01:00
|
|
|
DB_USERNAME: WHEN_DB_URL_SET,
|
|
|
|
DB_PASSWORD: WHEN_DB_URL_SET,
|
|
|
|
DB_DATABASE_NAME: WHEN_DB_URL_SET,
|
|
|
|
DB_URL: Joi.string().optional(),
|
2022-10-13 21:54:29 +02:00
|
|
|
JWT_SECRET: Joi.string().required().custom(jwtSecretValidator),
|
2022-09-23 04:50:05 +02:00
|
|
|
DISABLE_REVERSE_GEOCODING: Joi.boolean().optional().valid(true, false).default(false),
|
2022-10-23 23:54:54 +02:00
|
|
|
REVERSE_GEOCODING_PRECISION: Joi.number().optional().valid(0, 1, 2, 3).default(3),
|
2023-01-13 15:23:12 +01:00
|
|
|
LOG_LEVEL: Joi.string().optional().valid('simple', 'verbose', 'debug', 'log', 'warn', 'error').default('log'),
|
2022-02-03 17:06:44 +01:00
|
|
|
}),
|
|
|
|
};
|