Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

bash - Automate Heroku CLI login

I'm developing a bash script to automatic clone some projects and another task in dev VM's, but we have one project in Heroku and repository is in it. In my .sh file I have:

> heroku login

And this prompt to enter credentials, I read the "help" guide included on binary and documentation but I can't found anything to automatic insert username and password, I want something like this:

> heroku login -u someUser -p mySecurePassword

Exist any way similar to it?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The Heroku CLI only uses your username and password to retrieve your API key, which it stores in your ~/.netrc file ($HOME\_netrc on Windows).

You can manually retrieve your API key and add it to your ~/.netrc file:

  1. Log into the Heroku web interface
  2. Navigate to your Account settings page
  3. Scroll down to the API Key section and click the Reveal button
  4. Copy your API key
  5. Open your ~/.netrc file, or create it, with your favourite text editor
  6. Add the following content:

    machine api.heroku.com
      login <your-email@address>
      password <your-api-key>
    machine git.heroku.com
      login <your-email@address>
      password <your-api-key>
    

    Replace <your-email@address> with the email address registered with Heroku, and <your-api-key> with the API key you copied from Heroku.

This should manually accomplish what heroku login does automatically. However, I don't recommend this. Running heroku login does the same thing more easily and with fewer opportunities to make a mistake.

If you decide to copy ~/.netrc files between machines or accounts you should be aware of two major caveats:

Please be very careful if you intend to log into Heroku using any mechanism other than heroku login.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...