Class: API::Support::GitAccessActor

Inherits:
Object
  • Object
show all
Extended by:
Gitlab::Identifier
Defined in:
lib/api/support/git_access_actor.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Gitlab::Identifier

identification_cache, identify, identify_using_ssh_key, identify_using_user, identify_with_cache

Constructor Details

#initialize(user: nil, key: nil) ⇒ GitAccessActor

Returns a new instance of GitAccessActor.



10
11
12
13
14
15
# File 'lib/api/support/git_access_actor.rb', line 10

def initialize(user: nil, key: nil)
  @user = user
  @key = key

  @user = key.user if !user && key
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



8
9
10
# File 'lib/api/support/git_access_actor.rb', line 8

def key
  @key
end

#userObject (readonly)

Returns the value of attribute user.



8
9
10
# File 'lib/api/support/git_access_actor.rb', line 8

def user
  @user
end

Class Method Details

.from_params(params) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/api/support/git_access_actor.rb', line 17

def self.from_params(params)
  if params[:key_id]
    new(key: Key.auth.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)
  elsif params[:identifier]
    new(user: identify(params[:identifier]))
  else
    new
  end
end

Instance Method Details

#deploy_key_or_userObject



35
36
37
# File 'lib/api/support/git_access_actor.rb', line 35

def deploy_key_or_user
  key.instance_of?(DeployKey) ? key : user
end

#key_detailsObject



49
50
51
52
53
54
55
56
# File 'lib/api/support/git_access_actor.rb', line 49

def key_details
  return {} unless key

  {
    gl_key_type: key.model_name.singular,
    gl_key_id: key.id
  }
end

#key_or_userObject



31
32
33
# File 'lib/api/support/git_access_actor.rb', line 31

def key_or_user
  key || user
end

#update_last_used_at!Object



43
44
45
46
47
# File 'lib/api/support/git_access_actor.rb', line 43

def update_last_used_at!
  return if Feature.enabled?(:disable_ssh_key_used_tracking)

  key&.update_last_used_at
end

#usernameObject



39
40
41
# File 'lib/api/support/git_access_actor.rb', line 39

def username
  user&.username
end