Skip to content

Commit 444c491

Browse files
committed
fix(inventory): remove warning logging that hides initial access issues
1 parent c0b7948 commit 444c491

1 file changed

Lines changed: 40 additions & 48 deletions

File tree

aws-acm-orchestrator/Jobs/Inventory.cs

Lines changed: 40 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -94,64 +94,56 @@ internal JobResult PerformInventory(AwsExtensionCredential awsCredentials, Inven
9494
{
9595
List<CurrentInventoryItem> inventoryItems = new List<CurrentInventoryItem>();
9696

97-
try
98-
{
99-
Logger.LogDebug($"Certificate Inventory job will target AWS Region - {awsCredentials.Region.SystemName}");
100-
AcmClient = new AmazonCertificateManagerClient(awsCredentials.GetAwsCredentialObject(), awsCredentials.Region);
101-
Logger.LogTrace("ACM client created with loaded AWS Credentials and specified Region.");
97+
Logger.LogDebug($"Certificate Inventory job will target AWS Region - {awsCredentials.Region.SystemName}");
98+
AcmClient = new AmazonCertificateManagerClient(awsCredentials.GetAwsCredentialObject(), awsCredentials.Region);
99+
Logger.LogTrace("ACM client created with loaded AWS Credentials and specified Region.");
102100

103101

104-
var certList = AsyncHelpers.RunSync(() => AcmClient.ListCertificatesAsync());
105-
Logger.LogDebug($"Found {certList.CertificateSummaryList.Count} Certificates");
106-
Logger.LogTrace($"Cert List JSON: \n{JsonConvert.SerializeObject(certList)}");
102+
var certList = AsyncHelpers.RunSync(() => AcmClient.ListCertificatesAsync());
103+
Logger.LogDebug($"Found {certList.CertificateSummaryList.Count} Certificates");
104+
Logger.LogTrace($"Cert List JSON: \n{JsonConvert.SerializeObject(certList)}");
107105

108-
ListCertificatesRequest req = new ListCertificatesRequest();
106+
ListCertificatesRequest req = new ListCertificatesRequest();
109107

110-
//The Current Workaround For AWS Not Returning Certs Without A SAN
111-
List<String> keyTypes = new List<String> { KeyAlgorithm.RSA_1024, KeyAlgorithm.RSA_2048, KeyAlgorithm.RSA_4096, KeyAlgorithm.EC_prime256v1, KeyAlgorithm.EC_secp384r1, KeyAlgorithm.EC_secp521r1 };
112-
req.Includes = new Filters() { KeyTypes = keyTypes };
108+
//The Current Workaround For AWS Not Returning Certs Without A SAN
109+
List<String> keyTypes = new List<String> { KeyAlgorithm.RSA_1024, KeyAlgorithm.RSA_2048, KeyAlgorithm.RSA_4096, KeyAlgorithm.EC_prime256v1, KeyAlgorithm.EC_secp384r1, KeyAlgorithm.EC_secp521r1 };
110+
req.Includes = new Filters() { KeyTypes = keyTypes };
113111

114-
//Only fetch certificates that have been issued at one point
115-
req.CertificateStatuses = new List<string> { CertificateStatus.ISSUED, CertificateStatus.INACTIVE, CertificateStatus.EXPIRED, CertificateStatus.REVOKED };
116-
req.MaxItems = 100;
112+
//Only fetch certificates that have been issued at one point
113+
req.CertificateStatuses = new List<string> { CertificateStatus.ISSUED, CertificateStatus.INACTIVE, CertificateStatus.EXPIRED, CertificateStatus.REVOKED };
114+
req.MaxItems = 100;
117115

118-
Logger.LogTrace($"ListCertificatesRequest JSON: {JsonConvert.SerializeObject(req)}");
116+
Logger.LogTrace($"ListCertificatesRequest JSON: {JsonConvert.SerializeObject(req)}");
119117

120-
ListCertificatesResponse AllCertificates;
121-
do
122-
{
123-
AllCertificates = AsyncHelpers.RunSync(() => AcmClient.ListCertificatesAsync(req));//Fetch batch of certificates from ACM API
124-
Logger.LogTrace($"AllCertificates JSON: {JsonConvert.SerializeObject(AllCertificates)}");
118+
ListCertificatesResponse AllCertificates;
119+
do
120+
{
121+
AllCertificates = AsyncHelpers.RunSync(() => AcmClient.ListCertificatesAsync(req));//Fetch batch of certificates from ACM API
122+
Logger.LogTrace($"AllCertificates JSON: {JsonConvert.SerializeObject(AllCertificates)}");
125123

126-
totalCertificates += AllCertificates.CertificateSummaryList.Count;
127-
Logger.LogDebug($"Found {AllCertificates.CertificateSummaryList.Count} Certificates In Batch Amazon Certificate Manager Job.");
124+
totalCertificates += AllCertificates.CertificateSummaryList.Count;
125+
Logger.LogDebug($"Found {AllCertificates.CertificateSummaryList.Count} Certificates In Batch Amazon Certificate Manager Job.");
128126

129-
inventoryItems.AddRange(AllCertificates.CertificateSummaryList.Select(
130-
c =>
127+
inventoryItems.AddRange(AllCertificates.CertificateSummaryList.Select(
128+
c =>
129+
{
130+
try
131131
{
132-
try
133-
{
134-
return BuildInventoryItem(c.CertificateArn);
135-
}
136-
catch
137-
{
138-
Logger.LogWarning($"Could not fetch the certificate: {c?.DomainName} associated with arn {c?.CertificateArn}.");
139-
warningFlag = true;
140-
return new CurrentInventoryItem();
141-
}
142-
}).Where(acsii => acsii?.Certificates != null).ToList());
143-
144-
req.NextToken = AllCertificates.NextToken;
145-
} while (AllCertificates.NextToken != null);
146-
147-
Logger.LogDebug($"Found {totalCertificates} Total Certificates In Amazon Certificate Manager Inventory Job.");
148-
Logger.LogTrace($"inventoryItems Response JSON: {JsonConvert.SerializeObject(inventoryItems)}");
149-
}
150-
catch (Exception e)
151-
{
152-
warningFlag = true;
153-
Logger.LogError(e, "An error occurred while processing the Inventory.");
154-
}
132+
return BuildInventoryItem(c.CertificateArn);
133+
}
134+
catch
135+
{
136+
Logger.LogWarning($"Could not fetch the certificate: {c?.DomainName} associated with arn {c?.CertificateArn}.");
137+
warningFlag = true;
138+
return new CurrentInventoryItem();
139+
}
140+
}).Where(acsii => acsii?.Certificates != null).ToList());
141+
142+
req.NextToken = AllCertificates.NextToken;
143+
} while (AllCertificates.NextToken != null);
144+
145+
Logger.LogDebug($"Found {totalCertificates} Total Certificates In Amazon Certificate Manager Inventory Job.");
146+
Logger.LogTrace($"inventoryItems Response JSON: {JsonConvert.SerializeObject(inventoryItems)}");
155147

156148
siu.Invoke(inventoryItems);
157149

0 commit comments

Comments
 (0)