From dccce3cae1b8367fef58b77e82fdd336c050f266 Mon Sep 17 00:00:00 2001 From: Travis Gillitzer Date: Fri, 26 Sep 2025 08:14:02 -0500 Subject: [PATCH 1/2] Don't create GCPCASClient if Enabled == false --- GCPCAS/GCPCASCAPlugin.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/GCPCAS/GCPCASCAPlugin.cs b/GCPCAS/GCPCASCAPlugin.cs index 7990e06..b3a723d 100644 --- a/GCPCAS/GCPCASCAPlugin.cs +++ b/GCPCAS/GCPCASCAPlugin.cs @@ -171,6 +171,13 @@ private void GCPCASClientFromCAConnectionData(Dictionary connect _logger.LogTrace($"GCPCASClientFromCAConnectionData - CAId: {config?.CAId}"); _logger.LogTrace($"GCPCASClientFromCAConnectionData - Enabled: {config.Enabled}"); + if (!config.Enabled) + { + _logger.LogWarning($"The CA is currently in the Disabled state. It must be Enabled to perform operations. Skipping config validation and GCPCASClient creation..."); + _logger.MethodExit(); + return; + } + List missingFields = new List(); if (string.IsNullOrEmpty(config.LocationId)) missingFields.Add(nameof(config.LocationId)); From f6a399a2ed0eb506c7e84fbc6fb35f85e0d8b4c5 Mon Sep 17 00:00:00 2001 From: Travis Gillitzer Date: Mon, 29 Sep 2025 12:12:41 -0500 Subject: [PATCH 2/2] bypass ping if config is disabled --- GCPCAS/GCPCASCAPlugin.cs | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/GCPCAS/GCPCASCAPlugin.cs b/GCPCAS/GCPCASCAPlugin.cs index b3a723d..8babc00 100644 --- a/GCPCAS/GCPCASCAPlugin.cs +++ b/GCPCAS/GCPCASCAPlugin.cs @@ -36,6 +36,8 @@ public class GCPCASCAPlugin : IAnyCAPlugin IGCPCASClient Client { get; set; } private bool _gcpCasClientWasInjected = false; + private GCPCASPluginConfig.Config _config; + public GCPCASCAPlugin() { // Explicit default constructor @@ -80,9 +82,10 @@ public List GetProductIds() public async Task Ping() { _logger.MethodEntry(); - if (!Client.IsEnabled()) + if (!_config.Enabled) { - _logger.LogDebug("GCPCASClient is disabled. Skipping Ping"); + _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; } _logger.LogDebug("Pinging GCP CAS to validate connection"); @@ -163,15 +166,15 @@ private void GCPCASClientFromCAConnectionData(Dictionary connect _logger.MethodEntry(); _logger.LogDebug($"Validating GCP CAS CA Connection properties"); var rawData = JsonSerializer.Serialize(connectionData); - GCPCASPluginConfig.Config config = JsonSerializer.Deserialize(rawData); + _config = JsonSerializer.Deserialize(rawData); - _logger.LogTrace($"GCPCASClientFromCAConnectionData - LocationId: {config.LocationId}"); - _logger.LogTrace($"GCPCASClientFromCAConnectionData - ProjectId: {config.ProjectId}"); - _logger.LogTrace($"GCPCASClientFromCAConnectionData - CAPool: {config.CAPool}"); - _logger.LogTrace($"GCPCASClientFromCAConnectionData - CAId: {config?.CAId}"); - _logger.LogTrace($"GCPCASClientFromCAConnectionData - Enabled: {config.Enabled}"); + _logger.LogTrace($"GCPCASClientFromCAConnectionData - LocationId: {_config.LocationId}"); + _logger.LogTrace($"GCPCASClientFromCAConnectionData - ProjectId: {_config.ProjectId}"); + _logger.LogTrace($"GCPCASClientFromCAConnectionData - CAPool: {_config.CAPool}"); + _logger.LogTrace($"GCPCASClientFromCAConnectionData - CAId: {_config?.CAId}"); + _logger.LogTrace($"GCPCASClientFromCAConnectionData - Enabled: {_config.Enabled}"); - if (!config.Enabled) + if (!_config.Enabled) { _logger.LogWarning($"The CA is currently in the Disabled state. It must be Enabled to perform operations. Skipping config validation and GCPCASClient creation..."); _logger.MethodExit(); @@ -180,11 +183,11 @@ private void GCPCASClientFromCAConnectionData(Dictionary connect List missingFields = new List(); - if (string.IsNullOrEmpty(config.LocationId)) missingFields.Add(nameof(config.LocationId)); - if (string.IsNullOrEmpty(config.ProjectId)) missingFields.Add(nameof(config.ProjectId)); - if (string.IsNullOrEmpty(config.CAPool)) missingFields.Add(nameof(config.CAPool)); + if (string.IsNullOrEmpty(_config.LocationId)) missingFields.Add(nameof(_config.LocationId)); + if (string.IsNullOrEmpty(_config.ProjectId)) missingFields.Add(nameof(_config.ProjectId)); + if (string.IsNullOrEmpty(_config.CAPool)) missingFields.Add(nameof(_config.CAPool)); - if (config.Enabled && missingFields.Count > 0) + if (_config.Enabled && missingFields.Count > 0) { throw new ArgumentException($"The following required fields are missing or empty: {string.Join(", ", missingFields)}"); } @@ -196,10 +199,10 @@ private void GCPCASClientFromCAConnectionData(Dictionary connect else { _logger.LogDebug("Creating new GCPCASClient instance."); - Client = new GCPCASClient(config.LocationId, config.ProjectId, config.CAPool, config.CAId); + Client = new GCPCASClient(_config.LocationId, _config.ProjectId, _config.CAPool, _config.CAId); } - if (config.Enabled) + if (_config.Enabled) { Client.Enable(); }