I’m writing a ruby gem , which has a command line interface ( making use of Thor )
I’m calling it “myrubygem” .
User should be able to do the following :
myrubygem init
This should ask for a github login and password and create a repository on github using a github api (Apart from some other stuff that I want the gem to do).
myrubygem push
This should commit and push some files to the repo . This can be a repetitive operation and I don’t want to keep asking the user for his github login and password . Also , storing the password in a textfile won’t be a good idea as well .
Is there a way to cache the credentials so that only the first command needs the prompt , and the rest of the commands can remember the credentials ?
Having tried a couple of things to solve the issue , I’ll answer my own question and explain what I ended up doing .
1) Save Oauth token
This is the first thing I tried . I asked the user for the Github login and password , used github_api gem to authenticate using the Api . Then I created an OAuth token with adequate permissions . I stored this OAuth token and used the same to login henceforth .
This was messy , had security issues and looked buggy .
So I ended up doing this :
2) Hand over the responsibility to the system git command
I used a system command from ruby to use “git” command to do all git operations . Git would ask the user for login details , it knows how to cache login . Less headache and less code .