Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make project backup script auth-aware #1838

Merged
merged 2 commits into from
Nov 28, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions backup.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import path from "path";
import net from "net";

// Expected arguments: first arg is project ID (5dbf805650b51914727e06c4) or URL (http://localhost:8080/app/lexicon/5dbf805650b51914727e06c4)
// Second arg is "qa" or "staging" to copy from staging, "live" or "prod" or "production" to copy from production
// Second arg is the mongodb password of the selected environment
// Third arg is "qa" or "staging" to copy from staging, "live" or "prod" or "production" to copy from production
// NOTE: You must edit the context names below if they don't match the context names you have (see `kubectl config get-contexts` output)

// ===== EDIT THIS =====
Expand Down Expand Up @@ -107,8 +108,10 @@ if (!contexts.includes(prodContext)) {

// Process args

if (process.argv.length < 3) {
console.warn("Please pass project ID or URL as argument, e.g. node backup.mjs 5dbf805650b51914727e06c4");
if (process.argv.length < 4) {
console.warn(
"Please pass project ID or URL and MongoDB password as arguments, e.g. node backup.mjs 5dbf805650b51914727e06c4 pass",
);
process.exit(2);
}

Expand All @@ -128,8 +131,8 @@ if (URL.canParse(arg)) {
let context = defaultContext;
let contextName = defaultContextName;

if (process.argv.length > 3) {
const env = process.argv[3];
if (process.argv.length > 4) {
const env = process.argv[4];
switch (env) {
case "qa":
context = stagingContext;
Expand Down Expand Up @@ -209,7 +212,8 @@ console.warn("If that doesn't look right, hit Ctrl+C NOW");
await portForwardingPromise;
console.warn("Port forwarding is ready. Setting up remote Mongo connection...");

const remoteConnStr = `mongodb://localhost:${remoteMongoPort}`;
const pass = process.argv[3];
const remoteConnStr = `mongodb://lexbox:${pass}@localhost:${remoteMongoPort}`;
remoteConn = await MongoClient.connect(remoteConnStr);

console.warn("Remote Mongo connection established. Fetching project record...");
Expand Down
Loading