delete.js 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. "use strict";
  2. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  3. if (k2 === undefined) k2 = k;
  4. var desc = Object.getOwnPropertyDescriptor(m, k);
  5. if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
  6. desc = { enumerable: true, get: function() { return m[k]; } };
  7. }
  8. Object.defineProperty(o, k2, desc);
  9. }) : (function(o, m, k, k2) {
  10. if (k2 === undefined) k2 = k;
  11. o[k2] = m[k];
  12. }));
  13. var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
  14. Object.defineProperty(o, "default", { enumerable: true, value: v });
  15. }) : function(o, v) {
  16. o["default"] = v;
  17. });
  18. var __importStar = (this && this.__importStar) || function (mod) {
  19. if (mod && mod.__esModule) return mod;
  20. var result = {};
  21. if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  22. __setModuleDefault(result, mod);
  23. return result;
  24. };
  25. Object.defineProperty(exports, "__esModule", { value: true });
  26. exports.SSHDeleteCommand = void 0;
  27. const cli_framework_1 = require("@ionic/cli-framework");
  28. const color_1 = require("../../lib/color");
  29. const base_1 = require("./base");
  30. class SSHDeleteCommand extends base_1.SSHBaseCommand {
  31. async getMetadata() {
  32. return {
  33. name: 'delete',
  34. type: 'global',
  35. summary: 'Delete an SSH public key from Ionic',
  36. inputs: [
  37. {
  38. name: 'key-id',
  39. summary: 'The ID of the public key to delete',
  40. validators: [cli_framework_1.validators.required],
  41. },
  42. ],
  43. groups: ["deprecated" /* MetadataGroup.DEPRECATED */],
  44. };
  45. }
  46. async preRun(inputs, options) {
  47. const { SSHKeyClient } = await Promise.resolve().then(() => __importStar(require('../../lib/ssh')));
  48. if (!inputs[0]) {
  49. const user = this.env.session.getUser();
  50. const token = await this.env.session.getUserToken();
  51. const sshkeyClient = new SSHKeyClient({ client: this.env.client, user, token });
  52. const paginator = sshkeyClient.paginate();
  53. const [r] = paginator;
  54. const res = await r;
  55. if (res.data.length === 0) {
  56. this.env.log.warn(`No SSH keys found. Use ${(0, color_1.input)('ionic ssh add')} to add keys to Ionic.`);
  57. }
  58. inputs[0] = await this.env.prompt({
  59. type: 'list',
  60. name: 'id',
  61. message: 'Which SSH keys would you like to delete from Ionic?',
  62. choices: res.data.map(key => ({
  63. name: `${key.fingerprint} ${key.name} ${key.annotation}`,
  64. value: key.id,
  65. })),
  66. });
  67. }
  68. }
  69. async run(inputs, options) {
  70. const { SSHKeyClient } = await Promise.resolve().then(() => __importStar(require('../../lib/ssh')));
  71. const [id] = inputs;
  72. const user = this.env.session.getUser();
  73. const token = await this.env.session.getUserToken();
  74. const sshkeyClient = new SSHKeyClient({ client: this.env.client, user, token });
  75. await sshkeyClient.delete(id);
  76. this.env.log.ok(`Your public key (${(0, color_1.strong)(id)}) has been removed from Ionic.`);
  77. }
  78. }
  79. exports.SSHDeleteCommand = SSHDeleteCommand;