debian-mirror-gitlab/lib/api/support/git_access_actor.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

60 lines
1.2 KiB
Ruby
Raw Normal View History

2019-12-04 20:38:33 +05:30
# frozen_string_literal: true
module API
module Support
class GitAccessActor
2020-01-01 13:55:28 +05:30
extend ::Gitlab::Identifier
attr_reader :user, :key
2019-12-04 20:38:33 +05:30
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)
2020-01-01 13:55:28 +05:30
elsif params[:identifier]
new(user: identify(params[:identifier]))
else
new
2019-12-04 20:38:33 +05:30
end
end
def key_or_user
key || user
end
2022-08-27 11:52:29 +05:30
def deploy_key_or_user
key.instance_of?(DeployKey) ? key : user
end
2019-12-04 20:38:33 +05:30
def username
user&.username
end
def update_last_used_at!
2021-03-11 19:13:27 +05:30
return if Feature.enabled?(:disable_ssh_key_used_tracking)
2019-12-04 20:38:33 +05:30
key&.update_last_used_at
end
2020-10-24 23:57:45 +05:30
def key_details
return {} unless key
{
gl_key_type: key.model_name.singular,
gl_key_id: key.id
}
end
2019-12-04 20:38:33 +05:30
end
end
end