summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-05-31 12:51:03 +0000
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-05-31 12:51:03 +0000
commitc638971dc3b93dfd618f46d1695bae5de7f28c03 (patch)
tree49de04e76e20d6e4e9e946e65164d2121f4bb6e3
parent025f97aa0b9dd76f6ec7681801f7932384a523c6 (diff)
parent8402c1bce53c7b23cf6b4ba3e9225352947ca748 (diff)
downloadgitlab-shell-c638971dc3b93dfd618f46d1695bae5de7f28c03.tar.gz
Merge branch 'add-key-lock' into 'master'
Use lock file when add new entries to authorized_keys Fixes #21
-rw-r--r--CHANGELOG1
-rw-r--r--lib/gitlab_keys.rb8
-rw-r--r--spec/gitlab_keys_spec.rb1
3 files changed, 7 insertions, 3 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 07f6c1b..7a93900 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,5 +1,6 @@
v1.9.5
- Put authorized_keys.lock in the same directory as authorized_keys
+ - Use lock file when add new entries to authorized_keys
v1.9.4
- Use lock file when modify authorized_keys
diff --git a/lib/gitlab_keys.rb b/lib/gitlab_keys.rb
index faa0716..52a982b 100644
--- a/lib/gitlab_keys.rb
+++ b/lib/gitlab_keys.rb
@@ -29,9 +29,11 @@ class GitlabKeys
protected
def add_key
- $logger.info "Adding key #{@key_id} => #{@key.inspect}"
- auth_line = key_line(@key_id, @key)
- open(auth_file, 'a') { |file| file.puts(auth_line) }
+ lock do
+ $logger.info "Adding key #{@key_id} => #{@key.inspect}"
+ auth_line = key_line(@key_id, @key)
+ open(auth_file, 'a') { |file| file.puts(auth_line) }
+ end
true
end
diff --git a/spec/gitlab_keys_spec.rb b/spec/gitlab_keys_spec.rb
index 773b0b6..e742712 100644
--- a/spec/gitlab_keys_spec.rb
+++ b/spec/gitlab_keys_spec.rb
@@ -28,6 +28,7 @@ describe GitlabKeys do
context "without file writing" do
before { gitlab_keys.stub(:open) }
+ before { create_authorized_keys_fixture }
it "should log an add-key event" do
$logger.should_receive(:info).with('Adding key key-741 => "ssh-rsa AAAAB3NzaDAxx2E"')