BigW Consortium Gitlab

Commit 39e37677 by Dmitriy Zaporozhets

add remove keys from gitlab-shell by id

parent 081c272b
......@@ -81,7 +81,7 @@ class Key < ActiveRecord::Base
Key.where(identifier: identifier).count == 0
end
def owner_name
user.username
def shell_id
"key-#{self.id}"
end
end
......@@ -4,7 +4,7 @@ class KeyObserver < ActiveRecord::Observer
def after_save(key)
GitoliteWorker.perform_async(
:add_key,
key.owner_name,
key.shell_id,
key.key
)
end
......@@ -12,7 +12,7 @@ class KeyObserver < ActiveRecord::Observer
def after_destroy(key)
GitoliteWorker.perform_async(
:remove_key,
key.owner_name,
key.shell_id,
key.key,
)
end
......
......@@ -27,19 +27,19 @@ module Gitlab
# Add new key to gitlab-shell
#
# Ex.
# add_key("randx", "sha-rsa ...")
# add_key("key-42", "sha-rsa ...")
#
def add_key(username, key_content)
system("/home/git/gitlab-shell/bin/gitlab-keys add-key #{username} \"#{key_content}\"")
def add_key(key_id, key_content)
system("/home/git/gitlab-shell/bin/gitlab-keys add-key #{key_id} \"#{key_content}\"")
end
# Remove ssh key from gitlab shell
#
# Ex.
# remove_key("sha-rsa")
# remove_key("key-342", "sha-rsa ...")
#
def remove_key(username, key_content)
system("/home/git/gitlab-shell/bin/gitlab-keys rm-key #{username} \"#{key_content}\"")
def remove_key(key_id, key_content)
system("/home/git/gitlab-shell/bin/gitlab-keys rm-key #{key_id} \"#{key_content}\"")
end
......
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