From 4131718729923336988f9d1d173a53958d5f5e24 Mon Sep 17 00:00:00 2001 From: Victor Tran Date: Sun, 13 Aug 2023 21:20:04 +1000 Subject: [PATCH] Catch exception when no SSH key is generated --- .../RemoteCommunicationService.cs | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/Parlance/Services/RemoteCommunication/RemoteCommunicationService.cs b/Parlance/Services/RemoteCommunication/RemoteCommunicationService.cs index ed3b2830..04d534c0 100644 --- a/Parlance/Services/RemoteCommunication/RemoteCommunicationService.cs +++ b/Parlance/Services/RemoteCommunication/RemoteCommunicationService.cs @@ -16,14 +16,21 @@ public RemoteCommunicationService(ParlanceContext dbContext) public Credentials CredentialsHandler(string url, string usernameFromUrl, SupportedCredentialTypes types) { //TODO: Check number of retries - var key = _dbContext.SshKeys.First(); - - return new SshKeyMemoryCredentials + try { - Username = usernameFromUrl, - PublicKey = key.SshKeyContents, - PrivateKey = key.SshPrivateKeyContents - }; + var key = _dbContext.SshKeys.First(); + + return new SshKeyMemoryCredentials + { + Username = usernameFromUrl, + PublicKey = key.SshKeyContents, + PrivateKey = key.SshPrivateKeyContents + }; + } + catch (InvalidOperationException) + { + return new DefaultCredentials(); + } } public bool CertificateCheckHandler(Certificate certificate, bool valid, string host)