Commit 299a9a10400e7fdcc641a90db95290322058c529
1 parent
944b2450
Exists in
master
and in
4 other branches
keys to gitolite via sidekiq now
Showing
3 changed files
with
30 additions
and
6 deletions
Show diff stats
app/observers/key_observer.rb
| ... | ... | @@ -2,11 +2,21 @@ class KeyObserver < ActiveRecord::Observer |
| 2 | 2 | include Gitolited |
| 3 | 3 | |
| 4 | 4 | def after_save(key) |
| 5 | - gitolite.set_key(key.identifier, key.key, key.projects) | |
| 5 | + GitoliteWorker.perform_async( | |
| 6 | + :set_key, | |
| 7 | + key.identifier, | |
| 8 | + key.key, | |
| 9 | + key.projects.map(&:id) | |
| 10 | + ) | |
| 6 | 11 | end |
| 7 | 12 | |
| 8 | 13 | def after_destroy(key) |
| 9 | 14 | return if key.is_deploy_key && !key.last_deploy? |
| 10 | - gitolite.remove_key(key.identifier, key.projects) | |
| 15 | + | |
| 16 | + GitoliteWorker.perform_async( | |
| 17 | + :remove_key, | |
| 18 | + key.identifier, | |
| 19 | + key.projects.map(&:id) | |
| 20 | + ) | |
| 11 | 21 | end |
| 12 | 22 | end | ... | ... |
app/workers/gitolite_worker.rb
lib/gitlab/backend/gitolite.rb
| ... | ... | @@ -8,14 +8,28 @@ module Gitlab |
| 8 | 8 | Gitlab::GitoliteConfig.new |
| 9 | 9 | end |
| 10 | 10 | |
| 11 | - def set_key key_id, key_content, projects | |
| 11 | + # Update gitolite config with new key | |
| 12 | + # | |
| 13 | + # Ex. | |
| 14 | + # set_key("m_gitlab_com_12343", "sha-rsa ...", [2, 3, 6]) | |
| 15 | + # | |
| 16 | + def set_key(key_id, key_content, project_ids) | |
| 17 | + projects = Project.where(id: project_ids) | |
| 18 | + | |
| 12 | 19 | config.apply do |config| |
| 13 | 20 | config.write_key(key_id, key_content) |
| 14 | 21 | config.update_projects(projects) |
| 15 | 22 | end |
| 16 | 23 | end |
| 17 | 24 | |
| 18 | - def remove_key key_id, projects | |
| 25 | + # Remove ssh key from gitolite config | |
| 26 | + # | |
| 27 | + # Ex. | |
| 28 | + # remove_key("m_gitlab_com_12343", [2, 3, 6]) | |
| 29 | + # | |
| 30 | + def remove_key(key_id, project_ids) | |
| 31 | + projects = Project.where(id: project_ids) | |
| 32 | + | |
| 19 | 33 | config.apply do |config| |
| 20 | 34 | config.rm_key(key_id) |
| 21 | 35 | config.update_projects(projects) | ... | ... |