2020-03-12 08:09:17 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class AuthorizedKeysWorker
|
|
|
|
include ApplicationWorker
|
|
|
|
|
2021-04-30 14:10:09 -04:00
|
|
|
sidekiq_options retry: 3
|
|
|
|
|
2020-03-23 14:09:25 -04:00
|
|
|
PERMITTED_ACTIONS = %w[add_key remove_key].freeze
|
2020-03-12 08:09:17 -04:00
|
|
|
|
|
|
|
feature_category :source_code_management
|
|
|
|
urgency :high
|
|
|
|
weight 2
|
|
|
|
idempotent!
|
2020-06-12 08:08:56 -04:00
|
|
|
loggable_arguments 0
|
2020-03-12 08:09:17 -04:00
|
|
|
|
|
|
|
def perform(action, *args)
|
|
|
|
return unless Gitlab::CurrentSettings.authorized_keys_enabled?
|
|
|
|
|
2020-03-23 14:09:25 -04:00
|
|
|
case action.to_s
|
|
|
|
when 'add_key'
|
2020-03-12 08:09:17 -04:00
|
|
|
authorized_keys.add_key(*args)
|
2020-03-23 14:09:25 -04:00
|
|
|
when 'remove_key'
|
2020-03-12 08:09:17 -04:00
|
|
|
authorized_keys.remove_key(*args)
|
2020-03-23 14:09:25 -04:00
|
|
|
else
|
|
|
|
raise "Unknown action: #{action.inspect}"
|
2020-03-12 08:09:17 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def authorized_keys
|
|
|
|
@authorized_keys ||= Gitlab::AuthorizedKeys.new
|
|
|
|
end
|
|
|
|
end
|