Skip to content

Commit

Permalink
Add Enabled config flag
Browse files Browse the repository at this point in the history
Allows for creating the CA prior to having config info available, creating with Enabled = false skips config validation.
  • Loading branch information
dgaley committed Mar 11, 2024
1 parent 6730074 commit 48a3fe7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
29 changes: 29 additions & 0 deletions digicert-certcentral-anycagateway/CertCentralCAConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,13 @@ public Dictionary<string, PropertyConfigInfo> 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"
}
};
}
Expand Down Expand Up @@ -484,6 +491,14 @@ public Dictionary<string, PropertyConfigInfo> 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);
Expand Down Expand Up @@ -693,6 +708,20 @@ public async Task Synchronize(BlockingCollection<AnyCAPluginCertificate> blockin
public async Task ValidateCAConnectionInfo(Dictionary<string, object> 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...")

Check failure on line 715 in digicert-certcentral-anycagateway/CertCentralCAConnector.cs

View workflow job for this annotation

GitHub Actions / call-dotnet-build-and-release-workflow / dotnet-build-and-release

; expected

Check failure on line 715 in digicert-certcentral-anycagateway/CertCentralCAConnector.cs

View workflow job for this annotation

GitHub Actions / call-dotnet-build-and-release-workflow / dotnet-build-and-release

; expected
_logger.MethodExit(LogLevel.Trace);
return;
}
}
catch (Exception ex)
{
_logger.LogError($"Exception: {LogHandler.FlattenException(ex)}");
}

List<string> errors = new List<string>();

_logger.LogTrace("Checking the API Key.");
Expand Down
1 change: 1 addition & 0 deletions digicert-certcentral-anycagateway/CertCentralConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
1 change: 1 addition & 0 deletions digicert-certcentral-anycagateway/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 48a3fe7

Please sign in to comment.