diff options
author | Ash McKenzie <amckenzie@gitlab.com> | 2018-07-25 13:19:59 +1000 |
---|---|---|
committer | Ash McKenzie <amckenzie@gitlab.com> | 2018-07-25 22:01:14 +1000 |
commit | b03540ffe75d914db1e0d7de05e577db7d5e0c2c (patch) | |
tree | 68ce0ca024c301ce4d14a870cef249e5330bed4b /lib/gitlab_shell.rb | |
parent | 2c9237a2fc82e0a06125b91b878df078e6e9066c (diff) | |
download | gitlab-shell-b03540ffe75d914db1e0d7de05e577db7d5e0c2c.tar.gz |
Move User related logic into CurrentUserHelper
Diffstat (limited to 'lib/gitlab_shell.rb')
-rw-r--r-- | lib/gitlab_shell.rb | 25 |
1 files changed, 4 insertions, 21 deletions
diff --git a/lib/gitlab_shell.rb b/lib/gitlab_shell.rb index c1f3292..180e5eb 100644 --- a/lib/gitlab_shell.rb +++ b/lib/gitlab_shell.rb @@ -3,9 +3,11 @@ require 'pathname' require_relative 'gitlab_net' require_relative 'gitlab_metrics' +require_relative 'current_user_helper' require_relative 'api_command_helper' class GitlabShell # rubocop:disable Metrics/ClassLength + include CurrentUserHelper include APICommandHelper class AccessDeniedError < StandardError; end @@ -137,7 +139,7 @@ class GitlabShell # rubocop:disable Metrics/ClassLength 'repository' => @gitaly['repository'], 'gl_repository' => @gl_repository, 'gl_id' => key_id, - 'gl_username' => @username + 'gl_username' => username } args = [gitaly_address, JSON.dump(gitaly_request)] @@ -165,7 +167,7 @@ class GitlabShell # rubocop:disable Metrics/ClassLength 'GL_ID' => key_id, 'GL_PROTOCOL' => GL_PROTOCOL, 'GL_REPOSITORY' => @gl_repository, - 'GL_USERNAME' => @username + 'GL_USERNAME' => username } if @gitaly && @gitaly.include?('token') env['GITALY_TOKEN'] = @gitaly['token'] @@ -187,25 +189,6 @@ class GitlabShell # rubocop:disable Metrics/ClassLength GitlabNet.new end - def user - return @user if defined?(@user) - - begin - @user = api.discover(key_id) - rescue GitlabNet::ApiUnreachableError - @user = nil - end - end - - def username_from_discover - return nil unless user && user['username'] - - "@#{user['username']}" - end - - def username - @username ||= username_from_discover || 'Anonymous' - end # User identifier to be used in log messages. def log_username |