# Copyright (c) 2023 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details. # frozen_string_literal: true require 'contrast/utils/class_util' require 'contrast/utils/object_share' require 'contrast/agent/assess/tracker' module Contrast module Agent module Assess # This class is a convenient holder of our version of an Object. It creates a String version of the Object from # the original provided and keeps reference to the original's Tags, letting us determine if it was tracked when # we try to report to TeamServer. # # TODO: RUBY-1083 determine if this is expensive and/or worth not storing these values directly on ContrastEvent # and passing them around. Args probably make the argument for wrapping them b/c otherwise we'll have to keep # two arrays in synch or make an array of arrays, at which point, we may as well make this. class ContrastObject # @return [String] the Contrast String representation of the Object. attr_reader :object # @return [Integer] the __id__ of the original Object. attr_reader :tracked_object_id # @return [String] the name of the Class/Module of the Object. attr_reader :object_type # @return [Hash] the tags on the original Object. attr_reader :tags # Capture the details about the object which we need to render it in # TeamServer. # # @param object [Object, nil] the thing to keep a Contrast String of def initialize object if object @object = Contrast::Utils::ClassUtil.to_contrast_string(object) @tracked_object_id = object.__id__ @object_type = object.cs__class.cs__name @tags = Contrast::Agent::Assess::Tracker.properties(object)&.get_tags else @object = Contrast::Utils::ObjectShare::NIL_STRING @tracked_object_id = nil.__id__ @object_type = nil.cs__class.cs__name end end # Is the object this represents tracked or not? # # @return [Boolean] def tracked? !!tags&.any? end end end end end