sarif-ruby 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +5 -0
  3. data/CODE_OF_CONDUCT.md +10 -0
  4. data/LICENSE +21 -0
  5. data/README.md +191 -0
  6. data/Rakefile +10 -0
  7. data/lib/sarif/address.rb +67 -0
  8. data/lib/sarif/artifact.rb +76 -0
  9. data/lib/sarif/artifact_change.rb +46 -0
  10. data/lib/sarif/artifact_content.rb +49 -0
  11. data/lib/sarif/artifact_location.rb +52 -0
  12. data/lib/sarif/attachment.rb +52 -0
  13. data/lib/sarif/code_flow.rb +46 -0
  14. data/lib/sarif/configuration_override.rb +46 -0
  15. data/lib/sarif/conversion.rb +49 -0
  16. data/lib/sarif/edge.rb +52 -0
  17. data/lib/sarif/edge_traversal.rb +52 -0
  18. data/lib/sarif/exception.rb +52 -0
  19. data/lib/sarif/external_properties.rb +100 -0
  20. data/lib/sarif/external_property_file_reference.rb +49 -0
  21. data/lib/sarif/external_property_file_references.rb +88 -0
  22. data/lib/sarif/fix.rb +46 -0
  23. data/lib/sarif/graph.rb +49 -0
  24. data/lib/sarif/graph_traversal.rb +58 -0
  25. data/lib/sarif/invocation.rb +115 -0
  26. data/lib/sarif/location.rb +58 -0
  27. data/lib/sarif/location_relationship.rb +49 -0
  28. data/lib/sarif/log.rb +52 -0
  29. data/lib/sarif/logical_location.rb +58 -0
  30. data/lib/sarif/message.rb +52 -0
  31. data/lib/sarif/multiformat_message_string.rb +46 -0
  32. data/lib/sarif/node.rb +52 -0
  33. data/lib/sarif/notification.rb +64 -0
  34. data/lib/sarif/physical_location.rb +52 -0
  35. data/lib/sarif/property_bag.rb +40 -0
  36. data/lib/sarif/rectangle.rb +55 -0
  37. data/lib/sarif/region.rb +73 -0
  38. data/lib/sarif/replacement.rb +46 -0
  39. data/lib/sarif/reporting_configuration.rb +52 -0
  40. data/lib/sarif/reporting_descriptor.rb +79 -0
  41. data/lib/sarif/reporting_descriptor_reference.rb +52 -0
  42. data/lib/sarif/reporting_descriptor_relationship.rb +49 -0
  43. data/lib/sarif/result.rb +127 -0
  44. data/lib/sarif/result_provenance.rb +58 -0
  45. data/lib/sarif/run.rb +121 -0
  46. data/lib/sarif/run_automation_details.rb +52 -0
  47. data/lib/sarif/schema/sarif-schema-2.1.0.json +3389 -0
  48. data/lib/sarif/special_locations.rb +43 -0
  49. data/lib/sarif/stack.rb +46 -0
  50. data/lib/sarif/stack_frame.rb +52 -0
  51. data/lib/sarif/suppression.rb +55 -0
  52. data/lib/sarif/thread_flow.rb +55 -0
  53. data/lib/sarif/thread_flow_location.rb +79 -0
  54. data/lib/sarif/tool.rb +46 -0
  55. data/lib/sarif/tool_component.rb +121 -0
  56. data/lib/sarif/tool_component_reference.rb +49 -0
  57. data/lib/sarif/translation_metadata.rb +58 -0
  58. data/lib/sarif/version.rb +5 -0
  59. data/lib/sarif/version_control_details.rb +58 -0
  60. data/lib/sarif/web_request.rb +64 -0
  61. data/lib/sarif/web_response.rb +64 -0
  62. data/lib/sarif.rb +121 -0
  63. data/sig/sarif.rbs +4 -0
  64. metadata +106 -0
