I want to host two applications on one Linux server. One app for dev, another app for users. The problem which I have is that I try managed with sensitive data like connection string. Both databases (for dev and prod) are available on the Internet. Ideally, I want to write an app on the Windows, then push changes to GitHub, next go to console in Linux, get latest changes and build the app with proper commend either as the prod or as the dev build.
I don’t want to hardcode sensitive values in code or put them to a json file because by mistake I could commit that to GitHub. In that case, I decided to use SecretManager Tool in asp.net core 2. How is it work is nicely explained: https://docs.microsoft.com/en-us/aspnet/core/security/app-secrets?view=aspnetcore-2.1&tabs=visual-studio and https://dotnetcore.gaprogman.com/2017/09/07/user-secrets-what-are-they-and-why-do-i-need-them/
My secret.json looks like that:
{ "prodZamzarKey": "", "prodConnectionString": "", "devZamzarKey": "", "devConnectionString": "" }
So with one code, I want to be able to choose which connection string I want to use without changing environment variables on Linux. In that case, I decided to run the app with some commands. The idea comes from https://stackoverflow.com/questions/40748518/how-to-configure-mutilple-aspnetcore-environment-on-same-machine/40750166
dotnet Musiction.API.dll environment=dev dotnet Musiction.API.dll environment=prod
To select proper connection string I use that code:
var propName = Startup.Configuration["environment"] + "ConnectionString"; var connectionString = Startup.Configuration[propName];
And it’s work!
Code: https://github.com/Jaryn91/Music/commit/1f94a8d609785a50c56e5aaae3533a979674d5b2
Other links:
https://www.lifewire.com/create-directories-linux-mkdir-command-3991847