DB: Removed need for password and added docs

This commit is contained in:
Taso committed 2021-01-12 21:27:00 -05:00
1 parent 2b52612f65
commit c91d0729fb
3 files changed
+19 -12

No files matched your search

+10 -1
View File
@@ -4,7 +4,16 @@ The original repo for NPWD
TODO TODO
## Production Server Installation ### Production Server Installation
**Database**
NPWD uses its own database driver compatible with `mysql-async` and `ghmattimysql`'s connection string. If you
don't utilize these resources, ensure you have this set in your console.
```
set mysql_connection_string "server=127.0.0.1;database=es_extended;userid=user;password=pass"
```
### Configuration ### Configuration
+5 -6
View File
@@ -8,14 +8,13 @@ describe("parseSemiColonFormat", () => {
}); });
it("Correctly parses configuration options", () => { it("Correctly parses configuration options", () => {
const test = const test = "server=127.0.0.1;database=es_extended;userid=user;";
"server=127.0.0.1;database=es_extended;userid=user;password=pass";
const result = db.parseSemiColonFormat(test); const result = db.parseSemiColonFormat(test);
expect(result.server).toEqual("127.0.0.1"); expect(result.server).toEqual("127.0.0.1");
expect(result.database).toEqual("es_extended"); expect(result.database).toEqual("es_extended");
expect(result.userid).toEqual("user"); expect(result.userid).toEqual("user");
expect(result.password).toEqual("pass"); expect(result.password).toEqual(undefined);
}); });
}); });
@@ -80,9 +79,9 @@ describe("getUserId", () => {
}); });
describe("getPassword", () => { describe("getPassword", () => {
it("returns default", () => { // it("returns default", () => {
expect(() => db.getPassword({})).toThrowError(); // expect(() => db.getPassword({})).toThrowError();
}); // });
it("Correctly returns password", () => { it("Correctly returns password", () => {
expect(db.getPassword({ password: t })).toEqual(t); expect(db.getPassword({ password: t })).toEqual(t);
+4 -5
View File
@@ -15,7 +15,7 @@ export function parseSemiColonFormat(connectionString: string): Map {
const parts = connectionString.split(";"); const parts = connectionString.split(";");
if (parts.length === 1) { if (parts.length === 1) {
throw new Error( throw new Error(
`Connection string ${connectionString} is in the incorrect format.` `Connection string ${connectionString} is in the incorrect format. Please follow the README.`
); );
} }
@@ -59,13 +59,12 @@ export function getUserId(config: Map): string {
} }
/** /**
* Note: We are allowing no password as many FiveM servers love to not use one for an ungodly reason.
* allowed variable names: password | pwd * allowed variable names: password | pwd
* @param config - database config variables parsed from mysql_connection_string * @param config - database config variables parsed from mysql_connection_string
*/ */
export function getPassword(config: Map): string { export function getPassword(config: Map): string | undefined {
const password = config.password || config.pwd; const password = config.password || config.pwd;
if (!password) { if (!password) return undefined;
throw new Error("Password is a required field");
}
return password; return password;
} }