No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

database-instances-list.js 3.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.command = void 0;
  4. const command_1 = require("../command");
  5. const Table = require("cli-table");
  6. const clc = require("colorette");
  7. const ora = require("ora");
  8. const logger_1 = require("../logger");
  9. const requirePermissions_1 = require("../requirePermissions");
  10. const projectUtils_1 = require("../projectUtils");
  11. const firedata = require("../gcp/firedata");
  12. const types_1 = require("../emulator/types");
  13. const commandUtils_1 = require("../emulator/commandUtils");
  14. const experiments = require("../experiments");
  15. const projectUtils_2 = require("../projectUtils");
  16. const database_1 = require("../management/database");
  17. function logInstances(instances) {
  18. if (instances.length === 0) {
  19. logger_1.logger.info(clc.bold("No database instances found."));
  20. return;
  21. }
  22. const tableHead = ["Database Instance Name", "Location", "Type", "State"];
  23. const table = new Table({ head: tableHead, style: { head: ["green"] } });
  24. instances.forEach((db) => {
  25. table.push([db.name, db.location, db.type, db.state]);
  26. });
  27. logger_1.logger.info(table.toString());
  28. }
  29. function logInstancesCount(count = 0) {
  30. if (count === 0) {
  31. return;
  32. }
  33. logger_1.logger.info("");
  34. logger_1.logger.info(`${count} database instance(s) total.`);
  35. }
  36. exports.command = new command_1.Command("database:instances:list")
  37. .description("list realtime database instances, optionally filtered by a specified location")
  38. .before(requirePermissions_1.requirePermissions, ["firebasedatabase.instances.list"])
  39. .before(commandUtils_1.warnEmulatorNotSupported, types_1.Emulators.DATABASE)
  40. .action(async (options) => {
  41. const location = (0, database_1.parseDatabaseLocation)(options.location, database_1.DatabaseLocation.ANY);
  42. const spinner = ora("Preparing the list of your Firebase Realtime Database instances" +
  43. `${location === database_1.DatabaseLocation.ANY ? "" : ` for location: ${location}`}`).start();
  44. let instances;
  45. if (experiments.isEnabled("rtdbmanagement")) {
  46. const projectId = (0, projectUtils_2.needProjectId)(options);
  47. try {
  48. instances = await (0, database_1.listDatabaseInstances)(projectId, location);
  49. }
  50. catch (err) {
  51. spinner.fail();
  52. throw err;
  53. }
  54. spinner.succeed();
  55. logInstances(instances);
  56. logInstancesCount(instances.length);
  57. return instances;
  58. }
  59. const projectNumber = await (0, projectUtils_1.needProjectNumber)(options);
  60. try {
  61. instances = await firedata.listDatabaseInstances(projectNumber);
  62. }
  63. catch (err) {
  64. spinner.fail();
  65. throw err;
  66. }
  67. spinner.succeed();
  68. for (const instance of instances) {
  69. logger_1.logger.info(instance.instance);
  70. }
  71. logger_1.logger.info(`Project ${options.project} has ${instances.length} database instances`);
  72. return instances;
  73. });
  74. if (experiments.isEnabled("rtdbmanagement")) {
  75. exports.command = exports.command.option("-l, --location <location>", "(optional) location for the database instance, defaults to us-central1");
  76. }