Skip to content

Commit c6d7450

Browse files
added a tracelog in the initialize method that should log the current version of the integration
1 parent cf00704 commit c6d7450

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

hashicorp-vault-cagateway/HashicorpVaultCAConnector.cs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using System.Text.Json;
1919
using System.Threading;
2020
using System.Threading.Tasks;
21+
using System.Reflection;
2122

2223
namespace Keyfactor.Extensions.CAPlugin.HashicorpVault
2324
{
@@ -50,11 +51,22 @@ public void Initialize(IAnyCAPluginConfigProvider configProvider, ICertificateDa
5051
{
5152
logger.MethodEntry(LogLevel.Trace);
5253
string rawConfig = JsonSerializer.Serialize(configProvider.CAConnectionData);
53-
logger.LogTrace($"serialized config: {rawConfig}");
5454
_caConfig = JsonSerializer.Deserialize<HashicorpVaultCAConfig>(rawConfig);
5555
logger.MethodExit(LogLevel.Trace);
5656
_client = new HashicorpVaultClient(_caConfig);
5757
_certificateDataReader = certificateDataReader;
58+
59+
Assembly targetAssembly = typeof(HashicorpVaultCAConnector).Assembly;
60+
61+
// Get the AssemblyName object
62+
AssemblyName assemblyName = targetAssembly?.GetName();
63+
64+
// Get the Version object
65+
Version version = assemblyName?.Version;
66+
67+
logger.LogTrace($"-- {assemblyName?.Name ?? "unknown"} v{version} --");
68+
69+
logger.LogTrace($"serialized config: {rawConfig}");
5870
}
5971

6072
/// <summary>
@@ -264,7 +276,7 @@ public async Task Synchronize(BlockingCollection<AnyCAPluginCertificate> blockin
264276
}
265277
logger.LogTrace($"converting {certSerial} to database trackingId");
266278

267-
var trackingId = certSerial.Replace(":", "-"); // we store with '-'; hashi stores with ':'
279+
var trackingId = certSerial.Replace(":", "-"); // we store with '-'; hashi stores with ':'
268280

269281
// then, check for an existing local entry
270282
try
@@ -284,12 +296,12 @@ public async Task Synchronize(BlockingCollection<AnyCAPluginCertificate> blockin
284296
logger.LogTrace("attempting to retrieve the role name (productId) from the certificate metadata, if available");
285297

286298
var metaData = new MetadataResponse();
287-
299+
288300
try
289301
{
290302
metaData = await _client.GetCertMetadata(certSerial);
291303
}
292-
catch (Exception)
304+
catch (Exception)
293305
{
294306
logger.LogTrace("an error occurred when attempting to retrieve the metadata, continuing..");
295307
}
@@ -299,11 +311,11 @@ public async Task Synchronize(BlockingCollection<AnyCAPluginCertificate> blockin
299311
CARequestID = trackingId,
300312
Certificate = certFromVault.Certificate,
301313
Status = certFromVault.RevocationTime != null ? (int)EndEntityStatus.REVOKED : (int)EndEntityStatus.GENERATED,
302-
RevocationDate = certFromVault.RevocationTime,
314+
RevocationDate = certFromVault.RevocationTime,
303315
};
304316

305317
// if we were able to get the role name from metadata, we include it
306-
if (!string.IsNullOrEmpty(metaData?.Role))
318+
if (!string.IsNullOrEmpty(metaData?.Role))
307319
{
308320
newCert.ProductID = metaData.Role;
309321
}
@@ -347,7 +359,7 @@ public async Task Synchronize(BlockingCollection<AnyCAPluginCertificate> blockin
347359
/// </summary>
348360
/// <param name="connectionInfo">The information used to connect to the CA.</param>
349361
public async Task ValidateCAConnectionInfo(Dictionary<string, object> connectionInfo)
350-
{
362+
{
351363
logger.MethodEntry();
352364
logger.LogTrace(message: $"Validating CA connection info: {JsonSerializer.Serialize(connectionInfo)}");
353365

@@ -373,7 +385,7 @@ public async Task ValidateCAConnectionInfo(Dictionary<string, object> connection
373385

374386
// make sure an authentication mechanism is defined (either certificate or token)
375387
var token = connectionInfo[Constants.CAConfig.TOKEN] as string;
376-
388+
377389
//var cert = connectionInfo[Constants.CAConfig.CLIENTCERT] as string;
378390

379391
var cert = string.Empty; // temporary until client cert auth into vault is implemented
@@ -466,7 +478,7 @@ public Task ValidateProductInfo(EnrollmentProductInfo productInfo, Dictionary<st
466478
logger.LogError(LogHandler.FlattenException(ex));
467479
throw;
468480
}
469-
481+
470482
// if any errors, throw
471483
if (errors.Any())
472484
{

0 commit comments

Comments
 (0)