Skip to content

Commit 595ac9a

Browse files
dns changes
1 parent 253e986 commit 595ac9a

4 files changed

Lines changed: 80 additions & 206 deletions

File tree

AcmeCaPlugin/AcmeCaPlugin.cs

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,22 +64,72 @@ public class AcmeCaPlugin : IAnyCAPlugin
6464
private static readonly ILogger _logger = LogHandler.GetClassLogger<AcmeCaPlugin>();
6565
private IAnyCAPluginConfigProvider Config { get; set; }
6666
private IDomainValidator _domainValidator;
67+
private readonly IDomainValidatorFactory _validatorFactory;
6768

6869
// Constants for better maintainability
6970
private const string DEFAULT_PRODUCT_ID = "default";
7071
private const string DNS_CHALLENGE_TYPE = "dns-01";
7172
private const int DNS_PROPAGATION_DELAY_SECONDS = 30;
7273
private const string USER_AGENT = "KeyfactorAcmePlugin/1.0";
7374

75+
/// <summary>
76+
/// Default constructor for backward compatibility
77+
/// </summary>
78+
public AcmeCaPlugin() : this(null)
79+
{
80+
}
81+
82+
/// <summary>
83+
/// Constructor with dependency injection support for domain validator factory
84+
/// </summary>
85+
/// <param name="validatorFactory">Factory to resolve domain validators from plugins</param>
86+
public AcmeCaPlugin(IDomainValidatorFactory validatorFactory)
87+
{
88+
_validatorFactory = validatorFactory;
89+
}
90+
7491
/// <summary>
7592
/// Initialize the plugin with configuration and certificate data reader
7693
/// </summary>
7794
public void Initialize(IAnyCAPluginConfigProvider configProvider, ICertificateDataReader certificateDataReader)
7895
{
7996
_logger.MethodEntry();
8097
Config = configProvider ?? throw new ArgumentNullException(nameof(configProvider));
81-
_domainValidator = new Dns01DomainValidator();
82-
_domainValidator.Initialize(new DomainValidatorConfigProvider(configProvider.CAConnectionData));
98+
99+
// Try to use plugin-based domain validator if factory is available
100+
if (_validatorFactory != null)
101+
{
102+
_logger.LogInformation("Using plugin-based domain validator resolution");
103+
try
104+
{
105+
// Resolve domain validator from plugin system
106+
_domainValidator = _validatorFactory.ResolveDomainValidator(
107+
domain: "*", // Wildcard - let the factory choose the right provider
108+
validationType: DNS_CHALLENGE_TYPE
109+
);
110+
111+
if (_domainValidator != null)
112+
{
113+
_domainValidator.Initialize(new DomainValidatorConfigProvider(configProvider.CAConnectionData));
114+
_logger.LogInformation("Successfully initialized domain validator from plugin: {ValidatorType}",
115+
_domainValidator.GetType().FullName);
116+
}
117+
}
118+
catch (Exception ex)
119+
{
120+
_logger.LogWarning(ex, "Failed to resolve domain validator from plugin factory, falling back to embedded validator");
121+
_domainValidator = null;
122+
}
123+
}
124+
125+
// Fallback to embedded validator for backward compatibility
126+
if (_domainValidator == null)
127+
{
128+
_logger.LogInformation("Using embedded Dns01DomainValidator (legacy mode)");
129+
_domainValidator = new Dns01DomainValidator();
130+
_domainValidator.Initialize(new DomainValidatorConfigProvider(configProvider.CAConnectionData));
131+
}
132+
83133
_logger.MethodExit();
84134
}
85135

