From 6516e0dfd24508b838ba184c5015fbb42f6e6012 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Wed, 10 Jan 2018 17:37:41 +0000 Subject: [PATCH] Allow a user to pick existing sshkeys from ~/.ssh --- editor/js/ui/projects/projectUserSettings.js | 258 ++++++++++++------ editor/js/ui/projects/projects.js | 8 +- editor/sass/projects.scss | 9 + editor/sass/userSettings.scss | 6 +- red/api/editor/sshkeys.js | 2 +- .../localfilesystem/projects/Project.js | 4 +- .../storage/localfilesystem/sshkeys.js | 62 +++-- .../storage/localfilesystem/sshkeys_spec.js | 50 ++-- 8 files changed, 268 insertions(+), 131 deletions(-) diff --git a/editor/js/ui/projects/projectUserSettings.js b/editor/js/ui/projects/projectUserSettings.js index 021d47736..a4501bb0f 100644 --- a/editor/js/ui/projects/projectUserSettings.js +++ b/editor/js/ui/projects/projectUserSettings.js @@ -44,32 +44,44 @@ RED.projects.userSettings = (function() { function createSSHKeySection(pane) { var container = $('
').appendTo(pane); var popover; - var title = $('

').text("SSH Keys").appendTo(container); + var title = $('

').text("SSH Keys").appendTo(container); + var subtitle = $('
').appendTo(container).text("Allows you to create secure connections to remote git repositories."); - var addKeyButton = $('') - .appendTo(title) + var addKeyButton = $('') + .appendTo(subtitle) .click(function(evt) { addKeyButton.attr('disabled',true); + saveButton.attr('disabled',true); + // bg.children().removeClass("selected"); + // addLocalButton.click(); addKeyDialog.slideDown(200); keyNameInput.focus(); - saveButton.attr('disabled',true); }); var validateForm = function() { - var validName = /^[a-zA-Z0-9\-_]+$/.test(keyNameInput.val()); - var passphrase = passphraseInput.val(); - var validPassphrase = passphrase.length === 0 || passphrase.length >= 8; + var valid = /^[a-zA-Z0-9\-_]+$/.test(keyNameInput.val()); + keyNameInput.toggleClass('input-error',keyNameInputChanged&&!valid); - saveButton.attr('disabled',!validName || !validPassphrase); - keyNameInput.toggleClass('input-error',keyNameInputChanged&&!validName); - passphraseInput.toggleClass('input-error',!validPassphrase); - if (!validPassphrase) { - passphraseInputSubLabel.text("Passphrase too short"); - } else if (passphrase.length === 0) { - passphraseInputSubLabel.text("Optional"); - } else { - passphraseInputSubLabel.text(""); - } + // var selectedButton = bg.find(".selected"); + // if (selectedButton[0] === addLocalButton[0]) { + // valid = valid && localPublicKeyPathInput.val().length > 0 && localPrivateKeyPathInput.val().length > 0; + // } else if (selectedButton[0] === uploadButton[0]) { + // valid = valid && publicKeyInput.val().length > 0 && privateKeyInput.val().length > 0; + // } else if (selectedButton[0] === generateButton[0]) { + var passphrase = passphraseInput.val(); + var validPassphrase = passphrase.length === 0 || passphrase.length >= 8; + passphraseInput.toggleClass('input-error',!validPassphrase); + if (!validPassphrase) { + passphraseInputSubLabel.text("Passphrase too short"); + } else if (passphrase.length === 0) { + passphraseInputSubLabel.text("Optional"); + } else { + passphraseInputSubLabel.text(""); + } + valid = valid && validPassphrase; + // } + + saveButton.attr('disabled',!valid); if (popover) { popover.close(); @@ -79,27 +91,88 @@ RED.projects.userSettings = (function() { var row = $('
').appendTo(container); var addKeyDialog = $('
').hide().appendTo(row); - $('
').text('Generate SSH Key').appendTo(addKeyDialog); + $('
').text('Add SSH Key').appendTo(addKeyDialog); var addKeyDialogBody = $('
').appendTo(addKeyDialog); + + row = $('').appendTo(addKeyDialogBody); + $('
').appendTo(row).text("Generate a new public/private key pair"); + // var bg = $('
',{class:"button-group", style:"text-align: center"}).appendTo(row); + // var addLocalButton = $('').appendTo(bg); + // var uploadButton = $('').appendTo(bg); + // var generateButton = $('').appendTo(bg); + // bg.children().click(function(e) { + // e.preventDefault(); + // if ($(this).hasClass("selected")) { + // return; + // } + // bg.children().removeClass("selected"); + // $(this).addClass("selected"); + // if (this === addLocalButton[0]) { + // addLocalKeyPane.show(); + // generateKeyPane.hide(); + // uploadKeyPane.hide(); + // } else if (this === uploadButton[0]) { + // addLocalKeyPane.hide(); + // generateKeyPane.hide(); + // uploadKeyPane.show(); + // } else if (this === generateButton[0]){ + // addLocalKeyPane.hide(); + // generateKeyPane.show(); + // uploadKeyPane.hide(); + // } + // validateForm(); + // }) + + row = $('').appendTo(addKeyDialogBody); $('').text('Name').appendTo(row); + var keyNameInputChanged = false; var keyNameInput = $('').appendTo(row).on("change keyup paste",function() { keyNameInputChanged = true; validateForm(); }); - var keyNameInputChanged = false; $('').appendTo(row).find("small"); - row = $('').appendTo(addKeyDialogBody); + var generateKeyPane = $('
').appendTo(addKeyDialogBody); + row = $('').appendTo(generateKeyPane); $('').text('Passphrase').appendTo(row); - passphraseInput = $('').appendTo(row).on("change keyup paste",validateForm); + var passphraseInput = $('').appendTo(row).on("change keyup paste",validateForm); var passphraseInputSubLabel = $('').appendTo(row).find("small"); + // var addLocalKeyPane = $('
').hide().appendTo(addKeyDialogBody); + // row = $('').appendTo(addLocalKeyPane); + // $('').text('Public key').appendTo(row); + // var localPublicKeyPathInput = $('').appendTo(row).on("change keyup paste",validateForm); + // $('').appendTo(row).find("small"); + // row = $('').appendTo(addLocalKeyPane); + // $('').text('Private key').appendTo(row); + // var localPrivateKeyPathInput = $('').appendTo(row).on("change keyup paste",validateForm); + // $('').appendTo(row).find("small"); + // + // var uploadKeyPane = $('
').hide().appendTo(addKeyDialogBody); + // row = $('').appendTo(uploadKeyPane); + // $('').text('Public key').appendTo(row); + // var publicKeyInput = $('