Class: Temporalio::Worker::IllegalWorkflowCallValidator
- Inherits:
-
Object
- Object
- Temporalio::Worker::IllegalWorkflowCallValidator
- Defined in:
- lib/temporalio/worker/illegal_workflow_call_validator.rb
Overview
Custom validator for validating illegal workflow calls.
Defined Under Namespace
Classes: CallInfo
Instance Attribute Summary collapse
-
#block ⇒ Proc
readonly
Block provided in constructor to invoke.
-
#method_name ⇒ String?
readonly
Method name if this validator is specific to a method.
Class Method Summary collapse
-
.default_time_validators ⇒ Array<IllegalWorkflowCallValidator>
Set of advanced validators for Time calls.
-
.known_safe_mutex_validator ⇒ IllegalWorkflowCallValidator
Workflow call validator that is tailored to disallow most Mutex calls, but let others through for certain situations.
Instance Method Summary collapse
-
#initialize(method_name: nil) {|info| ... } ⇒ IllegalWorkflowCallValidator
constructor
Create a call validator.
Constructor Details
#initialize(method_name: nil) {|info| ... } ⇒ IllegalWorkflowCallValidator
Create a call validator.
64 65 66 67 68 69 70 |
# File 'lib/temporalio/worker/illegal_workflow_call_validator.rb', line 64 def initialize(method_name: nil, &block) raise 'Block required' unless block_given? raise TypeError, 'Method name must be Symbol' unless method_name.nil? || method_name.is_a?(Symbol) @method_name = method_name @block = block end |
Instance Attribute Details
#block ⇒ Proc (readonly)
Returns Block provided in constructor to invoke. See constructor for more details.
55 56 57 |
# File 'lib/temporalio/worker/illegal_workflow_call_validator.rb', line 55 def block @block end |
#method_name ⇒ String? (readonly)
Returns Method name if this validator is specific to a method.
52 53 54 |
# File 'lib/temporalio/worker/illegal_workflow_call_validator.rb', line 52 def method_name @method_name end |
Class Method Details
.default_time_validators ⇒ Array<IllegalWorkflowCallValidator>
Returns Set of advanced validators for Time calls.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/temporalio/worker/illegal_workflow_call_validator.rb', line 24 def self.default_time_validators @default_time_validators ||= [ # Do not consider initialize as invalid if year is present and not "true" IllegalWorkflowCallValidator.new(method_name: :initialize) do |info| year_val = info.trace_point.binding&.local_variable_get(:year) raise 'can only use if passing string or explicit time info' unless year_val && year_val != true end, IllegalWorkflowCallValidator.new(method_name: :now) do # When the xmlschema (aliased as iso8601) call is made, zone_offset is called which has a default parameter # of Time.now.year. We want to prevent failing in that specific case. It is expensive to access the caller # stack, but this is only done in the rare case they are calling this safely. next if caller_locations&.any? { |loc| loc.label == 'zone_offset' || loc.label == 'Time.zone_offset' } raise 'Invalid Time.now call' end ] end |
.known_safe_mutex_validator ⇒ IllegalWorkflowCallValidator
Returns Workflow call validator that is tailored to disallow most Mutex calls, but let others through for certain situations.
44 45 46 47 48 49 |
# File 'lib/temporalio/worker/illegal_workflow_call_validator.rb', line 44 def self.known_safe_mutex_validator @known_safe_mutex_validator ||= IllegalWorkflowCallValidator.new do # Only Google Protobuf use of Mutex is known to be safe, fail unless any caller location path has protobuf raise 'disallowed' unless caller_locations&.any? { |loc| loc.path&.include?('google/protobuf/') } end end |