Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Acl/src/EnvironmentOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ public class EnvironmentOptions

public string Environment { get; set; } = EnvironmentType.Test;

public string Cloud { get; set; } = CloudType.Public;
public string Cloud { get; set; } = CloudType.AzureCloud;
}
16 changes: 13 additions & 3 deletions Acl/src/EnvironmentOptionsExts/CloudType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,20 @@ public static class CloudType
/// <summary>
/// Represents the public cloud.
/// </summary>
public const string Public = "public";
public const string AzureCloud = nameof(AzureCloud);

/// <summary>
/// Represents the Fairfax (US Government) cloud.
/// Represents the US Government cloud.
/// </summary>
public const string Fairfax = "fairfax";
public const string AzureUSGovernment = nameof(AzureUSGovernment);

/// <summary>
/// Represents the Chine cloud.
/// </summary>
public const string AzureChinaCloud = nameof(AzureChinaCloud);

/// <summary>
/// Represents the German cloud.
/// </summary>
public const string AzureGermanCloud = nameof(AzureGermanCloud);
}
12 changes: 8 additions & 4 deletions Acl/src/EnvironmentOptionsExts/EnvironmentOptionsCosmosDbExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ public static class EnvironmentOptionsCosmosDbExt

public static string GetCosmosDbNameSharedUrl(this EnvironmentOptions settings)
{
if (settings.Cloud == CloudType.Public)
return $"https://{GetCosmosDbNameShared(settings)}.documents.azure.com:443/";

throw new NotSupportedException($"Cloud type '{settings.Cloud}' is not supported.");
return settings.Cloud switch
{
CloudType.AzureCloud => $"https://{GetCosmosDbNameShared(settings)}.documents.azure.com:443/",
CloudType.AzureUSGovernment => $"https://{GetCosmosDbNameShared(settings)}.documents.azure.us:443/",
CloudType.AzureChinaCloud => $"https://{GetCosmosDbNameShared(settings)}.documents.azure.cn:443/",
CloudType.AzureGermanCloud => $"https://{GetCosmosDbNameShared(settings)}.documents.azure.com:443/",
_ => throw new NotSupportedException($"Cloud type '{settings.Cloud}' is not supported.")
};
}
}
4 changes: 2 additions & 2 deletions Acl/src/EnvironmentOptionsExts/EnvironmentOptionsExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

public static class EnvironmentOptionsExt
{
public static string GetResourceName(this EnvironmentOptions settings, string name) => $"{settings.Environment}-{settings.RegionShortName}-{name}-{settings.ServiceName}".ToLowerInvariant();
public static string GetResourceNameShared(this EnvironmentOptions settings, string name) => $"{settings.Environment}-{name}-{settings.ServiceName}".ToLowerInvariant();
public static string GetResourceName(this EnvironmentOptions settings, string resourceType) => $"{settings.Environment}-{settings.RegionShortName}-{resourceType}-{settings.ServiceName}".ToLowerInvariant();
public static string GetResourceNameShared(this EnvironmentOptions settings, string resourceType) => $"{settings.Environment}-{resourceType}-{settings.ServiceName}".ToLowerInvariant();
}
19 changes: 11 additions & 8 deletions Acl/src/EnvironmentOptionsExts/EnvironmentOptionsKeyVaultExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ public static string GetKeyVaultUri(this EnvironmentOptions settings)
ArgumentNullException.ThrowIfNull(settings);

var keyVaultName = settings.GetKeyVaultName();
switch (settings.Cloud)

// Map cloud to the known Key Vault endpoint suffix
var dnsSuffix = settings.Cloud switch
{
case CloudType.Public:
return $"https://{keyVaultName}.vault.azure.net/";
case CloudType.Fairfax:
return $"https://{keyVaultName}.vault.usgovcloudapi.net/";
default:
throw new NotSupportedException($"Cloud type '{settings.Cloud}' is not supported for Key Vault URI generation.");
}
CloudType.AzureCloud => "vault.azure.net",
CloudType.AzureUSGovernment => "vault.usgovcloudapi.net",
CloudType.AzureChinaCloud => "vault.azure.cn",
CloudType.AzureGermanCloud => "vault.microsoftazure.de",
_ => throw new NotSupportedException($"Cloud type '{settings.Cloud}' is not supported for Key Vault URI generation.")
};

