-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Devise::SecretKeyFinder#find
deprioritizes use of the deprecated find method in rails
#5604
Devise::SecretKeyFinder#find
deprioritizes use of the deprecated find method in rails
#5604
Conversation
…nd method in `rails`.
Can you explain how did you expect to avoid this deprecation by moving it to the end? Does that means that in your application you have |
OK. Specifically, if In the current behavior, despite not using # Before
def find
if @application.respond_to?(:credentials) && key_exists?(@application.credentials)
@application.credentials.secret_key_base
# ↓↓ deprecation warning in if statement
elsif @application.respond_to?(:secrets) && key_exists?(@application.secrets)
@application.secrets.secret_key_base
# ↓↓ Actually get the value here
elsif @application.config.respond_to?(:secret_key_base) && key_exists?(@application.config)
@application.config.secret_key_base
elsif @application.respond_to?(:secret_key_base) && key_exists?(@application)
@application.secret_key_base
end
end However, by moving the execution order of the if statement ( # After
def find
if @application.respond_to?(:credentials) && key_exists?(@application.credentials)
@application.credentials.secret_key_base
# ↓↓ Get the value here and exit the if statement
elsif @application.config.respond_to?(:secret_key_base) && key_exists?(@application.config)
@application.config.secret_key_base
elsif @application.respond_to?(:secret_key_base) && key_exists?(@application)
@application.secret_key_base
# ↓↓ Never reach this if statement where the deprecation warning is raised
elsif @application.respond_to?(:secrets) && key_exists?(@application.secrets)
@application.secrets.secret_key_base
end
end Since the above two acquisition methods are not deprecated, I thought that extra deprecation warnings should not be output. |
My first thought on this was to shift to a Rails version check with three checks in order:
This ensures that the priority order is unaffected and respects the deprecations for the version. def find
credential_store = Rails.gem_version >= Gem::Version.new("7.2.x") ? :credential : :secrets
if @application.respond_to?(credential_store) && key_exists?(@application.public_send(credential_store))
@application.public_send(credential_store).secret_key_base
elsif @application.config.respond_to?(:secret_key_base) && key_exists?(@application.config)
@application.config.secret_key_base
elsif @application.respond_to?(:secret_key_base) && key_exists?(@application)
@application.secret_key_base
end
end |
@rgarver |
A couple of things:
def find
if @application.respond_to?(:secret_key_base) && key_exists?(@application)
@application.secret_key_base # Handles fallback logic since Rails 5.2
elsif @application.respond_to?(:secrets) && key_exists?(@application.secrets)
# Suppported since Rails 4.1
@application.secrets.secret_key_base
elsif @application.config.respond_to?(:secret_key_base) && key_exists?(@application.config)
# Support really unusual configurations for backward compatibility
@application.config.secret_key_base
end
end |
@soartec-lab thanks for submitting this PR 👍 If you weren't aware, EDIT: Found a better PR. |
closed by #5645 |
The
rails/rails
repository has deprecatedrails.application.secrets
due to this PR.Devise::SecretKeyFinder#find
sequentially examines the variables stored by searchingsecret_key_base
, but deprecatedRails.application.secrets
is searched first, so in many cases A warning will occur. This is noise in many cases.To fix this, I changed the search order so that the deprecated
Rails.application.secrets
doesn't take precedence.