From 48a3fe7f42081ef7ba4e4bceecd1ae1830f0d240 Mon Sep 17 00:00:00 2001 From: Dave Galey <89407235+dgaley@users.noreply.github.com> Date: Mon, 11 Mar 2024 11:20:43 -0400 Subject: [PATCH] Add Enabled config flag Allows for creating the CA prior to having config info available, creating with Enabled = false skips config validation. --- .../CertCentralCAConnector.cs | 29 +++++++++++++++++++ .../CertCentralConfig.cs | 1 + .../Constants.cs | 1 + 3 files changed, 31 insertions(+) diff --git a/digicert-certcentral-anycagateway/CertCentralCAConnector.cs b/digicert-certcentral-anycagateway/CertCentralCAConnector.cs index 3f8a512..6590a53 100644 --- a/digicert-certcentral-anycagateway/CertCentralCAConnector.cs +++ b/digicert-certcentral-anycagateway/CertCentralCAConnector.cs @@ -352,6 +352,13 @@ public Dictionary GetCAConnectorAnnotations() Hidden = false, DefaultValue = false, Type = "Boolean" + }, + [CertCentralConstants.Config.ENABLED] = new PropertyConfigInfo() + { + Comments = "Flag to Enable or Disable gateway functionality. Disabling is primarily used to allow creation of the CA prior to configuration information being available.", + Hidden = false, + DefaultValue = true, + Type = "Boolean" } }; } @@ -484,6 +491,14 @@ public Dictionary GetTemplateParameterAnnotations() public async Task Ping() { _logger.MethodEntry(LogLevel.Trace); + if (!_config.Enabled) + { + _logger.LogWarning($"The CA is currently in the Disabled state. It must be Enabled to perform operations. Skipping connectivity test..."); + _logger.MethodExit(LogLevel.Trace); + return; + } + + try { CertCentralClient client = CertCentralClientUtilities.BuildCertCentralClient(_config); @@ -693,6 +708,20 @@ public async Task Synchronize(BlockingCollection blockin public async Task ValidateCAConnectionInfo(Dictionary connectionInfo) { _logger.MethodEntry(LogLevel.Trace); + try + { + if (!(bool)connectionInfo[CertCentralConstants.Config.ENABLED]) + { + _logger.LogWarning($"The CA is currently in the Disabled state. It must be Enabled to perform operations. Skipping validation...") + _logger.MethodExit(LogLevel.Trace); + return; + } + } + catch (Exception ex) + { + _logger.LogError($"Exception: {LogHandler.FlattenException(ex)}"); + } + List errors = new List(); _logger.LogTrace("Checking the API Key."); diff --git a/digicert-certcentral-anycagateway/CertCentralConfig.cs b/digicert-certcentral-anycagateway/CertCentralConfig.cs index b29af9e..04415e5 100644 --- a/digicert-certcentral-anycagateway/CertCentralConfig.cs +++ b/digicert-certcentral-anycagateway/CertCentralConfig.cs @@ -12,5 +12,6 @@ public class CertCentralConfig public string Region { get; set; } = "US"; public int? DivisionId { get; set; } public bool? RevokeCertificateOnly { get; set; } + public bool Enabled { get; set; } = true; } } diff --git a/digicert-certcentral-anycagateway/Constants.cs b/digicert-certcentral-anycagateway/Constants.cs index 9e7a527..25964b4 100644 --- a/digicert-certcentral-anycagateway/Constants.cs +++ b/digicert-certcentral-anycagateway/Constants.cs @@ -26,6 +26,7 @@ public class Config public const string CA_CERT_ID = "CACertId"; public const string RENEWAL_WINDOW = "RenewalWindowDays"; public const string REVOKE_CERT = "RevokeCertificateOnly"; + public const string ENABLED = "Enabled"; } public class RequestAttributes