Class: Sarif::Run

Inherits:
Object
  • Object
show all
Defined in:
lib/sarif/run.rb

Overview

Describes a single run of an analysis tool, and contains the reported output of that run.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tool:, invocations: [], conversion: nil, language: "en-US", version_control_provenance: [], original_uri_base_ids: nil, artifacts: nil, logical_locations: [], graphs: [], results: nil, automation_details: nil, run_aggregates: [], baseline_guid: nil, redaction_tokens: [], default_encoding: nil, default_source_language: nil, newline_sequences: ["\r\n", "\n"], column_kind: nil, external_property_file_references: nil, thread_flow_locations: [], taxonomies: [], addresses: [], translations: [], policies: [], web_requests: [], web_responses: [], special_locations: nil, properties: nil) ⇒ Run

Returns a new instance of Run.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/sarif/run.rb', line 8

def initialize(tool:, invocations: [], conversion: nil, language: "en-US", version_control_provenance: [], original_uri_base_ids: nil, artifacts: nil, logical_locations: [], graphs: [], results: nil, automation_details: nil, run_aggregates: [], baseline_guid: nil, redaction_tokens: [], default_encoding: nil, default_source_language: nil, newline_sequences: ["\r\n", "\n"], column_kind: nil, external_property_file_references: nil, thread_flow_locations: [], taxonomies: [], addresses: [], translations: [], policies: [], web_requests: [], web_responses: [], special_locations: nil, properties: nil)
  @tool = tool
  @invocations = invocations
  @conversion = conversion
  @language = language
  @version_control_provenance = version_control_provenance
  @original_uri_base_ids = original_uri_base_ids
  @artifacts = artifacts
  @logical_locations = logical_locations
  @graphs = graphs
  @results = results
  @automation_details = automation_details
  @run_aggregates = run_aggregates
  @baseline_guid = baseline_guid
  @redaction_tokens = redaction_tokens
  @default_encoding = default_encoding
  @default_source_language = default_source_language
  @newline_sequences = newline_sequences
  @column_kind = column_kind
  @external_property_file_references = external_property_file_references
  @thread_flow_locations = thread_flow_locations
  @taxonomies = taxonomies
  @addresses = addresses
  @translations = translations
  @policies = policies
  @web_requests = web_requests
  @web_responses = web_responses
  @special_locations = special_locations
  @properties = properties
end

Instance Attribute Details

#addressesObject

Returns the value of attribute addresses.



6
7
8
# File 'lib/sarif/run.rb', line 6

def addresses
  @addresses
end

#artifactsObject

Returns the value of attribute artifacts.



6
7
8
# File 'lib/sarif/run.rb', line 6

def artifacts
  @artifacts
end

#automation_detailsObject

Returns the value of attribute automation_details.



6
7
8
# File 'lib/sarif/run.rb', line 6

def automation_details
  @automation_details
end

#baseline_guidObject

Returns the value of attribute baseline_guid.



6
7
8
# File 'lib/sarif/run.rb', line 6

def baseline_guid
  @baseline_guid
end

#column_kindObject

Returns the value of attribute column_kind.



6
7
8
# File 'lib/sarif/run.rb', line 6

def column_kind
  @column_kind
end

#conversionObject

Returns the value of attribute conversion.



6
7
8
# File 'lib/sarif/run.rb', line 6

def conversion
  @conversion
end

#default_encodingObject

Returns the value of attribute default_encoding.



6
7
8
# File 'lib/sarif/run.rb', line 6

def default_encoding
  @default_encoding
end

#default_source_languageObject

Returns the value of attribute default_source_language.



6
7
8
# File 'lib/sarif/run.rb', line 6

def default_source_language
  @default_source_language
end

#external_property_file_referencesObject

Returns the value of attribute external_property_file_references.



6
7
8
# File 'lib/sarif/run.rb', line 6

def external_property_file_references
  @external_property_file_references
end

#graphsObject

Returns the value of attribute graphs.



6
7
8
# File 'lib/sarif/run.rb', line 6

def graphs
  @graphs
end

#invocationsObject

Returns the value of attribute invocations.



6
7
8
# File 'lib/sarif/run.rb', line 6

def invocations
  @invocations
end

#languageObject

Returns the value of attribute language.



6
7
8
# File 'lib/sarif/run.rb', line 6

def language
  @language
end

#logical_locationsObject

Returns the value of attribute logical_locations.



6
7
8
# File 'lib/sarif/run.rb', line 6

def logical_locations
  @logical_locations
end

#newline_sequencesObject

Returns the value of attribute newline_sequences.



6
7
8
# File 'lib/sarif/run.rb', line 6

