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
sidekiq_options queue: :gitolite
- def perform(action, arg)
- gitolite.send(action, arg)
+ def perform(action, *arg)
+ gitolite.send(action, *arg)
end
end
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)