Skip to content

Commit 6481e27

Browse files
author
Lee Fine
committed
ab#72824
1 parent 18aecf5 commit 6481e27

File tree

3 files changed

+69
-29
lines changed

3 files changed

+69
-29
lines changed

F5Client.cs

Lines changed: 55 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,35 @@ private X509Certificate2Collection GetCertificateEntry(string path)
352352
return c.ToX509Certificate2Collection();
353353
}
354354

355+
public List<F5SSLProfile> GetSSLProfiles(int pageSize)
356+
{
357+
LogHandlerCommon.MethodEntry(logger, CertificateStore, "GetSSLProfiles");
358+
string partition = CertificateStore.StorePath;
359+
string query = $"/mgmt/tm/ltm/profile/client-ssl?$top={pageSize}&$skip=0";
360+
F5PagedSSLProfiles pagedProfiles = REST.Get<F5PagedSSLProfiles>(query);
361+
List<F5SSLProfile> profiles = new List<F5SSLProfile>();
362+
363+
if (pagedProfiles.totalItems == 0 || pagedProfiles.items?.Length == 0)
364+
{
365+
return profiles;
366+
}
367+
368+
for (int i = pagedProfiles.pageIndex; i <= pagedProfiles.totalPages; i++)
369+
{
370+
profiles.AddRange(pagedProfiles.items);
371+
372+
// The current paged profile will contain a link to the next set, unless the end has been reached
373+
if (string.IsNullOrEmpty(pagedProfiles.nextLink)) { break; }
374+
375+
// Get the next page of profiles
376+
query = pagedProfiles.nextLink.Replace("https://localhost", "");
377+
pagedProfiles = REST.Get<F5PagedSSLProfiles>(query);
378+
}
379+
380+
LogHandlerCommon.MethodExit(logger, CertificateStore, "GetCertificateEntries");
381+
return profiles;
382+
}
383+
355384
private void SetItemStatus(CurrentInventoryItem agentInventoryItem)
356385
{
357386
LogHandlerCommon.MethodEntry(logger, CertificateStore, "SetItemStatus");
@@ -611,67 +640,67 @@ private List<X509Certificate2> ReorderPEMLIst(List<X509Certificate2> certList)
611640
// WebServer
612641
#endregion
613642

614-
#region SSL Profiles
643+
#region SSL Certificates
615644

616-
public List<CurrentInventoryItem> GetSSLProfiles(int pageSize)
645+
public List<CurrentInventoryItem> GetCertificateEntries(int pageSize)
617646
{
618-
LogHandlerCommon.MethodEntry(logger, CertificateStore, "GetSSLProfiles");
647+
LogHandlerCommon.MethodEntry(logger, CertificateStore, "GetCertificateEntries");
619648
string partition = CertificateStore.StorePath;
620649
string query = $"/mgmt/tm/sys/file/ssl-cert?$filter=partition+eq+{partition}&$select=name,keyType,isBundle&$top={pageSize}&$skip=0";
621-
F5PagedSSLProfiles pagedProfiles = REST.Get<F5PagedSSLProfiles>(query);
622-
List<F5SSLProfile> profiles = new List<F5SSLProfile>();
650+
F5PagedSSLCertificates pagedCertificates = REST.Get<F5PagedSSLCertificates>(query);
651+
List<F5SSLCertificate> certificates = new List<F5SSLCertificate>();
623652
List<CurrentInventoryItem> inventory = new List<CurrentInventoryItem>();
624653

625-
if (pagedProfiles.totalItems == 0 || pagedProfiles.items?.Length == 0)
654+
if (pagedCertificates.totalItems == 0 || pagedCertificates.items?.Length == 0)
626655
{
627-
LogHandlerCommon.Trace(logger, CertificateStore, $"No SSL profiles found in partition '{partition}'");
628-
LogHandlerCommon.MethodExit(logger, CertificateStore, "GetSSLProfiles");
656+
LogHandlerCommon.Trace(logger, CertificateStore, $"No SSL certificates found in partition '{partition}'");
657+
LogHandlerCommon.MethodExit(logger, CertificateStore, "GetCertificateEntries");
629658
return inventory;
630659
}
631660
else
632661
{
633-
LogHandlerCommon.Trace(logger, CertificateStore, $"Compiling {pagedProfiles.totalPages} pages containing {pagedProfiles.totalItems} total inventory entries");
662+
LogHandlerCommon.Trace(logger, CertificateStore, $"Compiling {pagedCertificates.totalPages} pages containing {pagedCertificates.totalItems} total inventory entries");
634663
}
635664

636-
// Collected all of the profile entry names
637-
for (int i = pagedProfiles.pageIndex; i <= pagedProfiles.totalPages; i++)
665+
// Collected all of the certificate entry names
666+
for (int i = pagedCertificates.pageIndex; i <= pagedCertificates.totalPages; i++)
638667
{
639-
profiles.AddRange(pagedProfiles.items);
668+
certificates.AddRange(pagedCertificates.items);
640669

641-
// The current paged profile will contain a link to the next set, unless the end has been reached
642-
if (string.IsNullOrEmpty(pagedProfiles.nextLink)) { break; }
670+
// The current paged certificate list will contain a link to the next set, unless the end has been reached
671+
if (string.IsNullOrEmpty(pagedCertificates.nextLink)) { break; }
643672

644-
// Get the next page of profiles
645-
query = pagedProfiles.nextLink.Replace("https://localhost", "");
646-
pagedProfiles = REST.Get<F5PagedSSLProfiles>(query);
673+
// Get the next page of certificates
674+
query = pagedCertificates.nextLink.Replace("https://localhost", "");
675+
pagedCertificates = REST.Get<F5PagedSSLCertificates>(query);
647676
}
648677

649678
// Compile the entries into inventory items
650-
for (int i = 0; i < profiles.Count; i++)
679+
for (int i = 0; i < certificates.Count; i++)
651680
{
652681
try
653682
{
654-
LogHandlerCommon.Trace(logger, CertificateStore, $"Processing alias {profiles[i].name}");
683+
LogHandlerCommon.Trace(logger, CertificateStore, $"Processing alias {certificates[i].name}");
655684
// Exclude 'ca-bundle.crt' as that can only be managed by F5
656-
if (profiles[i].name.Equals("ca-bundle.crt", StringComparison.OrdinalIgnoreCase)
657-
|| profiles[i].name.Equals("f5-ca-bundle.crt", StringComparison.OrdinalIgnoreCase))
685+
if (certificates[i].name.Equals("ca-bundle.crt", StringComparison.OrdinalIgnoreCase)
686+
|| certificates[i].name.Equals("f5-ca-bundle.crt", StringComparison.OrdinalIgnoreCase))
658687
{
659-
LogHandlerCommon.Trace(logger, CertificateStore, $"Skipping '{profiles[i].name}' because it is managed by F5");
688+
LogHandlerCommon.Trace(logger, CertificateStore, $"Skipping '{certificates[i].name}' because it is managed by F5");
660689
continue;
661690
}
662-
inventory.Add(GetInventoryItem(partition, profiles[i].name, true));
691+
inventory.Add(GetInventoryItem(partition, certificates[i].name, true));
663692
}
664693
catch (Exception ex)
665694
{
666-
LogHandlerCommon.Error(logger, CertificateStore, ExceptionHandler.FlattenExceptionMessages(ex, $"Unable to process inventory item {profiles[i].name}."));
695+
LogHandlerCommon.Error(logger, CertificateStore, ExceptionHandler.FlattenExceptionMessages(ex, $"Unable to process inventory item {certificates[i].name}."));
667696
}
668697
}
669698

670-
LogHandlerCommon.MethodExit(logger, CertificateStore, "GetSSLProfiles");
699+
LogHandlerCommon.MethodExit(logger, CertificateStore, "GetCertificateEntries");
671700
return inventory;
672701
}
673702

674-
// SSL Profiles
703+
// SSL Certificates
675704
#endregion
676705

677706
#region Auth & Version

F5DataModels.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,18 @@ internal class F5CABundle
6262
public string[] includeBundle { get; set; }
6363
}
6464

