Commit 2153dec3 authored by Mehmet Emin INAC's avatar Mehmet Emin INAC

Use sha_attribute to encode string values

parent 84a66d66
...@@ -9,6 +9,8 @@ class Gitlab::BackgroundMigration::RecalculateVulnerabilitiesOccurrencesUuid ...@@ -9,6 +9,8 @@ class Gitlab::BackgroundMigration::RecalculateVulnerabilitiesOccurrencesUuid
end end
class VulnerabilitiesFinding < ActiveRecord::Base class VulnerabilitiesFinding < ActiveRecord::Base
include ShaAttribute
self.table_name = "vulnerability_occurrences" self.table_name = "vulnerability_occurrences"
belongs_to :primary_identifier, class_name: 'VulnerabilitiesIdentifier', inverse_of: :primary_findings, foreign_key: 'primary_identifier_id' belongs_to :primary_identifier, class_name: 'VulnerabilitiesIdentifier', inverse_of: :primary_findings, foreign_key: 'primary_identifier_id'
REPORT_TYPES = { REPORT_TYPES = {
...@@ -21,6 +23,9 @@ class Gitlab::BackgroundMigration::RecalculateVulnerabilitiesOccurrencesUuid ...@@ -21,6 +23,9 @@ class Gitlab::BackgroundMigration::RecalculateVulnerabilitiesOccurrencesUuid
api_fuzzing: 6 api_fuzzing: 6
}.with_indifferent_access.freeze }.with_indifferent_access.freeze
enum report_type: REPORT_TYPES enum report_type: REPORT_TYPES
sha_attribute :fingerprint
sha_attribute :location_fingerprint
end end
class CalculateFindingUUID class CalculateFindingUUID
...@@ -74,8 +79,8 @@ class Gitlab::BackgroundMigration::RecalculateVulnerabilitiesOccurrencesUuid ...@@ -74,8 +79,8 @@ class Gitlab::BackgroundMigration::RecalculateVulnerabilitiesOccurrencesUuid
uuid_v5_name_components = { uuid_v5_name_components = {
report_type: vulnerability_finding.report_type, report_type: vulnerability_finding.report_type,
primary_identifier_fingerprint: encode_to_hex(vulnerability_finding.fingerprint), primary_identifier_fingerprint: vulnerability_finding.fingerprint,
location_fingerprint: encode_to_hex(vulnerability_finding.location_fingerprint), location_fingerprint: vulnerability_finding.location_fingerprint,
project_id: vulnerability_finding.project_id project_id: vulnerability_finding.project_id
} }
...@@ -84,10 +89,6 @@ class Gitlab::BackgroundMigration::RecalculateVulnerabilitiesOccurrencesUuid ...@@ -84,10 +89,6 @@ class Gitlab::BackgroundMigration::RecalculateVulnerabilitiesOccurrencesUuid
CalculateFindingUUID.call(name) CalculateFindingUUID.call(name)
end end
def encode_to_hex(binary_string)
Gitlab::Database::ShaAttribute.new.deserialize(binary_string)
end
def logger def logger
@logger ||= Gitlab::BackgroundMigration::Logger.build @logger ||= Gitlab::BackgroundMigration::Logger.build
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