Updates
This commit is contained in:
@@ -1,30 +0,0 @@
|
||||
import grabDSQLConnection from "../../grab-dsql-connection";
|
||||
|
||||
/**
|
||||
* # DSQL user read-only DB handler
|
||||
* @requires DSQL_DB_CONN - Gobal Variable for Datasquirel Database
|
||||
*/
|
||||
export default async function DB_HANDLER(query: string, values?: any[]) {
|
||||
const CONNECTION = await grabDSQLConnection();
|
||||
|
||||
try {
|
||||
if (!CONNECTION)
|
||||
throw new Error("No Connection provided to DB_HANDLER function!");
|
||||
|
||||
const results = await CONNECTION.query(query, values);
|
||||
|
||||
if (Array.isArray(results)) {
|
||||
return Array.from(results);
|
||||
} else {
|
||||
return results;
|
||||
}
|
||||
} catch (error: any) {
|
||||
global.ERROR_CALLBACK?.(`DB_HANDLER Error`, error as Error);
|
||||
return {
|
||||
success: false,
|
||||
error: error.message,
|
||||
};
|
||||
} finally {
|
||||
await CONNECTION?.end();
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
import connDbHandler from "../../db/conn-db-handler";
|
||||
import grabDSQLConnection from "../../grab-dsql-connection";
|
||||
|
||||
type Param = {
|
||||
paradigm: "Full Access" | "FA" | "Read Only";
|
||||
queryString: string;
|
||||
queryValues?: string[];
|
||||
};
|
||||
|
||||
/**
|
||||
* # DSQL user read-only DB handler
|
||||
*/
|
||||
export default async function DSQL_USER_DB_HANDLER({
|
||||
paradigm,
|
||||
queryString,
|
||||
queryValues,
|
||||
}: Param) {
|
||||
const CONNECTION =
|
||||
paradigm == "Read Only"
|
||||
? await grabDSQLConnection({ ro: true })
|
||||
: await grabDSQLConnection({ fa: true });
|
||||
|
||||
try {
|
||||
return await connDbHandler(CONNECTION, queryString, queryValues);
|
||||
} catch (error: any) {
|
||||
global.ERROR_CALLBACK?.(`DSQL_USER_DB_HANDLER Error`, error as Error);
|
||||
return null;
|
||||
} finally {
|
||||
await CONNECTION?.end();
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
import grabDSQLConnection from "../../grab-dsql-connection";
|
||||
|
||||
/**
|
||||
* # DSQL user read-only DB handler
|
||||
*/
|
||||
export default async function LOCAL_DB_HANDLER(query: string, values?: any[]) {
|
||||
const CONNECTION = await grabDSQLConnection();
|
||||
|
||||
try {
|
||||
const results = await CONNECTION.query(query, values);
|
||||
|
||||
if (Array.isArray(results)) {
|
||||
return Array.from(results);
|
||||
} else {
|
||||
return results;
|
||||
}
|
||||
} catch (error: any) {
|
||||
global.ERROR_CALLBACK?.(`LOCAL_DB_HANDLER Error`, error as Error);
|
||||
return {
|
||||
success: false,
|
||||
error: error.message,
|
||||
};
|
||||
} finally {
|
||||
await CONNECTION?.end();
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
import grabDSQLConnection from "../../grab-dsql-connection";
|
||||
|
||||
/**
|
||||
* # DSQL user read-only DB handler
|
||||
*/
|
||||
export default async function NO_DB_HANDLER(query: string, values?: any[]) {
|
||||
const CONNECTION = await grabDSQLConnection();
|
||||
|
||||
try {
|
||||
return new Promise((resolve, reject) => {
|
||||
CONNECTION.query(query, values)
|
||||
.then(async (results) => {
|
||||
if (Array.isArray(results)) {
|
||||
resolve(Array.from(results));
|
||||
} else {
|
||||
resolve(results);
|
||||
}
|
||||
})
|
||||
.catch(async (err) => {
|
||||
resolve({
|
||||
error: err.message,
|
||||
sql: err.sql,
|
||||
});
|
||||
})
|
||||
.finally(async () => {
|
||||
await CONNECTION?.end();
|
||||
});
|
||||
});
|
||||
} catch (error: any) {
|
||||
global.ERROR_CALLBACK?.(`NO_DB_HANDLER Error`, error as Error);
|
||||
return {
|
||||
success: false,
|
||||
error: error.message,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -8,20 +8,21 @@ type Return = ConnectionConfig["ssl"] | undefined;
|
||||
* # Grab SSL
|
||||
*/
|
||||
export default function grabDbSSL(): Return {
|
||||
const { maxscaleSSLDir } = grabDirNames();
|
||||
if (!maxscaleSSLDir?.match(/./)) {
|
||||
const { maxscaleSSLCaCertFile } = grabDirNames();
|
||||
|
||||
const caFilePath = process.env.DSQL_SSL_CA_CERT || maxscaleSSLCaCertFile;
|
||||
|
||||
if (!caFilePath?.match(/./)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const caFilePath = `${maxscaleSSLDir}/ca-cert.pem`;
|
||||
|
||||
if (!fs.existsSync(caFilePath)) {
|
||||
console.log(`${caFilePath} does not exist`);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return {
|
||||
ca: fs.readFileSync(`${maxscaleSSLDir}/ca-cert.pem`),
|
||||
ca: fs.readFileSync(caFilePath),
|
||||
rejectUnauthorized: false,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -27,10 +27,7 @@ export default async function importMariadbDatabase({
|
||||
const finalMariadbHost = mariadbHost || process.env.DSQL_DB_HOST;
|
||||
const finalMariadbPass = mariadbPass || process.env.DSQL_DB_PASSWORD;
|
||||
|
||||
await connDbHandler(
|
||||
global.DSQL_DB_CONN,
|
||||
`CREATE DATABASE IF NOT EXISTS ${dbFullName}`
|
||||
);
|
||||
await connDbHandler(null, `CREATE DATABASE IF NOT EXISTS ${dbFullName}`);
|
||||
|
||||
const cmd = `${mysqlPath} -u ${finalMariadbUser} -h ${finalMariadbHost} -p"${finalMariadbPass}" ${dbFullName} < ${targetFilePath}`;
|
||||
|
||||
|
||||
@@ -45,11 +45,43 @@ export default function grabDirNames(param?: Param) {
|
||||
const appSSLDir = path.join(appDir, "ssl");
|
||||
const mainSSLDir = path.join(DATA_DIR, "ssl");
|
||||
|
||||
const installScriptFile = path.join(
|
||||
appDir,
|
||||
"scripts",
|
||||
"shell",
|
||||
"installation",
|
||||
"install.sh"
|
||||
);
|
||||
const updateScriptFile = path.join(
|
||||
appDir,
|
||||
"scripts",
|
||||
"shell",
|
||||
"installation",
|
||||
"update.sh"
|
||||
);
|
||||
|
||||
const installTypescriptFile = path.join(
|
||||
appDir,
|
||||
"scripts",
|
||||
"shell",
|
||||
"installation",
|
||||
"install.ts"
|
||||
);
|
||||
const updateTypescriptFile = path.join(
|
||||
appDir,
|
||||
"scripts",
|
||||
"shell",
|
||||
"installation",
|
||||
"update.ts"
|
||||
);
|
||||
|
||||
const maxscaleSSLDir = path.join(mainSSLDir, "maxscale");
|
||||
const mainDBSSLDir = path.join(mainSSLDir, "main");
|
||||
const replica1DBSSLDir = path.join(mainSSLDir, "replica-1");
|
||||
const replica2DBSSLDir = path.join(mainSSLDir, "replica-2");
|
||||
|
||||
const maxscaleSSLCaCertFile = path.join(maxscaleSSLDir, "ca-cert.pem");
|
||||
|
||||
const privateDataDir = path.join(DATA_DIR, "private");
|
||||
|
||||
/**
|
||||
@@ -158,15 +190,32 @@ export default function grabDirNames(param?: Param) {
|
||||
|
||||
let dockerComposeFile = path.join(appDir, "docker-compose.yml");
|
||||
let dockerComposeFileAlt = path.join(appDir, "docker-compose.yaml");
|
||||
const dbDockerComposeFileName = "db.docker-compose.yml";
|
||||
const dbDockerComposeFileNameAlt = "db.docker-compose.yaml";
|
||||
const dsqlDockerComposeFileName = "dsql.docker-compose.yml";
|
||||
const dsqlDockerComposeFileNameAlt = "dsql.docker-compose.yaml";
|
||||
const dsqlDbDockerComposeFileName = "dsql-db.docker-compose.yml";
|
||||
const dsqlDbDockerComposeFileNameAlt = "dsql-db.docker-compose.yaml";
|
||||
|
||||
const dsqlDockerComposeFile = path.join(appDir, dsqlDockerComposeFileName);
|
||||
const dsqlDockerComposeFileAlt = path.join(
|
||||
appDir,
|
||||
dsqlDockerComposeFileNameAlt
|
||||
);
|
||||
const dbDockerComposeFile = path.join(appDir, "db.docker-compose.yml");
|
||||
const dbDockerComposeFileAlt = path.join(appDir, "db.docker-compose.yaml");
|
||||
const dbDockerComposeFile = path.join(appDir, dbDockerComposeFileName);
|
||||
const dbDockerComposeFileAlt = path.join(
|
||||
appDir,
|
||||
dbDockerComposeFileNameAlt
|
||||
);
|
||||
const dsqlDbDockerComposeFile = path.join(
|
||||
appDir,
|
||||
dsqlDbDockerComposeFileName
|
||||
);
|
||||
const dsqlDbDockerComposeFileAlt = path.join(
|
||||
appDir,
|
||||
dsqlDbDockerComposeFileNameAlt
|
||||
);
|
||||
|
||||
const extraDockerComposeFile = path.join(
|
||||
appDir,
|
||||
"extra.docker-compose.yml"
|
||||
@@ -282,6 +331,7 @@ export default function grabDirNames(param?: Param) {
|
||||
schemasBackupDirName,
|
||||
userMainShemaJSONFilePath,
|
||||
maxscaleSSLDir,
|
||||
maxscaleSSLCaCertFile,
|
||||
mainDBSSLDir,
|
||||
replica1DBSSLDir,
|
||||
replica2DBSSLDir,
|
||||
@@ -304,5 +354,13 @@ export default function grabDirNames(param?: Param) {
|
||||
distroEnterpriseExportTarName,
|
||||
communityDistroTempDir,
|
||||
communityDistroDir,
|
||||
installScriptFile,
|
||||
updateScriptFile,
|
||||
installTypescriptFile,
|
||||
updateTypescriptFile,
|
||||
dsqlDbDockerComposeFile,
|
||||
dsqlDbDockerComposeFileAlt,
|
||||
dsqlDbDockerComposeFileName,
|
||||
dsqlDbDockerComposeFileNameAlt,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import grabDockerResourceIPNumbers from "../../grab-docker-resource-ip-numbers";
|
||||
|
||||
export default function grabIPAddresses() {
|
||||
const globalIPPrefix = process.env.DSQL_NETWORK_IP_PREFIX || "172.72.0";
|
||||
|
||||
const {
|
||||
cron,
|
||||
db,
|
||||
@@ -19,6 +20,7 @@ export default function grabIPAddresses() {
|
||||
const maxScaleIP = `${globalIPPrefix}.${maxscale}`;
|
||||
const mainDBIP = `${globalIPPrefix}.${db}`;
|
||||
const webSocketIP = `${globalIPPrefix}.${websocket}`;
|
||||
const dbCronIP = `${globalIPPrefix}.${db_cron}`;
|
||||
const localHostIP = `${globalIPPrefix}.1`;
|
||||
|
||||
return {
|
||||
@@ -29,5 +31,6 @@ export default function grabIPAddresses() {
|
||||
localHostIP,
|
||||
globalIPPrefix,
|
||||
webSocketIP,
|
||||
dbCronIP,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -45,7 +45,6 @@ export default function parseCookies({
|
||||
|
||||
return cookieObject;
|
||||
} catch (error: any) {
|
||||
global.ERROR_CALLBACK?.(`Parse Cookies Error`, error as Error);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user