Module: API::Helpers::InternalHelpers

Defined in:
lib/api/helpers/internal_helpers.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#redirected_pathObject (readonly)

Returns the value of attribute redirected_path.


6
7
8
# File 'lib/api/helpers/internal_helpers.rb', line 6

def redirected_path
  @redirected_path
end

Instance Method Details

#access_checker_for(actor, protocol) ⇒ Object

rubocop:enable Gitlab/ModuleWithInstanceVariables


31
32
33
34
35
36
# File 'lib/api/helpers/internal_helpers.rb', line 31

def access_checker_for(actor, protocol)
  access_checker_klass.new(actor.key_or_user, container, protocol,
    authentication_abilities: ssh_authentication_abilities,
    repository_path: repository_path,
    redirected_path: redirected_path)
end

#access_checker_klassObject


38
39
40
# File 'lib/api/helpers/internal_helpers.rb', line 38

def access_checker_klass
  repo_type.access_checker_class
end

#actorObject


10
11
12
# File 'lib/api/helpers/internal_helpers.rb', line 10

def actor
  @actor ||= Support::GitAccessActor.from_params(params)
end

#containerObject


25
26
27
28
# File 'lib/api/helpers/internal_helpers.rb', line 25

def container
  parse_repo_path unless defined?(@container)
  @container
end

#log_user_activity(actor) ⇒ Object


58
59
60
61
62
# File 'lib/api/helpers/internal_helpers.rb', line 58

def log_user_activity(actor)
  commands = Gitlab::GitAccess::DOWNLOAD_COMMANDS

  ::Users::ActivityService.new(actor).execute if commands.include?(params[:action])
end

#parse_envObject


50
51
52
53
54
55
56
# File 'lib/api/helpers/internal_helpers.rb', line 50

def parse_env
  return {} if params[:env].blank?

  Gitlab::Json.parse(params[:env])
rescue JSON::ParserError
  {}
end

#projectObject


20
21
22
23
# File 'lib/api/helpers/internal_helpers.rb', line 20

def project
  parse_repo_path unless defined?(@project)
  @project
end

#redis_pingObject


64
65
66
67
68
69
70
71
# File 'lib/api/helpers/internal_helpers.rb', line 64

def redis_ping
  result = Gitlab::Redis::SharedState.with { |redis| redis.ping }

  result == 'PONG'
rescue StandardError => e
  Gitlab::AppLogger.warn("GitLab: An unexpected error occurred in pinging to Redis: #{e}")
  false
end

#repo_typeObject

rubocop:disable Gitlab/ModuleWithInstanceVariables


15
16
17
18
# File 'lib/api/helpers/internal_helpers.rb', line 15

def repo_type
  parse_repo_path unless defined?(@repo_type)
  @repo_type
end

#ssh_authentication_abilitiesObject


42
43
44
45
46
47
48
# File 'lib/api/helpers/internal_helpers.rb', line 42

def ssh_authentication_abilities
  [
    :read_project,
    :download_code,
    :push_code
  ]
end