Skip to content

Commit

Permalink
Adding managed by acmebot certificate list (#404)
Browse files Browse the repository at this point in the history
* Adding managed by acmebot certificate list

* Fixed Dns01Precondition and SANs validation error

* Remove renew histories entry
  • Loading branch information
shibayan authored Nov 24, 2021
1 parent 298822b commit bba5a40
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 355 deletions.
4 changes: 2 additions & 2 deletions KeyVault.Acmebot.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29215.179
# Visual Studio Version 17
VisualStudioVersion = 17.0.31912.275
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KeyVault.Acmebot", "KeyVault.Acmebot\KeyVault.Acmebot.csproj", "{81F62D09-D16D-4B0C-9DAE-C075580F5021}"
EndProject
Expand Down
5 changes: 3 additions & 2 deletions KeyVault.Acmebot/Functions/RevokeCertificate.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using System;
using System.Threading.Tasks;

using Azure.WebJobs.Extensions.HttpApi;

Expand Down Expand Up @@ -47,7 +48,7 @@ public async Task<IActionResult> HttpStart(

log.LogInformation($"Started orchestration with ID = '{instanceId}'.");

return AcceptedAtFunction(nameof(GetInstanceState) + "_" + nameof(GetInstanceState.HttpStart), new { instanceId }, null);
return await starter.WaitForCompletionOrCreateCheckStatusResponseAsync(req, instanceId, TimeSpan.FromMinutes(1), returnInternalServerErrorOnFailure: true);
}
}
}
12 changes: 9 additions & 3 deletions KeyVault.Acmebot/Functions/SharedActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public async Task<IReadOnlyList<CertificateItem>> GetExpiringCertificates([Activ

await foreach (var certificate in certificates)
{
if (!certificate.TagsFilter(IssuerName, _options.Endpoint))
if (!certificate.IsAcmebotManaged(IssuerName, _options.Endpoint))
{
continue;
}
Expand All @@ -86,7 +86,11 @@ public async Task<IReadOnlyList<CertificateItem>> GetAllCertificates([ActivityTr

await foreach (var certificate in certificates)
{
result.Add((await _certificateClient.GetCertificateAsync(certificate.Name)).Value.ToCertificateItem());
var certificateItem = (await _certificateClient.GetCertificateAsync(certificate.Name)).Value.ToCertificateItem();

certificateItem.IsManaged = certificate.IsAcmebotManaged(IssuerName, _options.Endpoint);

result.Add(certificateItem);
}

return result;
Expand All @@ -112,10 +116,12 @@ public async Task<CertificatePolicyItem> GetCertificatePolicy([ActivityTrigger]
{
CertificatePolicy certificatePolicy = await _certificateClient.GetCertificatePolicyAsync(certificateName);

var dnsNames = certificatePolicy.SubjectAlternativeNames.DnsNames.ToArray();

return new CertificatePolicyItem
{
CertificateName = certificateName,
DnsNames = certificatePolicy.SubjectAlternativeNames.DnsNames.ToArray(),
DnsNames = dnsNames.Length > 0 ? dnsNames : new[] { certificatePolicy.Subject[3..] },
KeyType = certificatePolicy.KeyType?.ToString(),
KeySize = certificatePolicy.KeySize,
KeyCurveName = certificatePolicy.KeyCurveName?.ToString(),
Expand Down
2 changes: 1 addition & 1 deletion KeyVault.Acmebot/Internal/CertificateExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace KeyVault.Acmebot.Internal
{
internal static class CertificateExtensions
{
public static bool TagsFilter(this CertificateProperties properties, string issuer, string endpoint)
public static bool IsAcmebotManaged(this CertificateProperties properties, string issuer, string endpoint)
{
var tags = properties.Tags;

Expand Down
3 changes: 3 additions & 0 deletions KeyVault.Acmebot/Models/CertificateItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,8 @@ public class CertificateItem

[JsonProperty("reuseKey")]
public bool? ReuseKey { get; set; }

[JsonProperty("isManaged")]
public bool IsManaged { get; set; }
}
}
Loading

0 comments on commit bba5a40

Please sign in to comment.