Reputation: 4112
For some no explicable reason in my organization, developers have no access to the Azure portal as Contributor, that made very difficult the development because in the particular case of the settings stored in App Configuration are not accessible for us. I read that there is not emulator for App Configuration to work local, then the unique form to do this actually is switch in code to appsettings.json, or talk with the people of DevOps to make any change in value or add/delete settings.
Maybe you know a method or solution to develop locally without need to modify settings in Azure and also not need to maintain a second mechanism in code to switch from one type of configuration to another. Maybe some type of configuration file that can be accessed in the same form that App Configuration? Thanks in advance
Upvotes: 0
Views: 710
Reputation: 7392
AFAIK, there is no such emulator to access Azure App Configuration.
You can install the SDK's related to App Configuration and access the Resource locally.
For this you can store the settings either in local configuration appsettings.json
/secrets.json
file or in the Environment Variables.
Azure App Configuration
.But it is not an emulator.Secrets.json
file,
Right click on Application
=> Manage User Secrets
With the above step, required NuGet Packages will be Installed. secrets.json
and appsettings.json
file will be added with the necessary settings.
You must know your Connection String and Key names (Configuration Explorer).
My secrets.json
file:
{
"AppConfig": "Endpoint=https://harshuappconfig.azconfig.io;Id=RoKQ;Secret=h*****xgHpE*****6zBKP74*****inqUBtfqpphE="
}
My appsettings.json
file:
"Endpoints": {
"AppConfig": "https://harshuappconfig.azconfig.io"
}
Program.cs
file is updated with the below code.using Azure.Identity;
var builder = WebApplication.CreateBuilder(args);
var azAppConfigConnection = builder.Configuration["AppConfig"];
if (!string.IsNullOrEmpty(azAppConfigConnection))
{
builder.Configuration.AddAzureAppConfiguration(options =>
{
options.Connect(azAppConfigConnection)
.ConfigureRefresh(refresh =>
{
refresh.Register("TestApp:Settings:Sentinel", refreshAll: true);
});
});
}
else if (Uri.TryCreate(builder.Configuration["Endpoints:AppConfig"], UriKind.Absolute, out var endpoint))
{
builder.Configuration.AddAzureAppConfiguration(options =>
{
options.Connect(endpoint, new VisualStudioCredential())
.ConfigureRefresh(refresh =>
{
refresh.Register("TestApp:Settings:Sentinel", refreshAll: true);
});
});
}
builder.Services.AddAzureAppConfiguration();
-----
var app = builder.Build();
---
app.UseAzureAppConfiguration();
----
appsettings.json
file configuration, modify the code as belowvar envi = builder.Environment.EnvironmentName;
var config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{envi}.json", optional: true)
.AddUserSecrets(Assembly.GetExecutingAssembly())
.AddEnvironmentVariables()
.AddUserSecrets<Program>()
.Build();
appsettings.json
file to get the values which you define in the json file.Also refer MSQ&A and sample examples for more details.
Upvotes: 0