summaryrefslogtreecommitdiff
path: root/config/routes/git_http.rb
blob: 593f818e43450072246e44f069cd28a1e2021f28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
concern :gitactionable do
  scope(controller: :git_http) do
    get '/info/refs', action: :info_refs
    post '/git-upload-pack', action: :git_upload_pack
    post '/git-receive-pack', action: :git_receive_pack
  end
end

concern :lfsable do
  # Git LFS API (metadata)
  scope(path: 'info/lfs/objects', controller: :lfs_api) do
    post :batch
    post '/', action: :deprecated
    get '/*oid', action: :deprecated
  end

  scope(path: 'info/lfs') do
    resources :lfs_locks, controller: :lfs_locks_api, path: 'locks' do
      post :unlock, on: :member
      post :verify, on: :collection
    end
  end

  # GitLab LFS object storage
  scope(path: 'gitlab-lfs/objects/*oid', controller: :lfs_storage, constraints: { oid: /[a-f0-9]{64}/ }) do
    get '/', action: :download

    scope constraints: { size: /[0-9]+/ } do
      put '/*size/authorize', action: :upload_authorize
      put '/*size', action: :upload_finalize
    end
  end
end

scope(path: '*namespace_id/:repository_id',
      format: nil,
      constraints: { namespace_id: Gitlab::PathRegex.full_namespace_route_regex }) do
  scope(constraints: { repository_id: Gitlab::PathRegex.project_git_route_regex }) do
    scope(module: :repositories) do
      concerns :gitactionable
      concerns :lfsable
    end
  end

  # Redirect /group/project.wiki.git to the project wiki
  scope(format: true, constraints: { repository_id: Gitlab::PathRegex.project_wiki_git_route_regex, format: :git }) do
    wiki_redirect = redirect do |params, request|
      project_id = params[:repository_id].delete_suffix('.wiki')
      path = [params[:namespace_id], project_id, 'wikis'].join('/')
      path << "?#{request.query_string}" unless request.query_string.blank?
      path
    end

    get '/', to: wiki_redirect
  end

  # Redirect /group/project/info/refs to /group/project.git/info/refs
  scope(constraints: { repository_id: Gitlab::PathRegex.project_route_regex }) do
    # Allow /info/refs, /info/refs?service=git-upload-pack, and
    # /info/refs?service=git-receive-pack, but nothing else.
    #
    git_http_handshake = lambda do |request|
      ::Constraints::ProjectUrlConstrainer.new.matches?(request, existence_check: false) &&
        (request.query_string.blank? ||
         request.query_string.match(/\Aservice=git-(upload|receive)-pack\z/))
    end

    ref_redirect = redirect do |params, request|
      path = "#{params[:namespace_id]}/#{params[:repository_id]}.git/info/refs"
      path << "?#{request.query_string}" unless request.query_string.blank?
      path
    end

    get '/info/refs', constraints: git_http_handshake, to: ref_redirect
  end
end