35 lines
847 B
TypeScript
35 lines
847 B
TypeScript
import fs from "fs";
|
|
import grabDirNames from "./names/grab-dir-names";
|
|
import type { ConnectionConfig } from "mariadb";
|
|
|
|
type Return = ConnectionConfig["ssl"] | undefined;
|
|
|
|
/**
|
|
* # Grab SSL
|
|
*/
|
|
export default function grabDbSSL(): Return {
|
|
let maxscaleSSLCaCertFileFinal;
|
|
|
|
try {
|
|
const { maxscaleSSLCaCertFile } = grabDirNames();
|
|
maxscaleSSLCaCertFileFinal = maxscaleSSLCaCertFile;
|
|
} catch (error) {}
|
|
|
|
const caFilePath =
|
|
process.env.DSQL_SSL_CA_CERT || maxscaleSSLCaCertFileFinal;
|
|
|
|
if (!caFilePath?.match(/./)) {
|
|
return undefined;
|
|
}
|
|
|
|
if (!fs.existsSync(caFilePath)) {
|
|
console.log(`${caFilePath} does not exist`);
|
|
return undefined;
|
|
}
|
|
|
|
return {
|
|
ca: fs.readFileSync(caFilePath),
|
|
rejectUnauthorized: false,
|
|
};
|
|
}
|