summaryrefslogtreecommitdiff
path: root/lib/gitlab/background_migration/models/encrypt_columns/project.rb
blob: bfeae14584dcc330cec9507ec3807c032d188b01 (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
# frozen_string_literal: true

module Gitlab
  module BackgroundMigration
    module Models
      module EncryptColumns
        # This model is shared between synchronous and background migrations to
        # encrypt the `runners_token` column in `projects` table.
        #
        class Project < ActiveRecord::Base
          include ::EachBatch

          self.table_name = 'projects'
          self.inheritance_column = :_type_disabled

          def runners_token=(value)
            self.runners_token_encrypted =
              ::Gitlab::CryptoHelper.aes256_gcm_encrypt(value)
          end

          def self.encrypted_attributes
            { runners_token: { attribute: :runners_token_encrypted } }
          end
        end
      end
    end
  end
end