I have a project which I plan to open-source at some point. Currently I keep all of my API keys in a class which is not checked in - I have just linked the project to Azure but the API key class not being present causes the deployment to fail.
How can I hide secret API keys in a public project and still have it deploy to Azure?
I have read quite a few posts (this one for instance) but cannot find a solution that allows me to do what I want - does anyone know what I should do here? Is it possible?
For an Azure Web App, you can specify config values on the Configure tab in the portal (under "app settings"). These will override values specified in your Web.config
file.
This means you can leave these settings out of your public repository.
For developing locally, you can put the settings in a separate XML file. To do this, update the appSettings
in your Web.config like this:
<appSettings file="mysettings.xml" />
Then create mysettings.xml
and put your actual settings in a new <appSettings>
element there.
You can then add mysettings.xml
to your .gitignore
file so it won't be checked in to your public repository.
Azure doesn't mind that your mysettings.xml
file doesn't exist, and will pick up the settings you specify in the portal instead.