diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-07-19 11:13:51 +0000 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-07-19 11:13:51 +0000 |
commit | f13afa2db3f3b44a9a6f97b88eced3f324f80b51 (patch) | |
tree | bcdaab260a4016ac767318b3da064a6f365eb71f | |
parent | f31c38e8ea62c862e5d5bc29b4a2984ed608c2a1 (diff) | |
parent | 4de0ee3b8fbdbcc215b0e23ef87c7a97eadadafd (diff) | |
download | gitlab-shell-f13afa2db3f3b44a9a6f97b88eced3f324f80b51.tar.gz |
Merge branch 'avoid_sed_i' of /home/git/repositories/gitlab/gitlab-shell
-rw-r--r-- | lib/gitlab_keys.rb | 8 | ||||
-rw-r--r-- | spec/gitlab_keys_spec.rb | 5 |
2 files changed, 9 insertions, 4 deletions
diff --git a/lib/gitlab_keys.rb b/lib/gitlab_keys.rb index d09360f..dc54740 100644 --- a/lib/gitlab_keys.rb +++ b/lib/gitlab_keys.rb @@ -1,4 +1,4 @@ -require 'open3' +require 'tempfile' require_relative 'gitlab_config' require_relative 'gitlab_logger' @@ -36,8 +36,10 @@ class GitlabKeys def rm_key $logger.info "Removing key #{@key_id}" - cmd = "sed -i '/shell #{@key_id}\"/d' #{auth_file}" - system(cmd) + Tempfile.open('authorized_keys') do |temp| + cmd = "sed '/shell #{@key_id}\"/d' #{auth_file} > #{temp.path} && mv #{temp.path} #{auth_file}" + system(cmd) + end end def clear diff --git a/spec/gitlab_keys_spec.rb b/spec/gitlab_keys_spec.rb index 09f5872..c888b8e 100644 --- a/spec/gitlab_keys_spec.rb +++ b/spec/gitlab_keys_spec.rb @@ -31,9 +31,12 @@ describe GitlabKeys do describe :rm_key do let(:gitlab_keys) { build_gitlab_keys('rm-key', 'key-741', 'ssh-rsa AAAAB3NzaDAxx2E') } + let(:temp_file) { mock(:temp_file, path: 'tmp_path') } + before { Tempfile.should_receive(:open).and_yield(temp_file) } it "should receive valid cmd" do - valid_cmd = "sed -i '/shell key-741\"/d' #{GitlabConfig.new.auth_file}" + auth_file = GitlabConfig.new.auth_file + valid_cmd = "sed '/shell key-741\"/d' #{auth_file} > tmp_path && mv tmp_path #{auth_file}" gitlab_keys.should_receive(:system).with(valid_cmd) gitlab_keys.send :rm_key end |