I wonder how to hide an API key and replace it with let's say empty string
before pushing to Github or any source control.
for example, I've API keys like
object Constants {
const val API_KEY= "GOOGLE_API_KEY"
}
how to remove the actual one and add random or empty string when pushing.
CodePudding user response:
Secret manager
Take a look at secret manager.
Git hooks
A way to achieve this could be using git hooks.
On pre-commit
, use (for example) sed
to find and replace your API_KEY. You can even restore it in post-commit
.
Debug resources
Another way is to add the API_KEY to a resource file in the debug
variant folder. Add that file to your .gitignore
so you can use the API_KEY in your code, but will never be commited.