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

Reveal europe-west1 region for RTDB #2812

Merged
merged 16 commits into from
Nov 11, 2020
Merged
Show file tree
Hide file tree
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
Prev Previous commit
Next Next commit
Fix profiler, bring back flag for database:instances:list
  • Loading branch information
sarajmunjal committed Nov 11, 2020
commit 7a2dd6047da600ca375f9a6d30081f608afc320c
58 changes: 42 additions & 16 deletions src/commands/database-instances-list.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { Command } from "../command";
import Table = require("cli-table");
import * as clc from "cli-color";
import * as ora from "ora";

import logger = require("../logger");
import { requirePermissions } from "../requirePermissions";
import getProjectNumber = require("../getProjectNumber");
import firedata = require("../gcp/firedata");
import { Emulators } from "../emulator/types";
import { warnEmulatorNotSupported } from "../emulator/commandUtils";
import { previews } from "../previews";
import getProjectId = require("../getProjectId");
import {
listDatabaseInstances,
Expand All @@ -19,20 +23,27 @@ function logInstances(instances: DatabaseInstance[]): void {
logger.info(clc.bold("No database instances found."));
return;
}
const tableHead = ["Database Instance Name", "Location", "Type", "State"];
const table = new Table({ head: tableHead, style: { head: ["green"] } });
instances.forEach((db) => {
logger.info(db.name);
table.push([db.name, db.location, db.type, db.state]);
});

logger.info(table.toString());
}

const cmd = new Command("database:instances:list")
.option(
"-l, --location <location>",
"(optional) location for the database instance, defaults to us-central1"
)
function logInstancesCount(count = 0): void {
if (count === 0) {
return;
}
logger.info("");
logger.info(`${count} database instance(s) total.`);
}

let cmd = new Command("database:instances:list")
.description("list realtime database instances, optionally filtered by a specified location")
.before(requirePermissions, ["firebasedatabase.instances.list"])
.before(warnEmulatorNotSupported, Emulators.DATABASE)

.action(async (options: any) => {
const location = parseDatabaseLocation(options.location, DatabaseLocation.ANY);
const spinner = ora(
Expand All @@ -41,23 +52,38 @@ const cmd = new Command("database:instances:list")
).start();
let instances;

const projectId = getProjectId(options);
if (previews.rtdbmanagement) {
const projectId = getProjectId(options);
try {
instances = await listDatabaseInstances(projectId, location);
} catch (err) {
spinner.fail();
throw err;
}
spinner.succeed();
logInstances(instances);
logInstancesCount(instances.length);
return instances;
}
const projectNumber = await getProjectNumber(options);
try {
instances = await listDatabaseInstances(projectId, location);
instances = await firedata.listDatabaseInstances(projectNumber);
} catch (err) {
spinner.fail();
throw err;
}
spinner.succeed();
logInstances(instances);
// logInstancesCount(instances.length);
return instances;
logger.info(`Project ${options.project} has ${instances.length} database instances`);
return instances;

for (const instance of instances) {
logger.info(instance.instance);
}
logger.info(`Project ${options.project} has ${instances.length} database instances`);
return instances;
});

export default cmd;
if (previews.rtdbmanagement) {
cmd = cmd.option(
"-l, --location <location>",
"(optional) location for the database instance, defaults to us-central1"
);
}
export default cmd;
4 changes: 3 additions & 1 deletion src/previews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ interface PreviewFlags {
rtdbrules: boolean;
ext: boolean;
extdev: boolean;
rtdbmanagement: boolean;
}

export const previews: PreviewFlags = Object.assign(
Expand All @@ -13,6 +14,7 @@ export const previews: PreviewFlags = Object.assign(
rtdbrules: false,
ext: false,
extdev: false,
rtdbmanagement: false,
},
configstore.get("previews")
);
Expand All @@ -23,4 +25,4 @@ if (process.env.FIREBASE_CLI_PREVIEWS) {
set(previews, feature, true);
}
});
}
}
2 changes: 1 addition & 1 deletion src/profiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var responseToError = require("./responseToError");
const { realtimeOriginOrEmulatorOrCustomUrl } = require("./database/api");

module.exports = function(options) {
const origin = realtimeOriginOrEmulatorOrCustomUrl(options);
const origin = realtimeOriginOrEmulatorOrCustomUrl(options.instanceDetails.databaseUrl);
var url = utils.getDatabaseUrl(origin, options.instance, "/.settings/profile.json?");

var rl = readline.createInterface({
Expand Down