从 rake 任务中验证 Heroku gem

Authenticating Heroku gem from rake task

我正在尝试让我的自动备份脚本工作。我正在使用 heroku gem。该脚本 运行 来自 Heroku 的 Scheduler 插件。

require "heroku/command/pg"
require "heroku/command/pg_backups"

....
def initialize
  @client     = Heroku::Command::Pg.new([], app: ENV['APP_NAME'])
end

...
attachment = @client.send(:generate_resolver)
...

我一调用 attachment = @client.send(:generate_resolver),脚本就停止执行并请求

Enter your Heroku credentials.
Email: 

有没有办法避免这种情况,因为该任务无论如何都是从 heroku 内部启动的,因此应该已经过身份验证。

非常感谢任何帮助

对于非交互式登录,您需要使用 API 密钥,使用 heroku auth:token.[=14= 从登录 CLI 为您的帐户使用 Heroku will read from the HEROKU_API_KEY environment variable. You can fetch the key ]

无法避免身份验证只是因为您已经 运行 在 Heroku 中。这将对应用程序间安全产生重大影响。

另请查看 pgbackups-archive。看起来它可以满足您的需求,或者至少可以为您提供一些有用的技术。