return $"https://{keyVaultName}.{dnsSuffix}/";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ public static class EnvironmentOptionsServiceBusExt
{
public static string GetServiceBusName(this EnvironmentOptions settings) => settings.GetResourceNameShared("sbns");

public static string GetServiceBusNamespace(this EnvironmentOptions settings)
{
if (settings.Cloud == CloudType.Public)
return $"{GetServiceBusName(settings)}.servicebus.windows.net";
if (settings.Cloud == CloudType.Fairfax)
return $"{GetServiceBusName(settings)}.servicebus.usgovcloudapi.net";

throw new NotSupportedException($"Cloud type '{settings.Cloud}' is not supported.");
}
public static string GetServiceBusNamespace(this EnvironmentOptions settings) =>
settings.Cloud switch
{
CloudType.AzureCloud => $"{settings.GetServiceBusName()}.servicebus.windows.net",
CloudType.AzureUSGovernment => $"{settings.GetServiceBusName()}.servicebus.usgovcloudapi.net",
CloudType.AzureChinaCloud => $"{settings.GetServiceBusName()}.servicebus.chinacloudapi.cn",
CloudType.AzureGermanCloud => $"{settings.GetServiceBusName()}.servicebus.cloudapi.de",
_ => throw new NotSupportedException($"Cloud type '{settings.Cloud}' is not supported.")
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ public static string GetBlobStorageSharedUrl(this EnvironmentOptions settings)

return settings.Cloud switch
{
CloudType.Public => $"https://{GetStorageNameShared(settings)}.blob.core.windows.net",
CloudType.Fairfax => $"https://{GetStorageNameShared(settings)}.blob.core.usgovcloudapi.net",
CloudType.AzureCloud => $"https://{GetStorageNameShared(settings)}.blob.core.windows.net",
CloudType.AzureUSGovernment => $"https://{GetStorageNameShared(settings)}.blob.core.usgovcloudapi.net",
CloudType.AzureChinaCloud => $"https://{GetStorageNameShared(settings)}.blob.core.chinacloud.cn",
CloudType.AzureGermanCloud => $"https://{GetStorageNameShared(settings)}.blob.core.cloudapi.de",
_ => throw new NotSupportedException(
$"Cloud type '{settings.Cloud}' is not supported for Blob Storage URL generation.")
};
Expand Down
51 changes: 51 additions & 0 deletions Acl/tests/CosmosDbTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
namespace AntiCorruptionLayer.Tests;
using BestWeatherForecast.AntiCorruptionLayer;

public class CosmosDbTests
{
[Theory]
[InlineData("local")]
[InlineData("test")]
public void Will_get_CosmosDb_URL(string env)
{
// Arrange
EnvironmentOptions environmentOptions = new()
{
Environment = env,
RegionShortName = "usw2",
ServiceName = "bwf"
};

var expected = $"{env}-cosno-bwf";

// Act
var actual = environmentOptions.GetCosmosDbNameShared();

// Assert
actual.Should().Be(expected);
}

[Theory]
[InlineData(CloudType.AzureCloud, "https://ppe-cosno-bwf.documents.azure.com:443/")]
[InlineData(CloudType.AzureUSGovernment, "https://ppe-cosno-bwf.documents.azure.us:443/")]
[InlineData(CloudType.AzureChinaCloud, "https://ppe-cosno-bwf.documents.azure.cn:443/")]
[InlineData(CloudType.AzureGermanCloud, "https://ppe-cosno-bwf.documents.azure.com:443/")]
public void Will_get_url_for_Cloud(string cloudType, string expectedUrl)
{
// Arrange
EnvironmentOptions environmentOptions = new()
{
Environment = EnvironmentType.Ppe,
RegionShortName = "usw2",
ServiceName = "bwf",
Cloud = cloudType
};

// Act
var actualUrl = environmentOptions.GetCosmosDbNameSharedUrl();

// Assert
actualUrl.Should().Be(expectedUrl);

}
}
50 changes: 50 additions & 0 deletions Acl/tests/KeyVaultTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
namespace AntiCorruptionLayer.Tests;
using BestWeatherForecast.AntiCorruptionLayer;

public class KeyVaultTests
{
[Theory]
[InlineData("local")]
[InlineData("test")]
public void Will_get_KeyVault_name(string env)
{
// Arrange
EnvironmentOptions environmentOptions = new()
{
Environment = env,
RegionShortName = "usw2",
ServiceName = "bwf"
};

var expected = $"{env}-usw2-kv-bwf";

// Act
var actual = environmentOptions.GetKeyVaultName();

// Assert
actual.Should().Be(expected);
}

[Theory]
[InlineData(CloudType.AzureCloud, "https://ppe-usw2-kv-bwf.vault.azure.net/")]
[InlineData(CloudType.AzureUSGovernment, "https://ppe-usw2-kv-bwf.vault.usgovcloudapi.net/")]
[InlineData(CloudType.AzureChinaCloud, "https://ppe-usw2-kv-bwf.vault.azure.cn/")]
[InlineData(CloudType.AzureGermanCloud, "https://ppe-usw2-kv-bwf.vault.microsoftazure.de/")]
public void Will_get_keyvault_uri_for_Cloud(string cloudType, string expectedUri)
{
// Arrange
EnvironmentOptions environmentOptions = new()
{
Environment = EnvironmentType.Ppe,
RegionShortName = "usw2",
ServiceName = "bwf",
Cloud = cloudType
};

// Act
var actualUri = environmentOptions.GetKeyVaultUri();

// Assert
actualUri.Should().Be(expectedUri);
}
}
51 changes: 51 additions & 0 deletions Acl/tests/ServiceBusTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
namespace AntiCorruptionLayer.Tests;

using BestWeatherForecast.AntiCorruptionLayer;

public class ServiceBusTests
{
[Theory]
[InlineData("local")]
[InlineData("test")]
public void Will_get_ServiceBus_name(string env)
{
// Arrange
EnvironmentOptions environmentOptions = new()
{
Environment = env,
RegionShortName = "usw2",
ServiceName = "bwf"
};

var expected = $"{env}-sbns-bwf";

// Act
var actual = environmentOptions.GetServiceBusName();

// Assert
actual.Should().Be(expected);
}

[Theory]
[InlineData(CloudType.AzureCloud, "ppe-sbns-bwf.servicebus.windows.net")]
[InlineData(CloudType.AzureUSGovernment, "ppe-sbns-bwf.servicebus.usgovcloudapi.net")]
[InlineData(CloudType.AzureChinaCloud, "ppe-sbns-bwf.servicebus.chinacloudapi.cn")]
[InlineData(CloudType.AzureGermanCloud, "ppe-sbns-bwf.servicebus.cloudapi.de")]
public void Will_get_namespace_for_Cloud(string cloudType, string expectedNamespace)
{
// Arrange
EnvironmentOptions environmentOptions = new()
{
Environment = EnvironmentType.Ppe,
RegionShortName = "usw2",
ServiceName = "bwf",
Cloud = cloudType
};

// Act
var actualNamespace = environmentOptions.GetServiceBusNamespace();

// Assert
actualNamespace.Should().Be(expectedNamespace);
}
}
32 changes: 7 additions & 25 deletions Acl/tests/StorageNameTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,6 @@ public void Will_get_storage_name(string env)
actual.Should().Be(expected);
}

[Fact]
public void Will_get_blob_storage_url()
{
// Arrange
EnvironmentOptions environmentOptions = new()
{
Environment = EnvironmentType.Test,
RegionShortName = "usw2",
ServiceName = "bwf"
};

var expectedUrl = $"https://teststbwf.blob.core.windows.net";

// Act
var actualUrl = environmentOptions.GetBlobStorageSharedUrl();

// Assert
actualUrl.Should().Be(expectedUrl);
}

[Fact]
public void Will_throw_exception_name_too_long()
{
Expand All @@ -65,20 +45,22 @@ public void Will_throw_exception_name_too_long()
act.Should().Throw<ArgumentException>();
}

[Fact]
public void Will_get_blob_url_for_fairfax()
[Theory]
[InlineData(CloudType.AzureCloud, "https://ppestbwf.blob.core.windows.net")]
[InlineData(CloudType.AzureUSGovernment, "https://ppestbwf.blob.core.usgovcloudapi.net")]
[InlineData(CloudType.AzureChinaCloud, "https://ppestbwf.blob.core.chinacloud.cn")]
[InlineData(CloudType.AzureGermanCloud, "https://ppestbwf.blob.core.cloudapi.de")]
public void Will_get_blob_url_for_Cloud(string cloudType, string expectedUrl)
{
// Arrange
EnvironmentOptions environmentOptions = new()
{
Environment = EnvironmentType.Ppe,
RegionShortName = "usw2",
ServiceName = "bwf",
Cloud = CloudType.Fairfax
Cloud = cloudType
};

var expectedUrl = $"https://ppestbwf.blob.core.usgovcloudapi.net";

// Act
var actualUrl = environmentOptions.GetBlobStorageSharedUrl();

Expand Down