2019-09-06 00:06:25 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module API
|
|
|
|
# Pages Internal API
|
|
|
|
module Internal
|
2020-10-14 20:08:42 -04:00
|
|
|
class Pages < ::API::Base
|
2020-11-02 10:08:52 -05:00
|
|
|
feature_category :pages
|
|
|
|
|
2019-09-06 00:06:25 -04:00
|
|
|
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
|
2020-04-08 05:09:43 -04:00
|
|
|
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
|
|
|
|
|
2019-09-25 05:06:04 -04:00
|
|
|
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
|
2019-09-06 00:06:25 -04:00
|
|
|
get "/" do
|
2020-02-24 07:09:00 -05:00
|
|
|
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
|
2019-09-06 01:20:05 -04:00
|
|
|
|
2020-02-24 07:09:00 -05:00
|
|
|
virtual_domain = Serverless::VirtualDomain.new(serverless_domain)
|
|
|
|
no_content! unless virtual_domain
|
2019-09-06 01:20:05 -04:00
|
|
|
|
2020-02-24 07:09:00 -05:00
|
|
|
present virtual_domain, with: Entities::Internal::Serverless::VirtualDomain
|
|
|
|
else
|
|
|
|
# Handle Pages domains
|
2020-02-25 16:09:23 -05:00
|
|
|
host = Namespace.find_by_pages_host(params[:host]) || PagesDomain.find_by_domain_case_insensitive(params[:host])
|
2020-02-24 07:09:00 -05:00
|
|
|
no_content! unless host
|
|
|
|
|
|
|
|
virtual_domain = host.pages_virtual_domain
|
|
|
|
no_content! unless virtual_domain
|
|
|
|
|
|
|
|
present virtual_domain, with: Entities::Internal::Pages::VirtualDomain
|
|
|
|
end
|
2019-09-06 00:06:25 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|