Skip to content

Commit 7beec7d

Browse files
Added missing fields for a wrapped response. Changed awaiting mechanism for getting product ID's. Added check for a null response.
1 parent c6d7450 commit 7beec7d

3 files changed

Lines changed: 15 additions & 5 deletions

File tree

hashicorp-vault-cagateway/APIProxy/WrappedResponse.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ namespace Keyfactor.Extensions.CAPlugin.HashicorpVault.APIProxy
1212
{
1313
public class WrappedResponse<T>
1414
{
15+
[JsonPropertyName("request_id")]
16+
public string RequestId { get; set; }
17+
1518
[JsonPropertyName("lease_id")]
1619
public string LeaseId { get; set; }
1720

@@ -30,6 +33,9 @@ public class WrappedResponse<T>
3033
[JsonPropertyName("mount_point")]
3134
public string MountPoint { get; set; }
3235

36+
[JsonPropertyName("mount_type")]
37+
public string MountType { get; set; }
38+
3339
[JsonPropertyName("mount_running_plugin_version")]
3440
public string PluginVersion { get; set; }
3541

hashicorp-vault-cagateway/Client/VaultHttp.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,11 @@ public async Task<T> GetAsync<T>(string path, Dictionary<string, string> paramet
8989
if (string.IsNullOrEmpty(response.Content)) throw new Exception(response.ErrorMessage ?? "no content returned from Vault");
9090

9191
logger.LogTrace($"deserializing the response into a {typeof(T)}");
92-
var serialized = JsonConvert.DeserializeObject<T>(response.Content);
92+
var deserialized = JsonConvert.DeserializeObject<T>(response.Content);
9393

9494
logger.LogTrace($"successfully deserialized the reponse");
95-
return serialized;
95+
96+
return deserialized;
9697
}
9798
catch (Exception ex)
9899
{
@@ -120,7 +121,7 @@ public async Task<T> PostAsync<T>(string path, dynamic parameters = default)
120121
if (parameters != null)
121122
{
122123
string serializedParams = JsonConvert.SerializeObject(parameters);
123-
logger.LogTrace($"serialized parameters (from {parameters.GetType()?.Name}): {serializedParams}");
124+
logger.LogTrace($"deserialized parameters (from {parameters.GetType()?.Name}): {serializedParams}");
124125
request.AddJsonBody(serializedParams);
125126
}
126127

hashicorp-vault-cagateway/HashicorpVaultCAConnector.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ public async Task ValidateCAConnectionInfo(Dictionary<string, object> connection
440440
{
441441
logger.LogTrace("making an authenticated request to the Vault server to verify credentials (listing role names)..");
442442
var roleNames = await _client.GetRoleNamesAsync();
443-
logger.LogTrace($"successfule request: received a response containing {roleNames.Count} role names");
443+
logger.LogTrace($"successful request: received a response containing {roleNames?.Count} role names");
444444
}
445445
catch (Exception ex)
446446
{
@@ -583,7 +583,10 @@ public List<string> GetProductIds()
583583
try
584584
{
585585
logger.LogTrace("requesting role names from vault..");
586-
var roleNames = _client.GetRoleNamesAsync().Result;
586+
var roleNames = _client.GetRoleNamesAsync().GetAwaiter().GetResult();
587+
if (roleNames == null) {
588+
throw new Exception("no role names returned, or deserialization failed.");
589+
}
587590
logger.LogTrace($"got {roleNames.Count} role names from vault:");
588591
foreach (var name in roleNames)
589592
{

0 commit comments

Comments
 (0)