Movatterモバイル変換


[0]ホーム

URL:


Skip to ContentSkip to Search
Ruby on Rails 8.1.1

Class ActiveSupport::MessageVerifiers< Messages::RotationCoordinator

v8.1.1
Methods
#
C
N
O
P
R

Attributes

[RW]transitional

If true, the first two rotation option sets are swapped when building message verifiers. For example, with the following configuration, message verifiers will generate messages usingserializer: Marshal, url_safe: true, and will able to verify messages that were generated using any of the three option sets:

verifiers = ActiveSupport::MessageVerifiers.new { ... }verifiers.rotate(serializer: JSON, url_safe: true)verifiers.rotate(serializer: Marshal, url_safe: true)verifiers.rotate(serializer: Marshal, url_safe: false)verifiers.transitional = true

This can be useful when performing a rolling deploy of an application, wherein servers that have not yet been updated must still be able to verify messages from updated servers. In such a scenario, first perform a rolling deploy with the new rotation (e.g.serializer: JSON, url_safe: true) as the first rotation andtransitional = true. Then, after all servers have been updated, perform a second rolling deploy withtransitional = false.

Class Public methods

new(&secret_generator)Link

Initializes a new instance.secret_generator must accept a salt, and return a suitable secret (string).secret_generator may also accept arbitrary kwargs. Ifrotate is called with any options matching those kwargs, those options will be passed tosecret_generator instead of to the message verifier.

verifiers =ActiveSupport::MessageVerifiers.newdo|salt,base:|MySecretGenerator.new(base).generate(salt)endverifiers.rotate(base:"...")

Source:on GitHub

# File activesupport/lib/active_support/message_verifiers.rb, line 34

Instance Public methods

[](salt)Link

Returns aMessageVerifier configured with a secret derived from the givensalt, and options fromrotate.MessageVerifier instances will be memoized, so the samesalt will return the same instance.

Source:on GitHub

# File activesupport/lib/active_support/message_verifiers.rb, line 53

[]=(salt, verifier)Link

Overrides aMessageVerifier instance associated with a givensalt.

Source:on GitHub

# File activesupport/lib/active_support/message_verifiers.rb, line 64

clear_rotationsLink

Clears the list of option sets.

Source:on GitHub

# File activesupport/lib/active_support/message_verifiers.rb, line 161

on_rotation(&callback)Link

Sets a callback to invoke when a message is verified using an option set other than the first.

For example, this callback could log each time it is called, and thus indicate whether old option sets are still in use or can be removed from rotation.

Source:on GitHub

# File activesupport/lib/active_support/message_verifiers.rb, line 170

prepend(**options)
prepend(&block)
Link

Just likerotate, but prepends the given options or block to the list of option sets.

This can be useful when you have an already-configuredMessageVerifiers instance, but you want to override the way messages are signed.

module ThirdParty  VERIFIERS = ActiveSupport::MessageVerifiers.new { ... }.    rotate(serializer: Marshal, url_safe: true).    rotate(serializer: Marshal, url_safe: false)endThirdParty.VERIFIERS.prepend(serializer: JSON, url_safe: true)# Uses `serializer: JSON, url_safe: true`.# Falls back to `serializer: Marshal, url_safe: true` or# `serializer: Marshal, url_safe: false`.ThirdParty.VERIFIERS[:foo]

Source:on GitHub

# File activesupport/lib/active_support/message_verifiers.rb, line 124

rotate(**options)
rotate(&block)
Link

Addsoptions to the list of option sets.Messages will be signed using the first set in the list. When verifying, however, each set will be tried, in order, until one succeeds.

Notably, the:secret_generator option can specify a different secret generator than the one initially specified. The secret generator must respond tocall, accept a salt, and return a suitable secret (string). The secret generator may also accept arbitrary kwargs.

If any options match the kwargs of the operative secret generator, those options will be passed to the secret generator instead of to the message verifier.

For fine-grained per-salt rotations, a block form is supported. The block will receive the salt, and should return an appropriate optionsHash. The block may also returnnil to indicate that the rotation does not apply to the given salt. For example:

verifiers = ActiveSupport::MessageVerifiers.new { ... }verifiers.rotate do |salt|  case salt  when :foo    { serializer: JSON, url_safe: true }  when :bar    { serializer: Marshal, url_safe: true }  endendverifiers.rotate(serializer: Marshal, url_safe: false)# Uses `serializer: JSON, url_safe: true`.# Falls back to `serializer: Marshal, url_safe: false`.verifiers[:foo]# Uses `serializer: Marshal, url_safe: true`.# Falls back to `serializer: Marshal, url_safe: false`.verifiers[:bar]# Uses `serializer: Marshal, url_safe: false`.verifiers[:baz]

Source:on GitHub

# File activesupport/lib/active_support/message_verifiers.rb, line 73

rotate_defaultsLink

Invokesrotate with the default options.

Source:on GitHub

# File activesupport/lib/active_support/message_verifiers.rb, line 152

[8]ページ先頭

©2009-2025 Movatter.jp