2020-03-13 15:44:24 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module X509SerialNumberAttribute
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
class_methods do
|
|
|
|
def x509_serial_number_attribute(name)
|
|
|
|
return if ENV['STATIC_VERIFICATION']
|
|
|
|
|
|
|
|
validate_binary_column_exists!(name) unless Rails.env.production?
|
|
|
|
|
|
|
|
attribute(name, Gitlab::Database::X509SerialNumberAttribute.new)
|
|
|
|
end
|
|
|
|
|
|
|
|
# This only gets executed in non-production environments as an additional check to ensure
|
|
|
|
# the column is the correct type. In production it should behave like any other attribute.
|
|
|
|
# See https://gitlab.com/gitlab-org/gitlab/merge_requests/5502 for more discussion
|
|
|
|
def validate_binary_column_exists!(name)
|
|
|
|
return unless database_exists?
|
|
|
|
|
|
|
|
unless table_exists?
|
|
|
|
warn "WARNING: x509_serial_number_attribute #{name.inspect} is invalid since the table doesn't exist - you may need to run database migrations"
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
column = columns.find { |c| c.name == name.to_s }
|
|
|
|
|
|
|
|
unless column
|
|
|
|
warn "WARNING: x509_serial_number_attribute #{name.inspect} is invalid since the column doesn't exist - you may need to run database migrations"
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
unless column.type == :binary
|
2021-06-08 01:23:25 +05:30
|
|
|
raise ArgumentError, "x509_serial_number_attribute #{name.inspect} is invalid since the column type is not :binary"
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
2022-08-27 11:52:29 +05:30
|
|
|
rescue StandardError => e
|
|
|
|
Gitlab::AppLogger.error "X509SerialNumberAttribute initialization: #{e.message}"
|
2020-03-13 15:44:24 +05:30
|
|
|
raise
|
|
|
|
end
|
|
|
|
|
|
|
|
def database_exists?
|
2021-12-11 22:18:48 +05:30
|
|
|
database.exists?
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|