Switch to a single message verifier

No need for this proliferation
上级 9e81741b
......@@ -2,17 +2,15 @@
# 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
......
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 @@ class Engine < Rails::Engine # :nodoc:
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 @@
require "active_storage/variation"
ActiveStorage::Variation.verifier = ActiveSupport::MessageVerifier.new("Testing")
ActiveStorage.verifier = ActiveSupport::MessageVerifier.new("Testing")
class ActiveSupport::TestCase
private
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册