Class: Temporalio::Worker::IllegalWorkflowCallValidator

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method_name: nil) {|info| ... } ⇒ IllegalWorkflowCallValidator

Create a call validator.

Parameters:

  • method_name (String, nil) (defaults to: nil)

    Method name to check. This must be provided if the validator is in an illegal call array, this cannot be provided if it is a top-level class validator.

Yields:

  • Required block that is called each time validation is needed. If the call raises, the exception message is used as the reason why the call is considered invalid. Return value is ignored.

Yield Parameters:

  • info (CallInfo)

    Information about the current call.

Raises:

  • (TypeError)


55
56
57
58
59
60
61
# File 'lib/temporalio/worker/illegal_workflow_call_validator.rb', line 55

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

#blockProc (readonly)

Returns Block provided in constructor to invoke. See constructor for more details.

Returns:

  • (Proc)

    Block provided in constructor to invoke. See constructor for more details.



46
47
48
# File 'lib/temporalio/worker/illegal_workflow_call_validator.rb', line 46

def block
  @block
end

#method_nameString? (readonly)

Returns Method name if this validator is specific to a method.

Returns:

  • (String, nil)

    Method name if this validator is specific to a method.



43
44
45
# File 'lib/temporalio/worker/illegal_workflow_call_validator.rb', line 43

def method_name
  @method_name
end

Class Method Details

.default_time_validatorsArray<IllegalWorkflowCallValidator>

Returns Set of advanced validators for Time calls.

Returns:



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