def newline_sequences
  @newline_sequences
end

#original_uri_base_idsObject

Returns the value of attribute original_uri_base_ids.



6
7
8
# File 'lib/sarif/run.rb', line 6

def original_uri_base_ids
  @original_uri_base_ids
end

#policiesObject

Returns the value of attribute policies.



6
7
8
# File 'lib/sarif/run.rb', line 6

def policies
  @policies
end

#propertiesObject

Returns the value of attribute properties.



6
7
8
# File 'lib/sarif/run.rb', line 6

def properties
  @properties
end

#redaction_tokensObject

Returns the value of attribute redaction_tokens.



6
7
8
# File 'lib/sarif/run.rb', line 6

def redaction_tokens
  @redaction_tokens
end

#resultsObject

Returns the value of attribute results.



6
7
8
# File 'lib/sarif/run.rb', line 6

def results
  @results
end

#run_aggregatesObject

Returns the value of attribute run_aggregates.



6
7
8
# File 'lib/sarif/run.rb', line 6

def run_aggregates
  @run_aggregates
end

#special_locationsObject

Returns the value of attribute special_locations.



6
7
8
# File 'lib/sarif/run.rb', line 6

def special_locations
  @special_locations
end

#taxonomiesObject

Returns the value of attribute taxonomies.



6
7
8
# File 'lib/sarif/run.rb', line 6

def taxonomies
  @taxonomies
end

#thread_flow_locationsObject

Returns the value of attribute thread_flow_locations.



6
7
8
# File 'lib/sarif/run.rb', line 6

def thread_flow_locations
  @thread_flow_locations
end

#toolObject

Returns the value of attribute tool.



6
7
8
# File 'lib/sarif/run.rb', line 6

def tool
  @tool
end

#translationsObject

Returns the value of attribute translations.



6
7
8
# File 'lib/sarif/run.rb', line 6

def translations
  @translations
end

#version_control_provenanceObject

Returns the value of attribute version_control_provenance.



6
7
8
# File 'lib/sarif/run.rb', line 6

def version_control_provenance
  @version_control_provenance
end

#web_requestsObject

Returns the value of attribute web_requests.



6
7
8
# File 'lib/sarif/run.rb', line 6

def web_requests
  @web_requests
end

#web_responsesObject

Returns the value of attribute web_responses.



6
7
8
# File 'lib/sarif/run.rb', line 6

def web_responses
  @web_responses
end

Class Method Details

.from_hash(h) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/sarif/run.rb', line 76

def self.from_hash(h)
  return nil if h.nil?
  new(
    tool: Tool.from_hash(h["tool"]),
    invocations: h["invocations"]&.map { |v| Invocation.from_hash(v) } || [],
    conversion: Conversion.from_hash(h["conversion"]),
    language: h["language"] || "en-US",
    version_control_provenance: h["versionControlProvenance"]&.map { |v| VersionControlDetails.from_hash(v) } || [],
    original_uri_base_ids: h["originalUriBaseIds"],
    artifacts: h["artifacts"]&.map { |v| Artifact.from_hash(v) },
    logical_locations: h["logicalLocations"]&.map { |v| LogicalLocation.from_hash(v) } || [],
    graphs: h["graphs"]&.map { |v| Graph.from_hash(v) } || [],
    results: h["results"]&.map { |v| Result.from_hash(v) },
    automation_details: RunAutomationDetails.from_hash(h["automationDetails"]),
    run_aggregates: h["runAggregates"]&.map { |v| RunAutomationDetails.from_hash(v) } || [],
    baseline_guid: h["baselineGuid"],
    redaction_tokens: h["redactionTokens"] || [],
    default_encoding: h["defaultEncoding"],
    default_source_language: h["defaultSourceLanguage"],
    newline_sequences: h.key?("newlineSequences") ? h["newlineSequences"] : ["\r\n", "\n"],
    column_kind: h["columnKind"],
    external_property_file_references: ExternalPropertyFileReferences.from_hash(h["externalPropertyFileReferences"]),
    thread_flow_locations: h["threadFlowLocations"]&.map { |v| ThreadFlowLocation.from_hash(v) } || [],
    taxonomies: h["taxonomies"]&.map { |v| ToolComponent.from_hash(v) } || [],
    addresses: h["addresses"]&.map { |v| Address.from_hash(v) } || [],
    translations: h["translations"]&.map { |v| ToolComponent.from_hash(v) } || [],
    policies: h["policies"]&.map { |v| ToolComponent.from_hash(v) } || [],
    web_requests: h["webRequests"]&.map { |v| WebRequest.from_hash(v) } || [],
    web_responses: h["webResponses"]&.map { |v| WebResponse.from_hash(v) } || [],
    special_locations: SpecialLocations.from_hash(h["specialLocations"]),
    properties: h["properties"]
  )
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



