英文:
How can I access environment variables manually added to credentials.yml.enc in Rails 7?
问题
我正在使用Rails 7,并能够使用命令Rails.application.secret_key_base
获取secret_key_base,但是当我尝试获取credentials.yml.enc中保存的另一个变量,比如Rails.application.new_key
时,我会收到错误消息。
请问如何使用命令EDITOR='code --wait' rails credentials:edit
获取我手动添加到credentials.yml.enc文件中的变量?
这是我的credentials.yml.enc文件的样子:
# aws:
# access_key_id: 123
# secret_access_key: 345
# 用作Rails中所有MessageVerifiers的基本密钥,包括保护cookie的密钥。
secret_key_base: dkud
new_key: qwerty
我还尝试了命令Rails.application.credentials
,它可以用于secret_key_base
,但对于credentials.yml.enc中的其他变量则不起作用。
英文:
I'm using Rails 7 and able to get the secret_key_base with the command Rails.application.secret_key_base
but when I try get another variable that I saved in the credentials.yml.enc like Rails.application.new_key
I get error.
Please how can I get variable that I manuelly added to the credentials.yml.enc file using the command EDITOR='code --wait' rails credentials:edit
Here is what my credentials.yml.enc file look like:
# aws:
# access_key_id: 123
# secret_access_key: 345
# Used as the base secret for all MessageVerifiers in Rails, including the one protecting cookies.
secret_key_base: dkud
new_key: qwerty
I also try the command Rails.application.credentials
it works with the secret_key_base
but not with other variables in the credentials.yml.enc
答案1
得分: 1
凭证文件中保存的机密信息可通过 Rails.application.credentials
访问,您需要在命令中添加 .credentials
:
irb(main):001:0> Rails.application.credentials.new_key
=> "qwerty"
irb(main):002:0> Rails.application.credentials[:new_key]
=> "qwerty"
默认情况下,只能使用 Rails.application
检索 secret_key_base
。
在指南中了解更多有关机密信息的信息。
英文:
Secrets kept in the credentials file are accessible via Rails.application.credentials
, you are missing .credentials
to your command:
irb(main):001:0> Rails.application.credentials.new_key
=> "qwerty"
irb(main):002:0> Rails.application.credentials[:new_key]
=> "qwerty"
By default only secret_key_base
can be retrieved using Rails.application
Learn more on secrets in the guide.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论