debian-mirror-gitlab/lib/tasks/tokens.rake

37 lines
1.2 KiB
Ruby
Raw Normal View History

2021-03-11 19:13:27 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require_relative '../../app/models/concerns/token_authenticatable.rb'
2018-11-18 11:00:15 +05:30
require_relative '../../app/models/concerns/token_authenticatable_strategies/base.rb'
require_relative '../../app/models/concerns/token_authenticatable_strategies/insecure.rb'
require_relative '../../app/models/concerns/token_authenticatable_strategies/digest.rb'
2017-08-17 22:00:37 +05:30
namespace :tokens do
2018-03-17 18:26:18 +05:30
desc "Reset all GitLab incoming email tokens"
2017-08-17 22:00:37 +05:30
task reset_all_email: :environment do
reset_all_users_token(:reset_incoming_email_token!)
end
2018-11-08 19:23:39 +05:30
desc "Reset all GitLab feed tokens"
task reset_all_feed: :environment do
reset_all_users_token(:reset_feed_token!)
2017-09-10 17:25:29 +05:30
end
2017-08-17 22:00:37 +05:30
def reset_all_users_token(reset_token_method)
TmpUser.find_in_batches do |batch|
puts "Processing batch starting with user ID: #{batch.first.id}"
STDOUT.flush
batch.each(&reset_token_method)
end
end
end
2019-07-07 11:18:12 +05:30
class TmpUser < ActiveRecord::Base # rubocop:disable Rails/ApplicationRecord
2017-08-17 22:00:37 +05:30
include TokenAuthenticatable
self.table_name = 'users'
2018-11-18 11:00:15 +05:30
add_authentication_token_field :incoming_email_token, token_generator: -> { SecureRandom.hex.to_i(16).to_s(36) }
add_authentication_token_field :feed_token
2017-08-17 22:00:37 +05:30
end