自动化Heroku CLI登录 [英] Automate Heroku CLI login
问题描述
我正在开发一个bash脚本,以自动克隆开发VM中的某些项目和另一个任务,但是我们在Heroku中有一个项目,并且其中包含存储库.在我的.sh文件中,我有:
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?
推荐答案
Heroku CLI 仅使用您的用户名和密码来检索您的API密钥,它存储在您的~/.netrc
文件(在Windows中为$HOME\_netrc
).
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).
您可以手动检索API密钥并将其添加到您的~/.netrc
文件中:
You can manually retrieve your API key and add it to your ~/.netrc
file:
- 登录到Heroku Web界面
- 导航到您的帐户设置页面
- 向下滚动到 API密钥部分,然后单击 Reveal 按钮
- 复制您的API密钥
- 使用您喜欢的文本编辑器打开或创建
~/.netrc
文件 -
添加以下内容:
- Log into the Heroku web interface
- Navigate to your Account settings page
- Scroll down to the API Key section and click the Reveal button
- Copy your API key
- Open your
~/.netrc
file, or create it, with your favourite text editor 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>
用在Heroku中注册的电子邮件地址替换<your-email@address>
,并用从Heroku中复制的API密钥替换<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.
这应该手动完成heroku login
自动执行的操作. 但是,我不推荐这样做.运行heroku login
可以更轻松地完成同一件事,并且犯错的机会更少.
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.
如果您决定在计算机或帐户之间复制~/.netrc
文件,则应注意两个主要警告:
If you decide to copy ~/.netrc
files between machines or accounts you should be aware of two major caveats:
- 许多 程序;注意只复制所需的配置节.
- 您的API密钥可提供对您帐户的完全编程访问权限.您应该像保护密码一样保护它.
- This file is used by many other programs; be careful to only copy the configuration stanzas you want.
- Your API key offers full programmatic access to your account. You should protect it as strongly as you protect your password.
如果您打算使用heroku login
以外的任何机制登录Heroku,请非常小心.
Please be very careful if you intend to log into Heroku using any mechanism other than heroku login
.
这篇关于自动化Heroku CLI登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!