Commit aa10b70f authored by Bob Van Landuyt's avatar Bob Van Landuyt

Display the username instead of fullname

When running `ssh git@gitlab.example.com` we used to reply with the
full name. But it might actually be more useful to display the
username. This is unique and can help support identifying issues.

Closes #131
parent aa1a39a9
...@@ -18,7 +18,7 @@ class GitlabShell # rubocop:disable Metrics/ClassLength ...@@ -18,7 +18,7 @@ class GitlabShell # rubocop:disable Metrics/ClassLength
API_COMMANDS = %w(2fa_recovery_codes).freeze API_COMMANDS = %w(2fa_recovery_codes).freeze
GL_PROTOCOL = 'ssh'.freeze GL_PROTOCOL = 'ssh'.freeze
attr_accessor :key_id, :gl_repository, :repo_name, :command, :git_access, :username attr_accessor :key_id, :gl_repository, :repo_name, :command, :git_access
attr_reader :repo_path attr_reader :repo_path
def initialize(key_id) def initialize(key_id)
...@@ -197,7 +197,7 @@ class GitlabShell # rubocop:disable Metrics/ClassLength ...@@ -197,7 +197,7 @@ class GitlabShell # rubocop:disable Metrics/ClassLength
end end
def username def username
user && user['name'] || 'Anonymous' @username ||= user && user['username'] || 'Anonymous'
end end
# User identifier to be used in log messages. # User identifier to be used in log messages.
......
...@@ -167,7 +167,7 @@ describe GitlabShell do ...@@ -167,7 +167,7 @@ describe GitlabShell do
it "should use usernames if configured to do so" do it "should use usernames if configured to do so" do
GitlabConfig.any_instance.stub(audit_usernames: true) GitlabConfig.any_instance.stub(audit_usernames: true)
$logger.should_receive(:info).with("executing git command", hash_including(user: 'John Doe')) $logger.should_receive(:info).with("executing git command", hash_including(user: 'testuser'))
end end
end end
...@@ -202,7 +202,7 @@ describe GitlabShell do ...@@ -202,7 +202,7 @@ describe GitlabShell do
it "should use usernames if configured to do so" do it "should use usernames if configured to do so" do
GitlabConfig.any_instance.stub(audit_usernames: true) GitlabConfig.any_instance.stub(audit_usernames: true)
$logger.should_receive(:info).with("executing git command", hash_including(user: 'John Doe')) $logger.should_receive(:info).with("executing git command", hash_including(user: 'testuser'))
end end
end end
...@@ -248,7 +248,7 @@ describe GitlabShell do ...@@ -248,7 +248,7 @@ describe GitlabShell do
it "should use usernames if configured to do so" do it "should use usernames if configured to do so" do
GitlabConfig.any_instance.stub(audit_usernames: true) GitlabConfig.any_instance.stub(audit_usernames: true)
$logger.should_receive(:info).with("executing git command", hash_including(user: 'John Doe')) $logger.should_receive(:info).with("executing git command", hash_including(user: 'testuser'))
end end
end end
...@@ -275,7 +275,7 @@ describe GitlabShell do ...@@ -275,7 +275,7 @@ describe GitlabShell do
it "should use usernames if configured to do so" do it "should use usernames if configured to do so" do
GitlabConfig.any_instance.stub(audit_usernames: true) GitlabConfig.any_instance.stub(audit_usernames: true)
$logger.should_receive(:info).with("executing git command", hash_including(user: 'John Doe')) $logger.should_receive(:info).with("executing git command", hash_including(user: 'testuser'))
end end
end end
...@@ -452,7 +452,7 @@ describe GitlabShell do ...@@ -452,7 +452,7 @@ describe GitlabShell do
before do before do
Kernel.stub(:exec) Kernel.stub(:exec)
shell.gl_repository = gl_repository shell.gl_repository = gl_repository
shell.username = gl_username shell.instance_variable_set(:@username, gl_username)
end end
it "uses Kernel::exec method" do it "uses Kernel::exec method" do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment