Commit 6e99226c authored by Kamil Trzcinski's avatar Kamil Trzcinski Committed by James Edwards-Jones

Added PagesDomain

parent f034f6b3
class PagesDomain < ActiveRecord::Base
belongs_to :project
validates :domain, hostname: true
validates_uniqueness_of :domain, allow_nil: true, allow_blank: true
validates :certificate, certificate: true, allow_nil: true, allow_blank: true
validates :key, certificate_key: true, allow_nil: true, allow_blank: true
attr_encrypted :pages_custom_certificate_key, mode: :per_attribute_iv_and_salt, key: Gitlab::Application.secrets.db_key_base
after_create :update
after_save :update
after_destroy :update
def url
return unless domain
return unless Dir.exist?(project.public_pages_path)
if certificate
return "https://#{domain}"
else
return "http://#{domain}"
end
end
def update
UpdatePagesConfigurationService.new(project).execute
end
end
......@@ -150,6 +150,7 @@ class Project < ActiveRecord::Base
has_many :lfs_objects, through: :lfs_objects_projects
has_many :project_group_links, dependent: :destroy
has_many :invited_groups, through: :project_group_links, source: :group
has_many :pages_domains, dependent: :destroy
has_many :todos, dependent: :destroy
has_many :notification_settings, dependent: :destroy, as: :source
......@@ -205,18 +206,11 @@ class Project < ActiveRecord::Base
presence: true,
inclusion: { in: ->(_object) { Gitlab.config.repositories.storages.keys } }
validates :pages_custom_domain, hostname: true, allow_blank: true, allow_nil: true
validates_uniqueness_of :pages_custom_domain, allow_nil: true, allow_blank: true
validates :pages_custom_certificate, certificate: true, allow_nil: true, allow_blank: true
validates :pages_custom_certificate_key, certificate_key: true, allow_nil: true, allow_blank: true
add_authentication_token_field :runners_token
before_save :ensure_runners_token
mount_uploader :avatar, AvatarUploader
attr_encrypted :pages_custom_certificate_key, mode: :per_attribute_iv_and_salt, key: Gitlab::Application.secrets.db_key_base
# Scopes
default_scope { where(pending_delete: false) }
......@@ -1184,17 +1178,6 @@ class Project < ActiveRecord::Base
"#{url}/#{path}"
end
def pages_custom_url
return unless pages_custom_domain
return unless Dir.exist?(public_pages_path)
if Gitlab.config.pages.https
return "https://#{pages_custom_domain}"
else
return "http://#{pages_custom_domain}"
end
end
def pages_path
File.join(Settings.pages.path, path_with_namespace)
end
......@@ -1203,32 +1186,15 @@ class Project < ActiveRecord::Base
File.join(pages_path, 'public')
end
def remove_pages_certificate
update(
pages_custom_certificate: nil,
pages_custom_certificate_key: nil
)
UpdatePagesConfigurationService.new(self).execute
end
def remove_pages
# 1. We rename pages to temporary directory
# 2. We wait 5 minutes, due to NFS caching
# 3. We asynchronously remove pages with force
temp_path = "#{path}.#{SecureRandom.hex}"
temp_path = "#{path}.#{SecureRandom.hex}.deleted"
if Gitlab::PagesTransfer.new.rename_project(path, temp_path, namespace.path)
PagesWorker.perform_in(5.minutes, :remove, namespace.path, temp_path)
end
update(
pages_custom_certificate: nil,
pages_custom_certificate_key: nil,
pages_custom_domain: nil
)
UpdatePagesConfigurationService.new(self).execute
end
def wiki
......
class AddPagesCustomDomainToProjects < ActiveRecord::Migration
def change
add_column :projects, :pages_custom_certificate, :text
add_column :projects, :encrypted_pages_custom_certificate_key, :text
add_column :projects, :encrypted_pages_custom_certificate_key_iv, :string
add_column :projects, :encrypted_pages_custom_certificate_key_salt, :string
add_column :projects, :pages_custom_domain, :string, unique: true
add_column :projects, :pages_redirect_http, :boolean, default: false, null: false
end
end
class CreatePagesDomain < ActiveRecord::Migration
def change
create_table :pages_domains do |t|
t.integer :project_id
t.text :certificate
t.text :encrypted_key
t.string :encrypted_key_iv
t.string :encrypted_key_salt
t.string :domain
end
add_index :pages_domains, :domain, unique: true
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment