Skip to content

Commit c42bb5c

Browse files
authored
Merge pull request #4 from Keyfactor/ab#69246
Updated inventory to pull only client certs tied to default keystore. This should be a final "prototype" state that can be used for demo purposes ONLY.
2 parents edb25da + 54b5738 commit c42bb5c

1 file changed

Lines changed: 24 additions & 5 deletions

File tree

AxisIPCamera/Inventory.cs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,30 @@ public JobResult ProcessJob(InventoryJobConfiguration config, SubmitInventoryUpd
8181
// Perform cert inventory
8282
CertificateData data2 = client.ListCertificates();
8383

84+
// Get the default keystore
85+
Constants.Keystore defaultKeystore = client.GetDefaultKeystore();
86+
string defaultKeystoreString = Enum.GetName(typeof(Constants.Keystore), defaultKeystore);
87+
_logger.LogDebug($"Inventory - Default keystore: {defaultKeystoreString}");
88+
89+
// Create new list of client certs that are only tied to the default keystore
90+
CertificateData data2DefKey = new CertificateData
91+
{
92+
Status = Constants.Status.Success,
93+
Certs = new List<Certificate>()
94+
};
95+
foreach (Certificate cert in data2.Certs)
96+
{
97+
if (cert.Keystore == defaultKeystore)
98+
{
99+
data2DefKey.Certs.Add(cert);
100+
}
101+
}
102+
84103
// Lookup the certificate used for HTTPS
85104
string httpAlias = client.GetBinding(Constants.CertificateUsage.Https);
86105

87-
// Set the binding on the certificate object if the aliases match
88-
foreach (Certificate c in data2.Certs)
106+
// Set the binding on the client certificates object if the aliases match
107+
foreach (Certificate c in data2DefKey.Certs)
89108
{
90109
if (c.Alias.Equals(httpAlias))
91110
{
@@ -116,7 +135,7 @@ public JobResult ProcessJob(InventoryJobConfiguration config, SubmitInventoryUpd
116135
}
117136
}).Where(item => item?.Certificates != null).ToList());
118137

119-
inventoryItems.AddRange(data2.Certs.Select(
138+
inventoryItems.AddRange(data2DefKey.Certs.Select(
120139
c =>
121140
{
122141
try
@@ -146,7 +165,7 @@ public JobResult ProcessJob(InventoryJobConfiguration config, SubmitInventoryUpd
146165
catch (Exception ex)
147166
{
148167
//Status: 2=Success, 3=Warning, 4=Error
149-
return new JobResult() { Result = Keyfactor.Orchestrators.Common.Enums.OrchestratorJobStatusJobResult.Failure, JobHistoryId = config.JobHistoryId, FailureMessage = "Custom message you want to show to show up as the error message in Job History in KF Command" };
168+
return new JobResult() { Result = Keyfactor.Orchestrators.Common.Enums.OrchestratorJobStatusJobResult.Failure, JobHistoryId = config.JobHistoryId, FailureMessage = $"Inventory Job Failed During Inventory Item Creation: {ex.Message}" };
150169
}
151170

152171
try
@@ -162,7 +181,7 @@ public JobResult ProcessJob(InventoryJobConfiguration config, SubmitInventoryUpd
162181
{
163182
// NOTE: if the cause of the submitInventory.Invoke exception is a communication issue between the Orchestrator server and the Command server, the job status returned here
164183
// may not be reflected in Keyfactor Command.
165-
return new JobResult() { Result = Keyfactor.Orchestrators.Common.Enums.OrchestratorJobStatusJobResult.Failure, JobHistoryId = config.JobHistoryId, FailureMessage = "Custom message you want to show to show up as the error message in Job History in KF Command" };
184+
return new JobResult() { Result = Keyfactor.Orchestrators.Common.Enums.OrchestratorJobStatusJobResult.Failure, JobHistoryId = config.JobHistoryId, FailureMessage = $"Inventory Job Failed During Inventory Item Submission: {ex.Message}" };
166185
}
167186
}
168187

0 commit comments

Comments
 (0)