Skip to content

Commit 7fff094

Browse files
authored
Make project backup script auth-aware (#1838)
It looks like we added MongoDB auth right after the backup script was created, so it was missing this.
1 parent 85bf417 commit 7fff094

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

backup.mjs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import net from "net";
88
// Expected arguments: first arg is project ID (5dbf805650b51914727e06c4) or URL (http://localhost:8080/app/lexicon/5dbf805650b51914727e06c4)
99
// Second arg is "qa" or "staging" to copy from staging, "live" or "prod" or "production" to copy from production
1010
// NOTE: You must edit the context names below if they don't match the context names you have (see `kubectl config get-contexts` output)
11+
// A MONGO_PASS env var must be available for the selected environment
1112

1213
// ===== EDIT THIS =====
1314

@@ -112,12 +113,18 @@ if (process.argv.length < 3) {
112113
process.exit(2);
113114
}
114115

116+
const mongoPass = process.env.MONGO_PASS;
117+
if (!mongoPass) {
118+
console.warn("Please provide a MongoDB password in the MONGO_PASS environment variable");
119+
process.exit(2);
120+
}
121+
115122
let projId;
116123
const arg = process.argv[2];
117124
if (URL.canParse(arg)) {
118125
const url = new URL(arg);
119126
if (url.pathname.startsWith("/app/lexicon/")) {
120-
projId = url.pathname.substring("/app/lexicon/".length);
127+
projId = url.pathname.substring("/app/lexicon/".length).split("/")[0];
121128
} else {
122129
projId = url.pathname; // Will probably fail, but worth a try
123130
}
@@ -209,7 +216,7 @@ console.warn("If that doesn't look right, hit Ctrl+C NOW");
209216
await portForwardingPromise;
210217
console.warn("Port forwarding is ready. Setting up remote Mongo connection...");
211218

212-
const remoteConnStr = `mongodb://localhost:${remoteMongoPort}`;
219+
const remoteConnStr = `mongodb://admin:${mongoPass}@localhost:${remoteMongoPort}`;
213220
remoteConn = await MongoClient.connect(remoteConnStr);
214221

215222
console.warn("Remote Mongo connection established. Fetching project record...");

0 commit comments

Comments
 (0)