Sha256: 9bdb9130d63c8c9a764784cc8520fe1ca4a4499ab77085098ec94d2eb377f176

Contents?: true

Size: 1.88 KB

Versions: 2

Compression:

Stored size: 1.88 KB

Contents

# Copyright (c) 2023 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
# frozen_string_literal: true

module Contrast
  module Agent
    module Assess
      module Policy
        module Propagator
          # A propagator is a method which can transform data, as described by
          # the Contrast::Agent::Assess::Policy::PropagationNode class. Each
          # type of propagator does so differently, but always acts on a Source
          # to pass tags from it to a Target.
          class Base
            class << self
              # Retrieve the source from the preshift state.
              #
              # @param source [Symbol] the source to retrieve.
              # @param preshift [Contrast::Agent::Assess::PreShift] the pre-call state of the things.
              def find_source source, preshift
                case source
                when Contrast::Utils::ObjectShare::OBJECT_KEY
                  preshift.object
                else
                  preshift.args[source]
                end
              end

              # Check if tags are present on the given target.
              #
              # @return [Boolean]
              def tracked_value? value
                Contrast::Agent::Assess::Tracker.tracked?(value)
              end

              # Propagate the tags from the source to the target.
              # This method should be extended by the subclasses.
              #
              # @raise [NoMethodError] This is being raised if any of the implementing subclasses does not have
              #     that method implemented, but is being called on.
              def propagate _propagation_node, _preshift, _target
                raise(NoMethodError("Expected Base propagator subclass: #{ cs__class } to implement #propagate"))
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
contrast-agent-7.6.1 lib/contrast/agent/assess/policy/propagator/base.rb
contrast-agent-7.6.0 lib/contrast/agent/assess/policy/propagator/base.rb