diff options
author | Douwe Maan <douwe@gitlab.com> | 2018-12-13 11:36:09 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2018-12-13 11:36:09 +0000 |
commit | 47dc17bce2e59b403dffa9eacc8b146618dba2c2 (patch) | |
tree | 544fda407b7df029b0dd122f949fd0dfe3ad9694 /lib/gitlab_keys.rb | |
parent | df89099ed954a6673bb8388ef74480940d40a759 (diff) | |
download | gitlab-shell-47dc17bce2e59b403dffa9eacc8b146618dba2c2.tar.gz |
Revert "Merge branch 'sh-bump-ruby-version' into 'master'"
This reverts merge request !257
Diffstat (limited to 'lib/gitlab_keys.rb')
-rw-r--r-- | lib/gitlab_keys.rb | 28 |
1 files changed, 10 insertions, 18 deletions
diff --git a/lib/gitlab_keys.rb b/lib/gitlab_keys.rb index c67d336..0600a18 100644 --- a/lib/gitlab_keys.rb +++ b/lib/gitlab_keys.rb @@ -1,5 +1,4 @@ require 'timeout' -require 'open3' require_relative 'gitlab_config' require_relative 'gitlab_logger' @@ -15,7 +14,7 @@ class GitlabKeys # rubocop:disable Metrics/ClassLength end def self.command_key(key_id) - unless /\A[a-z0-9-]+\z/ =~ key_id # rubocop:disable Performance/RegexpMatch + unless /\A[a-z0-9-]+\z/ =~ key_id raise KeyError, "Invalid key_id: #{key_id.inspect}" end @@ -108,9 +107,7 @@ class GitlabKeys # rubocop:disable Metrics/ClassLength open_auth_file('r') do |f| f.each_line do |line| matchd = line.match(/key-(\d+)/) - next unless matchd - puts matchd[1] end end @@ -141,7 +138,6 @@ class GitlabKeys # rubocop:disable Metrics/ClassLength open_auth_file('r+') do |f| while line = f.gets # rubocop:disable Lint/AssignmentInCondition next unless line.start_with?("command=\"#{self.class.command_key(@key_id)}\"") - f.seek(-line.length, IO::SEEK_CUR) # Overwrite the line with #'s. Because the 'line' variable contains # a terminating '\n', we write line.length - 1 '#' characters. @@ -159,24 +155,20 @@ class GitlabKeys # rubocop:disable Metrics/ClassLength def check_permissions open_auth_file(File::RDWR | File::CREAT) { true } - rescue StandardError => ex + rescue => ex puts "error: could not open #{auth_file}: #{ex}" - - cmd = if File.exist?(auth_file) - %W{ls -l #{auth_file}} - else - # Maybe the parent directory is not writable? - %W{ls -ld #{File.dirname(auth_file)}} - end - - output, = Open3.capture2e(cmd.join(' ')) - puts output + if File.exist?(auth_file) + system('ls', '-l', auth_file) + else + # Maybe the parent directory is not writable? + system('ls', '-ld', File.dirname(auth_file)) + end false end def lock(timeout = 10) File.open(lock_file, "w+") do |f| - begin # rubocop:disable Style/RedundantBegin + begin f.flock File::LOCK_EX Timeout.timeout(timeout) { yield } ensure @@ -190,7 +182,7 @@ class GitlabKeys # rubocop:disable Metrics/ClassLength end def open_auth_file(mode) - File.open(auth_file, mode, 0o600) do |file| + open(auth_file, mode, 0o600) do |file| file.chmod(0o600) yield file end |