data/lib/sarif/run.rb ADDED
@@ -0,0 +1,121 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sarif
4
+ # Describes a single run of an analysis tool, and contains the reported output of that run.
5
+ class Run
6
+ attr_accessor :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
7
+
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)
9
+ @tool = tool
10
+ @invocations = invocations
11
+ @conversion = conversion
12
+ @language = language
13
+ @version_control_provenance = version_control_provenance
14
+ @original_uri_base_ids = original_uri_base_ids
15
+ @artifacts = artifacts
16
+ @logical_locations = logical_locations
17
+ @graphs = graphs
18
+ @results = results
19
+ @automation_details = automation_details
20
+ @run_aggregates = run_aggregates
21
+ @baseline_guid = baseline_guid
22
+ @redaction_tokens = redaction_tokens
23
+ @default_encoding = default_encoding
24
+ @default_source_language = default_source_language
25
+ @newline_sequences = newline_sequences
26
+ @column_kind = column_kind
27
+ @external_property_file_references = external_property_file_references
28
+ @thread_flow_locations = thread_flow_locations
29
+ @taxonomies = taxonomies
30
+ @addresses = addresses
31
+ @translations = translations
32
+ @policies = policies
33
+ @web_requests = web_requests
34
+ @web_responses = web_responses
35
+ @special_locations = special_locations
36
+ @properties = properties
37
+ end
38
+
39
+ def to_h
40
+ h = {}
41
+ h["tool"] = @tool&.to_h
42
+ h["invocations"] = @invocations&.map(&:to_h) if @invocations&.any?
43
+ h["conversion"] = @conversion&.to_h unless @conversion.nil?
44
+ h["language"] = @language if @language && @language != "en-US"
45
+ h["versionControlProvenance"] = @version_control_provenance&.map(&:to_h) if @version_control_provenance&.any?
46
+ h["originalUriBaseIds"] = @original_uri_base_ids unless @original_uri_base_ids.nil?
47
+ h["artifacts"] = @artifacts&.map(&:to_h) if @artifacts&.any?
48
+ h["logicalLocations"] = @logical_locations&.map(&:to_h) if @logical_locations&.any?
49
+ h["graphs"] = @graphs&.map(&:to_h) if @graphs&.any?
50
+ h["results"] = @results&.map(&:to_h) if @results&.any?
51
+ h["automationDetails"] = @automation_details&.to_h unless @automation_details.nil?
52
+ h["runAggregates"] = @run_aggregates&.map(&:to_h) if @run_aggregates&.any?
53
+ h["baselineGuid"] = @baseline_guid unless @baseline_guid.nil?
54
+ h["redactionTokens"] = @redaction_tokens if @redaction_tokens&.any?
55
+ h["defaultEncoding"] = @default_encoding unless @default_encoding.nil?
56
+ h["defaultSourceLanguage"] = @default_source_language unless @default_source_language.nil?
57
+ h["newlineSequences"] = @newline_sequences if @newline_sequences&.any?
58
+ h["columnKind"] = @column_kind&.to_s unless @column_kind.nil?
59
+ h["externalPropertyFileReferences"] = @external_property_file_references&.to_h unless @external_property_file_references.nil?
60
+ h["threadFlowLocations"] = @thread_flow_locations&.map(&:to_h) if @thread_flow_locations&.any?
61
+ h["taxonomies"] = @taxonomies&.map(&:to_h) if @taxonomies&.any?
62
+ h["addresses"] = @addresses&.map(&:to_h) if @addresses&.any?
63
+ h["translations"] = @translations&.map(&:to_h) if @translations&.any?
64
+ h["policies"] = @policies&.map(&:to_h) if @policies&.any?
65
+ h["webRequests"] = @web_requests&.map(&:to_h) if @web_requests&.any?
66
+ h["webResponses"] = @web_responses&.map(&:to_h) if @web_responses&.any?
67
+ h["specialLocations"] = @special_locations&.to_h unless @special_locations.nil?
68
+ h["properties"] = @properties unless @properties.nil?
69
+ h
70
+ end
71
+
72
+ def to_json(pretty: false)
73
+ pretty ? JSON.pretty_generate(to_h) : JSON.generate(to_h)
74
+ end
75
+
76
+ def self.from_hash(h)
77
+ return nil if h.nil?
78
+ new(
79
+ tool: Tool.from_hash(h["tool"]),
80
+ invocations: h["invocations"]&.map { |v| Invocation.from_hash(v) } || [],
81
+ conversion: Conversion.from_hash(h["conversion"]),
82
+ language: h["language"] || "en-US",
83
+ version_control_provenance: h["versionControlProvenance"]&.map { |v| VersionControlDetails.from_hash(v) } || [],
84
+ original_uri_base_ids: h["originalUriBaseIds"],
85
+ artifacts: h["artifacts"]&.map { |v| Artifact.from_hash(v) },
86
+ logical_locations: h["logicalLocations"]&.map { |v| LogicalLocation.from_hash(v) } || [],
87
+ graphs: h["graphs"]&.map { |v| Graph.from_hash(v) } || [],
88
+ results: h["results"]&.map { |v| Result.from_hash(v) },
89
+ automation_details: RunAutomationDetails.from_hash(h["automationDetails"]),
90
+ run_aggregates: h["runAggregates"]&.map { |v| RunAutomationDetails.from_hash(v) } || [],
91
+ baseline_guid: h["baselineGuid"],
92
+ redaction_tokens: h["redactionTokens"] || [],
93
+ default_encoding: h["defaultEncoding"],
94
+ default_source_language: h["defaultSourceLanguage"],
95
+ newline_sequences: h.key?("newlineSequences") ? h["newlineSequences"] : ["\r\n", "\n"],
96
+ column_kind: h["columnKind"],
97
+ external_property_file_references: ExternalPropertyFileReferences.from_hash(h["externalPropertyFileReferences"]),
98
+ thread_flow_locations: h["threadFlowLocations"]&.map { |v| ThreadFlowLocation.from_hash(v) } || [],
99
+ taxonomies: h["taxonomies"]&.map { |v| ToolComponent.from_hash(v) } || [],
100
+ addresses: h["addresses"]&.map { |v| Address.from_hash(v) } || [],
101
+ translations: h["translations"]&.map { |v| ToolComponent.from_hash(v) } || [],
102
+ policies: h["policies"]&.map { |v| ToolComponent.from_hash(v) } || [],
103
+ web_requests: h["webRequests"]&.map { |v| WebRequest.from_hash(v) } || [],
104
+ web_responses: h["webResponses"]&.map { |v| WebResponse.from_hash(v) } || [],
105
+ special_locations: SpecialLocations.from_hash(h["specialLocations"]),
106
+ properties: h["properties"]
107
+ )
108
+ end
109
+
110
+ def ==(other)
111
+ return false unless other.is_a?(Run)
112
+ @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
113
+ end
114
+
115
+ alias eql? ==
116
+
117
+ def hash
118
+ [@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
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sarif
4
+ # Information that describes a run's identity and role within an engineering system process.
5
+ class RunAutomationDetails
6
+ attr_accessor :description, :id, :guid, :correlation_guid, :properties
7
+
8
+ def initialize(description: nil, id: nil, guid: nil, correlation_guid: nil, properties: nil)
9
+ @description = description
10
+ @id = id
11
+ @guid = guid
12
+ @correlation_guid = correlation_guid
13
+ @properties = properties
14
+ end
15
+
16
+ def to_h
17
+ h = {}
18
+ h["description"] = @description&.to_h unless @description.nil?
19
+ h["id"] = @id unless @id.nil?
20
+ h["guid"] = @guid unless @guid.nil?
21
+ h["correlationGuid"] = @correlation_guid unless @correlation_guid.nil?
22
+ h["properties"] = @properties unless @properties.nil?
23
+ h
24
+ end
25
+
26
+ def to_json(pretty: false)
27
+ pretty ? JSON.pretty_generate(to_h) : JSON.generate(to_h)
28
+ end
29
+
30
+ def self.from_hash(h)
31
+ return nil if h.nil?
32
+ new(
33
+ description: Message.from_hash(h["description"]),
34
+ id: h["id"],
35
+ guid: h["guid"],
36
+ correlation_guid: h["correlationGuid"],
37
+ properties: h["properties"]
38
+ )
39
+ end
40
+
41
+ def ==(other)
42
+ return false unless other.is_a?(RunAutomationDetails)
43
+ @description == other.description && @id == other.id && @guid == other.guid && @correlation_guid == other.correlation_guid && @properties == other.properties
44
+ end
45
+
46
+ alias eql? ==
47
+
48
+ def hash
49
+ [@description, @id, @guid, @correlation_guid, @properties].hash
50
+ end
51
+ end
52
+ end