AcmeCaPlugin/AcmeCaPlugin.csproj

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,45 @@
99
<AssemblyName>AcmeCaPlugin</AssemblyName>
1010
</PropertyGroup>
1111
<ItemGroup>
12+
<!-- Core ACME and CA Plugin dependencies -->
1213
<PackageReference Include="ACMESharpCore" Version="2.2.0.148" />
1314
<PackageReference Include="Autofac" Version="8.3.0" />
14-
<PackageReference Include="AWSSDK.Core" Version="4.0.3.11" />
15-
<PackageReference Include="AWSSDK.Route53" Version="4.0.8.8" />
16-
<PackageReference Include="Azure.Identity" Version="1.14.0" />
17-
<PackageReference Include="Azure.ResourceManager.Cdn" Version="1.4.0" />
18-
<PackageReference Include="Azure.ResourceManager.Dns" Version="1.1.1" />
1915
<PackageReference Include="BouncyCastle.Cryptography" Version="2.6.2" />
2016
<PackageReference Include="DnsClient" Version="1.8.0" />
21-
<PackageReference Include="ARSoft.Tools.Net" Version="3.6.0" />
22-
<PackageReference Include="Google.Apis.Dns.v1" Version="1.69.0.3753" />
2317
<PackageReference Include="Keyfactor.AnyGateway.IAnyCAPlugin" Version="3.3.0-PRERELEASE-78770-979f582005" />
2418
<PackageReference Include="Keyfactor.Logging" Version="1.1.1" />
2519
<PackageReference Include="Keyfactor.PKI" Version="5.5.0" />
2620
<PackageReference Include="Microsoft.Extensions.Http" Version="9.0.5" />
27-
<PackageReference Include="Nager.PublicSuffix" Version="3.5.0" />
2821
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
2922
<PackageReference Include="System.Drawing.Common" Version="10.0.2" />
3023
<PackageReference Include="System.Net.Http.WinHttpHandler" Version="9.0.5" />
3124
<PackageReference Include="System.Security.Cryptography.ProtectedData" Version="9.0.5" />
25+
26+
<!-- DNS Provider dependencies - REMOVE THESE after migrating all providers to plugins -->
27+
<!-- TODO: These should be removed once all DNS providers are moved to separate plugin projects -->
28+
<!-- Google DNS - MIGRATED to Keyfactor.DnsProvider.Google plugin -->
29+
<!-- <PackageReference Include="Google.Apis.Dns.v1" Version="1.69.0.3753" /> -->
30+
31+
<!-- AWS Route53 - TODO: Migrate to plugin -->
32+
<PackageReference Include="AWSSDK.Core" Version="4.0.3.11" />
33+
<PackageReference Include="AWSSDK.Route53" Version="4.0.8.8" />
34+
35+
<!-- Azure DNS - TODO: Migrate to plugin -->
36+
<PackageReference Include="Azure.Identity" Version="1.14.0" />
37+
<PackageReference Include="Azure.ResourceManager.Cdn" Version="1.4.0" />
38+
<PackageReference Include="Azure.ResourceManager.Dns" Version="1.1.1" />
39+
40+
<!-- RFC2136 - TODO: Migrate to plugin -->
41+
<PackageReference Include="ARSoft.Tools.Net" Version="3.6.0" />
42+
43+
<!-- Cloudflare - TODO: Migrate to plugin (uses standard HTTP client) -->
44+
45+
<!-- NS1 - TODO: Migrate to plugin (uses standard HTTP client) -->
46+
47+
<!-- Infoblox - TODO: Migrate to plugin (uses standard HTTP client) -->
48+
49+
<!-- Public Suffix - TODO: Evaluate if needed in core or per-provider -->
50+
<PackageReference Include="Nager.PublicSuffix" Version="3.5.0" />
3251
</ItemGroup>
3352
<ItemGroup>
3453
<None Update="manifest.json">

AcmeCaPlugin/Clients/DNS/DnsProviderFactory.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@ public static IDnsProvider Create(AcmeClientConfig config, ILogger logger)
1313
switch (config.DnsProvider.Trim().ToLowerInvariant())
1414
{
1515
case "google":
16-
return new GoogleDnsProvider(
17-
config.Google_ServiceAccountKeyPath,
18-
config.Google_ServiceAccountKeyJson,
19-
config.Google_ProjectId
20-
);
16+
2117

2218
case "cloudflare":
2319
return new CloudflareDnsProvider(

AcmeCaPlugin/Clients/DNS/GoogleDnsProvider.cs

Lines changed: 0 additions & 191 deletions
This file was deleted.

0 commit comments

Comments
 (0)