自动化 Heroku CLI 登录 [英] Automate Heroku CLI login

查看:25
本文介绍了自动化 Heroku CLI 登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 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:

  1. 登录 Heroku 网络界面
  2. 导航到您的帐户设置页面
  3. 向下滚动到API 密钥部分,然后点击显示按钮
  4. 复制您的 API 密钥
  5. 打开您的 ~/.netrc 文件,或使用您喜欢的文本编辑器创建它
  6. 添加以下内容:

  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>

替换为在 Heroku 注册的电子邮件地址,并将 替换为您从中复制的 API 密钥Heroku.

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:

  • 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