debian-mirror-gitlab/lib/gitlab/ci/parsers/sbom/source/dependency_scanning.rb
2022-10-11 01:57:18 +05:30

49 lines
1 KiB
Ruby

# frozen_string_literal: true
module Gitlab
module Ci
module Parsers
module Sbom
module Source
class DependencyScanning
REQUIRED_ATTRIBUTES = [
%w[input_file path]
].freeze
def self.source(...)
new(...).source
end
def initialize(data)
@data = data
end
def source
return unless required_attributes_present?
::Gitlab::Ci::Reports::Sbom::Source.new(
type: :dependency_scanning,
data: data,
fingerprint: fingerprint
)
end
private
attr_reader :data
def required_attributes_present?
REQUIRED_ATTRIBUTES.all? do |keys|
data.dig(*keys).present?
end
end
def fingerprint
Digest::SHA256.hexdigest(data.to_json)
end
end
end
end
end
end
end