The Azure App Configuration project delivers you with a simulated Azure App Configuration experience.
To run the simulator use the command line below:
docker run --rm -it -p 8101:8101 -p 8201:8201 ghcr.io/manorrock/ocelot-azure-appconfig
To validate the simulator is up and running point your browser to http://localhost:8101/ Or if you want to access the simulator over HTTPS (which is what the Azure SDK would use) browse to https://localhost:8201
If you want to generate your own certificate you can use the command-line below:
keytool -genkey -alias self-signed -keyalg RSA -keystore keystore \
-keysize 4096 -storepass password -dname "CN=localhost"
You first must to export the certificate into a .pfx file.
dotnet dev-certs https -ep cert.pfx -p password
Then you must convert the .pfx file to a Java keystore.
keytool -importkeystore -srckeystore cert.pfx -srcstorepass password \
-destkeystore keystore -deststorepass password
And now you can use the instructions below to use the keystore.
If you want to supply your own certificate instead of the generated one you can mount the certificate directory.
For example:
docker run --rm -it -p 8101:8101 -p 8201:8201 \
-v $PWD/certs:/home/piranha/certs manorrock/ocelot-azure-appconfig
Replace $PWD/certs with the local directory that contains the keystore
file.
If the port used is 8201
the App Configuration URL would be:
https://localhost:8201
The sample snippet below shows you how you would interact with the simulator using the Azure SDK for Java.
var credential = new BasicAuthenticationCredential("username", "password");
var endpoint = "https://localhost:8201";
var configClient = new ConfigurationClientBuilder()
.endpoint(endpoint)
.credential(credential)
.httpLogOptions(new HttpLogOptions().setLogLevel(BODY_AND_HEADERS))
.buildClient();
configClient.setConfigurationSetting("key", "label", "my_value");
String value = configClient.getConfigurationSetting("key", "label").getValue());
The sample snippet below shows you how you would interact with the simulator using the Azure SDK for .NET
var appConfigUrl = "https://localhost:8201";
var client = new ConfigurationClient(new Uri(appConfigUrl),
new TestCredential(), CreateDefaultOptions());
var value = client.GetConfigurationSetting("myConfig");
ConfigurationClientOptions CreateDefaultOptions() =>
new()
{
Diagnostics =
{
LoggedContentSizeLimit = 8192,
IsLoggingContentEnabled = true
},
Retry =
{
Delay = TimeSpan.FromSeconds(2),
MaxDelay = TimeSpan.FromSeconds(16),
MaxRetries = 5,
Mode = RetryMode.Exponential
}
};
internal class TestCredential : TokenCredential
{
public override AccessToken GetToken(TokenRequestContext requestContext, CancellationToken cancellationToken)
{
return new AccessToken("test", DateTimeOffset.UtcNow.AddHours(100));
}
public override ValueTask<AccessToken> GetTokenAsync(TokenRequestContext requestContext, CancellationToken cancellationToken)
{
return new ValueTask<AccessToken>(GetToken(requestContext, cancellationToken));
}
}
See the REST API.