0

Is there a way to hide a String automatically before commiting using Intellij's git implementation? I have a java class like this:

public class TGBot extends TelegramLongPollingBot {

    public void onUpdateReceived(Update update) {
        KChat.handleUpdateEvent(update);
    }

    public String getBotUsername() {
        return "karatekbot";
    }

    public String getBotToken() {
        return "xxxxxxxxx:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
    }

I'd like to replace the real token with a placeholder so it is not available on GitHub. Is there any way how to do so?

Thanks

~Jens

  • 1
    There is no anything with "Intellij's git" implementation. Maybe it's a good idea to use envs to store values? – funnydman Dec 21 '19 at 18:22
  • Does this answer your question? [git commit config on initial commit but never again?](https://stackoverflow.com/questions/9345839/git-commit-config-on-initial-commit-but-never-again) – phd Dec 21 '19 at 18:29
  • https://stackoverflow.com/search?q=%5Bgit%5D+application+config – phd Dec 21 '19 at 18:29

1 Answers1

1

There isn't a way to hide strings in Git repositories. Anyone with the repository can see all of the data.

The usual way that people handle secrets in code is to pass them in via the environment. This would work well here, where you could return the value for the bot username and token from environment variables.

bk2204
  • 64,793
  • 6
  • 84
  • 100