110
111
112
113
# File 'lib/sarif/run.rb', line 110

def ==(other)
  return false unless other.is_a?(Run)
  @tool == other.tool && @invocations == other.invocations && @conversion == other.conversion && @language == other.language && @version_control_provenance == other.version_control_provenance && @original_uri_base_ids == other.original_uri_base_ids && @artifacts == other.artifacts && @logical_locations == other.logical_locations && @graphs == other.graphs && @results == other.results && @automation_details == other.automation_details && @run_aggregates == other.run_aggregates && @baseline_guid == other.baseline_guid && @redaction_tokens == other.redaction_tokens && @default_encoding == other.default_encoding && @default_source_language == other.default_source_language && @newline_sequences == other.newline_sequences && @column_kind == other.column_kind && @external_property_file_references == other.external_property_file_references && @thread_flow_locations == other.thread_flow_locations && @taxonomies == other.taxonomies && @addresses == other.addresses && @translations == other.translations && @policies == other.policies && @web_requests == other.web_requests && @web_responses == other.web_responses && @special_locations == other.special_locations && @properties == other.properties
end

#hashObject



117
118
119
# File 'lib/sarif/run.rb', line 117

def hash
  [@tool, @invocations, @conversion, @language, @version_control_provenance, @original_uri_base_ids, @artifacts, @logical_locations, @graphs, @results, @automation_details, @run_aggregates, @baseline_guid, @redaction_tokens, @default_encoding, @default_source_language, @newline_sequences, @column_kind, @external_property_file_references, @thread_flow_locations, @taxonomies, @addresses, @translations, @policies, @web_requests, @web_responses, @special_locations, @properties].hash
end

#to_hObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/sarif/run.rb', line 39

def to_h
  h = {}
  h["tool"] = @tool&.to_h
  h["invocations"] = @invocations&.map(&:to_h) if @invocations&.any?
  h["conversion"] = @conversion&.to_h unless @conversion.nil?
  h["language"] = @language if @language && @language != "en-US"
  h["versionControlProvenance"] = @version_control_provenance&.map(&:to_h) if @version_control_provenance&.any?
  h["originalUriBaseIds"] = @original_uri_base_ids unless @original_uri_base_ids.nil?
  h["artifacts"] = @artifacts&.map(&:to_h) if @artifacts&.any?
  h["logicalLocations"] = @logical_locations&.map(&:to_h) if @logical_locations&.any?
  h["graphs"] = @graphs&.map(&:to_h) if @graphs&.any?
  h["results"] = @results.map(&:to_h) unless @results.nil?
  h["automationDetails"] = @automation_details&.to_h unless @automation_details.nil?
  h["runAggregates"] = @run_aggregates&.map(&:to_h) if @run_aggregates&.any?
  h["baselineGuid"] = @baseline_guid unless @baseline_guid.nil?
  h["redactionTokens"] = @redaction_tokens if @redaction_tokens&.any?
  h["defaultEncoding"] = @default_encoding unless @default_encoding.nil?
  h["defaultSourceLanguage"] = @default_source_language unless @default_source_language.nil?
  h["newlineSequences"] = @newline_sequences if @newline_sequences&.any?
  h["columnKind"] = @column_kind&.to_s unless @column_kind.nil?
  h["externalPropertyFileReferences"] = @external_property_file_references&.to_h unless @external_property_file_references.nil?
  h["threadFlowLocations"] = @thread_flow_locations&.map(&:to_h) if @thread_flow_locations&.any?
  h["taxonomies"] = @taxonomies&.map(&:to_h) if @taxonomies&.any?
  h["addresses"] = @addresses&.map(&:to_h) if @addresses&.any?
  h["translations"] = @translations&.map(&:to_h) if @translations&.any?
  h["policies"] = @policies&.map(&:to_h) if @policies&.any?
  h["webRequests"] = @web_requests&.map(&:to_h) if @web_requests&.any?
  h["webResponses"] = @web_responses&.map(&:to_h) if @web_responses&.any?
  h["specialLocations"] = @special_locations&.to_h unless @special_locations.nil?
  h["properties"] = @properties unless @properties.nil?
  h
end

#to_json(pretty: false) ⇒ Object



72
73
74
# File 'lib/sarif/run.rb', line 72

def to_json(pretty: false)
  pretty ? JSON.pretty_generate(to_h) : JSON.generate(to_h)
end