Skip to content

Commit

Permalink
Hub: implement instance and keyword filter of managed items
Browse files Browse the repository at this point in the history
  • Loading branch information
webprofusion-chrisc committed Oct 29, 2024
1 parent 52be075 commit 00ff988
Showing 1 changed file with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ public HubController(ILogger<CertificateController> logger, ICertifyInternalApiC
[Route("items")]
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(ManagedCertificateSummaryResult))]
public async Task<IActionResult> GetHubManagedItems(string? keyword, int? page = null, int? pageSize = null)
public async Task<IActionResult> GetHubManagedItems(string? instanceId, string? keyword, int? page = null, int? pageSize = null)
{

var result = new ManagedCertificateSummaryResult();

var managedItems = _mgmtStateProvider.GetManagedInstanceItems();
Expand All @@ -61,20 +60,27 @@ public async Task<IActionResult> GetHubManagedItems(string? keyword, int? page =
var list = new List<ManagedCertificateSummary>();
foreach (var remote in managedItems.Values)
{
list.AddRange(remote.Items.Select(i => new ManagedCertificateSummary
if (string.IsNullOrEmpty(instanceId) || (instanceId == remote.InstanceId))
{
InstanceId = remote.InstanceId,
InstanceTitle = instances.FirstOrDefault(i => i.InstanceId == remote.InstanceId)?.Title,
Id = i.Id ?? "",
Title = $"[remote] {i.Name}" ?? "",
PrimaryIdentifier = i.GetCertificateIdentifiers().FirstOrDefault(p => p.Value == i.RequestConfig.PrimaryDomain) ?? i.GetCertificateIdentifiers().FirstOrDefault(),
Identifiers = i.GetCertificateIdentifiers(),
DateRenewed = i.DateRenewed,
DateExpiry = i.DateExpiry,
Comments = i.Comments ?? "",
Status = i.LastRenewalStatus?.ToString() ?? "",
HasCertificate = !string.IsNullOrEmpty(i.CertificatePath)
}));
list.AddRange(
remote.Items
.Where(i => string.IsNullOrWhiteSpace(keyword) || (!string.IsNullOrWhiteSpace(keyword) && i.Name?.Contains(keyword) == true))
.Select(i => new ManagedCertificateSummary
{
InstanceId = remote.InstanceId,
InstanceTitle = instances.FirstOrDefault(i => i.InstanceId == remote.InstanceId)?.Title,
Id = i.Id ?? "",
Title = $"[remote] {i.Name}" ?? "",
PrimaryIdentifier = i.GetCertificateIdentifiers().FirstOrDefault(p => p.Value == i.RequestConfig.PrimaryDomain) ?? i.GetCertificateIdentifiers().FirstOrDefault(),
Identifiers = i.GetCertificateIdentifiers(),
DateRenewed = i.DateRenewed,
DateExpiry = i.DateExpiry,
Comments = i.Comments ?? "",
Status = i.LastRenewalStatus?.ToString() ?? "",
HasCertificate = !string.IsNullOrEmpty(i.CertificatePath)
})
);
}
}

result.Results = list.OrderBy(l => l.Title);
Expand Down

0 comments on commit 00ff988

Please sign in to comment.