@catladder/cli
Version:
Panter cli tool for cloud CI/CD and DevOps
67 lines (66 loc) • 2.72 kB
JavaScript
;
var __importDefault = this && this.__importDefault || function (mod) {
return mod && mod.__esModule ? mod : {
"default": mod
};
};
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.commandMongoPortForward = void 0;
const defineCommand_1 = require("../../core/defineCommand");
const getProjectConfig_1 = require("../../config/getProjectConfig");
const portForward_1 = require("../../kubernetes/portForward");
const projects_1 = require("../../utils/projects");
const ensureCluster_1 = require("../../apps/cli/commands/project/utils/ensureCluster");
const utils_1 = require("../../apps/cli/commands/mongodb/utils");
const clipboardy_1 = __importDefault(require("clipboardy"));
const autocompletions_1 = require("../../apps/cli/commands/project/utils/autocompletions");
const availability_1 = require("../availability");
exports.commandMongoPortForward = (0, defineCommand_1.defineCommand)({
name: "project mongo port-forward",
description: "port forward to a mongodb",
group: "mongodb",
isAvailable: (0, availability_1.hasDeployType)("kubernetes"),
inputs: {
envComponent: {
type: "string",
message: "environment:component",
positional: true,
choices: async () => (0, autocompletions_1.envAndComponents)()
},
podName: {
type: "string",
message: "Which pod? 🤔",
choices: async ctx => (0, utils_1.getProjectMongodbAllPodsSortedWithLabel)(await ctx.get("envComponent"))
},
localPort: {
type: "number",
message: "Local port: ",
default: 30000
}
},
execute: async ctx => {
const envComponent = await ctx.get("envComponent");
await (0, ensureCluster_1.ensureCluster)(ctx, envComponent);
const namespace = await (0, projects_1.getProjectNamespace)(envComponent);
const podName = await ctx.get("podName");
const localPort = await ctx.get("localPort");
const {
env,
componentName
} = (0, getProjectConfig_1.parseChoice)(envComponent);
const envVars = await (0, getProjectConfig_1.getEnvVarsResolved)(ctx, env, componentName);
const MONGODB_ROOT_PASSWORD = envVars === null || envVars === void 0 ? void 0 : envVars.MONGODB_ROOT_PASSWORD;
const connectionUrl = `mongodb://root:${MONGODB_ROOT_PASSWORD}@localhost:${localPort}`;
clipboardy_1.default.writeSync(connectionUrl);
ctx.log("");
ctx.log("username: root");
ctx.log(`password: ${MONGODB_ROOT_PASSWORD}`);
ctx.log(`connection string: ${connectionUrl}`);
ctx.log("");
ctx.log("👆 connection string has been copied to your clipboard!");
ctx.log("");
return (0, portForward_1.startKubePortForward)(podName, localPort, 27017, namespace);
}
});