summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAsh McKenzie <amckenzie@gitlab.com>2019-04-02 17:11:15 +1100
committerAsh McKenzie <amckenzie@gitlab.com>2019-04-04 13:32:30 +1100
commit5cd13175c94912651202a61ab755cfead33a3ee9 (patch)
treeb69113a89dc6f80cafaca5dfaa0dc9c63873bb2f
parent02088137c28f7b822a7d979f985ca38f3e0583ef (diff)
downloadgitlab-shell-5cd13175c94912651202a61ab755cfead33a3ee9.tar.gz
Using ConsoleHelper::write_stderr
-rw-r--r--lib/gitlab_access_status.rb10
-rw-r--r--lib/gitlab_shell.rb2
-rw-r--r--spec/gitlab_shell_spec.rb17
3 files changed, 25 insertions, 4 deletions
diff --git a/lib/gitlab_access_status.rb b/lib/gitlab_access_status.rb
index dc577f4..22e11a2 100644
--- a/lib/gitlab_access_status.rb
+++ b/lib/gitlab_access_status.rb
@@ -3,12 +3,14 @@ require 'json'
class GitAccessStatus
HTTP_MULTIPLE_CHOICES = '300'.freeze
- attr_reader :message, :gl_repository, :gl_project_path, :gl_id, :gl_username, :gitaly, :git_protocol, :git_config_options, :payload
+ attr_reader :message, :gl_repository, :gl_project_path, :gl_id, :gl_username,
+ :gitaly, :git_protocol, :git_config_options, :payload,
+ :gl_console_messages
def initialize(status, status_code, message, gl_repository: nil,
gl_project_path: nil, gl_id: nil,
gl_username: nil, gitaly: nil, git_protocol: nil,
- git_config_options: nil, payload: nil)
+ git_config_options: nil, payload: nil, gl_console_messages: [])
@status = status
@status_code = status_code
@message = message
@@ -20,6 +22,7 @@ class GitAccessStatus
@gitaly = gitaly
@git_protocol = git_protocol
@payload = payload
+ @gl_console_messages = gl_console_messages
end
def self.create_from_json(json, status_code)
@@ -34,7 +37,8 @@ class GitAccessStatus
git_config_options: values["git_config_options"],
gitaly: values["gitaly"],
git_protocol: values["git_protocol"],
- payload: values["payload"])
+ payload: values["payload"],
+ gl_console_messages: values["gl_console_messages"])
end
def allowed?
diff --git a/lib/gitlab_shell.rb b/lib/gitlab_shell.rb
index c615805..303f4d5 100644
--- a/lib/gitlab_shell.rb
+++ b/lib/gitlab_shell.rb
@@ -66,6 +66,8 @@ class GitlabShell # rubocop:disable Metrics/ClassLength
@username = access_status.gl_username
@git_config_options = access_status.git_config_options
@gl_id = access_status.gl_id if defined?(@who)
+
+ write_stderr(access_status.gl_console_messages)
elsif !defined?(@gl_id)
# We're processing an API command like 2fa_recovery_codes, but
# don't have a @gl_id yet, that means we're in the "username"
diff --git a/spec/gitlab_shell_spec.rb b/spec/gitlab_shell_spec.rb
index c261e6f..6a059aa 100644
--- a/spec/gitlab_shell_spec.rb
+++ b/spec/gitlab_shell_spec.rb
@@ -33,7 +33,8 @@ describe GitlabShell do
gl_username: gl_username,
git_config_options: git_config_options,
gitaly: { 'repository' => { 'relative_path' => repo_name, 'storage_name' => 'default'} , 'address' => 'unix:gitaly.socket' },
- git_protocol: git_protocol
+ git_protocol: git_protocol,
+ gl_console_messages: gl_console_messages
)
end
@@ -69,6 +70,7 @@ describe GitlabShell do
let(:gl_username) { 'testuser' }
let(:git_config_options) { ['receive.MaxInputSize=10000'] }
let(:git_protocol) { 'version=2' }
+ let(:gl_console_messages) { nil }
before do
allow_any_instance_of(GitlabConfig).to receive(:audit_usernames).and_return(false)
@@ -438,6 +440,19 @@ describe GitlabShell do
end
end
end
+
+ context 'with a console message' do
+ let(:ssh_cmd) { "git-receive-pack gitlab-ci.git" }
+ let(:gl_console_messages) { 'Very important message' }
+
+ before do
+ allow(api).to receive(:check_access).and_return(gitaly_check_access)
+ end
+
+ it 'displays the message on $stderr' do
+ expect { subject.exec(ssh_cmd) }.to output("> GitLab: #{gl_console_messages}\n").to_stderr
+ end
+ end
end
describe '#validate_access' do