Welcome to mirror list, hosted at ThFree Co, Russian Federation.

migrate_u2f_webauthn.rb « background_migration « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 091e6660bacb034c05d52ee797e5c2cc3f5a4db0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# frozen_string_literal: true
# rubocop:disable Style/Documentation
require "webauthn/u2f_migrator"

module Gitlab
  module BackgroundMigration
    class MigrateU2fWebauthn
      class U2fRegistration < ActiveRecord::Base
        self.table_name = 'u2f_registrations'
      end

      class WebauthnRegistration < ActiveRecord::Base
        self.table_name = 'webauthn_registrations'
      end

      def perform(start_id, end_id)
        old_registrations = U2fRegistration.where(id: start_id..end_id)
        old_registrations.each_slice(100) do |slice|
          values = slice.map do |u2f_registration|
            converter = Gitlab::Auth::U2fWebauthnConverter.new(u2f_registration)
            converter.convert
          end

          WebauthnRegistration.insert_all(values, unique_by: :credential_xid, returning: false)
        end
      end
    end
  end
end