summaryrefslogtreecommitdiff
path: root/lib/gitlab_access.rb
diff options
context:
space:
mode:
authorAsh McKenzie <amckenzie@gitlab.com>2018-07-31 21:06:56 +1000
committerAsh McKenzie <amckenzie@gitlab.com>2018-08-01 10:12:09 +1000
commit4c4d9f5ef4a2e3ac16d0b02e18b19ba513849f57 (patch)
treeda1206876526db68f4484dd34ea9c00ae08ebb21 /lib/gitlab_access.rb
parent2f733baacdf5d0dca98276cc9b6e895097d5e8d2 (diff)
downloadgitlab-shell-4c4d9f5ef4a2e3ac16d0b02e18b19ba513849f57.tar.gz
Use actor when we don't know if it's a Key or User
* Use gl_id when we don't know if it's a key-X or user-X * Use Actor.new_from(gl_id) which will figure out if it's a Key or User * Use key_str when we're referring to key-X as key_id is confusing
Diffstat (limited to 'lib/gitlab_access.rb')
-rw-r--r--lib/gitlab_access.rb19
1 files changed, 14 insertions, 5 deletions
diff --git a/lib/gitlab_access.rb b/lib/gitlab_access.rb
index a1a8b93..6683ee7 100644
--- a/lib/gitlab_access.rb
+++ b/lib/gitlab_access.rb
@@ -1,6 +1,7 @@
require 'json'
require_relative 'errors'
+require_relative 'actor'
require_relative 'gitlab_init'
require_relative 'gitlab_net'
require_relative 'names_helper'
@@ -10,17 +11,17 @@ require_relative 'object_dirs_helper'
class GitlabAccess
include NamesHelper
- def initialize(gl_repository, repo_path, key_id, changes, protocol)
+ def initialize(gl_repository, repo_path, gl_id, changes, protocol)
@gl_repository = gl_repository
@repo_path = repo_path.strip
- @key_id = key_id
+ @gl_id = gl_id
@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, key_id, changes, protocol, env: ObjectDirsHelper.all_attributes.to_json)
+ api.check_access('git-receive-pack', gl_repository, repo_path, actor, changes, protocol, env: ObjectDirsHelper.all_attributes.to_json)
end
true
rescue GitlabNet::ApiUnreachableError
@@ -33,9 +34,17 @@ class GitlabAccess
private
- attr_reader :gl_repository, :repo_path, :key_id, :changes, :protocol
+ attr_reader :gl_repository, :repo_path, :gl_id, :changes, :protocol
def api
- GitlabNet.new
+ @api ||= GitlabNet.new
+ end
+
+ def config
+ @config ||= GitlabConfig.new
+ end
+
+ def actor
+ @actor ||= Actor.new_from(gl_id, audit_usernames: config.audit_usernames)
end
end