diff options
author | Robert Speicher <robert@gitlab.com> | 2018-08-14 18:49:15 +0000 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2018-08-14 18:49:15 +0000 |
commit | 02457041814fe4497b3df00e0e45edbee107c823 (patch) | |
tree | 6b07ce701bf00608cb21a3c1322a15c71a48d137 /lib/gitlab_access.rb | |
parent | 2dcf8b77a61c4c7cfebe8ae13f8112a0471056b0 (diff) | |
parent | c36e35c4510cf78ba3e642346bf7aa7cbc0efab3 (diff) | |
download | gitlab-shell-02457041814fe4497b3df00e0e45edbee107c823.tar.gz |
Merge branch 'revert-refactor' into 'master'
Revert refactor
Closes #147
See merge request gitlab-org/gitlab-shell!228
Diffstat (limited to 'lib/gitlab_access.rb')
-rw-r--r-- | lib/gitlab_access.rb | 36 |
1 files changed, 16 insertions, 20 deletions
diff --git a/lib/gitlab_access.rb b/lib/gitlab_access.rb index 6683ee7..e1a5e35 100644 --- a/lib/gitlab_access.rb +++ b/lib/gitlab_access.rb @@ -1,28 +1,34 @@ -require 'json' - -require_relative 'errors' -require_relative 'actor' require_relative 'gitlab_init' require_relative 'gitlab_net' +require_relative 'gitlab_access_status' require_relative 'names_helper' require_relative 'gitlab_metrics' require_relative 'object_dirs_helper' +require 'json' class GitlabAccess + class AccessDeniedError < StandardError; end + include NamesHelper - def initialize(gl_repository, repo_path, gl_id, changes, protocol) + attr_reader :config, :gl_repository, :repo_path, :changes, :protocol + + def initialize(gl_repository, repo_path, actor, changes, protocol) + @config = GitlabConfig.new @gl_repository = gl_repository @repo_path = repo_path.strip - @gl_id = gl_id + @actor = actor @changes = changes.lines @protocol = protocol end def exec - GitlabMetrics.measure('check-access:git-receive-pack') do - api.check_access('git-receive-pack', gl_repository, repo_path, actor, changes, protocol, env: ObjectDirsHelper.all_attributes.to_json) + status = GitlabMetrics.measure('check-access:git-receive-pack') do + api.check_access('git-receive-pack', @gl_repository, @repo_path, @actor, @changes, @protocol, env: ObjectDirsHelper.all_attributes.to_json) end + + raise AccessDeniedError, status.message unless status.allowed? + true rescue GitlabNet::ApiUnreachableError $stderr.puts "GitLab: Failed to authorize your Git request: internal API unreachable" @@ -32,19 +38,9 @@ class GitlabAccess false end - private - - attr_reader :gl_repository, :repo_path, :gl_id, :changes, :protocol + protected def api - @api ||= GitlabNet.new - end - - def config - @config ||= GitlabConfig.new - end - - def actor - @actor ||= Actor.new_from(gl_id, audit_usernames: config.audit_usernames) + GitlabNet.new end end |