diff options
| author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-02-03 21:35:29 +0200 |
|---|---|---|
| committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-02-03 21:35:29 +0200 |
| commit | c6fa7e5e86d7fdb5fcba88bdb8a4f506aabd3305 (patch) | |
| tree | c751f1b6a31dae6578f479e8e186638860f4efc3 /lib/gitlab_keys.rb | |
| parent | b83ab386abc1b1591e7f9afa3d5d5b6cc1f5ae50 (diff) | |
| download | gitlab-shell-c6fa7e5e86d7fdb5fcba88bdb8a4f506aabd3305.tar.gz | |
add/remove keys to authorized_keys
Diffstat (limited to 'lib/gitlab_keys.rb')
| -rw-r--r-- | lib/gitlab_keys.rb | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/gitlab_keys.rb b/lib/gitlab_keys.rb new file mode 100644 index 0000000..7defc45 --- /dev/null +++ b/lib/gitlab_keys.rb @@ -0,0 +1,44 @@ +require 'open3' +require 'yaml' + +class GitlabKeys + attr_accessor :auth_file, :key, :username + + def initialize + @command = ARGV.shift + @username = ARGV.shift + @key = ARGV.shift + + config = YAML.load_file(File.join(ROOT_PATH, 'config.yml')) + @auth_file = config['auth_file'] + end + + def exec + case @command + when 'add-key'; add_key + when 'rm-key'; rm_key + when 'rm-user'; rm_user + else + puts 'not allowed' + end + end + + protected + + def add_key + cmd = "command=\"#{ROOT_PATH}/bin/gitlab-shell #{@username}\",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty #{@key}" + cmd = "echo \"#{cmd}\" >> #{auth_file}" + system(cmd) + end + + def rm_key + cmd = "sed '/#{@key}/d' #{auth_file}" + system(cmd) + end + + def rm_user + cmd = "sed -i '/#{@username}/d' #{auth_file}" + puts cmd + system(cmd) + end +end |
