diff options
author | Ash McKenzie <amckenzie@gitlab.com> | 2018-12-06 20:16:05 +1100 |
---|---|---|
committer | Ash McKenzie <amckenzie@gitlab.com> | 2018-12-13 14:22:08 +1100 |
commit | 67be30cf4fdc66d90696f5cba610af863c3ee16d (patch) | |
tree | cd60f3e749452a7b82fa5265b33a5c7427222134 | |
parent | e21d41c7146ede24273d5ecd148c1e7426a972e8 (diff) | |
download | gitlab-shell-67be30cf4fdc66d90696f5cba610af863c3ee16d.tar.gz |
Use open3 so we have more control over output
-rw-r--r-- | lib/gitlab_keys.rb | 19 | ||||
-rw-r--r-- | spec/gitlab_shell_gitlab_shell_spec.rb | 8 |
2 files changed, 17 insertions, 10 deletions
diff --git a/lib/gitlab_keys.rb b/lib/gitlab_keys.rb index aeebf62..96b4803 100644 --- a/lib/gitlab_keys.rb +++ b/lib/gitlab_keys.rb @@ -1,4 +1,5 @@ require 'timeout' +require 'open3' require_relative 'gitlab_config' require_relative 'gitlab_logger' @@ -159,13 +160,17 @@ class GitlabKeys # rubocop:disable Metrics/ClassLength def check_permissions open_auth_file(File::RDWR | File::CREAT) { true } rescue StandardError => ex - puts "error: could not open #{auth_file}: #{ex}" - 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 + warn "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(' ')) + warn output false end diff --git a/spec/gitlab_shell_gitlab_shell_spec.rb b/spec/gitlab_shell_gitlab_shell_spec.rb index 9afeac8..e5342b7 100644 --- a/spec/gitlab_shell_gitlab_shell_spec.rb +++ b/spec/gitlab_shell_gitlab_shell_spec.rb @@ -1,4 +1,5 @@ require_relative 'spec_helper' +require 'open3' describe 'bin/gitlab-shell' do def original_root_path @@ -131,12 +132,13 @@ describe 'bin/gitlab-shell' do def run!(args) cmd = [ + 'SSH_CONNECTION=fake', gitlab_shell_path, args - ].flatten.compact + ].flatten.join(' ') - output = IO.popen({'SSH_CONNECTION' => 'fake'}, cmd, &:read) + stdout, _stderr, status = Open3.capture3(cmd) - [output, $?] + [stdout, status] end end |