-
-
Notifications
You must be signed in to change notification settings - Fork 340
feat: add azure app configuration module #1200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tnc1997
wants to merge
2
commits into
testcontainers:develop
Choose a base branch
from
tnc1997:feat/1198
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+302
−0
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| root = true |
108 changes: 108 additions & 0 deletions
108
src/Testcontainers.AzureAppConfiguration/AzureAppConfigurationBuilder.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| namespace Testcontainers.AzureAppConfiguration; | ||
|
|
||
| /// <inheritdoc cref="ContainerBuilder{TBuilderEntity, TContainerEntity, TConfigurationEntity}" /> | ||
| [PublicAPI] | ||
| public sealed class AzureAppConfigurationBuilder : ContainerBuilder<AzureAppConfigurationBuilder, AzureAppConfigurationContainer, AzureAppConfigurationConfiguration> | ||
| { | ||
| public const string AzureAppConfigurationImage = "tnc1997/azure-app-configuration-emulator:1.0"; | ||
|
|
||
| public const ushort AzureAppConfigurationPort = 8080; | ||
|
|
||
| public const string DefaultCredential = "abcd"; | ||
|
|
||
| public const string DefaultSecret = "c2VjcmV0"; | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="AzureAppConfigurationBuilder" /> class. | ||
| /// </summary> | ||
| public AzureAppConfigurationBuilder() | ||
| : this(new AzureAppConfigurationConfiguration()) | ||
| { | ||
| DockerResourceConfiguration = Init().DockerResourceConfiguration; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="AzureAppConfigurationBuilder" /> class. | ||
| /// </summary> | ||
| /// <param name="resourceConfiguration">The Docker resource configuration.</param> | ||
| private AzureAppConfigurationBuilder(AzureAppConfigurationConfiguration resourceConfiguration) | ||
| : base(resourceConfiguration) | ||
| { | ||
| DockerResourceConfiguration = resourceConfiguration; | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| protected override AzureAppConfigurationConfiguration DockerResourceConfiguration { get; } | ||
|
|
||
| /// <summary> | ||
| /// Sets the Azure App Configuration credential. | ||
| /// </summary> | ||
| /// <param name="credential">The Azure App Configuration credential.</param> | ||
| /// <returns>A configured instance of <see cref="AzureAppConfigurationBuilder" />.</returns> | ||
| public AzureAppConfigurationBuilder WithCredential(string credential) | ||
| { | ||
| return Merge(DockerResourceConfiguration, new AzureAppConfigurationConfiguration(credential: credential)) | ||
| .WithEnvironment("Authentication__Schemes__Hmac__Credential", credential); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Sets the Azure App Configuration secret. | ||
| /// </summary> | ||
| /// <param name="secret">The Azure App Configuration secret.</param> | ||
| /// <returns>A configured instance of <see cref="AzureAppConfigurationBuilder" />.</returns> | ||
| public AzureAppConfigurationBuilder WithSecret(string secret) | ||
| { | ||
| return Merge(DockerResourceConfiguration, new AzureAppConfigurationConfiguration(secret: secret)) | ||
| .WithEnvironment("Authentication__Schemes__Hmac__Secret", secret); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public override AzureAppConfigurationContainer Build() | ||
| { | ||
| Validate(); | ||
| return new AzureAppConfigurationContainer(DockerResourceConfiguration); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| protected override AzureAppConfigurationBuilder Init() | ||
| { | ||
| return base.Init() | ||
| .WithImage(AzureAppConfigurationImage) | ||
| .WithPortBinding(AzureAppConfigurationPort, true) | ||
| .WithCredential(DefaultCredential) | ||
| .WithSecret(DefaultSecret) | ||
| .WithWaitStrategy(Wait.ForUnixContainer().UntilMessageIsLogged("Now listening on")); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| protected override void Validate() | ||
| { | ||
| base.Validate(); | ||
|
|
||
| _ = Guard.Argument(DockerResourceConfiguration.Credential, nameof(DockerResourceConfiguration.Credential)) | ||
| .NotNull() | ||
| .NotEmpty(); | ||
|
|
||
| _ = Guard.Argument(DockerResourceConfiguration.Secret, nameof(DockerResourceConfiguration.Secret)) | ||
| .NotNull() | ||
| .NotEmpty(); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| protected override AzureAppConfigurationBuilder Clone(IResourceConfiguration<CreateContainerParameters> resourceConfiguration) | ||
| { | ||
| return Merge(DockerResourceConfiguration, new AzureAppConfigurationConfiguration(resourceConfiguration)); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| protected override AzureAppConfigurationBuilder Clone(IContainerConfiguration resourceConfiguration) | ||
| { | ||
| return Merge(DockerResourceConfiguration, new AzureAppConfigurationConfiguration(resourceConfiguration)); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| protected override AzureAppConfigurationBuilder Merge(AzureAppConfigurationConfiguration oldValue, AzureAppConfigurationConfiguration newValue) | ||
| { | ||
| return new AzureAppConfigurationBuilder(new AzureAppConfigurationConfiguration(oldValue, newValue)); | ||
| } | ||
| } |
69 changes: 69 additions & 0 deletions
69
src/Testcontainers.AzureAppConfiguration/AzureAppConfigurationConfiguration.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| namespace Testcontainers.AzureAppConfiguration; | ||
|
|
||
| /// <inheritdoc cref="ContainerConfiguration" /> | ||
| [PublicAPI] | ||
| public sealed class AzureAppConfigurationConfiguration : ContainerConfiguration | ||
| { | ||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="AzureAppConfigurationConfiguration" /> class. | ||
| /// </summary> | ||
| /// <param name="credential">The Azure App Configuration credential.</param> | ||
| /// <param name="secret">The Azure App Configuration secret.</param> | ||
| public AzureAppConfigurationConfiguration(string credential = null, string secret = null) | ||
| { | ||
| Credential = credential; | ||
| Secret = secret; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="AzureAppConfigurationConfiguration" /> class. | ||
| /// </summary> | ||
| /// <param name="resourceConfiguration">The Docker resource configuration.</param> | ||
| public AzureAppConfigurationConfiguration(IResourceConfiguration<CreateContainerParameters> resourceConfiguration) | ||
| : base(resourceConfiguration) | ||
| { | ||
| // Passes the configuration upwards to the base implementations to create an updated immutable copy. | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="AzureAppConfigurationConfiguration" /> class. | ||
| /// </summary> | ||
| /// <param name="resourceConfiguration">The Docker resource configuration.</param> | ||
| public AzureAppConfigurationConfiguration(IContainerConfiguration resourceConfiguration) | ||
| : base(resourceConfiguration) | ||
| { | ||
| // Passes the configuration upwards to the base implementations to create an updated immutable copy. | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="AzureAppConfigurationConfiguration" /> class. | ||
| /// </summary> | ||
| /// <param name="resourceConfiguration">The Docker resource configuration.</param> | ||
| public AzureAppConfigurationConfiguration(AzureAppConfigurationConfiguration resourceConfiguration) | ||
| : this(new AzureAppConfigurationConfiguration(), resourceConfiguration) | ||
| { | ||
| // Passes the configuration upwards to the base implementations to create an updated immutable copy. | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="AzureAppConfigurationConfiguration" /> class. | ||
| /// </summary> | ||
| /// <param name="oldValue">The old Docker resource configuration.</param> | ||
| /// <param name="newValue">The new Docker resource configuration.</param> | ||
| public AzureAppConfigurationConfiguration(AzureAppConfigurationConfiguration oldValue, AzureAppConfigurationConfiguration newValue) | ||
| : base(oldValue, newValue) | ||
| { | ||
| Credential = BuildConfiguration.Combine(oldValue.Credential, newValue.Credential); | ||
| Secret = BuildConfiguration.Combine(oldValue.Secret, newValue.Secret); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets the Azure App Configuration credential. | ||
| /// </summary> | ||
| public string Credential { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the Azure App Configuration secret. | ||
| /// </summary> | ||
| public string Secret { get; } | ||
| } |
31 changes: 31 additions & 0 deletions
31
src/Testcontainers.AzureAppConfiguration/AzureAppConfigurationContainer.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| namespace Testcontainers.AzureAppConfiguration; | ||
|
|
||
| /// <inheritdoc cref="DockerContainer" /> | ||
| [PublicAPI] | ||
| public sealed class AzureAppConfigurationContainer : DockerContainer | ||
| { | ||
| private readonly AzureAppConfigurationConfiguration _configuration; | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="AzureAppConfigurationContainer" /> class. | ||
| /// </summary> | ||
| /// <param name="configuration">The container configuration.</param> | ||
| public AzureAppConfigurationContainer(AzureAppConfigurationConfiguration configuration) | ||
| : base(configuration) | ||
| { | ||
| _configuration = configuration; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets the Azure App Configuration connection string. | ||
| /// </summary> | ||
| /// <returns>The Azure App Configuration connection string.</returns> | ||
| public string GetConnectionString() | ||
| { | ||
| var properties = new Dictionary<string, string>(); | ||
| properties.Add("Endpoint", new UriBuilder(Uri.UriSchemeHttp, Hostname, GetMappedPublicPort(AzureAppConfigurationBuilder.AzureAppConfigurationPort)).ToString()); | ||
| properties.Add("Id", _configuration.Credential); | ||
| properties.Add("Secret", _configuration.Secret); | ||
| return string.Join(";", properties.Select(property => string.Join("=", property.Key, property.Value))); | ||
| } | ||
| } |
12 changes: 12 additions & 0 deletions
12
src/Testcontainers.AzureAppConfiguration/Testcontainers.AzureAppConfiguration.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <TargetFrameworks>net6.0;net8.0;netstandard2.0;netstandard2.1</TargetFrameworks> | ||
| <LangVersion>latest</LangVersion> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <PackageReference Include="JetBrains.Annotations" VersionOverride="2023.3.0" PrivateAssets="All"/> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <ProjectReference Include="../Testcontainers/Testcontainers.csproj"/> | ||
| </ItemGroup> | ||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| global using System; | ||
| global using System.Collections.Generic; | ||
| global using System.Linq; | ||
| global using Docker.DotNet.Models; | ||
| global using DotNet.Testcontainers; | ||
| global using DotNet.Testcontainers.Builders; | ||
| global using DotNet.Testcontainers.Configurations; | ||
| global using DotNet.Testcontainers.Containers; | ||
| global using JetBrains.Annotations; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| root = true |
34 changes: 34 additions & 0 deletions
34
tests/Testcontainers.AzureAppConfiguration.Tests/AzureAppConfigurationContainerTest.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| namespace Testcontainers.AzureAppConfiguration; | ||
|
|
||
| public sealed class AzureAppConfigurationContainerTest : IAsyncLifetime | ||
| { | ||
| private readonly AzureAppConfigurationContainer _azureAppConfigurationContainer = new AzureAppConfigurationBuilder().Build(); | ||
|
|
||
| public Task InitializeAsync() | ||
| { | ||
| return _azureAppConfigurationContainer.StartAsync(); | ||
| } | ||
|
|
||
| public Task DisposeAsync() | ||
| { | ||
| return _azureAppConfigurationContainer.DisposeAsync().AsTask(); | ||
| } | ||
|
|
||
| [Fact] | ||
| [Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))] | ||
| public async Task GetConfigurationSettingReturnsSetConfigurationSetting() | ||
| { | ||
| // Given | ||
| var client = new ConfigurationClient(_azureAppConfigurationContainer.GetConnectionString()); | ||
|
|
||
| // When | ||
| await client.SetConfigurationSettingAsync(nameof(ConfigurationSetting.Key), nameof(ConfigurationSetting.Value)) | ||
| .ConfigureAwait(true); | ||
|
|
||
| var response = await client.GetConfigurationSettingAsync(nameof(ConfigurationSetting.Key)) | ||
| .ConfigureAwait(true); | ||
|
|
||
| // Then | ||
| Assert.Equal(nameof(ConfigurationSetting.Value), response.Value.Value); | ||
| } | ||
| } |
18 changes: 18 additions & 0 deletions
18
...tcontainers.AzureAppConfiguration.Tests/Testcontainers.AzureAppConfiguration.Tests.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <TargetFrameworks>net8.0</TargetFrameworks> | ||
| <IsPackable>false</IsPackable> | ||
| <IsPublishable>false</IsPublishable> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.NET.Test.Sdk"/> | ||
| <PackageReference Include="coverlet.collector"/> | ||
| <PackageReference Include="xunit.runner.visualstudio"/> | ||
| <PackageReference Include="xunit"/> | ||
| <PackageReference Include="Azure.Data.AppConfiguration" Version="1.4.1"/> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <ProjectReference Include="../../src/Testcontainers.AzureAppConfiguration/Testcontainers.AzureAppConfiguration.csproj"/> | ||
| <ProjectReference Include="../Testcontainers.Commons/Testcontainers.Commons.csproj"/> | ||
| </ItemGroup> | ||
| </Project> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| global using System.Threading.Tasks; | ||
| global using Azure.Data.AppConfiguration; | ||
| global using DotNet.Testcontainers.Commons; | ||
| global using Xunit; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.