0

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.

3

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.