Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,326 changes: 678 additions & 648 deletions BoschIPCamera/Client/BoschIPCameraClient.cs

Large diffs are not rendered by default.

405 changes: 287 additions & 118 deletions BoschIPCamera/Client/Constants.cs

Large diffs are not rendered by default.

96 changes: 70 additions & 26 deletions BoschIPCamera/Jobs/Inventory.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Keyfactor
// Copyright 2026 Keyfactor
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using System.Collections.Generic;
using System.Linq;
using Keyfactor.Extensions.Orchestrator.BoschIPCamera.Client;
Expand All @@ -36,41 +37,84 @@

public string ExtensionName => "BoschIPCamera";

public JobResult ProcessJob(InventoryJobConfiguration jobConfiguration,
SubmitInventoryUpdate submitInventoryUpdate)
public JobResult ProcessJob(InventoryJobConfiguration jobConfiguration, SubmitInventoryUpdate submitInventoryUpdate)
{
_logger.MethodEntry(LogLevel.Debug);
var client = new BoschIpCameraClient(jobConfiguration, jobConfiguration.CertificateStoreDetails, _pam, _logger);
List<CurrentInventoryItem> inventoryItems;

try
{
_logger.MethodEntry(LogLevel.Debug);
_logger.LogTrace(
$"Begin Inventory for Client Machine {jobConfiguration.CertificateStoreDetails.ClientMachine}...");

var client = new BoschIpCameraClient(jobConfiguration, jobConfiguration.CertificateStoreDetails, _pam,
_logger);

var files = client.ListCerts();
_logger.LogDebug($"Found {files.Count} certificates");
var files = client.ListCerts();
_logger.LogDebug($"Found {files.Count} certificates");

// get cert usage
// need request cert usage lists for each cert usage type, and parse names from response to match types
// key = cert name, value = cert usage enum
var certUsages = client.GetCertUsageList();
_logger.LogDebug($"Found {certUsages.Count} certificates with a matching usage");
// get cert usage
// need request cert usage lists for each cert usage type, and parse names from response to match types
// key = cert name, value = cert usage enum
var certUsages = client.GetCertUsageList();
_logger.LogDebug($"Found {certUsages.Count} certificates with a matching usage");

var inventory = files.Select(f => new CurrentInventoryItem()
{
Alias = f.Key,
Certificates = new List<string>() { f.Value },
PrivateKeyEntry = false,
UseChainLevel = false,
Parameters = new Dictionary<string, object>
inventoryItems = files.Select(f => new CurrentInventoryItem()
{
{ "Name", f.Key },
{ "CertificateUsage", certUsages.ContainsKey(f.Key) ? certUsages[f.Key].ToReadableText() : "" }
}
}).ToList();
Alias = f.Key,
Certificates = new List<string>() { f.Value },
PrivateKeyEntry = false,
UseChainLevel = false,
Parameters = new Dictionary<string, object>
{
{ "Name", f.Key },
{ "CertificateUsage", certUsages.ContainsKey(f.Key) ? certUsages[f.Key].ToReadableText() : "" }
}
}).ToList();
}
catch (Exception e1)
{
// Status: 2=Success, 3=Warning, 4=Error
return new JobResult()
{
Result = OrchestratorJobStatusJobResult.Failure,
JobHistoryId = jobConfiguration.JobHistoryId,
FailureMessage = $"Inventory Job Failed During Inventory Item Creation: {e1.Message} - Refer to the Orchestrator logs and Command API logs for more detailed information."
};
}

bool success = true;
Exception? error = null;

Check warning on line 87 in BoschIPCamera/Jobs/Inventory.cs

View workflow job for this annotation

GitHub Actions / call-starter-workflow / call-dotnet-build-and-release-workflow / dotnet-build-and-release

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 87 in BoschIPCamera/Jobs/Inventory.cs

View workflow job for this annotation

GitHub Actions / call-starter-workflow / call-dotnet-build-and-release-workflow / dotnet-build-and-release

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 87 in BoschIPCamera/Jobs/Inventory.cs

View workflow job for this annotation

GitHub Actions / call-starter-workflow / call-dotnet-build-and-release-workflow / dotnet-build-and-release

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 87 in BoschIPCamera/Jobs/Inventory.cs

View workflow job for this annotation

GitHub Actions / call-starter-workflow / call-dotnet-build-and-release-workflow / dotnet-build-and-release

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

submitInventoryUpdate(inventory);
try
{
// Sends inventoried certificates back to KF Command
_logger.LogTrace("Submitting Inventory to Keyfactor via submitInventory.Invoke");
success = submitInventoryUpdate.Invoke(inventoryItems);
}
catch (Exception e1)
{
success = false;
error = e1;
}

if (!success)
{
// ** 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
// may not be reflected in Keyfactor Command.
return new JobResult()
{
Result = OrchestratorJobStatusJobResult.Failure,
JobHistoryId = jobConfiguration.JobHistoryId,
FailureMessage = $"Inventory Job Failed During Inventory Item Submission: {(error is not null ? error.ToString() : "Unknown error occurred.")} - " +
$"Refer to the Orchestrator logs and Command API logs for more detailed information." };
}

_logger.LogTrace("Successfully submitted Inventory To Keyfactor via submitInventory.Invoke");
return new JobResult()
{
Result = OrchestratorJobStatusJobResult.Success,
JobHistoryId = jobConfiguration.JobHistoryId,
FailureMessage = ""
JobHistoryId = jobConfiguration.JobHistoryId
};
}
}
Expand Down
6 changes: 5 additions & 1 deletion BoschIPCamera/Jobs/Management.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Keyfactor
// Copyright 2026 Keyfactor
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -51,6 +51,10 @@ public JobResult ProcessJob(ManagementJobConfiguration jobConfiguration)

public JobResult removeCert(ManagementJobConfiguration jobConfiguration)
{
_logger.MethodEntry(LogLevel.Debug);
_logger.LogTrace(
$"Begin Management for Client Machine {jobConfiguration.CertificateStoreDetails.ClientMachine}...");

_logger.LogTrace($"Management Config {JsonConvert.SerializeObject(jobConfiguration)}");
BoschIpCameraClient client = new BoschIpCameraClient(jobConfiguration, jobConfiguration.CertificateStoreDetails, _pam, _logger);

Expand Down
Loading
Loading