在Rails 5.2上将credentials.yml与heroku结合使用 [英] Using credentials.yml with heroku on Rails 5.2

查看:74
本文介绍了在Rails 5.2上将credentials.yml与heroku结合使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Rails 5.2上有一个应用程序,以前曾在DigitalOcean上托管过,但我需要在heroku上托管它.我一直在阅读heroku无法读取Credentials.yml,因为它位于gitignore上,当然我也不想将其公开.

I have an app on Rails 5.2 and it was previously hosted on DigitalOcean, but I need to host it on heroku. I've been reading that heroku can't read Credentials.yml of because it's on gitignore and of course I don't want it public.

所以我的关键变量是这样的(还有redis的例子):

So my key variables are like this (and example with redis):

host: Rails.application.credentials.redis_host,
  password: Rails.application.credentials.redis_password

Heroku无法阅读此内容.所以我的问题是将其更改为heroku ENV变量的最佳方法是什么?我需要将所有当前密钥(大约340个)编辑为ENV ['SOMEKEY']吗?

Heroku can't read this. So my question is what is the best approach to change that in to heroku ENV variables? Do I need to edit all my current keys (there about 340) to ENV['SOMEKEY']?

感谢您的帮助!

推荐答案

创建certificate.yml和主密钥:

Create credentials.yml and master key:

rails credentials:edit 

编辑credentails:

Edit credentails:

EDITOR=vim rails credentials:edit

使用VIM:

  • 用于插入
  • 按i//进行必要的编辑
  • 要退出,请按Esc
  • :wq//用于退出和保存
  • :q!//无需保存即退出

凭证的示例.YML可以显示:

EXAMPLE OF HOW CREDENTIALS.YML can look:

development:
   github:
      client: acascascsacascascasc
      secret: vdsvsvg34g34g
production:
   github:
      client: 34g3rvv
      secret: erberb43

查找凭证:

rails c
Rails.application.credentials.dig(:aws, :access_key_id)

或者如果使用env变量

or if an env variable is used

Rails.application.credentials[Rails.env.to_sym][:aws][:access_key_id]

凭据.yml文件不应位于gitignore中.

解密凭据的主密钥应位于gitignore中.

要在生产环境中设置主密钥,请执行以下操作:

heroku config:set RAILS_MASTER_KEY=123456789

heroku config:set RAILS_MASTER_KEY=`cat config/master.key`

您需要了解的所有有关Ruby on Rails中的凭证的信息.祝你好运:)

That's all you need to know about credentials in Ruby on Rails. Good luck :)

这篇关于在Rails 5.2上将credentials.yml与heroku结合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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