@twilio/plugin-microvisor
Version:
Interact with your Twilio Microvisor devices
73 lines (72 loc) • 3.02 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TwilioClientCommand = void 0;
const tslib_1 = require("tslib");
const { TwilioClientCommand } = require('@twilio/cli-core').baseCommands;
exports.TwilioClientCommand = TwilioClientCommand;
const core_1 = require("@oclif/core");
const { TwilioCliError } = require('@twilio/cli-core').services.error;
const { generateKeyPairSync } = require('node:crypto');
const fs = tslib_1.__importStar(require("fs"));
class MicrovisorDebugGenerateKeypair extends TwilioClientCommand {
async run() {
await super.run();
try {
const { publicKey, privateKey } = generateKeyPairSync('ec', {
namedCurve: 'prime256v1',
publicKeyEncoding: {
type: 'spki',
format: 'pem'
},
privateKeyEncoding: {
type: 'sec1',
format: 'pem',
}
});
var privateKeyFile = this.flags['debug-auth-privkey'];
if (fs.existsSync(privateKeyFile) && !this.flags.force)
throw new TwilioCliError(`${privateKeyFile} already exists (use --force)`);
try {
fs.writeFileSync(privateKeyFile, privateKey);
}
catch (err) {
this.logger.debug(err);
throw new TwilioCliError(`Failed to write ${privateKeyFile}`);
}
var publicKeyFile = this.flags['debug-auth-pubkey'];
if (fs.existsSync(publicKeyFile) && !this.flags.force)
throw new TwilioCliError(`${publicKeyFile} already exists (use --force)`);
try {
fs.writeFileSync(publicKeyFile, publicKey);
}
catch (err) {
this.logger.debug(err);
throw new TwilioCliError(`Failed to write ${publicKeyFile}`);
}
}
catch (err) {
if (err instanceof TwilioCliError) {
throw err;
}
else {
this.logger.debug(err);
throw new TwilioCliError("Failed to generate keypair");
}
}
}
async runCommand() {
return this.run();
}
}
exports.default = MicrovisorDebugGenerateKeypair;
MicrovisorDebugGenerateKeypair.flags = Object.assign({ 'debug-auth-privkey': core_1.Flags.string({
description: 'Private key output filename',
default: 'debug-private-key.pem'
}), 'debug-auth-pubkey': core_1.Flags.string({
description: 'Public key output filename',
default: 'debug-public-key.pem'
}), force: core_1.Flags.boolean({ char: 'f', default: false }) }, TwilioClientCommand.flags);
// output format doesnt make sense here, we provide logs raw
delete MicrovisorDebugGenerateKeypair.flags['cli-output-format'];
// nor does silent, the sole purpose of this command is output
delete MicrovisorDebugGenerateKeypair.flags.silent;