mirror of
				https://github.com/node-red/node-red.git
				synced 2025-03-01 10:36:34 +00:00 
			
		
		
		
	Add better handling of host-key-verify error with projects
This commit is contained in:
		| @@ -977,7 +977,8 @@ | ||||
|             "passphrase": "Passphrase", | ||||
|             "retry": "Retry", | ||||
|             "update-failed": "Failed to update auth", | ||||
|             "unhandled": "Unhandled error response" | ||||
|             "unhandled": "Unhandled error response", | ||||
|             "host-key-verify-failed": "<p>Host key verification failed.</p><p>The repository host key could not be verified. Please update your <code>known_hosts</code> file and try again." | ||||
|         }, | ||||
|         "create-branch-list": { | ||||
|             "invalid": "Invalid branch", | ||||
|   | ||||
| @@ -1939,100 +1939,121 @@ RED.projects = (function() { | ||||
|             } | ||||
|         }).fail(function(xhr,textStatus,err) { | ||||
|             var responses; | ||||
|  | ||||
|             if (options.responses && options.responses[xhr.status]) { | ||||
|                 responses = options.responses[xhr.status]; | ||||
|                 if (typeof responses === 'function') { | ||||
|                     resultCallback = responses; | ||||
|                     resultCallbackArgs = {error:responses.statusText}; | ||||
|                     return; | ||||
|                 } else if (options.handleAuthFail !== false && xhr.responseJSON.code === 'git_auth_failed') { | ||||
|                     var url = activeProject.git.remotes[xhr.responseJSON.remote||options.remote||'origin'].fetch; | ||||
|                 } else if (options.handleAuthFail !== false && (xhr.responseJSON.code === 'git_auth_failed' || xhr.responseJSON.code === 'git_host_key_verification_failed')) { | ||||
|                     if (xhr.responseJSON.code === 'git_auth_failed') { | ||||
|                         var url = activeProject.git.remotes[xhr.responseJSON.remote||options.remote||'origin'].fetch; | ||||
|  | ||||
|                     var message = $('<div>'+ | ||||
|                         var message = $('<div>'+ | ||||
|                         '<div class="form-row">'+RED._("projects.send-req.auth-req")+':</div>'+ | ||||
|                         '<div class="form-row"><div style="margin-left: 20px;">'+url+'</div></div>'+ | ||||
|                         '</div>'); | ||||
|  | ||||
|                     var isSSH = false; | ||||
|                     if (/^https?:\/\//.test(url)) { | ||||
|                         $('<div class="form-row"><label for="projects-user-auth-username">'+RED._("projects.send-req.username")+'</label><input id="projects-user-auth-username" type="text"></input></div>'+ | ||||
|                           '<div class="form-row"><label for=projects-user-auth-password">'+RED._("projects.send-req.password")+'</label><input id="projects-user-auth-password" type="password"></input></div>').appendTo(message); | ||||
|                     } else if (/^(?:ssh|[\d\w\.\-_]+@[\w\.]+):(?:\/\/)?/.test(url)) { | ||||
|                         isSSH = true; | ||||
|                         var row = $('<div class="form-row"></div>').appendTo(message); | ||||
|                         $('<label for="projects-user-auth-key">SSH Key</label>').appendTo(row); | ||||
|                         var projectRepoSSHKeySelect = $('<select id="projects-user-auth-key">').width('70%').appendTo(row); | ||||
|                         $.getJSON("settings/user/keys", function(data) { | ||||
|                             var count = 0; | ||||
|                             data.keys.forEach(function(key) { | ||||
|                                 projectRepoSSHKeySelect.append($("<option></option>").val(key.name).text(key.name)); | ||||
|                                 count++; | ||||
|                         var isSSH = false; | ||||
|                         if (/^https?:\/\//.test(url)) { | ||||
|                             $('<div class="form-row"><label for="projects-user-auth-username">'+RED._("projects.send-req.username")+'</label><input id="projects-user-auth-username" type="text"></input></div>'+ | ||||
|                             '<div class="form-row"><label for=projects-user-auth-password">'+RED._("projects.send-req.password")+'</label><input id="projects-user-auth-password" type="password"></input></div>').appendTo(message); | ||||
|                         } else if (/^(?:ssh|[\d\w\.\-_]+@[\w\.]+):(?:\/\/)?/.test(url)) { | ||||
|                             isSSH = true; | ||||
|                             var row = $('<div class="form-row"></div>').appendTo(message); | ||||
|                             $('<label for="projects-user-auth-key">SSH Key</label>').appendTo(row); | ||||
|                             var projectRepoSSHKeySelect = $('<select id="projects-user-auth-key">').width('70%').appendTo(row); | ||||
|                             $.getJSON("settings/user/keys", function(data) { | ||||
|                                 var count = 0; | ||||
|                                 data.keys.forEach(function(key) { | ||||
|                                     projectRepoSSHKeySelect.append($("<option></option>").val(key.name).text(key.name)); | ||||
|                                     count++; | ||||
|                                 }); | ||||
|                                 if (count === 0) { | ||||
|                                     //TODO: handle no keys yet setup | ||||
|                                 } | ||||
|                             }); | ||||
|                             if (count === 0) { | ||||
|                                 //TODO: handle no keys yet setup | ||||
|                             } | ||||
|                         }); | ||||
|                         row = $('<div class="form-row"></div>').appendTo(message); | ||||
|                         $('<label for="projects-user-auth-passphrase">'+RED._("projects.send-req.passphrase")+'</label>').appendTo(row); | ||||
|                         $('<input id="projects-user-auth-passphrase" type="password"></input>').appendTo(row); | ||||
|                     } | ||||
|                             row = $('<div class="form-row"></div>').appendTo(message); | ||||
|                             $('<label for="projects-user-auth-passphrase">'+RED._("projects.send-req.passphrase")+'</label>').appendTo(row); | ||||
|                             $('<input id="projects-user-auth-passphrase" type="password"></input>').appendTo(row); | ||||
|                         } | ||||
|  | ||||
|                     var notification = RED.notify(message,{ | ||||
|                         type:"error", | ||||
|                         fixed: true, | ||||
|                         modal: true, | ||||
|                         buttons: [ | ||||
|                             { | ||||
|                                 //id: "node-dialog-delete", | ||||
|                                 //class: 'leftButton', | ||||
|                                 text: RED._("common.label.cancel"), | ||||
|                                 click: function() { | ||||
|                                     notification.close(); | ||||
|                                 } | ||||
|                             },{ | ||||
|                                 text: '<span><i class="fa fa-refresh"></i> ' +RED._("projects.send-req.retry") +'</span>', | ||||
|                                 click: function() { | ||||
|                                     body = body || {}; | ||||
|                                     var authBody = {}; | ||||
|                                     if (isSSH) { | ||||
|                                         authBody.keyFile = $('#projects-user-auth-key').val(); | ||||
|                                         authBody.passphrase = $('#projects-user-auth-passphrase').val(); | ||||
|                                     } else { | ||||
|                                         authBody.username = $('#projects-user-auth-username').val(); | ||||
|                                         authBody.password = $('#projects-user-auth-password').val(); | ||||
|                         var notification = RED.notify(message,{ | ||||
|                             type:"error", | ||||
|                             fixed: true, | ||||
|                             modal: true, | ||||
|                             buttons: [ | ||||
|                                 { | ||||
|                                     //id: "node-dialog-delete", | ||||
|                                     //class: 'leftButton', | ||||
|                                     text: RED._("common.label.cancel"), | ||||
|                                     click: function() { | ||||
|                                         notification.close(); | ||||
|                                     } | ||||
|                                     var done = function(err) { | ||||
|                                         if (err) { | ||||
|                                             console.log(RED._("projects.send-req.update-failed")); | ||||
|                                             console.log(err); | ||||
|                                 },{ | ||||
|                                     text: '<span><i class="fa fa-refresh"></i> ' +RED._("projects.send-req.retry") +'</span>', | ||||
|                                     click: function() { | ||||
|                                         body = body || {}; | ||||
|                                         var authBody = {}; | ||||
|                                         if (isSSH) { | ||||
|                                             authBody.keyFile = $('#projects-user-auth-key').val(); | ||||
|                                             authBody.passphrase = $('#projects-user-auth-passphrase').val(); | ||||
|                                         } else { | ||||
|                                             sendRequest(options,body); | ||||
|                                             notification.close(); | ||||
|                                             authBody.username = $('#projects-user-auth-username').val(); | ||||
|                                             authBody.password = $('#projects-user-auth-password').val(); | ||||
|                                         } | ||||
|                                         var done = function(err) { | ||||
|                                             if (err) { | ||||
|                                                 console.log(RED._("projects.send-req.update-failed")); | ||||
|                                                 console.log(err); | ||||
|                                             } else { | ||||
|                                                 sendRequest(options,body); | ||||
|                                                 notification.close(); | ||||
|                                             } | ||||
|  | ||||
|                                     } | ||||
|                                     sendRequest({ | ||||
|                                         url: "projects/"+activeProject.name+"/remotes/"+(xhr.responseJSON.remote||options.remote||'origin'), | ||||
|                                         type: "PUT", | ||||
|                                         responses: { | ||||
|                                             0: function(error) { | ||||
|                                                 done(error,null); | ||||
|                                             }, | ||||
|                                             200: function(data) { | ||||
|                                                 done(null,data); | ||||
|                                             }, | ||||
|                                             400: { | ||||
|                                                 'unexpected_error': function(error) { | ||||
|                                                     done(error,null); | ||||
|                                                 } | ||||
|                                             }, | ||||
|                                         } | ||||
|                                     },{auth:authBody}); | ||||
|                                         sendRequest({ | ||||
|                                             url: "projects/"+activeProject.name+"/remotes/"+(xhr.responseJSON.remote||options.remote||'origin'), | ||||
|                                             type: "PUT", | ||||
|                                             responses: { | ||||
|                                                 0: function(error) { | ||||
|                                                     done(error,null); | ||||
|                                                 }, | ||||
|                                                 200: function(data) { | ||||
|                                                     done(null,data); | ||||
|                                                 }, | ||||
|                                                 400: { | ||||
|                                                     'unexpected_error': function(error) { | ||||
|                                                         done(error,null); | ||||
|                                                     } | ||||
|                                                 }, | ||||
|                                             } | ||||
|                                         },{auth:authBody}); | ||||
|                                     } | ||||
|                                 } | ||||
|                             } | ||||
|                         ] | ||||
|                     }); | ||||
|                     return; | ||||
|                             ] | ||||
|                         }); | ||||
|                         return; | ||||
|                     } else if (xhr.responseJSON.code === 'git_host_key_verification_failed') { | ||||
|                         var message = $('<div>'+ | ||||
|                             '<div class="form-row">'+RED._("projects.send-req.host-key-verify-failed")+'</div>'+ | ||||
|                             '</div>'); | ||||
|                         var notification = RED.notify(message,{ | ||||
|                             type:"error", | ||||
|                             fixed: true, | ||||
|                             modal: true, | ||||
|                             buttons: [ | ||||
|                                 { | ||||
|                                     text: RED._("common.label.close"), | ||||
|                                     click: function() { | ||||
|                                         notification.close(); | ||||
|                                     } | ||||
|                                 } | ||||
|                             ] | ||||
|                         }); | ||||
|                         return; | ||||
|                     } | ||||
|                 } else if (responses[xhr.responseJSON.code]) { | ||||
|                     resultCallback = responses[xhr.responseJSON.code]; | ||||
|                     resultCallbackArgs = xhr.responseJSON; | ||||
|   | ||||
| @@ -41,6 +41,9 @@ function runGitCommand(args,cwd,env,emit) { | ||||
|             err.code = "git_connection_failed"; | ||||
|         } else if (/Connection timed out/i.test(stderr)) { | ||||
|             err.code = "git_connection_failed"; | ||||
|         } else if(/Host key verification failed/i.test(stderr)) { | ||||
|             // TODO: handle host key verification errors separately | ||||
|             err.code = "git_host_key_verification_failed"; | ||||
|         } else if (/fatal: could not read/i.test(stderr)) { | ||||
|             // Username/Password | ||||
|             err.code = "git_auth_failed"; | ||||
| @@ -48,9 +51,6 @@ function runGitCommand(args,cwd,env,emit) { | ||||
|             err.code = "git_auth_failed"; | ||||
|         } else if(/Permission denied \(publickey\)/i.test(stderr)) { | ||||
|             err.code = "git_auth_failed"; | ||||
|         } else if(/Host key verification failed/i.test(stderr)) { | ||||
|             // TODO: handle host key verification errors separately | ||||
|             err.code = "git_auth_failed"; | ||||
|         } else if (/commit your changes or stash/i.test(stderr)) { | ||||
|             err.code = "git_local_overwrite"; | ||||
|         } else if (/CONFLICT/.test(err.stdout)) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user