UI for Zipcoin Blue

list.js 3.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const tslib_1 = require("tslib");
  4. const chalk_1 = require("chalk");
  5. const cli_utils_1 = require("@ionic/cli-utils");
  6. const guards_1 = require("@ionic/cli-utils/guards");
  7. const command_1 = require("@ionic/cli-utils/lib/command");
  8. const base_1 = require("./base");
  9. let SSHListCommand = class SSHListCommand extends base_1.SSHBaseCommand {
  10. preRun() {
  11. return tslib_1.__awaiter(this, void 0, void 0, function* () {
  12. yield this.checkForOpenSSH();
  13. });
  14. }
  15. run(inputs, options) {
  16. return tslib_1.__awaiter(this, void 0, void 0, function* () {
  17. const { createFatalAPIFormat } = yield Promise.resolve().then(() => require('@ionic/cli-utils/lib/http'));
  18. const { columnar } = yield Promise.resolve().then(() => require('@ionic/cli-utils/lib/utils/format'));
  19. const { findHostSection, getConfigPath, isHostDirective, loadFromPath, } = yield Promise.resolve().then(() => require('@ionic/cli-utils/lib/ssh-config'));
  20. const token = yield this.env.session.getUserToken();
  21. const config = yield this.env.config.load();
  22. let activeFingerprint;
  23. let foundActiveKey = false;
  24. const sshConfigPath = getConfigPath();
  25. const conf = yield loadFromPath(sshConfigPath);
  26. const section = findHostSection(conf, yield this.env.config.getGitHost());
  27. if (section && section.config) {
  28. const [identityFile] = section.config.filter(line => {
  29. return isHostDirective(line) && line.param === 'IdentityFile';
  30. });
  31. if (isHostDirective(identityFile)) {
  32. const output = yield this.env.shell.run('ssh-keygen', ['-E', 'sha256', '-lf', identityFile.value], { showCommand: false, fatalOnError: false });
  33. activeFingerprint = output.trim().split(' ')[1];
  34. }
  35. }
  36. const { req } = yield this.env.client.make('GET', `/users/${config.user.id}/sshkeys`);
  37. req.set('Authorization', `Bearer ${token}`);
  38. const res = yield this.env.client.do(req);
  39. if (!guards_1.isSSHKeyListResponse(res)) {
  40. throw createFatalAPIFormat(req, res);
  41. }
  42. if (res.data.length === 0) {
  43. this.env.log.warn(`No SSH keys found. Use ${chalk_1.default.green('ionic ssh add')} to add keys to Ionic.`);
  44. return;
  45. }
  46. const keysMatrix = res.data.map(sshkey => {
  47. const data = [sshkey.fingerprint, sshkey.name, sshkey.annotation];
  48. if (sshkey.fingerprint === activeFingerprint) {
  49. foundActiveKey = true;
  50. return data.map(v => chalk_1.default.bold(v));
  51. }
  52. return data;
  53. });
  54. const table = columnar(keysMatrix, {
  55. columnHeaders: ['fingerprint', 'name', 'annotation'],
  56. });
  57. this.env.log.nl();
  58. if (foundActiveKey) {
  59. this.env.log.info(`The row in ${chalk_1.default.bold('bold')} is the key that this computer is using. To change, use ${chalk_1.default.green('ionic ssh use')}.\n`);
  60. }
  61. this.env.log.msg(table);
  62. this.env.log.nl();
  63. this.env.log.ok(`Showing ${chalk_1.default.bold(String(res.data.length))} SSH key${res.data.length === 1 ? '' : 's'}.`);
  64. this.env.log.nl();
  65. });
  66. }
  67. };
  68. SSHListCommand = tslib_1.__decorate([
  69. command_1.CommandMetadata({
  70. name: 'list',
  71. type: 'global',
  72. backends: [cli_utils_1.BACKEND_PRO],
  73. description: 'List your SSH public keys on Ionic',
  74. })
  75. ], SSHListCommand);
  76. exports.SSHListCommand = SSHListCommand;