Class: Contrast::Agent::Reporting::LibraryDiscovery
- Inherits:
-
ReportableHash
- Object
- ReportableHash
- Contrast::Agent::Reporting::LibraryDiscovery
- Defined in:
- lib/contrast/agent/reporting/reporting_events/library_discovery.rb
Overview
This is the new Library Discovery class which will include all the needed information for the new reporting system to relay this information in the Application Update messages. These libraries are used by TeamServer to construct the dependency information for the SCA feature. They represent those gems that are included in the GemSpec, not necessarily those that have had files in them required.
Constant Summary collapse
- StringUtils =
Contrast::Utils::StringUtils
Instance Attribute Summary collapse
-
#class_count ⇒ Object
readonly
optional attributes.
-
#external_date ⇒ Object
readonly
required attributes.
-
#file ⇒ Object
readonly
required attributes.
-
#hash ⇒ Object
readonly
required attributes.
-
#internal_date ⇒ Object
readonly
required attributes.
-
#manifest ⇒ Object
Returns the value of attribute manifest.
-
#tags ⇒ Object
readonly
optional attributes.
-
#url ⇒ Object
readonly
optional attributes.
-
#version ⇒ Object
readonly
optional attributes.
Instance Method Summary collapse
-
#initialize(digest, spec) ⇒ LibraryDiscovery
constructor
A new instance of LibraryDiscovery.
-
#to_controlled_hash ⇒ Hash
Convert the instance variables on the class, and other information, into the identifiers required for TeamServer to process the JSON form of this message.
-
#validate ⇒ Object
Ensure the required fields are present.
Methods inherited from ReportableHash
Methods included from Components::Logger::InstanceMethods
Constructor Details
#initialize(digest, spec) ⇒ LibraryDiscovery
Returns a new instance of LibraryDiscovery.
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/contrast/agent/reporting/reporting_events/library_discovery.rb', line 34 def initialize digest, spec @file = StringUtils.force_utf8(spec.name) # rubocop:disable Security/Module/Name @hash = StringUtils.force_utf8(digest) @version = StringUtils.force_utf8(spec.version) @manifest = StringUtils.force_utf8(StringUtils.force_utf8(spec.to_yaml.to_s)) @external_date = (spec.date.to_f * 1000.0).to_i @internal_date = @external_date @url = StringUtils.force_utf8(spec.homepage) @class_count = Contrast::Utils::Sha256Builder.instance.files(spec.full_gem_path.to_s).length @tags = Contrast::INVENTORY. super() end |
Instance Attribute Details
#class_count ⇒ Object (readonly)
optional attributes
25 26 27 |
# File 'lib/contrast/agent/reporting/reporting_events/library_discovery.rb', line 25 def class_count @class_count end |
#external_date ⇒ Object (readonly)
required attributes
25 26 27 |
# File 'lib/contrast/agent/reporting/reporting_events/library_discovery.rb', line 25 def external_date @external_date end |
#file ⇒ Object (readonly)
required attributes
25 26 27 |
# File 'lib/contrast/agent/reporting/reporting_events/library_discovery.rb', line 25 def file @file end |
#hash ⇒ Object (readonly)
required attributes
25 26 27 |
# File 'lib/contrast/agent/reporting/reporting_events/library_discovery.rb', line 25 def hash @hash end |
#internal_date ⇒ Object (readonly)
required attributes
25 26 27 |
# File 'lib/contrast/agent/reporting/reporting_events/library_discovery.rb', line 25 def internal_date @internal_date end |
#manifest ⇒ Object
Returns the value of attribute manifest.
32 33 34 |
# File 'lib/contrast/agent/reporting/reporting_events/library_discovery.rb', line 32 def manifest @manifest end |
#tags ⇒ Object (readonly)
optional attributes
25 26 27 |
# File 'lib/contrast/agent/reporting/reporting_events/library_discovery.rb', line 25 def @tags end |
#url ⇒ Object (readonly)
optional attributes
25 26 27 |
# File 'lib/contrast/agent/reporting/reporting_events/library_discovery.rb', line 25 def url @url end |
#version ⇒ Object (readonly)
optional attributes
25 26 27 |
# File 'lib/contrast/agent/reporting/reporting_events/library_discovery.rb', line 25 def version @version end |
Instance Method Details
#to_controlled_hash ⇒ Hash
Convert the instance variables on the class, and other information, into the identifiers required for TeamServer to process the JSON form of this message.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/contrast/agent/reporting/reporting_events/library_discovery.rb', line 52 def to_controlled_hash validate { classCount: class_count, externalDate: external_date, file: file, hash: hash, internalDate: internal_date, manifest: manifest, url: url, version: version, tags: }.compact end |
#validate ⇒ Object
Ensure the required fields are present.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/contrast/agent/reporting/reporting_events/library_discovery.rb', line 70 def validate if Contrast::Utils::DuckUtils.empty_duck?(file) raise(ArgumentError, "#{ self } did not have a proper file. Unable to continue.") end if Contrast::Utils::DuckUtils.empty_duck?(hash) raise(ArgumentError, "#{ self } did not have a proper hash. Unable to continue.") end unless external_date raise(ArgumentError, "#{ self } did not have a proper external date. Unable to continue.") end unless internal_date raise(ArgumentError, "#{ self } did not have a proper internal date. Unable to continue.") end nil end |