summaryrefslogtreecommitdiff
path: root/lib/api
diff options
context:
space:
mode:
authorKamil Trzciński <ayufan@ayufan.eu>2019-03-04 14:32:45 +0100
committerKamil Trzciński <ayufan@ayufan.eu>2019-04-24 13:50:47 +0200
commit2a00858533f1dcae71e97ba52386bfb2bfc1f752 (patch)
tree9c5a2eeaef991d154baec8e7c30ee8fcde92d926 /lib/api
parent4f2005df1dc7ca91673ae4ed5ef35130c714ddd9 (diff)
downloadgitlab-ce-2a00858533f1dcae71e97ba52386bfb2bfc1f752.tar.gz
Add the most boring pages API implementation
Diffstat (limited to 'lib/api')
-rw-r--r--lib/api/api.rb1
-rw-r--r--lib/api/internals/pages.rb82
-rw-r--r--lib/api/pages.rb0
3 files changed, 83 insertions, 0 deletions
diff --git a/lib/api/api.rb b/lib/api/api.rb
index bf8ddba6f0d..1719010ab48 100644
--- a/lib/api/api.rb
+++ b/lib/api/api.rb
@@ -115,6 +115,7 @@ module API
mount ::API::GroupVariables
mount ::API::ImportGithub
mount ::API::Internal
+ mount ::API::Internals::Pages
mount ::API::Issues
mount ::API::JobArtifacts
mount ::API::Jobs
diff --git a/lib/api/internals/pages.rb b/lib/api/internals/pages.rb
new file mode 100644
index 00000000000..a8631827b3d
--- /dev/null
+++ b/lib/api/internals/pages.rb
@@ -0,0 +1,82 @@
+# frozen_string_literal: true
+
+module API
+ module Internals
+ class Pages < Grape::API
+ namespace 'internals' do
+ params do
+ requires :host, type: String, desc: 'The Pages host'
+ end
+ get 'pages/query' do
+ if namespace_name = find_namespace_name(params[:host])
+ namespace_domain(namespace_name, params[:host].downcase)
+ elsif domain = find_user_domain(params[:host])
+ user_domain(domain)
+ else
+ status :not_found
+ end
+ end
+ end
+
+ helpers do
+ def namespace_domain(namespace_name, host)
+ lookup_paths = []
+
+ if namespace = Namespace.find_by_full_path(namespace_name)
+ namespace.all_projects.with_pages.each do |project|
+ prefix = project.full_path.delete_prefix(namespace.full_path)
+ lookup_paths << project_params(project, prefix)
+ end
+
+ lookup_paths << namespace_project_params(namespace, host, "")
+ end
+
+ status :ok
+
+ { lookup_paths: lookup_paths.compact }
+ end
+
+ def user_domain(domain)
+ lookup_paths = []
+ lookup_paths << project_params(domain.project, "")
+
+ status :ok
+
+ {
+ certificate: domain.certificate,
+ key: domain.certificate_key,
+ lookup_paths: lookup_paths.compact
+ }
+ end
+
+ def find_namespace_name(host)
+ host = host.downcase
+ gitlab_host = "." + ::Settings.pages.host.downcase
+ host.delete_suffix(gitlab_host) if host.ends_with?(gitlab_host)
+ end
+
+ def find_user_domain(host)
+ PagesDomain.find_by(domain: host.downcase)
+ end
+
+ def namespace_project_params(namespace, project_name, prefix)
+ project = namespace.projects.with_pages.find_by(path: project_name)
+ project_params(project, prefix)
+ end
+
+ def project_params(project, prefix)
+ return unless project
+ return unless project.pages_deployed?
+
+ {
+ https_only: project.pages_https_only?,
+ project_id: project.project_id,
+ access_control: !project.public_pages?,
+ prefix: "#{prefix}/",
+ path: "#{project.public_pages_path}/"
+ }
+ end
+ end
+ end
+ end
+end
diff --git a/lib/api/pages.rb b/lib/api/pages.rb
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/lib/api/pages.rb