Sha256: a1ac62440468f4cbc89fea88886ee69f9da94f3bc6712b2e7fcc0d08dfb13178

Contents?: true

Size: 1.98 KB

Versions: 18

Compression:

Stored size: 1.98 KB

Contents

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

require 'contrast/utils/string_utils'
require 'contrast/agent/reporting/reporting_events/reportable_hash'
require 'contrast/utils/duck_utils'

module Contrast
  module Agent
    module Reporting
      # This is the new Route Discovery Observation class which will include all the needed information for the new
      # reporting system to relay this information in the Application Update messages. These route observations are
      # used by TeamServer to construct the route coverage information for the assess feature. They represent the
      # literal URL and HTTP verb used to invoke a method in the application, as routed by the application framework.
      class RouteDiscoveryObservation < Contrast::Agent::Reporting::ReportableHash
        # @return [String] the URL requested to hit this endpoint. Required for reporting; required attributes
        attr_accessor :url
        # @return [String] the HTTP Method requested to his this endpoint. Empty means all, so is allowed for
        #   reporting; optional attributes
        attr_accessor :verb

        def initialize url, verb
          @url = url
          @verb = verb if Contrast::Utils::StringUtils.present?(verb)
          super()
        end

        # Convert the instance variables on the class, and other information, into the identifiers required for
        # TeamServer to process the JSON form of this message.
        #
        # @return [Hash]
        # @raise [ArgumentError]
        def to_controlled_hash
          validate
          { url: url, verb: verb }.compact
        end

        # Ensure the required fields are present.
        #
        # @raise [ArgumentError]
        def validate
          return unless Contrast::Utils::DuckUtils.empty_duck?(url)

          raise(ArgumentError, "#{ self } did not have a proper url. Unable to continue.")
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
contrast-agent-7.6.1 lib/contrast/agent/reporting/reporting_events/route_discovery_observation.rb
contrast-agent-7.6.0 lib/contrast/agent/reporting/reporting_events/route_discovery_observation.rb
contrast-agent-7.5.0 lib/contrast/agent/reporting/reporting_events/route_discovery_observation.rb
contrast-agent-7.4.1 lib/contrast/agent/reporting/reporting_events/route_discovery_observation.rb
contrast-agent-7.4.0 lib/contrast/agent/reporting/reporting_events/route_discovery_observation.rb
contrast-agent-7.3.2 lib/contrast/agent/reporting/reporting_events/route_discovery_observation.rb
contrast-agent-7.3.1 lib/contrast/agent/reporting/reporting_events/route_discovery_observation.rb
contrast-agent-7.3.0 lib/contrast/agent/reporting/reporting_events/route_discovery_observation.rb
contrast-agent-7.2.0 lib/contrast/agent/reporting/reporting_events/route_discovery_observation.rb
contrast-agent-7.1.0 lib/contrast/agent/reporting/reporting_events/route_discovery_observation.rb
contrast-agent-7.0.0 lib/contrast/agent/reporting/reporting_events/route_discovery_observation.rb
contrast-agent-6.15.3 lib/contrast/agent/reporting/reporting_events/route_discovery_observation.rb
contrast-agent-6.15.2 lib/contrast/agent/reporting/reporting_events/route_discovery_observation.rb
contrast-agent-6.15.1 lib/contrast/agent/reporting/reporting_events/route_discovery_observation.rb
contrast-agent-6.15.0 lib/contrast/agent/reporting/reporting_events/route_discovery_observation.rb
contrast-agent-6.14.0 lib/contrast/agent/reporting/reporting_events/route_discovery_observation.rb
contrast-agent-6.13.0 lib/contrast/agent/reporting/reporting_events/route_discovery_observation.rb
contrast-agent-6.12.0 lib/contrast/agent/reporting/reporting_events/route_discovery_observation.rb