Skip to content

Commit 9f2fea8

Browse files
Enabled Flag For Gateway Functionality
1 parent bda5adb commit 9f2fea8

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

AcmeCaPlugin/AcmeCaPlugin.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public class AcmeCaPlugin : IAnyCAPlugin
6363
{
6464
private static readonly ILogger _logger = LogHandler.GetClassLogger<AcmeCaPlugin>();
6565
private IAnyCAPluginConfigProvider Config { get; set; }
66+
private AcmeClientConfig _config;
6667

6768
// Constants for better maintainability
6869
private const string DEFAULT_PRODUCT_ID = "default";
@@ -77,6 +78,16 @@ public void Initialize(IAnyCAPluginConfigProvider configProvider, ICertificateDa
7778
{
7879
_logger.MethodEntry();
7980
Config = configProvider ?? throw new ArgumentNullException(nameof(configProvider));
81+
_config = GetConfig();
82+
_logger.LogTrace("Enabled: {Enabled}", _config.Enabled);
83+
84+
if (!_config.Enabled)
85+
{
86+
_logger.LogWarning("The CA is currently in the Disabled state. It must be Enabled to perform operations. Skipping config validation...");
87+
_logger.MethodExit();
88+
return;
89+
}
90+
8091
_logger.MethodExit();
8192
}
8293

@@ -89,6 +100,12 @@ public void Initialize(IAnyCAPluginConfigProvider configProvider, ICertificateDa
89100
public async Task Ping()
90101
{
91102
_logger.MethodEntry();
103+
if (!_config.Enabled)
104+
{
105+
_logger.LogWarning("The CA is currently in the Disabled state. It must be Enabled to perform operations. Skipping connectivity test...");
106+
_logger.MethodExit();
107+
return;
108+
}
92109

93110
HttpClient httpClient = null;
94111
try
@@ -166,6 +183,13 @@ public Task ValidateCAConnectionInfo(Dictionary<string, object> connectionInfo)
166183
var rawData = JsonConvert.SerializeObject(connectionInfo);
167184
var config = JsonConvert.DeserializeObject<AcmeClientConfig>(rawData);
168185

186+
if (config != null && !config.Enabled)
187+
{
188+
_logger.LogWarning("The CA is currently in the Disabled state. It must be Enabled to perform operations. Skipping config validation...");
189+
_logger.MethodExit();
190+
return Task.CompletedTask;
191+
}
192+
169193
// Validate required configuration fields
170194
var missingFields = new List<string>();
171195
if (string.IsNullOrWhiteSpace(config?.DirectoryUrl))
@@ -231,6 +255,17 @@ public async Task<EnrollmentResult> Enroll(
231255
{
232256
_logger.MethodEntry();
233257

258+
if (!_config.Enabled)
259+
{
260+
_logger.LogWarning("The CA is currently in the Disabled state. It must be Enabled to perform operations. Enrollment rejected.");
261+
_logger.MethodExit();
262+
return new EnrollmentResult
263+
{
264+
Status = (int)EndEntityStatus.FAILED,
265+
StatusMessage = "CA connector is disabled. Enable it in the CA configuration to perform enrollments."
266+
};
267+
}
268+
234269
if (string.IsNullOrWhiteSpace(csr))
235270
throw new ArgumentException("CSR cannot be null or empty", nameof(csr));
236271
if (string.IsNullOrWhiteSpace(subject))

AcmeCaPlugin/AcmeCaPluginConfig.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ public static Dictionary<string, PropertyConfigInfo> GetPluginAnnotations()
99
{
1010
return new Dictionary<string, PropertyConfigInfo>()
1111
{
12+
["Enabled"] = new PropertyConfigInfo()
13+
{
14+
Comments = "Enable or disable this CA connector. When disabled, all operations (ping, enroll, sync) are skipped.",
15+
Hidden = false,
16+
DefaultValue = "true",
17+
Type = "Bool"
18+
},
1219
["DirectoryUrl"] = new PropertyConfigInfo()
1320
{
1421
Comments = "ACME directory URL (e.g. Let's Encrypt, ZeroSSL, etc.)",

AcmeCaPlugin/AcmeClientConfig.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ namespace Keyfactor.Extensions.CAPlugin.Acme
44
{
55
public class AcmeClientConfig
66
{
7+
public bool Enabled { get; set; } = true;
78
public string DirectoryUrl { get; set; } = "https://acme-v02.api.letsencrypt.org/directory";
89
public string Email { get; set; } = string.Empty;
910
public string EabKid { get; set; } = null;

0 commit comments

Comments
 (0)