Update oputil_ssh_key.js per feedback
This commit is contained in:
@@ -15,7 +15,7 @@ const getHelpFor = require('./oputil_help.js').getHelpFor;
|
|||||||
|
|
||||||
// deps
|
// deps
|
||||||
const async = require('async');
|
const async = require('async');
|
||||||
const fs = require('graceful-fs');
|
const fs = require('fs-extra');
|
||||||
const exec = require('child_process').exec;
|
const exec = require('child_process').exec;
|
||||||
const inq = require('inquirer');
|
const inq = require('inquirer');
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
@@ -47,8 +47,6 @@ const QUESTIONS = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function execute(ui, command) {
|
function execute(ui, command) {
|
||||||
ui.log.write("Ping!");
|
|
||||||
ui.log.write(command);
|
|
||||||
exec(
|
exec(
|
||||||
command,
|
command,
|
||||||
function (error, stdout, stderr) {
|
function (error, stdout, stderr) {
|
||||||
@@ -75,8 +73,6 @@ function execute(ui, command) {
|
|||||||
function createNew(cb) {
|
function createNew(cb) {
|
||||||
const ui = new inq.ui.BottomBar();
|
const ui = new inq.ui.BottomBar();
|
||||||
|
|
||||||
let sslPassword;
|
|
||||||
|
|
||||||
async.waterfall(
|
async.waterfall(
|
||||||
[
|
[
|
||||||
function init(callback) {
|
function init(callback) {
|
||||||
@@ -89,8 +85,8 @@ function createNew(cb) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get Answer Value
|
// Get Answer Value
|
||||||
sslPassword = answers.password;
|
const sslPassword = answers.password.trim();
|
||||||
if (!sslPassword || sslPassword.replaceAll(" ", "") == "") {
|
if (!sslPassword || sslPassword == "") {
|
||||||
ui.log.write('Password must be set.');
|
ui.log.write('Password must be set.');
|
||||||
|
|
||||||
return callback('exit');
|
return callback('exit');
|
||||||
@@ -106,31 +102,16 @@ function createNew(cb) {
|
|||||||
const sshKeyFilename = "ssh_private_key.pem";
|
const sshKeyFilename = "ssh_private_key.pem";
|
||||||
const targetKeyFile = sshKeyPath + sshKeyFilename;
|
const targetKeyFile = sshKeyPath + sshKeyFilename;
|
||||||
|
|
||||||
// Check if Keyfile Exists
|
|
||||||
if (fs.existsSync(targetKeyFile)) {
|
|
||||||
ui.log.write(`${targetKeyFile} already exists.`)
|
|
||||||
|
|
||||||
return callback('exit');
|
|
||||||
}
|
|
||||||
|
|
||||||
ui.log.write(`Creating SSH Key: ${targetKeyFile}`);
|
ui.log.write(`Creating SSH Key: ${targetKeyFile}`);
|
||||||
|
|
||||||
// Create Dir
|
// Create Dir
|
||||||
if (!fs.existsSync(sshKeyPath)) {
|
if (!fs.pathExists(sshKeyPath)) {
|
||||||
ui.log.write(`Creating Directory: ${sshKeyPath}`);
|
ui.log.write(`Creating Directory: ${sshKeyPath}`);
|
||||||
exec(`mkdir -p ${sshKeyPath}`);
|
exec(`mkdir -p ${sshKeyPath}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if OpenSSL binary is installed
|
|
||||||
const binaryPath = "/usr/bin/openssl";
|
|
||||||
if (!fs.existsSync(binaryPath)) {
|
|
||||||
ui.log.write(`${binaryPath} was not found in your path`);
|
|
||||||
|
|
||||||
return callback('exit');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create SSH Keys
|
// Create SSH Keys
|
||||||
const command = `${binaryPath} genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -pkeyopt rsa_keygen_pubexp:65537 | openssl rsa -out ./${targetKeyFile} -aes128 -traditional -passout pass:`;
|
const command = `openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -pkeyopt rsa_keygen_pubexp:65537 | openssl rsa -out ./${targetKeyFile} -aes128 -traditional -passout pass:`;
|
||||||
execute(ui, `${command}${sslPassword}`);
|
execute(ui, `${command}${sslPassword}`);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user