Welcome to mirror list, hosted at ThFree Co, Russian Federation.

pages.rb « internal « api « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6be2679af1464174d42b9bbc40440f27ada9bf52 (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
# frozen_string_literal: true

module API
  # Pages Internal API
  module Internal
    class Pages < ::API::Base
      feature_category :pages

      before do
        authenticate_gitlab_pages_request!
      end

      helpers do
        def authenticate_gitlab_pages_request!
          unauthorized! unless Gitlab::Pages.verify_api_request(headers)
        end
      end

      namespace 'internal' do
        namespace 'pages' do
          desc 'Indicates that pages API is enabled and auth token is valid' do
            detail 'This feature was introduced in GitLab 12.10.'
          end
          get "status" do
            no_content!
          end

          desc 'Get GitLab Pages domain configuration by hostname' do
            detail 'This feature was introduced in GitLab 12.3.'
          end
          params do
            requires :host, type: String, desc: 'The host to query for'
          end
          get "/" do
            ##
            # Serverless domain proxy has been deprecated and disabled as per
            #   https://gitlab.com/gitlab-org/gitlab-pages/-/issues/467
            #
            # serverless_domain_finder = ServerlessDomainFinder.new(params[:host])
            # if serverless_domain_finder.serverless?
            #   # Handle Serverless domains
            #   serverless_domain = serverless_domain_finder.execute
            #   no_content! unless serverless_domain
            #
            #   virtual_domain = Serverless::VirtualDomain.new(serverless_domain)
            #   no_content! unless virtual_domain
            #
            #   present virtual_domain, with: Entities::Internal::Serverless::VirtualDomain
            # end

            host = Namespace.find_by_pages_host(params[:host]) || PagesDomain.find_by_domain_case_insensitive(params[:host])
            no_content! unless host

            virtual_domain = host.pages_virtual_domain
            no_content! unless virtual_domain

            if virtual_domain.cache_key.present?
              # Cache context is not added to make it easier to expire the cache with
              # Gitlab::Pages::CacheControl
              present_cached virtual_domain,
                cache_context: nil,
                with: Entities::Internal::Pages::VirtualDomain,
                expires_in: ::Gitlab::Pages::CacheControl::EXPIRE
            else
              present virtual_domain, with: Entities::Internal::Pages::VirtualDomain
            end
          end
        end
      end
    end
  end
end