- We tried to reproduced the same scenario and we did it with
secrets.json
file with in azure function and now its is working as excepted.
- You can use the following code to read secrets file value.
Example :- local.settings.json file
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"GetValue_from_local_settings": " local.settings.json file value"
}
}
secrets.json file
{
"GetValue_from_Secrets": "Secrets.json file value"
}
Azure Function file
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Microsoft.Extensions.Configuration;
namespace Secretsfrom_secretsJson
{
public class Function1
{
private readonly IConfiguration _configuration;
public Function1(IConfiguration dIConfiguration)
{
this._configuration = dIConfiguration;
}
[FunctionName("Function1")]
public string Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
ILogger log )
{
string localsettingjson = System.Environment.GetEnvironmentVariable("GetValue_from_local_settings");
string Secrets_values = _configuration.GetSection("GetValue_from_Secrets").Value;
string result = "Local Setting value" + localsettingjson + " , Secrets value " + Secrets_values;
return result;
}
}
}
Find the values during application debugging
.
output
secrets.json
. That file is used by the Configuration middleware to store sensitive settings values during development so they aren't committed accidentally to a source repo. You aren't using the Configuration middleware at all. In a production environmentsecrets.json
offers no security as the values aren't encrypted. – Gawk