I have an Azure Function application. The secrets are stored in local.settings.json and also in secrets.json:
{
"Values": {
"BASIC_AUTH_USERNAME": "<USERNAME>",
"BASIC_AUTH_PASSWORD": "<PASSWORD>"
}
}
The Azure function code that consumes the secrets:
string username = Environment.GetEnvironmentVariable("BASIC_AUTH_USERNAME", EnvironmentVariableTarget.Process);
string password = Environment.GetEnvironmentVariable("BASIC_AUTH_PASSWORD", EnvironmentVariableTarget.Process);
Here https://www.koskila.net/how-to-configure-azure-functions-startup/ I found how to add startup.cs file with the Startup class and Configure function:
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Hosting;
using Microsoft.Extensions.Configuration;
[assembly: WebJobsStartup(typeof(Startup))]
namespace LATICRETE.IdentityFunctions
{
public class Startup : IWebJobsStartup
{
public void Configure(IWebJobsBuilder builder)
{
var config = new ConfigurationBuilder()
.AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
}
}
}
But the GetEnvironmentVariable() method returns only null, and the Startup.Configure() method is never executed. What am I missing?