Skip to content

Conversation

@joevanwanzeeleKF
Copy link
Contributor

  • bug fix: _certDataReader is now initialized in the Initialize method

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a bug where the _certDataReader field was not being initialized in the Initialize method, along with multiple improvements to API response handling, logging, and spelling corrections throughout the codebase. The changes also update package dependencies and refactor how Vault API responses are deserialized by properly handling the wrapped response format.

Key changes:

  • Fixed bug where _certificateDataReader was not initialized in the Initialize method (line 57)
  • Changed RevocationTime from DateTime? to string in CertResponse to properly handle RFC3339 formatted timestamps from Vault API
  • Updated multiple package dependencies to newer versions, including several to version 10.0.0
  • Refactored Vault API calls to use WrappedResponse<T> wrapper for proper deserialization of nested response data
  • Corrected multiple spelling errors ("retreive" → "retrieve", "successfule" → "successful")

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
hashicorp-vault-cagateway/HashicorpVaultCAConnector.cs Initializes _certificateDataReader, adds assembly version logging, changes RevocationTime handling from DateTime to string, fixes spelling errors, adds cancellation token to sync operations
hashicorp-vault-cagateway/Client/VaultHttp.cs Enhanced logging, improved deserialization handling, fixed error message terminology
hashicorp-vault-cagateway/Client/HashicorpVaultClient.cs Refactored to use WrappedResponse wrapper for API calls, fixed spelling in documentation
hashicorp-vault-cagateway/APIProxy/WrappedResponse.cs Added RequestId and MountType properties to match Vault API response structure
hashicorp-vault-cagateway/APIProxy/CertResponse.cs Changed RevocationTime from DateTime? to string, added RevocationTimestamp property
hashicorp-vault-cagateway/hashicorp-vault-caplugin.csproj Updated package versions and added Microsoft.Extensions.Logging.Abstractions, removed Resources configuration
hashicorp-vault-cagateway/Properties/launchSettings.json Removed launch settings file
readme_source.md Fixed spelling error in documentation
CHANGELOG.md Added entry documenting the bug fix

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Certificate = certFromVault.Certificate,
Status = vaultStatus,
RevocationDate = certFromVault.RevocationTime
RevocationDate = !string.IsNullOrEmpty(certFromVault.RevocationTime) ? DateTime.Parse(certFromVault.RevocationTime) : null,
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The DateTime.Parse call should specify culture and DateTimeStyles for consistent parsing. Line 173 properly handles this with CultureInfo.InvariantCulture and DateTimeStyles, but this line doesn't. Consider using the same pattern for consistency: DateTime.Parse(certFromVault.RevocationTime, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AdjustToUniversal | System.Globalization.DateTimeStyles.AssumeUniversal)

Copilot uses AI. Check for mistakes.
string serializedParams = JsonSerializer.Serialize(parameters, _serializerOptions);
logger.LogTrace($"serialized parameters (from {parameters.GetType()?.Name}): {serializedParams}");
string serializedParams = JsonSerializer.Serialize(parameters);
logger.LogTrace($"deserialized parameters (from {parameters.GetType()?.Name}): {serializedParams}");
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The log message refers to "deserialized parameters" but should be "serialized parameters" since the code is serializing the parameters object into JSON format.

Suggested change
logger.LogTrace($"deserialized parameters (from {parameters.GetType()?.Name}): {serializedParams}");
logger.LogTrace($"serialized parameters (from {parameters.GetType()?.Name}): {serializedParams}");

Copilot uses AI. Check for mistakes.
{
var res = await _vaultHttp.GetAsync<WrappedResponse<KeyedList>>("certs/?list=true");
return res.Data.Entries;
return res.Data?.Entries;
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential null reference issue: The code accesses res.Data?.Entries without null-checking res itself. If the GetAsync call returns null, this will throw a NullReferenceException. Consider adding a null check for the response object before accessing its Data property.

Copilot uses AI. Check for mistakes.
var res = await _vaultHttp.GetAsync<KeyedList>("certs/revoked");
keys = res.Entries;
var res = await _vaultHttp.GetAsync<WrappedResponse<KeyedList>>("certs/revoked");
keys = res.Data?.Entries;
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential null reference issue: The code accesses res.Data?.Entries without null-checking res itself. If the GetAsync call returns null, this will throw a NullReferenceException. Consider adding a null check for the response object before accessing its Data property.

Copilot uses AI. Check for mistakes.
};
};

blockingBuffer.Add(newCert);
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The blockingBuffer.Add() call at line 357 is missing the cancellation token parameter, while line 331 correctly includes it. For consistency and proper cancellation handling, this should be: blockingBuffer.Add(newCert, cancelToken);

Suggested change
blockingBuffer.Add(newCert);
blockingBuffer.Add(newCert, cancelToken);

Copilot uses AI. Check for mistakes.
Status = certFromVault.RevocationTime != null ? (int)EndEntityStatus.REVOKED : (int)EndEntityStatus.GENERATED,
RevocationDate = certFromVault.RevocationTime,
Status = !string.IsNullOrEmpty(certFromVault.RevocationTime) ? (int)EndEntityStatus.REVOKED : (int)EndEntityStatus.GENERATED,
RevocationDate = !string.IsNullOrEmpty(certFromVault.RevocationTime) ? DateTime.Parse(certFromVault.RevocationTime) : null
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The DateTime.Parse call should specify culture and DateTimeStyles for consistent parsing. Line 173 properly handles this with CultureInfo.InvariantCulture and DateTimeStyles, but this line doesn't. Consider using the same pattern for consistency: DateTime.Parse(certFromVault.RevocationTime, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AdjustToUniversal | System.Globalization.DateTimeStyles.AssumeUniversal)

Suggested change
RevocationDate = !string.IsNullOrEmpty(certFromVault.RevocationTime) ? DateTime.Parse(certFromVault.RevocationTime) : null
RevocationDate = !string.IsNullOrEmpty(certFromVault.RevocationTime)
? DateTime.Parse(
certFromVault.RevocationTime,
System.Globalization.CultureInfo.InvariantCulture,
System.Globalization.DateTimeStyles.AdjustToUniversal | System.Globalization.DateTimeStyles.AssumeUniversal)
: null

Copilot uses AI. Check for mistakes.
Certificate = cert.Certificate,
Status = revoked ? (int)EndEntityStatus.REVOKED : (int)EndEntityStatus.GENERATED,
RevocationDate = cert.RevocationTime
RevocationDate = cert.RevocationTime != null ? DateTime.Parse(cert.RevocationTime.ToString(), System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AdjustToUniversal | System.Globalization.DateTimeStyles.AssumeUniversal) : null
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The RevocationDate parsing should handle the new string-based RevocationTime property more carefully. Since RevocationTime is now a string (changed in CertResponse.cs), you should check if it's null or empty before parsing: RevocationDate = !string.IsNullOrEmpty(cert.RevocationTime) ? DateTime.Parse(cert.RevocationTime) : null. The current code calls .ToString() on a string, which is redundant and may mask potential issues.

Copilot uses AI. Check for mistakes.
string rawConfig = JsonSerializer.Serialize(configProvider.CAConnectionData);
logger.LogTrace($"serialized config: {rawConfig}");
_caConfig = JsonSerializer.Deserialize<HashicorpVaultCAConfig>(rawConfig);
logger.MethodExit(LogLevel.Trace);
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logger.MethodExit() call at line 55 is placed before the initialization completes. The method continues with additional initialization steps (lines 56-69) after this exit log. This should be moved to line 69, just before the closing brace, to accurately reflect when the method completes.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants