summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorKrasimir Angelov <kangelov@gitlab.com>2019-09-06 17:20:05 +1200
committerKrasimir Angelov <kangelov@gitlab.com>2019-09-10 13:56:07 +1200
commit676675dc0b95194be72dfa13829b5ba06e0d1844 (patch)
tree21a2227c9ea34b715016456ef37e2f0b4eed5df2 /app
parent8ce331c206dd97bbfc672a554afb8bc0f8039983 (diff)
downloadgitlab-ce-676675dc0b95194be72dfa13829b5ba06e0d1844.tar.gz
Add support for custom domains to the internal Pages API
Update the `/internal/pages` endpoint to return virtual domain configuration for custom domains.
Diffstat (limited to 'app')
-rw-r--r--app/models/pages/lookup_path.rb38
-rw-r--r--app/models/pages/virtual_domain.rb28
-rw-r--r--app/models/pages_domain.rb4
-rw-r--r--app/models/project.rb14
-rw-r--r--app/models/project_feature.rb4
5 files changed, 83 insertions, 5 deletions
diff --git a/app/models/pages/lookup_path.rb b/app/models/pages/lookup_path.rb
new file mode 100644
index 00000000000..1b3183a2a43
--- /dev/null
+++ b/app/models/pages/lookup_path.rb
@@ -0,0 +1,38 @@
+# frozen_string_literal: true
+
+module Pages
+ class LookupPath
+ def initialize(project, domain: nil)
+ @project = project
+ @domain = domain
+ end
+
+ def project_id
+ project.id
+ end
+
+ def access_control
+ project.private_pages?
+ end
+
+ def https_only
+ domain_https = domain ? domain.https? : true
+ project.pages_https_only? && domain_https
+ end
+
+ def source
+ {
+ type: 'file',
+ path: File.join(project.full_path, 'public/')
+ }
+ end
+
+ def prefix
+ '/'
+ end
+
+ private
+
+ attr_reader :project, :domain
+ end
+end
diff --git a/app/models/pages/virtual_domain.rb b/app/models/pages/virtual_domain.rb
new file mode 100644
index 00000000000..3a876dc06a2
--- /dev/null
+++ b/app/models/pages/virtual_domain.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+module Pages
+ class VirtualDomain
+ def initialize(projects, domain: nil)
+ @projects = projects
+ @domain = domain
+ end
+
+ def certificate
+ domain&.certificate
+ end
+
+ def key
+ domain&.key
+ end
+
+ def lookup_paths
+ projects.map do |project|
+ project.pages_lookup_path(domain: domain)
+ end.sort_by(&:prefix).reverse
+ end
+
+ private
+
+ attr_reader :projects, :domain
+ end
+end
diff --git a/app/models/pages_domain.rb b/app/models/pages_domain.rb
index a2a471074a9..22a6bae7cf7 100644
--- a/app/models/pages_domain.rb
+++ b/app/models/pages_domain.rb
@@ -185,6 +185,10 @@ class PagesDomain < ApplicationRecord
self.certificate_source = 'gitlab_provided' if key_changed?
end
+ def pages_virtual_domain
+ Pages::VirtualDomain.new([project], domain: self)
+ end
+
private
def set_verification_code
diff --git a/app/models/project.rb b/app/models/project.rb
index d948410e397..12f5da05efa 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -61,11 +61,11 @@ class Project < ApplicationRecord
cache_markdown_field :description, pipeline: :description
- delegate :feature_available?, :builds_enabled?, :wiki_enabled?,
- :merge_requests_enabled?, :issues_enabled?, :pages_enabled?, :public_pages?,
- :merge_requests_access_level, :issues_access_level, :wiki_access_level,
- :snippets_access_level, :builds_access_level, :repository_access_level,
- to: :project_feature, allow_nil: true
+ delegate :feature_available?, :builds_enabled?, :wiki_enabled?, :merge_requests_enabled?,
+ :issues_enabled?, :pages_enabled?, :public_pages?, :private_pages?,
+ :merge_requests_access_level, :issues_access_level, :wiki_access_level,
+ :snippets_access_level, :builds_access_level, :repository_access_level,
+ to: :project_feature, allow_nil: true
delegate :base_dir, :disk_path, :ensure_storage_path_exists, to: :storage
@@ -2201,6 +2201,10 @@ class Project < ApplicationRecord
members.maintainers.order_recent_sign_in.limit(ACCESS_REQUEST_APPROVERS_TO_BE_NOTIFIED_LIMIT)
end
+ def pages_lookup_path(domain: nil)
+ Pages::LookupPath.new(self, domain: domain)
+ end
+
private
def merge_requests_allowing_collaboration(source_branch = nil)
diff --git a/app/models/project_feature.rb b/app/models/project_feature.rb
index 78e82955342..efa3fbcf015 100644
--- a/app/models/project_feature.rb
+++ b/app/models/project_feature.rb
@@ -129,6 +129,10 @@ class ProjectFeature < ApplicationRecord
pages_access_level == PUBLIC || pages_access_level == ENABLED && project.public?
end
+ def private_pages?
+ !public_pages?
+ end
+
private
# Validates builds and merge requests access level