mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Switch to a single message verifier
No need for this proliferation
This commit is contained in:
parent
9e81741b34
commit
8f20624820
5 changed files with 9 additions and 15 deletions
|
@ -2,17 +2,15 @@ require "active_support/core_ext/object/inclusion"
|
|||
|
||||
# A set of transformations that can be applied to a blob to create a variant.
|
||||
class ActiveStorage::Variation
|
||||
class_attribute :verifier
|
||||
|
||||
attr_reader :transformations
|
||||
|
||||
class << self
|
||||
def decode(key)
|
||||
new verifier.verify(key)
|
||||
new ActiveStorage.verifier.verify(key)
|
||||
end
|
||||
|
||||
def encode(transformations)
|
||||
verifier.generate(transformations)
|
||||
ActiveStorage.verifier.generate(transformations)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
class ActiveStorage::VerifiedKeyWithExpiration
|
||||
class_attribute :verifier
|
||||
|
||||
class << self
|
||||
def encode(key, expires_in: nil)
|
||||
verifier.generate([ key, expires_at(expires_in) ])
|
||||
ActiveStorage.verifier.generate([ key, expires_at(expires_in) ])
|
||||
end
|
||||
|
||||
def decode(encoded_key)
|
||||
key, expires_at = verifier.verified(encoded_key)
|
||||
key, expires_at = ActiveStorage.verifier.verified(encoded_key)
|
||||
|
||||
key if key && fresh?(expires_at)
|
||||
end
|
||||
|
|
|
@ -6,4 +6,6 @@ module ActiveStorage
|
|||
|
||||
autoload :Blob
|
||||
autoload :Service
|
||||
|
||||
mattr_accessor :verifier
|
||||
end
|
||||
|
|
|
@ -22,14 +22,9 @@ module ActiveStorage
|
|||
end
|
||||
end
|
||||
|
||||
initializer "active_storage.verifiers" do
|
||||
require "active_storage/verified_key_with_expiration"
|
||||
require "active_storage/variation"
|
||||
|
||||
initializer "active_storage.verifier" do
|
||||
config.after_initialize do |app|
|
||||
ActiveStorage::VerifiedKeyWithExpiration.verifier = \
|
||||
ActiveStorage::Variation.verifier = \
|
||||
Rails.application.message_verifier("ActiveStorage")
|
||||
ActiveStorage.verifier = Rails.application.message_verifier("ActiveStorage")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ ActiveStorage::VerifiedKeyWithExpiration.verifier = ActiveSupport::MessageVerifi
|
|||
|
||||
require "active_storage/variation"
|
||||
ActiveStorage::Variation.verifier = ActiveSupport::MessageVerifier.new("Testing")
|
||||
ActiveStorage.verifier = ActiveSupport::MessageVerifier.new("Testing")
|
||||
|
||||
class ActiveSupport::TestCase
|
||||
private
|
||||
|
|
Loading…
Reference in a new issue