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_deploy_key, 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_identifier(identifier) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/api/support/git_access_actor.rb', line 31

def self.from_identifier(identifier)
  user = identify(identifier)
  if user
    new(user: user)
  else
    new(key: identify_using_deploy_key(identifier))
  end
end

.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]
    from_identifier(params[:identifier])
  else
    new
  end
end

Instance Method Details

#deploy_key_or_userObject



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

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

#key_detailsObject



56
57
58
59
60
61
62
63
# File 'lib/api/support/git_access_actor.rb', line 56

def key_details
  return {} unless key

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

#key_or_userObject



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

def key_or_user
  key || user
end

#update_last_used_at!Object



52
53
54
# File 'lib/api/support/git_access_actor.rb', line 52

def update_last_used_at!
  key&.update_last_used_at
end

#usernameObject



48
49
50
# File 'lib/api/support/git_access_actor.rb', line 48

def username
  user&.username
end