首页 > 解决方案 > 无法理解 secret_token 的 Rails 弃用警告

问题描述

从 升级rails 5.1到后,rails 5.2.3我收到此弃用警告:

secrets.secret_token` is deprecated in favor of `secret_key_base` and will be removed in Rails 6.0. (called from <main> at /config/initializers/stripe.rb:3

如果我查看条带初始化程序,我有:

Rails.configuration.stripe = {
  publishable_key: Rails.application.secrets.stripe_publishable_key,
  secret_key:      Rails.application.secrets.stripe_secret_key
}

所以没有提及secret.token. 如果我看config.secrets.yml我有

test:
  secret_key_base: some-key
  stripe_secret_key: another_key
  stripe_publishable_key: yet_another_key

那么为什么我会收到弃用警告?

标签: ruby-on-railsstripe-payments

解决方案


Rails 5.2 已将机密替换为凭据,以在存储库中存储加密的凭据或 API 密钥。您可以在以下文章中阅读有关从机密更改为凭据的更多信息。

https://medium.com/@wintermeyer/goodbye-secrets-welcome-credentials-f4709d9f4698

尽管 Rails 5.2 已经用凭证替换了秘密,但如果你愿意,你仍然可以使用秘密。然而,正如警告消息所述,机密将从 Rails 6 中删除,您必须接受使用凭证来存储 API 密钥和 secret_keys。


推荐阅读