I have asp net core project which I am deploying inside linux containers in kubernetes cluster. My secrets are mounted in /secrets folder in the container and I found https://github.com/aspnet/Configuration/tree/master/src/Config.KeyPerFile and tried to use builder.AddKeyPerFile("/secrets", false); to load the secrets. But it does not work. configuration["File1"] returns empty where File1 is a file inside "/secrets" folder which contains one of the secrets.
When I execute the below in the service code, I am able to read the secrets.
List<KeyValuePair<string, string>> secrets =
new List<KeyValuePair<string, string>>();
foreach (var secretFile in Directory.GetFiles("/secrets", "*.*", System.IO.SearchOption.AllDirectories))
{
secrets.Add(
new KeyValuePair<string, string>(
Path.GetFileName(secretFile), File.ReadAllText(secretFile)));
}
I am trying to find out how to use builder.AddKeyPerFile extension method for this.