Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to store the JSON file which will be referenced for the environment variable in asp.net hosted on Azure

I have created a Web Service using ASP.NET and will be storing data in Firestore. Hence, I will need to set the GOOGLE_APPLICATION_CREDENTIALS environment variable referring to a JSON file. This works locally on my machine, but it doesn't work when it's published to Azure. The problem is I couldn't find the JSON file to locate the file path, I have double checked my local project folder whether the JSON file is in there before publishing. May I know where is the best place to store my JSON file, so that I can locate the file path and GOOGLE_APPLICATION_CREDENTIALS can refer to it in the Azure Portal.

Thank you.

like image 660
vomoxon Avatar asked Dec 17 '18 19:12

vomoxon


People also ask

Where are environment variables stored in Azure?

In Azure App Service, application settings are variables passed as environment variables to the application code. For Linux apps and custom containers, App Service passes app settings to the container using the --env flag to set the environment variable in the container.

Can you use environment variables in JSON?

You have to wrap the environment variable of choice into another set of quotes in order for it to be valid JSON.

What are JSON files in ASP.NET Core?

Different configuration json files in ASP.net Core There are mainly 6 configuration JSON files in ASP.net Core. global.json launchsettings.json appsettings.json bundleconfig.json project.json bower.json.


1 Answers

Here's another alternative if you're looking to avoid having that credential file checked into source control or on dev machines, and you already have a secure place to store string configuration data.

You can spin up your Firestore client this way and give it credentials manually:

 var credential = GoogleCredential.FromJson(<JSON AS STRING>);
 var channelCredentials = credential.ToChannelCredentials();
 var channel = new Channel(FirestoreClient.DefaultEndpoint.ToString(), channelCredentials);
 var client = FirestoreClient.Create(channel);

(Code using the Nuget package here: https://www.nuget.org/packages/Google.Cloud.Firestore/)

like image 161
Veatch Avatar answered Nov 10 '22 00:11

Veatch