datasquirel/package-shared/utils/backend/grabDbSSL.ts

30 lines
634 B
TypeScript
Raw Normal View History

2025-01-10 19:10:28 +00:00
import fs from "fs";
2024-11-07 14:28:28 +00:00
2025-01-10 19:10:28 +00:00
type Return =
| string
| (import("tls").SecureContextOptions & {
rejectUnauthorized?: boolean | undefined;
})
| undefined;
2024-11-07 14:28:28 +00:00
/**
2025-01-10 19:10:28 +00:00
* # Grall SSL
2024-11-07 14:28:28 +00:00
*/
2025-01-10 19:10:28 +00:00
export default function grabDbSSL(): Return {
2024-11-07 14:28:28 +00:00
const SSL_DIR = process.env.DSQL_SSL_DIR;
2024-11-08 19:15:37 +00:00
if (!SSL_DIR?.match(/./)) {
return undefined;
}
2024-11-07 14:28:28 +00:00
const caFilePath = `${SSL_DIR}/ca-cert.pem`;
2024-11-08 19:15:37 +00:00
2024-11-07 14:28:28 +00:00
if (!fs.existsSync(caFilePath)) {
console.log(`${caFilePath} does not exist`);
return undefined;
}
return {
ca: fs.readFileSync(`${SSL_DIR}/ca-cert.pem`),
};
2025-01-10 19:10:28 +00:00
}