Skip to content

Commit

Permalink
code factor suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Suraiya-Hameed committed Jan 29, 2025
1 parent d7d9007 commit a944384
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,31 @@ public ValidationResult Run()
errorMessages.Add("No Azure cloud was configured");
}

errorMessages.AddRange(ValidateAzureCloudEnvironment());

if (_azureLandscape.Subscriptions == null || _azureLandscape.Subscriptions.Count == 0)
{
errorMessages.Add("No subscription id(s) were configured to query");
}
else
{
if (_azureLandscape.Subscriptions.Distinct().Count() != _azureLandscape.Subscriptions.Count)
{
errorMessages.Add("Duplicate subscription ids were configured to query");
}

if (_azureLandscape.Subscriptions.Any(string.IsNullOrWhiteSpace))
{
errorMessages.Add("Empty subscription is configured to query");
}
}

return errorMessages.Any() ? ValidationResult.Failure(ComponentName, errorMessages) : ValidationResult.Successful(ComponentName);
}

private IEnumerable<string> ValidateAzureCloudEnvironment()
{
var errorMessages = new List<string>();
if (_azureLandscape.Cloud == AzureCloud.Global)
{
_azureLandscape.AzureEnvironment = AzureEnvironment.AzureGlobalCloud;
Expand Down Expand Up @@ -75,29 +100,11 @@ public ValidationResult Run()
_azureLandscape.AzureEnvironment.Name = _azureLandscape.Cloud.GetEnvironmentName();
}
}
else
{
errorMessages.Add($"{nameof(_azureLandscape.Cloud)} No Azure environment is known for in legacy SDK");
}

if (_azureLandscape.Subscriptions == null || _azureLandscape.Subscriptions.Any() == false)
{
errorMessages.Add("No subscription id(s) were configured to query");
}
else
{
if (_azureLandscape.Subscriptions.Distinct().Count() != _azureLandscape.Subscriptions.Count)
{
errorMessages.Add("Duplicate subscription ids were configured to query");
}

if (_azureLandscape.Subscriptions.Any(string.IsNullOrWhiteSpace))
{
errorMessages.Add("Empty subscription is configured to query");
}
errorMessages.Add($"{nameof(_azureLandscape.Cloud)} No Azure environment is known for in legacy SDK");
}

return errorMessages.Any() ? ValidationResult.Failure(ComponentName, errorMessages) : ValidationResult.Successful(ComponentName);
return errorMessages;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using ValidationResult = Promitor.Agents.Core.Validation.ValidationResult;
using Promitor.Core.Serialization.Enum;
using Microsoft.Azure.Management.ResourceManager.Fluent;
using Promitor.Core.Scraping.Configuration.Serialization.v1.Model;

namespace Promitor.Agents.Scraper.Validation.Steps
{
Expand Down Expand Up @@ -132,6 +133,15 @@ private static IEnumerable<string> ValidateAzureMetadata(AzureMetadata azureMeta
errorMessages.Add("No Azure cloud is configured");
}

errorMessages.AddRange(ValidateAzureCloudEnvironment(azureMetadata));

return errorMessages;
}

private static IEnumerable<string> ValidateAzureCloudEnvironment(AzureMetadata azureMetadata)
{
var errorMessages = new List<string>();

if (azureMetadata.Cloud == AzureCloud.Global)
{
azureMetadata.AzureEnvironment = AzureEnvironment.AzureGlobalCloud;
Expand Down Expand Up @@ -172,7 +182,6 @@ private static IEnumerable<string> ValidateAzureMetadata(AzureMetadata azureMeta
{
errorMessages.Add($"{nameof(azureMetadata.Cloud)} No Azure environment is known for in legacy SDK");
}

return errorMessages;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ public void Validate_AzureCustomCloudWithMissingEndpoints_Fails()

[Fact]
public void Validate_AzureGlobalCloud_ProvidesCorrectEnvironmentInfo()

{
// Arrange
var azureLandscapeConfiguration = CreateLandscapeConfiguration();
Expand Down

0 comments on commit a944384

Please sign in to comment.