datasquirel/package-shared/utils/backend/grabDbSSL.ts
2025-01-10 20:10:28 +01:00

30 lines
634 B
TypeScript

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