Skip to content

Commit

Permalink
Fixed new certificate issue error (#797)
Browse files Browse the repository at this point in the history
  • Loading branch information
shibayan authored Jan 3, 2025
1 parent 6e06532 commit eaec7d5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
9 changes: 2 additions & 7 deletions KeyVault.Acmebot/Functions/SharedActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -386,14 +386,9 @@ public async Task<OrderDetails> FinalizeOrder([ActivityTrigger] (CertificatePoli
try
{
var certificatePolicy = certificatePolicyItem.ToCertificatePolicy();
var metadata = certificatePolicyItem.ToCertificateMetadata(_options.Endpoint);

var certificateOperation = await _certificateClient.StartCreateCertificateAsync(certificatePolicyItem.CertificateName, certificatePolicy, tags: new Dictionary<string, string>
{
{ "Issuer", "Acmebot" },
{ "Endpoint", _options.Endpoint.Host },
{ "DnsProvider", certificatePolicyItem.DnsProviderName },
{ "DnsAlias", certificatePolicyItem.DnsAlias }
});
var certificateOperation = await _certificateClient.StartCreateCertificateAsync(certificatePolicyItem.CertificateName, certificatePolicy, tags: metadata);

csr = certificateOperation.Properties.Csr;
}
Expand Down
18 changes: 17 additions & 1 deletion KeyVault.Acmebot/Internal/CertificateExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,23 @@ public static CertificatePolicyItem ToCertificatePolicyItem(this KeyVaultCertifi
};
}

public static IDictionary<string, string> ToCertificateMetadata(this CertificatePolicyItem certificatePolicyItem, Uri endpoint)
{
var metadata = new Dictionary<string, string>
{
{ IssuerKey, IssuerValue },
{ EndpointKey, endpoint.Host },
{ DnsProviderKey, certificatePolicyItem.DnsProviderName }
};

if (!string.IsNullOrEmpty(certificatePolicyItem.DnsAlias))
{
metadata.Add(DnsAliasKey, certificatePolicyItem.DnsAlias);
}

return metadata;
}

private const string IssuerKey = "Issuer";
private const string EndpointKey = "Endpoint";
private const string DnsProviderKey = "DnsProvider";
Expand All @@ -75,7 +92,6 @@ public static CertificatePolicyItem ToCertificatePolicyItem(this KeyVaultCertifi

private static bool TryGetDnsAlias(this IDictionary<string, string> tags, out string dnsAlias) => tags.TryGetValue(DnsAliasKey, out dnsAlias);


private static string ToHexString(byte[] bytes)
{
ArgumentNullException.ThrowIfNull(bytes);
Expand Down

0 comments on commit eaec7d5

Please sign in to comment.