Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 24 additions & 14 deletions GCPCAS/GCPCASCAPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -80,9 +82,10 @@ public List<string> 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");
Expand Down Expand Up @@ -163,21 +166,28 @@ private void GCPCASClientFromCAConnectionData(Dictionary<string, object> connect
_logger.MethodEntry();
_logger.LogDebug($"Validating GCP CAS CA Connection properties");
var rawData = JsonSerializer.Serialize(connectionData);
GCPCASPluginConfig.Config config = JsonSerializer.Deserialize<GCPCASPluginConfig.Config>(rawData);
_config = JsonSerializer.Deserialize<GCPCASPluginConfig.Config>(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)
{
_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<string> missingFields = new List<string>();

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)}");
}
Expand All @@ -189,10 +199,10 @@ private void GCPCASClientFromCAConnectionData(Dictionary<string, object> 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();
}
Expand Down
Loading