65+
internal class F5PagedSSLCertificates : F5PagedResult
66+
{
67+
public F5SSLCertificate[] items { get; set; }
68+
}
69+
70+
internal class F5SSLCertificate
71+
{
72+
public string name { get; set; }
73+
public bool isBundle { get; set; }
74+
public string keyType { get; set; }
75+
}
76+
6577
internal class F5PagedSSLProfiles : F5PagedResult
6678
{
6779
public F5SSLProfile[] items { get; set; }
@@ -70,8 +82,7 @@ internal class F5PagedSSLProfiles : F5PagedResult
7082
internal class F5SSLProfile
7183
{
7284
public string name { get; set; }
73-
public bool isBundle { get; set; }
74-
public string keyType { get; set; }
85+
public string cert { get; set; }
7586
}
7687

7788
internal class F5Key

SSLProfile/Inventory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public override JobResult ProcessJob(InventoryJobConfiguration config, SubmitInv
4545
ValidateF5Release(logger, JobConfig.CertificateStoreDetails, f5);
4646

4747
LogHandlerCommon.Debug(logger, JobConfig.CertificateStoreDetails, $"Getting inventory from '{config.CertificateStoreDetails.StorePath}'");
48-
inventory = f5.GetSSLProfiles(20);
48+
inventory = f5.GetCertificateEntries(20);
4949

5050
LogHandlerCommon.Debug(logger, JobConfig.CertificateStoreDetails, $"Submitting {inventory?.Count} inventory entries for '{config.CertificateStoreDetails.StorePath}'");
5151
submitInventory.Invoke(inventory);

0 commit comments

Comments
 (0)