Commit 299a9a10 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

keys to gitolite via sidekiq now

parent 944b2450
......@@ -2,11 +2,21 @@ class KeyObserver < ActiveRecord::Observer
include Gitolited
def after_save(key)
gitolite.set_key(key.identifier, key.key, key.projects)
GitoliteWorker.perform_async(
:set_key,
key.identifier,
key.key,
key.projects.map(&:id)
)
end
def after_destroy(key)
return if key.is_deploy_key && !key.last_deploy?
gitolite.remove_key(key.identifier, key.projects)
GitoliteWorker.perform_async(
:remove_key,
key.identifier,
key.projects.map(&:id)
)
end
end
......@@ -4,7 +4,7 @@ class GitoliteWorker
sidekiq_options queue: :gitolite
def perform(action, arg)
gitolite.send(action, arg)
def perform(action, *arg)
gitolite.send(action, *arg)
end
end
......@@ -8,14 +8,28 @@ module Gitlab
Gitlab::GitoliteConfig.new
end
def set_key key_id, key_content, projects
# Update gitolite config with new key
#
# Ex.
# set_key("m_gitlab_com_12343", "sha-rsa ...", [2, 3, 6])
#
def set_key(key_id, key_content, project_ids)
projects = Project.where(id: project_ids)
config.apply do |config|
config.write_key(key_id, key_content)
config.update_projects(projects)
end
end
def remove_key key_id, projects
# Remove ssh key from gitolite config
#
# Ex.
# remove_key("m_gitlab_com_12343", [2, 3, 6])
#
def remove_key(key_id, project_ids)
projects = Project.where(id: project_ids)
config.apply do |config|
config.rm_key(key_id)
config.update_projects(projects)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment