Skip to content

Commit

Permalink
Merge pull request #5 from Keyfactor/emptygcpissue
Browse files Browse the repository at this point in the history
Emptygcpissue
  • Loading branch information
bhillkeyfactor authored Aug 4, 2022
2 parents 5da194b + e4f7df8 commit 6b50822
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 43 deletions.
89 changes: 46 additions & 43 deletions GcpCertManager/Jobs/Inventory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private JobResult PerformInventory(InventoryJobConfiguration config, SubmitInven
var client = new GcpCertificateManagerClient();
_logger.LogTrace("Getting Credentials from Google...");
var svc = client.GetGoogleCredentials(config.CertificateStoreDetails.ClientMachine);
_logger.LogTrace($"Got Credentials from Google");
_logger.LogTrace("Got Credentials from Google");


var warningFlag = false;
Expand Down Expand Up @@ -84,31 +84,31 @@ private JobResult PerformInventory(InventoryJobConfiguration config, SubmitInven

nextPageToken = null;
//Debug Write Certificate List Response from Google Cert Manager

inventoryItems.AddRange(certificatesResponse.Certificates.Select(
c =>
{
try
{
_logger.LogTrace(
$"Building Cert List Inventory Item Alias: {c.Name} Pem: {c.PemCertificate} Private Key: dummy (from PA API)");
return BuildInventoryItem(c.Name, c.PemCertificate,
true, storePath, svc,
storeProps
.ProjectNumber); //todo figure out how to see if private key exists not in Google Api return
}
catch
if (certificatesResponse?.Certificates != null)
inventoryItems.AddRange(certificatesResponse.Certificates.Select(
c =>
{
_logger.LogWarning(
$"Could not fetch the certificate: {c?.Name} associated with description {c?.Description}.");
sb.Append(
$"Could not fetch the certificate: {c?.Name} associated with issuer {c?.Description}.{Environment.NewLine}");
warningFlag = true;
return new CurrentInventoryItem();
}
}).Where(acsii => acsii?.Certificates != null).ToList());

if (certificatesResponse.NextPageToken?.Length > 0)
try
{
_logger.LogTrace(
$"Building Cert List Inventory Item Alias: {c.Name} Pem: {c.PemCertificate} Private Key: dummy (from PA API)");
return BuildInventoryItem(c.Name, c.PemCertificate,
true, storePath, svc,
storeProps
.ProjectNumber); //todo figure out how to see if private key exists not in Google Api return
}
catch
{
_logger.LogWarning(
$"Could not fetch the certificate: {c?.Name} associated with description {c?.Description}.");
sb.Append(
$"Could not fetch the certificate: {c?.Name} associated with issuer {c?.Description}.{Environment.NewLine}");
warningFlag = true;
return new CurrentInventoryItem();
}
}).Where(acsii => acsii?.Certificates != null).ToList());

if (certificatesResponse?.NextPageToken?.Length > 0)
nextPageToken = certificatesResponse.NextPageToken;
} while (nextPageToken?.Length > 0);
}
Expand Down Expand Up @@ -215,7 +215,8 @@ protected Dictionary<string, object> GetCertificateAttributes(string storePath)
}
catch (Exception e)
{
_logger.LogError($"Error Occurred in Inventory.GetCertificateAttributes: {LogHandler.FlattenException(e)}");
_logger.LogError(
$"Error Occurred in Inventory.GetCertificateAttributes: {LogHandler.FlattenException(e)}");
throw;
}
}
Expand All @@ -241,25 +242,27 @@ protected Dictionary<string, string> GetMapSettings(string storePath, string cer
_logger.LogTrace(
$"mapListResponse: {JsonConvert.SerializeObject(mapListResponse)}");


foreach (var map in mapListResponse.CertificateMaps)
{
var mapEntryListRequest = svc.Projects.Locations.CertificateMaps.CertificateMapEntries.List(map.Name);
mapEntryListRequest.Filter = $"certificates:\"{certName}\"";
var mapEntryListResponse = mapEntryListRequest.Execute();
_logger.LogTrace(
$"mapEntryListResponse: {JsonConvert.SerializeObject(mapEntryListResponse)}");

if (mapEntryListResponse?.CertificateMapEntries?.Count > 0)
if (mapListResponse?.CertificateMaps != null)
foreach (var map in mapListResponse.CertificateMaps)
{
var mapEntry = mapEntryListResponse.CertificateMapEntries[0];
_logger.LogTrace($"mapEntry: {mapEntry}");
siteSettingsDict.Add("Certificate Map Name", map.Name.Split('/')[5]);
siteSettingsDict.Add("Certificate Map Entry Name", mapEntry.Name.Split('/')[7]);
_logger.MethodExit();
return siteSettingsDict;
var mapEntryListRequest =
svc.Projects.Locations.CertificateMaps.CertificateMapEntries.List(map.Name);
mapEntryListRequest.Filter = $"certificates:\"{certName}\"";
var mapEntryListResponse = mapEntryListRequest.Execute();
_logger.LogTrace(
$"mapEntryListResponse: {JsonConvert.SerializeObject(mapEntryListResponse)}");

if (mapEntryListResponse?.CertificateMapEntries?.Count > 0)
{
var mapEntry = mapEntryListResponse.CertificateMapEntries[0];
_logger.LogTrace($"mapEntry: {mapEntry}");
siteSettingsDict.Add("Certificate Map Name", map.Name.Split('/')[5]);
siteSettingsDict.Add("Certificate Map Entry Name", mapEntry.Name.Split('/')[7]);
_logger.MethodExit();
return siteSettingsDict;
}
}
}

_logger.MethodExit();
return siteSettingsDict;
}
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ The Universal Orchestrator is part of the Keyfactor software distribution and is

The Universal Orchestrator is the successor to the Windows Orchestrator. This Capability plugin only works with the Universal Orchestrator and does not work with the Windows Orchestrator.

---




---

**Google Cloud Platform Certificate Manager**
Expand Down

0 comments on commit 6b50822

Please sign in to comment.