Sha256: 0a34f88cd90190e32033ca1af2769defc0bf9a60f9e41836d4400a1319bf2877

Contents?: true

Size: 1.96 KB

Versions: 2

Compression:

Stored size: 1.96 KB

Contents

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

require 'contrast/components/interface'
require 'contrast/utils/string_utils'

module Contrast
  module Api
    module Decorators
      # Used to decorate the {Contrast::Api::Dtm::ApplicationUpdate} protobuf
      # model so it can own some of the data massaging required for AppUpdate
      # dtm.
      module ApplicationUpdate
        include Contrast::Components::Interface
        access_component :config

        def self.included klass
          klass.extend(ClassMethods)
        end

        def append_library_update library_dtm_list
          library_dtm_list.each do |library_dtm|
            libraries[library_dtm.hash_code] = library_dtm
          end
        end

        # TS only allows you to report 500 routes per application
        def append_route_coverage_data route_coverage_dtms
          route_coverage_dtms.take(500).each do |route_coverage_dtm|
            routes << route_coverage_dtm
          end
        end

        def append_platform_version platform_version
          self.platform = Contrast::Api::Dtm::Platform.new if platform.nil?
          platform.major = platform_version.major
          platform.minor = platform_version.minor
          platform.build = platform_version.patch
        end

        # Used to add class methods to the ApplicationUpdate class on inclusion of the decorator
        module ClassMethods
          def build
            msg = new
            msg.append_route_coverage_data(Contrast::Agent.framework_manager.find_route_discovery_data)
            msg.append_platform_version(Contrast::Agent.framework_manager.platform_version)
            msg.append_library_update(Contrast::Utils::GemfileReader.instance.library_pb_list)
            msg
          end
        end
      end
    end
  end
end

Contrast::Api::Dtm::ApplicationUpdate.include(Contrast::Api::Decorators::ApplicationUpdate)

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
contrast-agent-3.16.0 lib/contrast/api/decorators/application_update.rb
contrast-agent-3.15.0 lib/contrast/api/decorators/application_update.rb