2019-08-07 03:51:12 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module API
|
|
|
|
module Support
|
|
|
|
class GitAccessActor
|
2019-12-03 19:06:15 -05:00
|
|
|
extend ::Gitlab::Identifier
|
|
|
|
|
|
|
|
attr_reader :user, :key
|
2019-08-07 03:51:12 -04:00
|
|
|
|
|
|
|
def initialize(user: nil, key: nil)
|
|
|
|
@user = user
|
|
|
|
@key = key
|
|
|
|
|
|
|
|
@user = key.user if !user && key
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.from_params(params)
|
|
|
|
if params[:key_id]
|
|
|
|
new(key: Key.find_by_id(params[:key_id]))
|
|
|
|
elsif params[:user_id]
|
|
|
|
new(user: UserFinder.new(params[:user_id]).find_by_id)
|
|
|
|
elsif params[:username]
|
|
|
|
new(user: UserFinder.new(params[:username]).find_by_username)
|
2019-12-03 19:06:15 -05:00
|
|
|
elsif params[:identifier]
|
|
|
|
new(user: identify(params[:identifier]))
|
|
|
|
else
|
|
|
|
new
|
2019-08-07 03:51:12 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def key_or_user
|
|
|
|
key || user
|
|
|
|
end
|
|
|
|
|
|
|
|
def username
|
|
|
|
user&.username
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_last_used_at!
|
|
|
|
key&.update_last_used_at
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|