# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details. # frozen_string_literal: true cs__scoped_require 'contrast/components/interface' cs__scoped_require 'contrast/utils/string_utils' module Contrast module Api module Decorators # Used to decorate the 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_view_technology_descriptor_data view_technology_descriptors view_technology_descriptors.each do |vtd| vtd.technology_names.each do |tech_name| technologies[tech_name] = true end end end def append_library_update library_dtm_list, library_tags lib_tags = Contrast::Utils::StringUtils.protobuf_format(library_tags) library_dtm_list.each do |library_dtm| library_dtm.tags = lib_tags 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_view_technology_descriptor_data(Contrast::Agent.framework_manager.find_applicable_view_technologies) 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, CONFIG.root.inventory.tags) msg end end end end end end Contrast::Api::Dtm::ApplicationUpdate.include(Contrast::Api::Decorators::ApplicationUpdate)