Commit 96c1c465 authored by Tetiana Chupryna's avatar Tetiana Chupryna

Move duplicating method to concern

Functionality for deprecated report format is moved
to separate concern and can be included when is needed.
parent eca94c0f
# frozen_string_literal: true
module Gitlab
module Ci
module Parsers
module Security
module Concerns
module DeprecatedSyntax
extend ActiveSupport::Concern
included do
extend ::Gitlab::Utils::Override
override :parse_report
end
def parse_report(json_data)
report = super
if report.is_a?(Array)
puts self.class
report = {
"version" => self.class::DEPRECATED_REPORT_VERSION,
"vulnerabilities" => report
}
end
report
end
end
end
end
end
end
end
...@@ -5,24 +5,10 @@ module Gitlab ...@@ -5,24 +5,10 @@ module Gitlab
module Parsers module Parsers
module Security module Security
class ContainerScanning < Common class ContainerScanning < Common
extend ::Gitlab::Utils::Override include Security::Concerns::DeprecatedSyntax
DEPRECATED_REPORT_VERSION = "1.3".freeze DEPRECATED_REPORT_VERSION = "1.3".freeze
override :parse_report
def parse_report(json_data)
report = super
if report.is_a?(Array)
report = {
"version" => DEPRECATED_REPORT_VERSION,
"vulnerabilities" => report
}
end
report
end
def parse!(json_data, report) def parse!(json_data, report)
vulnerabilities = format_report(JSON.parse!(json_data)) vulnerabilities = format_report(JSON.parse!(json_data))
......
...@@ -5,26 +5,12 @@ module Gitlab ...@@ -5,26 +5,12 @@ module Gitlab
module Parsers module Parsers
module Security module Security
class DependencyScanning < Common class DependencyScanning < Common
extend ::Gitlab::Utils::Override include Security::Concerns::DeprecatedSyntax
DEPRECATED_REPORT_VERSION = "1.3".freeze DEPRECATED_REPORT_VERSION = "1.3".freeze
private private
override :parse_report
def parse_report(json_data)
report = super
if report.is_a?(Array)
report = {
"version" => DEPRECATED_REPORT_VERSION,
"vulnerabilities" => report
}
end
report
end
def generate_location_fingerprint(location) def generate_location_fingerprint(location)
Digest::SHA1.hexdigest("#{location['file']}:#{location.dig('dependency', 'package', 'name')}") Digest::SHA1.hexdigest("#{location['file']}:#{location.dig('dependency', 'package', 'name')}")
end end
......
...@@ -5,26 +5,12 @@ module Gitlab ...@@ -5,26 +5,12 @@ module Gitlab
module Parsers module Parsers
module Security module Security
class Sast < Common class Sast < Common
extend ::Gitlab::Utils::Override include Security::Concerns::DeprecatedSyntax
DEPRECATED_REPORT_VERSION = "1.2".freeze DEPRECATED_REPORT_VERSION = "1.2".freeze
private private
override :parse_report
def parse_report(json_data)
report = super
if report.is_a?(Array)
report = {
"version" => DEPRECATED_REPORT_VERSION,
"vulnerabilities" => report
}
end
report
end
def generate_location_fingerprint(location) def generate_location_fingerprint(location)
Digest::SHA1.hexdigest("#{location['file']}:#{location['start_line']}:#{location['end_line']}") Digest::SHA1.hexdigest("#{location['file']}:#{location['start_line']}:#{location['end_line']}")
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment