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
37
# 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,
    namespace_path: namespace_path,
    repository_path: project_path,
    redirected_path: redirected_path)
end

#access_checker_klassObject


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

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


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

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

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

#namespace_pathObject


78
79
80
# File 'lib/api/helpers/internal_helpers.rb', line 78

def namespace_path
  project&.namespace&.full_path || project_path_match[:namespace_path]
end

#parse_envObject


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

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

#project_pathObject


74
75
76
# File 'lib/api/helpers/internal_helpers.rb', line 74

def project_path
  project&.path || project_path_match[:project_path]
end

#redis_pingObject


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

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

  result == 'PONG'
rescue => 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


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

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