From 24f4c14e91846550311add7b136ff1365452b5b2 Mon Sep 17 00:00:00 2001 From: Christopher Cook Date: Tue, 5 Nov 2024 08:19:12 +0800 Subject: [PATCH] Fix name typo and update error handling --- ...als.cs => CertifyCLI.StoredCredentials.cs} | 34 +++++++++++++------ 1 file changed, 23 insertions(+), 11 deletions(-) rename src/Certify.CLI/{CertifyCLI,StoredCredentials.cs => CertifyCLI.StoredCredentials.cs} (52%) diff --git a/src/Certify.CLI/CertifyCLI,StoredCredentials.cs b/src/Certify.CLI/CertifyCLI.StoredCredentials.cs similarity index 52% rename from src/Certify.CLI/CertifyCLI,StoredCredentials.cs rename to src/Certify.CLI/CertifyCLI.StoredCredentials.cs index 11d4a9620..3c4d20934 100644 --- a/src/Certify.CLI/CertifyCLI,StoredCredentials.cs +++ b/src/Certify.CLI/CertifyCLI.StoredCredentials.cs @@ -25,25 +25,32 @@ internal async Task UpdateStoredCredential(string[] args) var cred = new StoredCredential { StorageKey = storageKey, - DateCreated = DateTime.Now, + DateCreated = DateTime.UtcNow, ProviderType = credentialType, Secret = secretValue, Title = title }; - var result = await _certifyClient.UpdateCredentials(cred); - - if (result != null) + try { - var resultObject = new { Status = "OK", Message = "Credential updated", StorageKey = result?.StorageKey }; - var output = JsonConvert.SerializeObject(resultObject, Formatting.Indented); - Console.WriteLine(output); + var result = await _certifyClient.UpdateCredentials(cred); + if (result != null) + { + + var resultObject = new { Status = "OK", Message = "Credential updated", StorageKey = result?.StorageKey }; + var output = JsonConvert.SerializeObject(resultObject, Formatting.Indented); + Console.WriteLine(output); + } + else + { + var resultObject = new { Status = "Error", Message = "Credential update failed" }; + var output = JsonConvert.SerializeObject(resultObject, Formatting.Indented); + Console.WriteLine(output); + } } - else + catch (Exception ex) { - var resultObject = new { Status = "Error", Message = "Credential update failed" }; - var output = JsonConvert.SerializeObject(resultObject, Formatting.Indented); - Console.WriteLine(output); + Console.WriteLine($"Error updating credentials: {ex.Message}"); } } @@ -55,5 +62,10 @@ internal async Task ListStoredCredentials(string[] args) Console.WriteLine(output); } + private void WriteOutput(object resultObject) + { + var output = JsonConvert.SerializeObject(resultObject, Formatting.Indented); + Console.WriteLine(output); + } } }